summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2021-11-17 00:05:54 (GMT)
committerRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2022-08-23 15:06:16 (GMT)
commit91a7bd6c38536be2062806dfbfb9df824b94b79a (patch)
tree24f4c6e2b9bdf3bdcc0eeb7add21abeb432fe813
parent3ad5fe9d84138da1451429bfac3b9b4024393d25 (diff)
downloadmonitoring-plugins-91a7bd6.tar.gz
Sync with the latest Gnulib code (1a268176f)
-rwxr-xr-xbuild-aux/config.rpath22
-rw-r--r--build-aux/snippet/_Noreturn.h10
-rw-r--r--build-aux/snippet/arg-nonnull.h26
-rw-r--r--build-aux/snippet/c++defs.h271
-rw-r--r--build-aux/snippet/warn-on-use.h109
-rw-r--r--gl/Makefile.am1808
-rw-r--r--gl/_Noreturn.h45
-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/arpa_inet.in.h32
-rw-r--r--gl/asnprintf.c18
-rw-r--r--gl/asprintf.c18
-rw-r--r--gl/attribute.h226
-rw-r--r--gl/base64.c126
-rw-r--r--gl/base64.h38
-rw-r--r--gl/basename-lgpl.c38
-rw-r--r--gl/basename-lgpl.h78
-rw-r--r--gl/basename.c54
-rw-r--r--gl/btowc.c18
-rw-r--r--gl/byteswap.in.h44
-rw-r--r--gl/calloc.c55
-rw-r--r--gl/cdefs.h704
-rw-r--r--gl/cloexec.c83
-rw-r--r--gl/cloexec.h36
-rw-r--r--gl/close.c75
-rw-r--r--gl/config.charset684
-rw-r--r--gl/dirname-lgpl.c18
-rw-r--r--gl/dirname.c4
-rw-r--r--gl/dirname.h54
-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.h441
-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.c230
-rw-r--r--gl/fpurge.c150
-rw-r--r--gl/freading.c76
-rw-r--r--gl/freading.h55
-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.h21
-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.c178
-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.c176
-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.h43
-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.h28
-rw-r--r--gl/ialloc.c21
-rw-r--r--gl/ialloc.h100
-rw-r--r--gl/idpriv-droptemp.c12
-rw-r--r--gl/idpriv.h10
-rw-r--r--gl/idx.h134
-rw-r--r--gl/inet_ntop.c20
-rw-r--r--gl/intprops.h484
-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.h191
-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.m445
-rw-r--r--gl/m4/arpa_inet_h.m435
-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.m419
-rw-r--r--gl/m4/calloc.m482
-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.m412
-rw-r--r--gl/m4/error.m48
-rw-r--r--gl/m4/exponentd.m42
-rw-r--r--gl/m4/extensions.m4209
-rw-r--r--gl/m4/extern-inline.m479
-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.m436
-rw-r--r--gl/m4/floorf.m418
-rw-r--r--gl/m4/fopen.m4148
-rw-r--r--gl/m4/fpurge.m473
-rw-r--r--gl/m4/freading.m411
-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.m499
-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.m437
-rw-r--r--gl/m4/getprogname.m443
-rw-r--r--gl/m4/gettext.m4107
-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.m438
-rw-r--r--gl/m4/gnulib-common.m4815
-rw-r--r--gl/m4/gnulib-comp.m4601
-rw-r--r--gl/m4/gnulib-tool.m42
-rw-r--r--gl/m4/host-cpu-c-abi.m4675
-rw-r--r--gl/m4/hostent.m48
-rw-r--r--gl/m4/iconv.m4171
-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-thread-locale.m4219
-rw-r--r--gl/m4/intl.m4271
-rw-r--r--gl/m4/intldir.m419
-rw-r--r--gl/m4/intlmacosx.m441
-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.m482
-rw-r--r--gl/m4/lcmessage.m435
-rw-r--r--gl/m4/lib-ld.m4163
-rw-r--r--gl/m4/lib-link.m4184
-rw-r--r--gl/m4/lib-prefix.m4241
-rw-r--r--gl/m4/limits-h.m444
-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.m4170
-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.m4115
-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.m42
-rw-r--r--gl/m4/nl_langinfo.m437
-rw-r--r--gl/m4/nls.m414
-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.m467
-rw-r--r--gl/m4/printf-posix.m448
-rw-r--r--gl/m4/printf.m4490
-rw-r--r--gl/m4/progtest.m420
-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/sha1.m48
-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.m416
-rw-r--r--gl/m4/stdbool.m484
-rw-r--r--gl/m4/stddef_h.m464
-rw-r--r--gl/m4/stdint.m4167
-rw-r--r--gl/m4/stdint_h.m42
-rw-r--r--gl/m4/stdio_h.m4200
-rw-r--r--gl/m4/stdlib_h.m4161
-rw-r--r--gl/m4/strcase.m48
-rw-r--r--gl/m4/strcasestr.m461
-rw-r--r--gl/m4/strerror.m428
-rw-r--r--gl/m4/string_h.m4145
-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.m483
-rw-r--r--gl/m4/sys_stat_h.m4127
-rw-r--r--gl/m4/sys_types_h.m450
-rw-r--r--gl/m4/sys_uio_h.m425
-rw-r--r--gl/m4/threadlib.m4665
-rw-r--r--gl/m4/time_h.m4106
-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.m4205
-rw-r--r--gl/m4/unlocked-io.m436
-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.m448
-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/year2038.m4124
-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.h178
-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.c166
-rw-r--r--gl/malloca.h69
-rw-r--r--gl/malloca.valgrind7
-rw-r--r--gl/math.c19
-rw-r--r--gl/math.in.h692
-rw-r--r--gl/mbrtowc-impl-utf8.h138
-rw-r--r--gl/mbrtowc-impl.h262
-rw-r--r--gl/mbrtowc.c394
-rw-r--r--gl/mbsinit.c49
-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.c809
-rw-r--r--gl/mountlist.c484
-rw-r--r--gl/mountlist.h11
-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.c39
-rw-r--r--gl/ref-add.sin29
-rw-r--r--gl/ref-del.sin24
-rw-r--r--gl/regcomp.c607
-rw-r--r--gl/regex.c21
-rw-r--r--gl/regex.h142
-rw-r--r--gl/regex_internal.c350
-rw-r--r--gl/regex_internal.h263
-rw-r--r--gl/regexec.c1097
-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-stream.c129
-rw-r--r--gl/sha1.c125
-rw-r--r--gl/sha1.h63
-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.h252
-rw-r--r--gl/stat-w32.c461
-rw-r--r--gl/stat-w32.h37
-rw-r--r--gl/stat.c440
-rw-r--r--gl/stdalign.in.h54
-rw-r--r--gl/stdbool.in.h24
-rw-r--r--gl/stddef.in.h111
-rw-r--r--gl/stdint.in.h834
-rw-r--r--gl/stdio-impl.h212
-rw-r--r--gl/stdio.in.h712
-rw-r--r--gl/stdlib.in.h740
-rw-r--r--gl/str-two-way.h26
-rw-r--r--gl/strcasecmp.c20
-rw-r--r--gl/strcasestr.c18
-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.c21
-rw-r--r--gl/string.in.h333
-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.c22
-rw-r--r--gl/sys-limits.h42
-rw-r--r--gl/sys_socket.c19
-rw-r--r--gl/sys_socket.in.h137
-rw-r--r--gl/sys_stat.in.h928
-rw-r--r--gl/sys_types.in.h77
-rw-r--r--gl/sys_uio.in.h18
-rw-r--r--gl/time.in.h257
-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.h980
-rw-r--r--gl/unlocked-io.h136
-rw-r--r--gl/unsetenv.c18
-rw-r--r--gl/vasnprintf.c699
-rw-r--r--gl/vasnprintf.h41
-rw-r--r--gl/vasprintf.c18
-rw-r--r--gl/verify.h154
-rw-r--r--gl/vsnprintf.c18
-rw-r--r--gl/w32sock.h24
-rw-r--r--gl/wchar.in.h504
-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.c4
-rw-r--r--gl/xalloc-oversized.h79
-rw-r--r--gl/xalloc.h231
-rw-r--r--gl/xmalloc.c303
-rw-r--r--gl/xsize.c18
-rw-r--r--gl/xsize.h44
-rw-r--r--gl/xstrndup.c36
-rw-r--r--gl/xstrndup.h23
426 files changed, 39357 insertions, 15246 deletions
diff --git a/build-aux/config.rpath b/build-aux/config.rpath
index c38b914..4b7dc49 100755
--- a/build-aux/config.rpath
+++ b/build-aux/config.rpath
@@ -2,7 +2,7 @@
2# Output a system dependent set of variables, describing how to set the 2# Output a system dependent set of variables, describing how to set the
3# run time search path of shared libraries in an executable. 3# run time search path of shared libraries in an executable.
4# 4#
5# Copyright 1996-2013 Free Software Foundation, Inc. 5# Copyright 1996-2021 Free Software Foundation, Inc.
6# Taken from GNU libtool, 2001 6# Taken from GNU libtool, 2001
7# Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996 7# Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
8# 8#
@@ -367,15 +367,11 @@ else
367 dgux*) 367 dgux*)
368 hardcode_libdir_flag_spec='-L$libdir' 368 hardcode_libdir_flag_spec='-L$libdir'
369 ;; 369 ;;
370 freebsd2.2*) 370 freebsd2.[01]*)
371 hardcode_libdir_flag_spec='-R$libdir'
372 hardcode_direct=yes
373 ;;
374 freebsd2*)
375 hardcode_direct=yes 371 hardcode_direct=yes
376 hardcode_minus_L=yes 372 hardcode_minus_L=yes
377 ;; 373 ;;
378 freebsd* | dragonfly*) 374 freebsd* | dragonfly* | midnightbsd*)
379 hardcode_libdir_flag_spec='-R$libdir' 375 hardcode_libdir_flag_spec='-R$libdir'
380 hardcode_direct=yes 376 hardcode_direct=yes
381 ;; 377 ;;
@@ -548,13 +544,11 @@ case "$host_os" in
548 dgux*) 544 dgux*)
549 library_names_spec='$libname$shrext' 545 library_names_spec='$libname$shrext'
550 ;; 546 ;;
551 freebsd* | dragonfly*) 547 freebsd[23].*)
552 case "$host_os" in 548 library_names_spec='$libname$shrext$versuffix'
553 freebsd[123]*) 549 ;;
554 library_names_spec='$libname$shrext$versuffix' ;; 550 freebsd* | dragonfly* | midnightbsd*)
555 *) 551 library_names_spec='$libname$shrext'
556 library_names_spec='$libname$shrext' ;;
557 esac
558 ;; 552 ;;
559 gnu*) 553 gnu*)
560 library_names_spec='$libname$shrext' 554 library_names_spec='$libname$shrext'
diff --git a/build-aux/snippet/_Noreturn.h b/build-aux/snippet/_Noreturn.h
deleted file mode 100644
index c44ad89..0000000
--- a/build-aux/snippet/_Noreturn.h
+++ /dev/null
@@ -1,10 +0,0 @@
1#if !defined _Noreturn && __STDC_VERSION__ < 201112
2# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \
3 || 0x5110 <= __SUNPRO_C)
4# define _Noreturn __attribute__ ((__noreturn__))
5# elif 1200 <= _MSC_VER
6# define _Noreturn __declspec (noreturn)
7# else
8# define _Noreturn
9# endif
10#endif
diff --git a/build-aux/snippet/arg-nonnull.h b/build-aux/snippet/arg-nonnull.h
deleted file mode 100644
index 8ea2a47..0000000
--- a/build-aux/snippet/arg-nonnull.h
+++ /dev/null
@@ -1,26 +0,0 @@
1/* A C macro for declaring that specific arguments must not be NULL.
2 Copyright (C) 2009-2013 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published
6 by the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
18 that the values passed as arguments n, ..., m must be non-NULL pointers.
19 n = 1 stands for the first argument, n = 2 for the second argument etc. */
20#ifndef _GL_ARG_NONNULL
21# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
22# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
23# else
24# define _GL_ARG_NONNULL(params)
25# endif
26#endif
diff --git a/build-aux/snippet/c++defs.h b/build-aux/snippet/c++defs.h
deleted file mode 100644
index b35b933..0000000
--- a/build-aux/snippet/c++defs.h
+++ /dev/null
@@ -1,271 +0,0 @@
1/* C++ compatible function declaration macros.
2 Copyright (C) 2010-2013 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published
6 by the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17#ifndef _GL_CXXDEFS_H
18#define _GL_CXXDEFS_H
19
20/* The three most frequent use cases of these macros are:
21
22 * For providing a substitute for a function that is missing on some
23 platforms, but is declared and works fine on the platforms on which
24 it exists:
25
26 #if @GNULIB_FOO@
27 # if !@HAVE_FOO@
28 _GL_FUNCDECL_SYS (foo, ...);
29 # endif
30 _GL_CXXALIAS_SYS (foo, ...);
31 _GL_CXXALIASWARN (foo);
32 #elif defined GNULIB_POSIXCHECK
33 ...
34 #endif
35
36 * For providing a replacement for a function that exists on all platforms,
37 but is broken/insufficient and needs to be replaced on some platforms:
38
39 #if @GNULIB_FOO@
40 # if @REPLACE_FOO@
41 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
42 # undef foo
43 # define foo rpl_foo
44 # endif
45 _GL_FUNCDECL_RPL (foo, ...);
46 _GL_CXXALIAS_RPL (foo, ...);
47 # else
48 _GL_CXXALIAS_SYS (foo, ...);
49 # endif
50 _GL_CXXALIASWARN (foo);
51 #elif defined GNULIB_POSIXCHECK
52 ...
53 #endif
54
55 * For providing a replacement for a function that exists on some platforms
56 but is broken/insufficient and needs to be replaced on some of them and
57 is additionally either missing or undeclared on some other platforms:
58
59 #if @GNULIB_FOO@
60 # if @REPLACE_FOO@
61 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
62 # undef foo
63 # define foo rpl_foo
64 # endif
65 _GL_FUNCDECL_RPL (foo, ...);
66 _GL_CXXALIAS_RPL (foo, ...);
67 # else
68 # if !@HAVE_FOO@ or if !@HAVE_DECL_FOO@
69 _GL_FUNCDECL_SYS (foo, ...);
70 # endif
71 _GL_CXXALIAS_SYS (foo, ...);
72 # endif
73 _GL_CXXALIASWARN (foo);
74 #elif defined GNULIB_POSIXCHECK
75 ...
76 #endif
77*/
78
79/* _GL_EXTERN_C declaration;
80 performs the declaration with C linkage. */
81#if defined __cplusplus
82# define _GL_EXTERN_C extern "C"
83#else
84# define _GL_EXTERN_C extern
85#endif
86
87/* _GL_FUNCDECL_RPL (func, rettype, parameters_and_attributes);
88 declares a replacement function, named rpl_func, with the given prototype,
89 consisting of return type, parameters, and attributes.
90 Example:
91 _GL_FUNCDECL_RPL (open, int, (const char *filename, int flags, ...)
92 _GL_ARG_NONNULL ((1)));
93 */
94#define _GL_FUNCDECL_RPL(func,rettype,parameters_and_attributes) \
95 _GL_FUNCDECL_RPL_1 (rpl_##func, rettype, parameters_and_attributes)
96#define _GL_FUNCDECL_RPL_1(rpl_func,rettype,parameters_and_attributes) \
97 _GL_EXTERN_C rettype rpl_func parameters_and_attributes
98
99/* _GL_FUNCDECL_SYS (func, rettype, parameters_and_attributes);
100 declares the system function, named func, with the given prototype,
101 consisting of return type, parameters, and attributes.
102 Example:
103 _GL_FUNCDECL_SYS (open, int, (const char *filename, int flags, ...)
104 _GL_ARG_NONNULL ((1)));
105 */
106#define _GL_FUNCDECL_SYS(func,rettype,parameters_and_attributes) \
107 _GL_EXTERN_C rettype func parameters_and_attributes
108
109/* _GL_CXXALIAS_RPL (func, rettype, parameters);
110 declares a C++ alias called GNULIB_NAMESPACE::func
111 that redirects to rpl_func, if GNULIB_NAMESPACE is defined.
112 Example:
113 _GL_CXXALIAS_RPL (open, int, (const char *filename, int flags, ...));
114 */
115#define _GL_CXXALIAS_RPL(func,rettype,parameters) \
116 _GL_CXXALIAS_RPL_1 (func, rpl_##func, rettype, parameters)
117#if defined __cplusplus && defined GNULIB_NAMESPACE
118# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
119 namespace GNULIB_NAMESPACE \
120 { \
121 rettype (*const func) parameters = ::rpl_func; \
122 } \
123 _GL_EXTERN_C int _gl_cxxalias_dummy
124#else
125# define _GL_CXXALIAS_RPL_1(func,rpl_func,rettype,parameters) \
126 _GL_EXTERN_C int _gl_cxxalias_dummy
127#endif
128
129/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
130 is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
131 except that the C function rpl_func may have a slightly different
132 declaration. A cast is used to silence the "invalid conversion" error
133 that would otherwise occur. */
134#if defined __cplusplus && defined GNULIB_NAMESPACE
135# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
136 namespace GNULIB_NAMESPACE \
137 { \
138 rettype (*const func) parameters = \
139 reinterpret_cast<rettype(*)parameters>(::rpl_func); \
140 } \
141 _GL_EXTERN_C int _gl_cxxalias_dummy
142#else
143# define _GL_CXXALIAS_RPL_CAST_1(func,rpl_func,rettype,parameters) \
144 _GL_EXTERN_C int _gl_cxxalias_dummy
145#endif
146
147/* _GL_CXXALIAS_SYS (func, rettype, parameters);
148 declares a C++ alias called GNULIB_NAMESPACE::func
149 that redirects to the system provided function func, if GNULIB_NAMESPACE
150 is defined.
151 Example:
152 _GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
153 */
154#if defined __cplusplus && defined GNULIB_NAMESPACE
155 /* If we were to write
156 rettype (*const func) parameters = ::func;
157 like above in _GL_CXXALIAS_RPL_1, the compiler could optimize calls
158 better (remove an indirection through a 'static' pointer variable),
159 but then the _GL_CXXALIASWARN macro below would cause a warning not only
160 for uses of ::func but also for uses of GNULIB_NAMESPACE::func. */
161# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
162 namespace GNULIB_NAMESPACE \
163 { \
164 static rettype (*func) parameters = ::func; \
165 } \
166 _GL_EXTERN_C int _gl_cxxalias_dummy
167#else
168# define _GL_CXXALIAS_SYS(func,rettype,parameters) \
169 _GL_EXTERN_C int _gl_cxxalias_dummy
170#endif
171
172/* _GL_CXXALIAS_SYS_CAST (func, rettype, parameters);
173 is like _GL_CXXALIAS_SYS (func, rettype, parameters);
174 except that the C function func may have a slightly different declaration.
175 A cast is used to silence the "invalid conversion" error that would
176 otherwise occur. */
177#if defined __cplusplus && defined GNULIB_NAMESPACE
178# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
179 namespace GNULIB_NAMESPACE \
180 { \
181 static rettype (*func) parameters = \
182 reinterpret_cast<rettype(*)parameters>(::func); \
183 } \
184 _GL_EXTERN_C int _gl_cxxalias_dummy
185#else
186# define _GL_CXXALIAS_SYS_CAST(func,rettype,parameters) \
187 _GL_EXTERN_C int _gl_cxxalias_dummy
188#endif
189
190/* _GL_CXXALIAS_SYS_CAST2 (func, rettype, parameters, rettype2, parameters2);
191 is like _GL_CXXALIAS_SYS (func, rettype, parameters);
192 except that the C function is picked among a set of overloaded functions,
193 namely the one with rettype2 and parameters2. Two consecutive casts
194 are used to silence the "cannot find a match" and "invalid conversion"
195 errors that would otherwise occur. */
196#if defined __cplusplus && defined GNULIB_NAMESPACE
197 /* The outer cast must be a reinterpret_cast.
198 The inner cast: When the function is defined as a set of overloaded
199 functions, it works as a static_cast<>, choosing the designated variant.
200 When the function is defined as a single variant, it works as a
201 reinterpret_cast<>. The parenthesized cast syntax works both ways. */
202# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
203 namespace GNULIB_NAMESPACE \
204 { \
205 static rettype (*func) parameters = \
206 reinterpret_cast<rettype(*)parameters>( \
207 (rettype2(*)parameters2)(::func)); \
208 } \
209 _GL_EXTERN_C int _gl_cxxalias_dummy
210#else
211# define _GL_CXXALIAS_SYS_CAST2(func,rettype,parameters,rettype2,parameters2) \
212 _GL_EXTERN_C int _gl_cxxalias_dummy
213#endif
214
215/* _GL_CXXALIASWARN (func);
216 causes a warning to be emitted when ::func is used but not when
217 GNULIB_NAMESPACE::func is used. func must be defined without overloaded
218 variants. */
219#if defined __cplusplus && defined GNULIB_NAMESPACE
220# define _GL_CXXALIASWARN(func) \
221 _GL_CXXALIASWARN_1 (func, GNULIB_NAMESPACE)
222# define _GL_CXXALIASWARN_1(func,namespace) \
223 _GL_CXXALIASWARN_2 (func, namespace)
224/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
225 we enable the warning only when not optimizing. */
226# if !__OPTIMIZE__
227# define _GL_CXXALIASWARN_2(func,namespace) \
228 _GL_WARN_ON_USE (func, \
229 "The symbol ::" #func " refers to the system function. " \
230 "Use " #namespace "::" #func " instead.")
231# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
232# define _GL_CXXALIASWARN_2(func,namespace) \
233 extern __typeof__ (func) func
234# else
235# define _GL_CXXALIASWARN_2(func,namespace) \
236 _GL_EXTERN_C int _gl_cxxalias_dummy
237# endif
238#else
239# define _GL_CXXALIASWARN(func) \
240 _GL_EXTERN_C int _gl_cxxalias_dummy
241#endif
242
243/* _GL_CXXALIASWARN1 (func, rettype, parameters_and_attributes);
244 causes a warning to be emitted when the given overloaded variant of ::func
245 is used but not when GNULIB_NAMESPACE::func is used. */
246#if defined __cplusplus && defined GNULIB_NAMESPACE
247# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
248 _GL_CXXALIASWARN1_1 (func, rettype, parameters_and_attributes, \
249 GNULIB_NAMESPACE)
250# define _GL_CXXALIASWARN1_1(func,rettype,parameters_and_attributes,namespace) \
251 _GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
252/* To work around GCC bug <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
253 we enable the warning only when not optimizing. */
254# if !__OPTIMIZE__
255# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
256 _GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
257 "The symbol ::" #func " refers to the system function. " \
258 "Use " #namespace "::" #func " instead.")
259# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
260# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
261 extern __typeof__ (func) func
262# else
263# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
264 _GL_EXTERN_C int _gl_cxxalias_dummy
265# endif
266#else
267# define _GL_CXXALIASWARN1(func,rettype,parameters_and_attributes) \
268 _GL_EXTERN_C int _gl_cxxalias_dummy
269#endif
270
271#endif /* _GL_CXXDEFS_H */
diff --git a/build-aux/snippet/warn-on-use.h b/build-aux/snippet/warn-on-use.h
deleted file mode 100644
index 1736a1b..0000000
--- a/build-aux/snippet/warn-on-use.h
+++ /dev/null
@@ -1,109 +0,0 @@
1/* A C macro for emitting warnings if a function is used.
2 Copyright (C) 2010-2013 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published
6 by the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17/* _GL_WARN_ON_USE (function, "literal string") issues a declaration
18 for FUNCTION which will then trigger a compiler warning containing
19 the text of "literal string" anywhere that function is called, if
20 supported by the compiler. If the compiler does not support this
21 feature, the macro expands to an unused extern declaration.
22
23 This macro is useful for marking a function as a potential
24 portability trap, with the intent that "literal string" include
25 instructions on the replacement function that should be used
26 instead. However, one of the reasons that a function is a
27 portability trap is if it has the wrong signature. Declaring
28 FUNCTION with a different signature in C is a compilation error, so
29 this macro must use the same type as any existing declaration so
30 that programs that avoid the problematic FUNCTION do not fail to
31 compile merely because they included a header that poisoned the
32 function. But this implies that _GL_WARN_ON_USE is only safe to
33 use if FUNCTION is known to already have a declaration. Use of
34 this macro implies that there must not be any other macro hiding
35 the declaration of FUNCTION; but undefining FUNCTION first is part
36 of the poisoning process anyway (although for symbols that are
37 provided only via a macro, the result is a compilation error rather
38 than a warning containing "literal string"). Also note that in
39 C++, it is only safe to use if FUNCTION has no overloads.
40
41 For an example, it is possible to poison 'getline' by:
42 - adding a call to gl_WARN_ON_USE_PREPARE([[#include <stdio.h>]],
43 [getline]) in configure.ac, which potentially defines
44 HAVE_RAW_DECL_GETLINE
45 - adding this code to a header that wraps the system <stdio.h>:
46 #undef getline
47 #if HAVE_RAW_DECL_GETLINE
48 _GL_WARN_ON_USE (getline, "getline is required by POSIX 2008, but"
49 "not universally present; use the gnulib module getline");
50 #endif
51
52 It is not possible to directly poison global variables. But it is
53 possible to write a wrapper accessor function, and poison that
54 (less common usage, like &environ, will cause a compilation error
55 rather than issue the nice warning, but the end result of informing
56 the developer about their portability problem is still achieved):
57 #if HAVE_RAW_DECL_ENVIRON
58 static char ***rpl_environ (void) { return &environ; }
59 _GL_WARN_ON_USE (rpl_environ, "environ is not always properly declared");
60 # undef environ
61 # define environ (*rpl_environ ())
62 #endif
63 */
64#ifndef _GL_WARN_ON_USE
65
66# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
67/* A compiler attribute is available in gcc versions 4.3.0 and later. */
68# define _GL_WARN_ON_USE(function, message) \
69extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
70# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
71/* Verify the existence of the function. */
72# define _GL_WARN_ON_USE(function, message) \
73extern __typeof__ (function) function
74# else /* Unsupported. */
75# define _GL_WARN_ON_USE(function, message) \
76_GL_WARN_EXTERN_C int _gl_warn_on_use
77# endif
78#endif
79
80/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
81 is like _GL_WARN_ON_USE (function, "string"), except that the function is
82 declared with the given prototype, consisting of return type, parameters,
83 and attributes.
84 This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
85 not work in this case. */
86#ifndef _GL_WARN_ON_USE_CXX
87# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
88# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
89extern rettype function parameters_and_attributes \
90 __attribute__ ((__warning__ (msg)))
91# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
92/* Verify the existence of the function. */
93# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
94extern rettype function parameters_and_attributes
95# else /* Unsupported. */
96# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
97_GL_WARN_EXTERN_C int _gl_warn_on_use
98# endif
99#endif
100
101/* _GL_WARN_EXTERN_C declaration;
102 performs the declaration with C linkage. */
103#ifndef _GL_WARN_EXTERN_C
104# if defined __cplusplus
105# define _GL_WARN_EXTERN_C extern "C"
106# else
107# define _GL_WARN_EXTERN_C extern
108# endif
109#endif
diff --git a/gl/Makefile.am b/gl/Makefile.am
index 15135c8..5451c47 100644
--- a/gl/Makefile.am
+++ b/gl/Makefile.am
@@ -1,6 +1,6 @@
1## DO NOT EDIT! GENERATED AUTOMATICALLY! 1## DO NOT EDIT! GENERATED AUTOMATICALLY!
2## Process this file with automake to produce Makefile.in. 2## Process this file with automake to produce Makefile.in.
3# Copyright (C) 2002-2013 Free Software Foundation, Inc. 3# Copyright (C) 2002-2021 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
@@ -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/sha1 \
38# dirname \
39# environ \
40# floorf \
41# fsusage \
42# getaddrinfo \
43# gethostname \
44# getloadavg \
45# getopt-gnu \
46# gettext \
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.11 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 =
@@ -49,6 +83,15 @@ libgnu_a_LIBADD = $(gl_LIBOBJS)
49libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) 83libgnu_a_DEPENDENCIES = $(gl_LIBOBJS)
50EXTRA_libgnu_a_SOURCES = 84EXTRA_libgnu_a_SOURCES =
51 85
86## begin gnulib module absolute-header
87
88# Use this preprocessor expression to decide whether #include_next works.
89# Do not rely on a 'configure'-time test for this, since the expression
90# might appear in an installed header, which is used by some other compiler.
91HAVE_INCLUDE_NEXT = (__GNUC__ || __clang__ || 60000000 <= __DECC_VER)
92
93## end gnulib module absolute-header
94
52## begin gnulib module alloca-opt 95## begin gnulib module alloca-opt
53 96
54BUILT_SOURCES += $(ALLOCA_H) 97BUILT_SOURCES += $(ALLOCA_H)
@@ -59,7 +102,7 @@ if GL_GENERATE_ALLOCA_H
59alloca.h: alloca.in.h $(top_builddir)/config.status 102alloca.h: alloca.in.h $(top_builddir)/config.status
60 $(AM_V_GEN)rm -f $@-t $@ && \ 103 $(AM_V_GEN)rm -f $@-t $@ && \
61 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 104 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
62 cat $(srcdir)/alloca.in.h; \ 105 sed -e 's|@''HAVE_ALLOCA_H''@|$(HAVE_ALLOCA_H)|g' < $(srcdir)/alloca.in.h; \
63 } > $@-t && \ 106 } > $@-t && \
64 mv -f $@-t $@ 107 mv -f $@-t $@
65else 108else
@@ -89,8 +132,9 @@ arpa/inet.h: arpa_inet.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON
89 -e 's|@''HAVE_FEATURES_H''@|$(HAVE_FEATURES_H)|g' \ 132 -e 's|@''HAVE_FEATURES_H''@|$(HAVE_FEATURES_H)|g' \
90 -e 's|@''NEXT_ARPA_INET_H''@|$(NEXT_ARPA_INET_H)|g' \ 133 -e 's|@''NEXT_ARPA_INET_H''@|$(NEXT_ARPA_INET_H)|g' \
91 -e 's|@''HAVE_ARPA_INET_H''@|$(HAVE_ARPA_INET_H)|g' \ 134 -e 's|@''HAVE_ARPA_INET_H''@|$(HAVE_ARPA_INET_H)|g' \
92 -e 's/@''GNULIB_INET_NTOP''@/$(GNULIB_INET_NTOP)/g' \ 135 -e 's/@''GNULIB_INET_NTOP''@/$(GL_GNULIB_INET_NTOP)/g' \
93 -e 's/@''GNULIB_INET_PTON''@/$(GNULIB_INET_PTON)/g' \ 136 -e 's/@''GNULIB_INET_PTON''@/$(GL_GNULIB_INET_PTON)/g' \
137 -e 's|@''HAVE_WS2TCPIP_H''@|$(HAVE_WS2TCPIP_H)|g' \
94 -e 's|@''HAVE_DECL_INET_NTOP''@|$(HAVE_DECL_INET_NTOP)|g' \ 138 -e 's|@''HAVE_DECL_INET_NTOP''@|$(HAVE_DECL_INET_NTOP)|g' \
95 -e 's|@''HAVE_DECL_INET_PTON''@|$(HAVE_DECL_INET_PTON)|g' \ 139 -e 's|@''HAVE_DECL_INET_PTON''@|$(HAVE_DECL_INET_PTON)|g' \
96 -e 's|@''REPLACE_INET_NTOP''@|$(REPLACE_INET_NTOP)|g' \ 140 -e 's|@''REPLACE_INET_NTOP''@|$(REPLACE_INET_NTOP)|g' \
@@ -108,12 +152,27 @@ EXTRA_DIST += arpa_inet.in.h
108 152
109## end gnulib module arpa_inet 153## end gnulib module arpa_inet
110 154
155## begin gnulib module attribute
156
157
158EXTRA_DIST += attribute.h
159
160## end gnulib module attribute
161
111## begin gnulib module base64 162## begin gnulib module base64
112 163
113libgnu_a_SOURCES += base64.h base64.c 164libgnu_a_SOURCES += base64.h base64.c
114 165
115## end gnulib module base64 166## end gnulib module base64
116 167
168## begin gnulib module basename-lgpl
169
170libgnu_a_SOURCES += basename-lgpl.c
171
172EXTRA_DIST += basename-lgpl.h
173
174## end gnulib module basename-lgpl
175
117## begin gnulib module btowc 176## begin gnulib module btowc
118 177
119 178
@@ -123,57 +182,85 @@ EXTRA_libgnu_a_SOURCES += btowc.c
123 182
124## end gnulib module btowc 183## end gnulib module btowc
125 184
126## begin gnulib module configmake 185## begin gnulib module byteswap
186
187BUILT_SOURCES += $(BYTESWAP_H)
127 188
128# Listed in the same order as the GNU makefile conventions, and 189# We need the following in order to create <byteswap.h> when the system
129# provided by autoconf 2.59c+. 190# doesn't have one.
130# The Automake-defined pkg* macros are appended, in the order 191if GL_GENERATE_BYTESWAP_H
131# listed in the Automake 1.10a+ documentation. 192byteswap.h: byteswap.in.h $(top_builddir)/config.status
132configmake.h: Makefile 193 $(AM_V_GEN)rm -f $@-t $@ && \
133 $(AM_V_GEN)rm -f $@-t && \
134 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ 194 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
135 echo '#define PREFIX "$(prefix)"'; \ 195 cat $(srcdir)/byteswap.in.h; \
136 echo '#define EXEC_PREFIX "$(exec_prefix)"'; \ 196 } > $@-t && \
137 echo '#define BINDIR "$(bindir)"'; \
138 echo '#define SBINDIR "$(sbindir)"'; \
139 echo '#define LIBEXECDIR "$(libexecdir)"'; \
140 echo '#define DATAROOTDIR "$(datarootdir)"'; \
141 echo '#define DATADIR "$(datadir)"'; \
142 echo '#define SYSCONFDIR "$(sysconfdir)"'; \
143 echo '#define SHAREDSTATEDIR "$(sharedstatedir)"'; \
144 echo '#define LOCALSTATEDIR "$(localstatedir)"'; \
145 echo '#define INCLUDEDIR "$(includedir)"'; \
146 echo '#define OLDINCLUDEDIR "$(oldincludedir)"'; \
147 echo '#define DOCDIR "$(docdir)"'; \
148 echo '#define INFODIR "$(infodir)"'; \
149 echo '#define HTMLDIR "$(htmldir)"'; \
150 echo '#define DVIDIR "$(dvidir)"'; \
151 echo '#define PDFDIR "$(pdfdir)"'; \
152 echo '#define PSDIR "$(psdir)"'; \
153 echo '#define LIBDIR "$(libdir)"'; \
154 echo '#define LISPDIR "$(lispdir)"'; \
155 echo '#define LOCALEDIR "$(localedir)"'; \
156 echo '#define MANDIR "$(mandir)"'; \
157 echo '#define MANEXT "$(manext)"'; \
158 echo '#define PKGDATADIR "$(pkgdatadir)"'; \
159 echo '#define PKGINCLUDEDIR "$(pkgincludedir)"'; \
160 echo '#define PKGLIBDIR "$(pkglibdir)"'; \
161 echo '#define PKGLIBEXECDIR "$(pkglibexecdir)"'; \
162 } | sed '/""/d' > $@-t && \
163 mv -f $@-t $@ 197 mv -f $@-t $@
198else
199byteswap.h: $(top_builddir)/config.status
200 rm -f $@
201endif
202MOSTLYCLEANFILES += byteswap.h byteswap.h-t
203
204EXTRA_DIST += byteswap.in.h
205
206## end gnulib module byteswap
164 207
165BUILT_SOURCES += configmake.h 208## begin gnulib module calloc-gnu
166CLEANFILES += configmake.h configmake.h-t
167 209
168## end gnulib module configmake 210
211EXTRA_DIST += calloc.c
212
213EXTRA_libgnu_a_SOURCES += calloc.c
214
215## end gnulib module calloc-gnu
216
217## begin gnulib module calloc-posix
218
219
220EXTRA_DIST += calloc.c
221
222EXTRA_libgnu_a_SOURCES += calloc.c
223
224## end gnulib module calloc-posix
225
226## begin gnulib module cloexec
227
228libgnu_a_SOURCES += cloexec.c
229
230EXTRA_DIST += cloexec.h
231
232## end gnulib module cloexec
233
234## begin gnulib module close
235
236
237EXTRA_DIST += close.c
238
239EXTRA_libgnu_a_SOURCES += close.c
240
241## end gnulib module close
242
243## begin gnulib module crypto/af_alg
244
245libgnu_a_SOURCES += af_alg.c
246
247EXTRA_DIST += af_alg.h sys-limits.h
248
249## end gnulib module crypto/af_alg
169 250
170## begin gnulib module crypto/sha1 251## begin gnulib module crypto/sha1
171 252
253libgnu_a_SOURCES += sha1-stream.c
254
255## end gnulib module crypto/sha1
256
257## begin gnulib module crypto/sha1-buffer
258
172libgnu_a_SOURCES += sha1.c 259libgnu_a_SOURCES += sha1.c
173 260
174EXTRA_DIST += sha1.h 261EXTRA_DIST += gl_openssl.h sha1.h
175 262
176## end gnulib module crypto/sha1 263## end gnulib module crypto/sha1-buffer
177 264
178## begin gnulib module dirname 265## begin gnulib module dirname
179 266
@@ -187,18 +274,56 @@ EXTRA_libgnu_a_SOURCES += stripslash.c
187 274
188## begin gnulib module dirname-lgpl 275## begin gnulib module dirname-lgpl
189 276
190libgnu_a_SOURCES += dirname-lgpl.c basename-lgpl.c stripslash.c 277libgnu_a_SOURCES += dirname-lgpl.c stripslash.c
191 278
192EXTRA_DIST += dirname.h 279EXTRA_DIST += dirname.h
193 280
194## end gnulib module dirname-lgpl 281## end gnulib module dirname-lgpl
195 282
196## begin gnulib module dosname 283## begin gnulib module dup2
284
285
286EXTRA_DIST += dup2.c
287
288EXTRA_libgnu_a_SOURCES += dup2.c
289
290## end gnulib module dup2
291
292## begin gnulib module dynarray
293
294BUILT_SOURCES += malloc/dynarray.gl.h malloc/dynarray-skeleton.gl.h
295
296malloc/dynarray.gl.h: malloc/dynarray.h
297 $(AM_V_at)$(MKDIR_P) malloc
298 $(AM_V_GEN)rm -f $@-t $@ && \
299 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
300 sed -e '/libc_hidden_proto/d' < $(srcdir)/malloc/dynarray.h; \
301 } > $@-t && \
302 mv $@-t $@
303MOSTLYCLEANFILES += malloc/dynarray.gl.h malloc/dynarray.gl.h-t
197 304
305malloc/dynarray-skeleton.gl.h: malloc/dynarray-skeleton.c
306 $(AM_V_at)$(MKDIR_P) malloc
307 $(AM_V_GEN)rm -f $@-t $@ && \
308 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
309 sed -e 's|<malloc/dynarray\.h>|<malloc/dynarray.gl.h>|g' \
310 -e 's|__attribute_maybe_unused__|_GL_ATTRIBUTE_MAYBE_UNUSED|g' \
311 -e 's|__attribute_nonnull__|_GL_ATTRIBUTE_NONNULL|g' \
312 -e 's|__attribute_warn_unused_result__|_GL_ATTRIBUTE_NODISCARD|g' \
313 -e 's|__glibc_likely|_GL_LIKELY|g' \
314 -e 's|__glibc_unlikely|_GL_UNLIKELY|g' \
315 < $(srcdir)/malloc/dynarray-skeleton.c; \
316 } > $@-t && \
317 mv $@-t $@
318MOSTLYCLEANFILES += malloc/dynarray-skeleton.gl.h malloc/dynarray-skeleton.gl.h-t
319
320libgnu_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
198 321
199EXTRA_DIST += dosname.h 322EXTRA_DIST += dynarray.h malloc/dynarray-skeleton.c malloc/dynarray.h
200 323
201## end gnulib module dosname 324EXTRA_libgnu_a_SOURCES += malloc/dynarray-skeleton.c
325
326## end gnulib module dynarray
202 327
203## begin gnulib module errno 328## begin gnulib module errno
204 329
@@ -251,6 +376,54 @@ EXTRA_DIST += exitfail.h
251 376
252## end gnulib module exitfail 377## end gnulib module exitfail
253 378
379## begin gnulib module fcntl
380
381
382EXTRA_DIST += fcntl.c
383
384EXTRA_libgnu_a_SOURCES += fcntl.c
385
386## end gnulib module fcntl
387
388## begin gnulib module fcntl-h
389
390BUILT_SOURCES += fcntl.h
391
392# We need the following in order to create <fcntl.h> when the system
393# doesn't have one that works with the given compiler.
394fcntl.h: fcntl.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
395 $(AM_V_GEN)rm -f $@-t $@ && \
396 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
397 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
398 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
399 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
400 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
401 -e 's|@''NEXT_FCNTL_H''@|$(NEXT_FCNTL_H)|g' \
402 -e 's/@''GNULIB_CREAT''@/$(GL_GNULIB_CREAT)/g' \
403 -e 's/@''GNULIB_FCNTL''@/$(GL_GNULIB_FCNTL)/g' \
404 -e 's/@''GNULIB_NONBLOCKING''@/$(GL_GNULIB_NONBLOCKING)/g' \
405 -e 's/@''GNULIB_OPEN''@/$(GL_GNULIB_OPEN)/g' \
406 -e 's/@''GNULIB_OPENAT''@/$(GL_GNULIB_OPENAT)/g' \
407 -e 's/@''GNULIB_MDA_CREAT''@/$(GL_GNULIB_MDA_CREAT)/g' \
408 -e 's/@''GNULIB_MDA_OPEN''@/$(GL_GNULIB_MDA_OPEN)/g' \
409 -e 's|@''HAVE_FCNTL''@|$(HAVE_FCNTL)|g' \
410 -e 's|@''HAVE_OPENAT''@|$(HAVE_OPENAT)|g' \
411 -e 's|@''REPLACE_CREAT''@|$(REPLACE_CREAT)|g' \
412 -e 's|@''REPLACE_FCNTL''@|$(REPLACE_FCNTL)|g' \
413 -e 's|@''REPLACE_OPEN''@|$(REPLACE_OPEN)|g' \
414 -e 's|@''REPLACE_OPENAT''@|$(REPLACE_OPENAT)|g' \
415 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
416 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
417 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
418 < $(srcdir)/fcntl.in.h; \
419 } > $@-t && \
420 mv $@-t $@
421MOSTLYCLEANFILES += fcntl.h fcntl.h-t
422
423EXTRA_DIST += fcntl.in.h
424
425## end gnulib module fcntl-h
426
254## begin gnulib module fd-hook 427## begin gnulib module fd-hook
255 428
256libgnu_a_SOURCES += fd-hook.c 429libgnu_a_SOURCES += fd-hook.c
@@ -259,6 +432,22 @@ EXTRA_DIST += fd-hook.h
259 432
260## end gnulib module fd-hook 433## end gnulib module fd-hook
261 434
435## begin gnulib module fflush
436
437
438EXTRA_DIST += fflush.c stdio-impl.h
439
440EXTRA_libgnu_a_SOURCES += fflush.c
441
442## end gnulib module fflush
443
444## begin gnulib module filename
445
446
447EXTRA_DIST += filename.h
448
449## end gnulib module filename
450
262## begin gnulib module float 451## begin gnulib module float
263 452
264BUILT_SOURCES += $(FLOAT_H) 453BUILT_SOURCES += $(FLOAT_H)
@@ -299,6 +488,77 @@ EXTRA_libgnu_a_SOURCES += floor.c floorf.c
299 488
300## end gnulib module floorf 489## end gnulib module floorf
301 490
491## begin gnulib module fopen
492
493
494EXTRA_DIST += fopen.c
495
496EXTRA_libgnu_a_SOURCES += fopen.c
497
498## end gnulib module fopen
499
500## begin gnulib module fopen-gnu
501
502
503EXTRA_DIST += fopen.c
504
505EXTRA_libgnu_a_SOURCES += fopen.c
506
507## end gnulib module fopen-gnu
508
509## begin gnulib module fpurge
510
511
512EXTRA_DIST += fpurge.c stdio-impl.h
513
514EXTRA_libgnu_a_SOURCES += fpurge.c
515
516## end gnulib module fpurge
517
518## begin gnulib module freading
519
520libgnu_a_SOURCES += freading.c
521
522EXTRA_DIST += freading.h stdio-impl.h
523
524## end gnulib module freading
525
526## begin gnulib module free-posix
527
528
529EXTRA_DIST += free.c
530
531EXTRA_libgnu_a_SOURCES += free.c
532
533## end gnulib module free-posix
534
535## begin gnulib module fseek
536
537
538EXTRA_DIST += fseek.c
539
540EXTRA_libgnu_a_SOURCES += fseek.c
541
542## end gnulib module fseek
543
544## begin gnulib module fseeko
545
546
547EXTRA_DIST += fseeko.c stdio-impl.h
548
549EXTRA_libgnu_a_SOURCES += fseeko.c
550
551## end gnulib module fseeko
552
553## begin gnulib module fstat
554
555
556EXTRA_DIST += fstat.c stat-w32.c stat-w32.h
557
558EXTRA_libgnu_a_SOURCES += fstat.c stat-w32.c
559
560## end gnulib module fstat
561
302## begin gnulib module fsusage 562## begin gnulib module fsusage
303 563
304 564
@@ -308,15 +568,23 @@ EXTRA_libgnu_a_SOURCES += fsusage.c
308 568
309## end gnulib module fsusage 569## end gnulib module fsusage
310 570
311## begin gnulib module full-read 571## begin gnulib module ftell
572
573
574EXTRA_DIST += ftell.c
312 575
313libgnu_a_SOURCES += full-read.h full-read.c 576EXTRA_libgnu_a_SOURCES += ftell.c
314 577
315EXTRA_DIST += full-write.c 578## end gnulib module ftell
316 579
317EXTRA_libgnu_a_SOURCES += full-write.c 580## begin gnulib module ftello
318 581
319## end gnulib module full-read 582
583EXTRA_DIST += ftello.c stdio-impl.h
584
585EXTRA_libgnu_a_SOURCES += ftello.c
586
587## end gnulib module ftello
320 588
321## begin gnulib module getaddrinfo 589## begin gnulib module getaddrinfo
322 590
@@ -327,6 +595,24 @@ EXTRA_libgnu_a_SOURCES += gai_strerror.c getaddrinfo.c
327 595
328## end gnulib module getaddrinfo 596## end gnulib module getaddrinfo
329 597
598## begin gnulib module getdelim
599
600
601EXTRA_DIST += getdelim.c
602
603EXTRA_libgnu_a_SOURCES += getdelim.c
604
605## end gnulib module getdelim
606
607## begin gnulib module getdtablesize
608
609
610EXTRA_DIST += getdtablesize.c
611
612EXTRA_libgnu_a_SOURCES += getdtablesize.c
613
614## end gnulib module getdtablesize
615
330## begin gnulib module gethostname 616## begin gnulib module gethostname
331 617
332 618
@@ -336,6 +622,15 @@ EXTRA_libgnu_a_SOURCES += gethostname.c
336 622
337## end gnulib module gethostname 623## end gnulib module gethostname
338 624
625## begin gnulib module getline
626
627
628EXTRA_DIST += getline.c
629
630EXTRA_libgnu_a_SOURCES += getline.c
631
632## end gnulib module getline
633
339## begin gnulib module getloadavg 634## begin gnulib module getloadavg
340 635
341 636
@@ -347,7 +642,7 @@ EXTRA_libgnu_a_SOURCES += getloadavg.c
347 642
348## begin gnulib module getopt-posix 643## begin gnulib module getopt-posix
349 644
350BUILT_SOURCES += $(GETOPT_H) 645BUILT_SOURCES += $(GETOPT_H) $(GETOPT_CDEFS_H)
351 646
352# We need the following in order to create <getopt.h> when the system 647# We need the following in order to create <getopt.h> when the system
353# doesn't have one that works with the given compiler. 648# doesn't have one that works with the given compiler.
@@ -364,14 +659,29 @@ getopt.h: getopt.in.h $(top_builddir)/config.status $(ARG_NONNULL_H)
364 < $(srcdir)/getopt.in.h; \ 659 < $(srcdir)/getopt.in.h; \
365 } > $@-t && \ 660 } > $@-t && \
366 mv -f $@-t $@ 661 mv -f $@-t $@
367MOSTLYCLEANFILES += getopt.h getopt.h-t
368 662
369EXTRA_DIST += getopt.c getopt.in.h getopt1.c getopt_int.h 663getopt-cdefs.h: getopt-cdefs.in.h $(top_builddir)/config.status
664 $(AM_V_GEN)rm -f $@-t $@ && \
665 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
666 sed -e 's|@''HAVE_SYS_CDEFS_H''@|$(HAVE_SYS_CDEFS_H)|g' \
667 < $(srcdir)/getopt-cdefs.in.h; \
668 } > $@-t && \
669 mv -f $@-t $@
670
671MOSTLYCLEANFILES += getopt.h getopt.h-t getopt-cdefs.h getopt-cdefs.h-t
672
673EXTRA_DIST += getopt-cdefs.in.h getopt-core.h getopt-ext.h getopt-pfx-core.h getopt-pfx-ext.h getopt.c getopt.in.h getopt1.c getopt_int.h
370 674
371EXTRA_libgnu_a_SOURCES += getopt.c getopt1.c 675EXTRA_libgnu_a_SOURCES += getopt.c getopt1.c
372 676
373## end gnulib module getopt-posix 677## end gnulib module getopt-posix
374 678
679## begin gnulib module getprogname
680
681libgnu_a_SOURCES += getprogname.h getprogname.c
682
683## end gnulib module getprogname
684
375## begin gnulib module gettext 685## begin gnulib module gettext
376 686
377# If your project uses "gettextize --intl" to put a source-code 687# If your project uses "gettextize --intl" to put a source-code
@@ -395,6 +705,14 @@ libgnu_a_SOURCES += gettext.h
395 705
396## end gnulib module gettext-h 706## end gnulib module gettext-h
397 707
708## begin gnulib module hard-locale
709
710libgnu_a_SOURCES += hard-locale.c
711
712EXTRA_DIST += hard-locale.h
713
714## end gnulib module hard-locale
715
398## begin gnulib module havelib 716## begin gnulib module havelib
399 717
400 718
@@ -402,6 +720,14 @@ EXTRA_DIST += $(top_srcdir)/build-aux/config.rpath
402 720
403## end gnulib module havelib 721## end gnulib module havelib
404 722
723## begin gnulib module ialloc
724
725libgnu_a_SOURCES += ialloc.c
726
727EXTRA_DIST += ialloc.h
728
729## end gnulib module ialloc
730
405## begin gnulib module idpriv-droptemp 731## begin gnulib module idpriv-droptemp
406 732
407libgnu_a_SOURCES += idpriv-droptemp.c 733libgnu_a_SOURCES += idpriv-droptemp.c
@@ -410,6 +736,12 @@ EXTRA_DIST += idpriv.h
410 736
411## end gnulib module idpriv-droptemp 737## end gnulib module idpriv-droptemp
412 738
739## begin gnulib module idx
740
741libgnu_a_SOURCES += idx.h
742
743## end gnulib module idx
744
413## begin gnulib module inet_ntop 745## begin gnulib module inet_ntop
414 746
415 747
@@ -426,6 +758,49 @@ EXTRA_DIST += intprops.h
426 758
427## end gnulib module intprops 759## end gnulib module intprops
428 760
761## begin gnulib module inttypes-incomplete
762
763BUILT_SOURCES += inttypes.h
764
765# We need the following in order to create <inttypes.h> when the system
766# doesn't have one that works with the given compiler.
767inttypes.h: inttypes.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H)
768 $(AM_V_GEN)rm -f $@-t $@ && \
769 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
770 sed -e 's/@''HAVE_INTTYPES_H''@/$(HAVE_INTTYPES_H)/g' \
771 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
772 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
773 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
774 -e 's|@''NEXT_INTTYPES_H''@|$(NEXT_INTTYPES_H)|g' \
775 -e 's/@''APPLE_UNIVERSAL_BUILD''@/$(APPLE_UNIVERSAL_BUILD)/g' \
776 -e 's/@''PRIPTR_PREFIX''@/$(PRIPTR_PREFIX)/g' \
777 -e 's/@''GNULIB_IMAXABS''@/$(GL_GNULIB_IMAXABS)/g' \
778 -e 's/@''GNULIB_IMAXDIV''@/$(GL_GNULIB_IMAXDIV)/g' \
779 -e 's/@''GNULIB_STRTOIMAX''@/$(GL_GNULIB_STRTOIMAX)/g' \
780 -e 's/@''GNULIB_STRTOUMAX''@/$(GL_GNULIB_STRTOUMAX)/g' \
781 -e 's/@''HAVE_DECL_IMAXABS''@/$(HAVE_DECL_IMAXABS)/g' \
782 -e 's/@''HAVE_DECL_IMAXDIV''@/$(HAVE_DECL_IMAXDIV)/g' \
783 -e 's/@''HAVE_DECL_STRTOIMAX''@/$(HAVE_DECL_STRTOIMAX)/g' \
784 -e 's/@''HAVE_DECL_STRTOUMAX''@/$(HAVE_DECL_STRTOUMAX)/g' \
785 -e 's/@''HAVE_IMAXDIV_T''@/$(HAVE_IMAXDIV_T)/g' \
786 -e 's/@''REPLACE_STRTOIMAX''@/$(REPLACE_STRTOIMAX)/g' \
787 -e 's/@''REPLACE_STRTOUMAX''@/$(REPLACE_STRTOUMAX)/g' \
788 -e 's/@''INT32_MAX_LT_INTMAX_MAX''@/$(INT32_MAX_LT_INTMAX_MAX)/g' \
789 -e 's/@''INT64_MAX_EQ_LONG_MAX''@/$(INT64_MAX_EQ_LONG_MAX)/g' \
790 -e 's/@''UINT32_MAX_LT_UINTMAX_MAX''@/$(UINT32_MAX_LT_UINTMAX_MAX)/g' \
791 -e 's/@''UINT64_MAX_EQ_ULONG_MAX''@/$(UINT64_MAX_EQ_ULONG_MAX)/g' \
792 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
793 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
794 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
795 < $(srcdir)/inttypes.in.h; \
796 } > $@-t && \
797 mv $@-t $@
798MOSTLYCLEANFILES += inttypes.h inttypes.h-t
799
800EXTRA_DIST += inttypes.in.h
801
802## end gnulib module inttypes-incomplete
803
429## begin gnulib module langinfo 804## begin gnulib module langinfo
430 805
431BUILT_SOURCES += langinfo.h 806BUILT_SOURCES += langinfo.h
@@ -441,9 +816,10 @@ langinfo.h: langinfo.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_U
441 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 816 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
442 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 817 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
443 -e 's|@''NEXT_LANGINFO_H''@|$(NEXT_LANGINFO_H)|g' \ 818 -e 's|@''NEXT_LANGINFO_H''@|$(NEXT_LANGINFO_H)|g' \
444 -e 's/@''GNULIB_NL_LANGINFO''@/$(GNULIB_NL_LANGINFO)/g' \ 819 -e 's/@''GNULIB_NL_LANGINFO''@/$(GL_GNULIB_NL_LANGINFO)/g' \
445 -e 's|@''HAVE_LANGINFO_CODESET''@|$(HAVE_LANGINFO_CODESET)|g' \ 820 -e 's|@''HAVE_LANGINFO_CODESET''@|$(HAVE_LANGINFO_CODESET)|g' \
446 -e 's|@''HAVE_LANGINFO_T_FMT_AMPM''@|$(HAVE_LANGINFO_T_FMT_AMPM)|g' \ 821 -e 's|@''HAVE_LANGINFO_T_FMT_AMPM''@|$(HAVE_LANGINFO_T_FMT_AMPM)|g' \
822 -e 's|@''HAVE_LANGINFO_ALTMON''@|$(HAVE_LANGINFO_ALTMON)|g' \
447 -e 's|@''HAVE_LANGINFO_ERA''@|$(HAVE_LANGINFO_ERA)|g' \ 823 -e 's|@''HAVE_LANGINFO_ERA''@|$(HAVE_LANGINFO_ERA)|g' \
448 -e 's|@''HAVE_LANGINFO_YESEXPR''@|$(HAVE_LANGINFO_YESEXPR)|g' \ 824 -e 's|@''HAVE_LANGINFO_YESEXPR''@|$(HAVE_LANGINFO_YESEXPR)|g' \
449 -e 's|@''HAVE_NL_LANGINFO''@|$(HAVE_NL_LANGINFO)|g' \ 825 -e 's|@''HAVE_NL_LANGINFO''@|$(HAVE_NL_LANGINFO)|g' \
@@ -459,77 +835,46 @@ EXTRA_DIST += langinfo.in.h
459 835
460## end gnulib module langinfo 836## end gnulib module langinfo
461 837
462## begin gnulib module localcharset 838## begin gnulib module libc-config
463 839
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 840
519charset.alias: config.charset 841EXTRA_DIST += cdefs.h libc-config.h
520 $(AM_V_GEN)rm -f t-$@ $@ && \ 842
521 $(SHELL) $(srcdir)/config.charset '$(host)' > t-$@ && \ 843## end gnulib module libc-config
522 mv t-$@ $@ 844
845## begin gnulib module limits-h
523 846
524SUFFIXES += .sed .sin 847BUILT_SOURCES += $(LIMITS_H)
525.sin.sed:
526 $(AM_V_GEN)rm -f t-$@ $@ && \
527 sed -e '/^#/d' -e 's/@''PACKAGE''@/$(PACKAGE)/g' $< > t-$@ && \
528 mv t-$@ $@
529 848
530CLEANFILES += charset.alias ref-add.sed ref-del.sed 849# We need the following in order to create <limits.h> when the system
850# doesn't have one that is compatible with GNU.
851if GL_GENERATE_LIMITS_H
852limits.h: limits.in.h $(top_builddir)/config.status
853 $(AM_V_GEN)rm -f $@-t $@ && \
854 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
855 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
856 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
857 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
858 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
859 -e 's|@''NEXT_LIMITS_H''@|$(NEXT_LIMITS_H)|g' \
860 < $(srcdir)/limits.in.h; \
861 } > $@-t && \
862 mv $@-t $@
863else
864limits.h: $(top_builddir)/config.status
865 rm -f $@
866endif
867MOSTLYCLEANFILES += limits.h limits.h-t
531 868
532EXTRA_DIST += config.charset ref-add.sin ref-del.sin 869EXTRA_DIST += limits.in.h
870
871## end gnulib module limits-h
872
873## begin gnulib module localcharset
874
875libgnu_a_SOURCES += localcharset.c
876
877EXTRA_DIST += localcharset.h
533 878
534## end gnulib module localcharset 879## end gnulib module localcharset
535 880
@@ -547,15 +892,22 @@ locale.h: locale.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
547 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 892 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
548 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 893 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
549 -e 's|@''NEXT_LOCALE_H''@|$(NEXT_LOCALE_H)|g' \ 894 -e 's|@''NEXT_LOCALE_H''@|$(NEXT_LOCALE_H)|g' \
550 -e 's/@''GNULIB_LOCALECONV''@/$(GNULIB_LOCALECONV)/g' \ 895 -e 's/@''GNULIB_LOCALECONV''@/$(GL_GNULIB_LOCALECONV)/g' \
551 -e 's/@''GNULIB_SETLOCALE''@/$(GNULIB_SETLOCALE)/g' \ 896 -e 's/@''GNULIB_SETLOCALE''@/$(GL_GNULIB_SETLOCALE)/g' \
552 -e 's/@''GNULIB_DUPLOCALE''@/$(GNULIB_DUPLOCALE)/g' \ 897 -e 's/@''GNULIB_SETLOCALE_NULL''@/$(GL_GNULIB_SETLOCALE_NULL)/g' \
898 -e 's/@''GNULIB_DUPLOCALE''@/$(GL_GNULIB_DUPLOCALE)/g' \
899 -e 's/@''GNULIB_LOCALENAME''@/$(GL_GNULIB_LOCALENAME)/g' \
900 -e 's|@''HAVE_NEWLOCALE''@|$(HAVE_NEWLOCALE)|g' \
553 -e 's|@''HAVE_DUPLOCALE''@|$(HAVE_DUPLOCALE)|g' \ 901 -e 's|@''HAVE_DUPLOCALE''@|$(HAVE_DUPLOCALE)|g' \
902 -e 's|@''HAVE_FREELOCALE''@|$(HAVE_FREELOCALE)|g' \
554 -e 's|@''HAVE_XLOCALE_H''@|$(HAVE_XLOCALE_H)|g' \ 903 -e 's|@''HAVE_XLOCALE_H''@|$(HAVE_XLOCALE_H)|g' \
555 -e 's|@''REPLACE_LOCALECONV''@|$(REPLACE_LOCALECONV)|g' \ 904 -e 's|@''REPLACE_LOCALECONV''@|$(REPLACE_LOCALECONV)|g' \
556 -e 's|@''REPLACE_SETLOCALE''@|$(REPLACE_SETLOCALE)|g' \ 905 -e 's|@''REPLACE_SETLOCALE''@|$(REPLACE_SETLOCALE)|g' \
906 -e 's|@''REPLACE_NEWLOCALE''@|$(REPLACE_NEWLOCALE)|g' \
557 -e 's|@''REPLACE_DUPLOCALE''@|$(REPLACE_DUPLOCALE)|g' \ 907 -e 's|@''REPLACE_DUPLOCALE''@|$(REPLACE_DUPLOCALE)|g' \
908 -e 's|@''REPLACE_FREELOCALE''@|$(REPLACE_FREELOCALE)|g' \
558 -e 's|@''REPLACE_STRUCT_LCONV''@|$(REPLACE_STRUCT_LCONV)|g' \ 909 -e 's|@''REPLACE_STRUCT_LCONV''@|$(REPLACE_STRUCT_LCONV)|g' \
910 -e 's|@''LOCALENAME_ENHANCE_LOCALE_FUNCS''@|$(LOCALENAME_ENHANCE_LOCALE_FUNCS)|g' \
559 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 911 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
560 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ 912 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
561 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ 913 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
@@ -583,6 +935,15 @@ libgnu_a_SOURCES += glthread/lock.h glthread/lock.c
583 935
584## end gnulib module lock 936## end gnulib module lock
585 937
938## begin gnulib module lseek
939
940
941EXTRA_DIST += lseek.c
942
943EXTRA_libgnu_a_SOURCES += lseek.c
944
945## end gnulib module lseek
946
586## begin gnulib module malloc-gnu 947## begin gnulib module malloc-gnu
587 948
588 949
@@ -605,7 +966,7 @@ EXTRA_libgnu_a_SOURCES += malloc.c
605 966
606libgnu_a_SOURCES += malloca.c 967libgnu_a_SOURCES += malloca.c
607 968
608EXTRA_DIST += malloca.h malloca.valgrind 969EXTRA_DIST += malloca.h
609 970
610## end gnulib module malloca 971## end gnulib module malloca
611 972
@@ -624,102 +985,108 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
624 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 985 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
625 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 986 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
626 -e 's|@''NEXT_AS_FIRST_DIRECTIVE_MATH_H''@|$(NEXT_AS_FIRST_DIRECTIVE_MATH_H)|g' \ 987 -e 's|@''NEXT_AS_FIRST_DIRECTIVE_MATH_H''@|$(NEXT_AS_FIRST_DIRECTIVE_MATH_H)|g' \
627 -e 's/@''GNULIB_ACOSF''@/$(GNULIB_ACOSF)/g' \ 988 -e 's/@''GNULIB_ACOSF''@/$(GL_GNULIB_ACOSF)/g' \
628 -e 's/@''GNULIB_ACOSL''@/$(GNULIB_ACOSL)/g' \ 989 -e 's/@''GNULIB_ACOSL''@/$(GL_GNULIB_ACOSL)/g' \
629 -e 's/@''GNULIB_ASINF''@/$(GNULIB_ASINF)/g' \ 990 -e 's/@''GNULIB_ASINF''@/$(GL_GNULIB_ASINF)/g' \
630 -e 's/@''GNULIB_ASINL''@/$(GNULIB_ASINL)/g' \ 991 -e 's/@''GNULIB_ASINL''@/$(GL_GNULIB_ASINL)/g' \
631 -e 's/@''GNULIB_ATANF''@/$(GNULIB_ATANF)/g' \ 992 -e 's/@''GNULIB_ATANF''@/$(GL_GNULIB_ATANF)/g' \
632 -e 's/@''GNULIB_ATANL''@/$(GNULIB_ATANL)/g' \ 993 -e 's/@''GNULIB_ATANL''@/$(GL_GNULIB_ATANL)/g' \
633 -e 's/@''GNULIB_ATAN2F''@/$(GNULIB_ATAN2F)/g' \ 994 -e 's/@''GNULIB_ATAN2F''@/$(GL_GNULIB_ATAN2F)/g' \
634 -e 's/@''GNULIB_CBRT''@/$(GNULIB_CBRT)/g' \ 995 -e 's/@''GNULIB_CBRT''@/$(GL_GNULIB_CBRT)/g' \
635 -e 's/@''GNULIB_CBRTF''@/$(GNULIB_CBRTF)/g' \ 996 -e 's/@''GNULIB_CBRTF''@/$(GL_GNULIB_CBRTF)/g' \
636 -e 's/@''GNULIB_CBRTL''@/$(GNULIB_CBRTL)/g' \ 997 -e 's/@''GNULIB_CBRTL''@/$(GL_GNULIB_CBRTL)/g' \
637 -e 's/@''GNULIB_CEIL''@/$(GNULIB_CEIL)/g' \ 998 -e 's/@''GNULIB_CEIL''@/$(GL_GNULIB_CEIL)/g' \
638 -e 's/@''GNULIB_CEILF''@/$(GNULIB_CEILF)/g' \ 999 -e 's/@''GNULIB_CEILF''@/$(GL_GNULIB_CEILF)/g' \
639 -e 's/@''GNULIB_CEILL''@/$(GNULIB_CEILL)/g' \ 1000 -e 's/@''GNULIB_CEILL''@/$(GL_GNULIB_CEILL)/g' \
640 -e 's/@''GNULIB_COPYSIGN''@/$(GNULIB_COPYSIGN)/g' \ 1001 -e 's/@''GNULIB_COPYSIGN''@/$(GL_GNULIB_COPYSIGN)/g' \
641 -e 's/@''GNULIB_COPYSIGNF''@/$(GNULIB_COPYSIGNF)/g' \ 1002 -e 's/@''GNULIB_COPYSIGNF''@/$(GL_GNULIB_COPYSIGNF)/g' \
642 -e 's/@''GNULIB_COPYSIGNL''@/$(GNULIB_COPYSIGNL)/g' \ 1003 -e 's/@''GNULIB_COPYSIGNL''@/$(GL_GNULIB_COPYSIGNL)/g' \
643 -e 's/@''GNULIB_COSF''@/$(GNULIB_COSF)/g' \ 1004 -e 's/@''GNULIB_COSF''@/$(GL_GNULIB_COSF)/g' \
644 -e 's/@''GNULIB_COSL''@/$(GNULIB_COSL)/g' \ 1005 -e 's/@''GNULIB_COSL''@/$(GL_GNULIB_COSL)/g' \
645 -e 's/@''GNULIB_COSHF''@/$(GNULIB_COSHF)/g' \ 1006 -e 's/@''GNULIB_COSHF''@/$(GL_GNULIB_COSHF)/g' \
646 -e 's/@''GNULIB_EXPF''@/$(GNULIB_EXPF)/g' \ 1007 -e 's/@''GNULIB_EXPF''@/$(GL_GNULIB_EXPF)/g' \
647 -e 's/@''GNULIB_EXPL''@/$(GNULIB_EXPL)/g' \ 1008 -e 's/@''GNULIB_EXPL''@/$(GL_GNULIB_EXPL)/g' \
648 -e 's/@''GNULIB_EXP2''@/$(GNULIB_EXP2)/g' \ 1009 -e 's/@''GNULIB_EXP2''@/$(GL_GNULIB_EXP2)/g' \
649 -e 's/@''GNULIB_EXP2F''@/$(GNULIB_EXP2F)/g' \ 1010 -e 's/@''GNULIB_EXP2F''@/$(GL_GNULIB_EXP2F)/g' \
650 -e 's/@''GNULIB_EXP2L''@/$(GNULIB_EXP2L)/g' \ 1011 -e 's/@''GNULIB_EXP2L''@/$(GL_GNULIB_EXP2L)/g' \
651 -e 's/@''GNULIB_EXPM1''@/$(GNULIB_EXPM1)/g' \ 1012 -e 's/@''GNULIB_EXPM1''@/$(GL_GNULIB_EXPM1)/g' \
652 -e 's/@''GNULIB_EXPM1F''@/$(GNULIB_EXPM1F)/g' \ 1013 -e 's/@''GNULIB_EXPM1F''@/$(GL_GNULIB_EXPM1F)/g' \
653 -e 's/@''GNULIB_EXPM1L''@/$(GNULIB_EXPM1L)/g' \ 1014 -e 's/@''GNULIB_EXPM1L''@/$(GL_GNULIB_EXPM1L)/g' \
654 -e 's/@''GNULIB_FABSF''@/$(GNULIB_FABSF)/g' \ 1015 -e 's/@''GNULIB_FABSF''@/$(GL_GNULIB_FABSF)/g' \
655 -e 's/@''GNULIB_FABSL''@/$(GNULIB_FABSL)/g' \ 1016 -e 's/@''GNULIB_FABSL''@/$(GL_GNULIB_FABSL)/g' \
656 -e 's/@''GNULIB_FLOOR''@/$(GNULIB_FLOOR)/g' \ 1017 -e 's/@''GNULIB_FLOOR''@/$(GL_GNULIB_FLOOR)/g' \
657 -e 's/@''GNULIB_FLOORF''@/$(GNULIB_FLOORF)/g' \ 1018 -e 's/@''GNULIB_FLOORF''@/$(GL_GNULIB_FLOORF)/g' \
658 -e 's/@''GNULIB_FLOORL''@/$(GNULIB_FLOORL)/g' \ 1019 -e 's/@''GNULIB_FLOORL''@/$(GL_GNULIB_FLOORL)/g' \
659 -e 's/@''GNULIB_FMA''@/$(GNULIB_FMA)/g' \ 1020 -e 's/@''GNULIB_FMA''@/$(GL_GNULIB_FMA)/g' \
660 -e 's/@''GNULIB_FMAF''@/$(GNULIB_FMAF)/g' \ 1021 -e 's/@''GNULIB_FMAF''@/$(GL_GNULIB_FMAF)/g' \
661 -e 's/@''GNULIB_FMAL''@/$(GNULIB_FMAL)/g' \ 1022 -e 's/@''GNULIB_FMAL''@/$(GL_GNULIB_FMAL)/g' \
662 -e 's/@''GNULIB_FMOD''@/$(GNULIB_FMOD)/g' \ 1023 -e 's/@''GNULIB_FMOD''@/$(GL_GNULIB_FMOD)/g' \
663 -e 's/@''GNULIB_FMODF''@/$(GNULIB_FMODF)/g' \ 1024 -e 's/@''GNULIB_FMODF''@/$(GL_GNULIB_FMODF)/g' \
664 -e 's/@''GNULIB_FMODL''@/$(GNULIB_FMODL)/g' \ 1025 -e 's/@''GNULIB_FMODL''@/$(GL_GNULIB_FMODL)/g' \
665 -e 's/@''GNULIB_FREXPF''@/$(GNULIB_FREXPF)/g' \ 1026 -e 's/@''GNULIB_FREXPF''@/$(GL_GNULIB_FREXPF)/g' \
666 -e 's/@''GNULIB_FREXP''@/$(GNULIB_FREXP)/g' \ 1027 -e 's/@''GNULIB_FREXP''@/$(GL_GNULIB_FREXP)/g' \
667 -e 's/@''GNULIB_FREXPL''@/$(GNULIB_FREXPL)/g' \ 1028 -e 's/@''GNULIB_FREXPL''@/$(GL_GNULIB_FREXPL)/g' \
668 -e 's/@''GNULIB_HYPOT''@/$(GNULIB_HYPOT)/g' \ 1029 -e 's/@''GNULIB_HYPOT''@/$(GL_GNULIB_HYPOT)/g' \
669 -e 's/@''GNULIB_HYPOTF''@/$(GNULIB_HYPOTF)/g' \ 1030 -e 's/@''GNULIB_HYPOTF''@/$(GL_GNULIB_HYPOTF)/g' \
670 -e 's/@''GNULIB_HYPOTL''@/$(GNULIB_HYPOTL)/g' \ 1031 -e 's/@''GNULIB_HYPOTL''@/$(GL_GNULIB_HYPOTL)/g' \
671 < $(srcdir)/math.in.h | \ 1032 < $(srcdir)/math.in.h | \
672 sed -e 's/@''GNULIB_ILOGB''@/$(GNULIB_ILOGB)/g' \ 1033 sed -e 's/@''GNULIB_ILOGB''@/$(GL_GNULIB_ILOGB)/g' \
673 -e 's/@''GNULIB_ILOGBF''@/$(GNULIB_ILOGBF)/g' \ 1034 -e 's/@''GNULIB_ILOGBF''@/$(GL_GNULIB_ILOGBF)/g' \
674 -e 's/@''GNULIB_ILOGBL''@/$(GNULIB_ILOGBL)/g' \ 1035 -e 's/@''GNULIB_ILOGBL''@/$(GL_GNULIB_ILOGBL)/g' \
675 -e 's/@''GNULIB_ISFINITE''@/$(GNULIB_ISFINITE)/g' \ 1036 -e 's/@''GNULIB_ISFINITE''@/$(GL_GNULIB_ISFINITE)/g' \
676 -e 's/@''GNULIB_ISINF''@/$(GNULIB_ISINF)/g' \ 1037 -e 's/@''GNULIB_ISINF''@/$(GL_GNULIB_ISINF)/g' \
677 -e 's/@''GNULIB_ISNAN''@/$(GNULIB_ISNAN)/g' \ 1038 -e 's/@''GNULIB_ISNAN''@/$(GL_GNULIB_ISNAN)/g' \
678 -e 's/@''GNULIB_ISNANF''@/$(GNULIB_ISNANF)/g' \ 1039 -e 's/@''GNULIB_ISNANF''@/$(GL_GNULIB_ISNANF)/g' \
679 -e 's/@''GNULIB_ISNAND''@/$(GNULIB_ISNAND)/g' \ 1040 -e 's/@''GNULIB_ISNAND''@/$(GL_GNULIB_ISNAND)/g' \
680 -e 's/@''GNULIB_ISNANL''@/$(GNULIB_ISNANL)/g' \ 1041 -e 's/@''GNULIB_ISNANL''@/$(GL_GNULIB_ISNANL)/g' \
681 -e 's/@''GNULIB_LDEXPF''@/$(GNULIB_LDEXPF)/g' \ 1042 -e 's/@''GNULIB_LDEXPF''@/$(GL_GNULIB_LDEXPF)/g' \
682 -e 's/@''GNULIB_LDEXPL''@/$(GNULIB_LDEXPL)/g' \ 1043 -e 's/@''GNULIB_LDEXPL''@/$(GL_GNULIB_LDEXPL)/g' \
683 -e 's/@''GNULIB_LOG''@/$(GNULIB_LOG)/g' \ 1044 -e 's/@''GNULIB_LOG''@/$(GL_GNULIB_LOG)/g' \
684 -e 's/@''GNULIB_LOGF''@/$(GNULIB_LOGF)/g' \ 1045 -e 's/@''GNULIB_LOGF''@/$(GL_GNULIB_LOGF)/g' \
685 -e 's/@''GNULIB_LOGL''@/$(GNULIB_LOGL)/g' \ 1046 -e 's/@''GNULIB_LOGL''@/$(GL_GNULIB_LOGL)/g' \
686 -e 's/@''GNULIB_LOG10''@/$(GNULIB_LOG10)/g' \ 1047 -e 's/@''GNULIB_LOG10''@/$(GL_GNULIB_LOG10)/g' \
687 -e 's/@''GNULIB_LOG10F''@/$(GNULIB_LOG10F)/g' \ 1048 -e 's/@''GNULIB_LOG10F''@/$(GL_GNULIB_LOG10F)/g' \
688 -e 's/@''GNULIB_LOG10L''@/$(GNULIB_LOG10L)/g' \ 1049 -e 's/@''GNULIB_LOG10L''@/$(GL_GNULIB_LOG10L)/g' \
689 -e 's/@''GNULIB_LOG1P''@/$(GNULIB_LOG1P)/g' \ 1050 -e 's/@''GNULIB_LOG1P''@/$(GL_GNULIB_LOG1P)/g' \
690 -e 's/@''GNULIB_LOG1PF''@/$(GNULIB_LOG1PF)/g' \ 1051 -e 's/@''GNULIB_LOG1PF''@/$(GL_GNULIB_LOG1PF)/g' \
691 -e 's/@''GNULIB_LOG1PL''@/$(GNULIB_LOG1PL)/g' \ 1052 -e 's/@''GNULIB_LOG1PL''@/$(GL_GNULIB_LOG1PL)/g' \
692 -e 's/@''GNULIB_LOG2''@/$(GNULIB_LOG2)/g' \ 1053 -e 's/@''GNULIB_LOG2''@/$(GL_GNULIB_LOG2)/g' \
693 -e 's/@''GNULIB_LOG2F''@/$(GNULIB_LOG2F)/g' \ 1054 -e 's/@''GNULIB_LOG2F''@/$(GL_GNULIB_LOG2F)/g' \
694 -e 's/@''GNULIB_LOG2L''@/$(GNULIB_LOG2L)/g' \ 1055 -e 's/@''GNULIB_LOG2L''@/$(GL_GNULIB_LOG2L)/g' \
695 -e 's/@''GNULIB_LOGB''@/$(GNULIB_LOGB)/g' \ 1056 -e 's/@''GNULIB_LOGB''@/$(GL_GNULIB_LOGB)/g' \
696 -e 's/@''GNULIB_LOGBF''@/$(GNULIB_LOGBF)/g' \ 1057 -e 's/@''GNULIB_LOGBF''@/$(GL_GNULIB_LOGBF)/g' \
697 -e 's/@''GNULIB_LOGBL''@/$(GNULIB_LOGBL)/g' \ 1058 -e 's/@''GNULIB_LOGBL''@/$(GL_GNULIB_LOGBL)/g' \
698 -e 's/@''GNULIB_MODF''@/$(GNULIB_MODF)/g' \ 1059 -e 's/@''GNULIB_MODF''@/$(GL_GNULIB_MODF)/g' \
699 -e 's/@''GNULIB_MODFF''@/$(GNULIB_MODFF)/g' \ 1060 -e 's/@''GNULIB_MODFF''@/$(GL_GNULIB_MODFF)/g' \
700 -e 's/@''GNULIB_MODFL''@/$(GNULIB_MODFL)/g' \ 1061 -e 's/@''GNULIB_MODFL''@/$(GL_GNULIB_MODFL)/g' \
701 -e 's/@''GNULIB_POWF''@/$(GNULIB_POWF)/g' \ 1062 -e 's/@''GNULIB_POWF''@/$(GL_GNULIB_POWF)/g' \
702 -e 's/@''GNULIB_REMAINDER''@/$(GNULIB_REMAINDER)/g' \ 1063 -e 's/@''GNULIB_REMAINDER''@/$(GL_GNULIB_REMAINDER)/g' \
703 -e 's/@''GNULIB_REMAINDERF''@/$(GNULIB_REMAINDERF)/g' \ 1064 -e 's/@''GNULIB_REMAINDERF''@/$(GL_GNULIB_REMAINDERF)/g' \
704 -e 's/@''GNULIB_REMAINDERL''@/$(GNULIB_REMAINDERL)/g' \ 1065 -e 's/@''GNULIB_REMAINDERL''@/$(GL_GNULIB_REMAINDERL)/g' \
705 -e 's/@''GNULIB_RINT''@/$(GNULIB_RINT)/g' \ 1066 -e 's/@''GNULIB_RINT''@/$(GL_GNULIB_RINT)/g' \
706 -e 's/@''GNULIB_RINTF''@/$(GNULIB_RINTF)/g' \ 1067 -e 's/@''GNULIB_RINTF''@/$(GL_GNULIB_RINTF)/g' \
707 -e 's/@''GNULIB_RINTL''@/$(GNULIB_RINTL)/g' \ 1068 -e 's/@''GNULIB_RINTL''@/$(GL_GNULIB_RINTL)/g' \
708 -e 's/@''GNULIB_ROUND''@/$(GNULIB_ROUND)/g' \ 1069 -e 's/@''GNULIB_ROUND''@/$(GL_GNULIB_ROUND)/g' \
709 -e 's/@''GNULIB_ROUNDF''@/$(GNULIB_ROUNDF)/g' \ 1070 -e 's/@''GNULIB_ROUNDF''@/$(GL_GNULIB_ROUNDF)/g' \
710 -e 's/@''GNULIB_ROUNDL''@/$(GNULIB_ROUNDL)/g' \ 1071 -e 's/@''GNULIB_ROUNDL''@/$(GL_GNULIB_ROUNDL)/g' \
711 -e 's/@''GNULIB_SIGNBIT''@/$(GNULIB_SIGNBIT)/g' \ 1072 -e 's/@''GNULIB_SIGNBIT''@/$(GL_GNULIB_SIGNBIT)/g' \
712 -e 's/@''GNULIB_SINF''@/$(GNULIB_SINF)/g' \ 1073 -e 's/@''GNULIB_SINF''@/$(GL_GNULIB_SINF)/g' \
713 -e 's/@''GNULIB_SINL''@/$(GNULIB_SINL)/g' \ 1074 -e 's/@''GNULIB_SINL''@/$(GL_GNULIB_SINL)/g' \
714 -e 's/@''GNULIB_SINHF''@/$(GNULIB_SINHF)/g' \ 1075 -e 's/@''GNULIB_SINHF''@/$(GL_GNULIB_SINHF)/g' \
715 -e 's/@''GNULIB_SQRTF''@/$(GNULIB_SQRTF)/g' \ 1076 -e 's/@''GNULIB_SQRTF''@/$(GL_GNULIB_SQRTF)/g' \
716 -e 's/@''GNULIB_SQRTL''@/$(GNULIB_SQRTL)/g' \ 1077 -e 's/@''GNULIB_SQRTL''@/$(GL_GNULIB_SQRTL)/g' \
717 -e 's/@''GNULIB_TANF''@/$(GNULIB_TANF)/g' \ 1078 -e 's/@''GNULIB_TANF''@/$(GL_GNULIB_TANF)/g' \
718 -e 's/@''GNULIB_TANL''@/$(GNULIB_TANL)/g' \ 1079 -e 's/@''GNULIB_TANL''@/$(GL_GNULIB_TANL)/g' \
719 -e 's/@''GNULIB_TANHF''@/$(GNULIB_TANHF)/g' \ 1080 -e 's/@''GNULIB_TANHF''@/$(GL_GNULIB_TANHF)/g' \
720 -e 's/@''GNULIB_TRUNC''@/$(GNULIB_TRUNC)/g' \ 1081 -e 's/@''GNULIB_TRUNC''@/$(GL_GNULIB_TRUNC)/g' \
721 -e 's/@''GNULIB_TRUNCF''@/$(GNULIB_TRUNCF)/g' \ 1082 -e 's/@''GNULIB_TRUNCF''@/$(GL_GNULIB_TRUNCF)/g' \
722 -e 's/@''GNULIB_TRUNCL''@/$(GNULIB_TRUNCL)/g' \ 1083 -e 's/@''GNULIB_TRUNCL''@/$(GL_GNULIB_TRUNCL)/g' \
1084 -e 's/@''GNULIB_MDA_J0''@/$(GL_GNULIB_MDA_J0)/g' \
1085 -e 's/@''GNULIB_MDA_J1''@/$(GL_GNULIB_MDA_J1)/g' \
1086 -e 's/@''GNULIB_MDA_JN''@/$(GL_GNULIB_MDA_JN)/g' \
1087 -e 's/@''GNULIB_MDA_Y0''@/$(GL_GNULIB_MDA_Y0)/g' \
1088 -e 's/@''GNULIB_MDA_Y1''@/$(GL_GNULIB_MDA_Y1)/g' \
1089 -e 's/@''GNULIB_MDA_YN''@/$(GL_GNULIB_MDA_YN)/g' \
723 | \ 1090 | \
724 sed -e 's|@''HAVE_ACOSF''@|$(HAVE_ACOSF)|g' \ 1091 sed -e 's|@''HAVE_ACOSF''@|$(HAVE_ACOSF)|g' \
725 -e 's|@''HAVE_ACOSL''@|$(HAVE_ACOSL)|g' \ 1092 -e 's|@''HAVE_ACOSL''@|$(HAVE_ACOSL)|g' \
@@ -818,13 +1185,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' \ 1185 -e 's|@''HAVE_DECL_TRUNCF''@|$(HAVE_DECL_TRUNCF)|g' \
819 -e 's|@''HAVE_DECL_TRUNCL''@|$(HAVE_DECL_TRUNCL)|g' \ 1186 -e 's|@''HAVE_DECL_TRUNCL''@|$(HAVE_DECL_TRUNCL)|g' \
820 | \ 1187 | \
821 sed -e 's|@''REPLACE_CBRTF''@|$(REPLACE_CBRTF)|g' \ 1188 sed -e 's|@''REPLACE_ACOSF''@|$(REPLACE_ACOSF)|g' \
1189 -e 's|@''REPLACE_ASINF''@|$(REPLACE_ASINF)|g' \
1190 -e 's|@''REPLACE_ATANF''@|$(REPLACE_ATANF)|g' \
1191 -e 's|@''REPLACE_ATAN2F''@|$(REPLACE_ATAN2F)|g' \
1192 -e 's|@''REPLACE_CBRTF''@|$(REPLACE_CBRTF)|g' \
822 -e 's|@''REPLACE_CBRTL''@|$(REPLACE_CBRTL)|g' \ 1193 -e 's|@''REPLACE_CBRTL''@|$(REPLACE_CBRTL)|g' \
823 -e 's|@''REPLACE_CEIL''@|$(REPLACE_CEIL)|g' \ 1194 -e 's|@''REPLACE_CEIL''@|$(REPLACE_CEIL)|g' \
824 -e 's|@''REPLACE_CEILF''@|$(REPLACE_CEILF)|g' \ 1195 -e 's|@''REPLACE_CEILF''@|$(REPLACE_CEILF)|g' \
825 -e 's|@''REPLACE_CEILL''@|$(REPLACE_CEILL)|g' \ 1196 -e 's|@''REPLACE_CEILL''@|$(REPLACE_CEILL)|g' \
1197 -e 's|@''REPLACE_COSF''@|$(REPLACE_COSF)|g' \
1198 -e 's|@''REPLACE_COSHF''@|$(REPLACE_COSHF)|g' \
1199 -e 's|@''REPLACE_EXPF''@|$(REPLACE_EXPF)|g' \
1200 -e 's|@''REPLACE_EXPL''@|$(REPLACE_EXPL)|g' \
826 -e 's|@''REPLACE_EXPM1''@|$(REPLACE_EXPM1)|g' \ 1201 -e 's|@''REPLACE_EXPM1''@|$(REPLACE_EXPM1)|g' \
827 -e 's|@''REPLACE_EXPM1F''@|$(REPLACE_EXPM1F)|g' \ 1202 -e 's|@''REPLACE_EXPM1F''@|$(REPLACE_EXPM1F)|g' \
1203 -e 's|@''REPLACE_EXPM1L''@|$(REPLACE_EXPM1L)|g' \
828 -e 's|@''REPLACE_EXP2''@|$(REPLACE_EXP2)|g' \ 1204 -e 's|@''REPLACE_EXP2''@|$(REPLACE_EXP2)|g' \
829 -e 's|@''REPLACE_EXP2L''@|$(REPLACE_EXP2L)|g' \ 1205 -e 's|@''REPLACE_EXP2L''@|$(REPLACE_EXP2L)|g' \
830 -e 's|@''REPLACE_FABSL''@|$(REPLACE_FABSL)|g' \ 1206 -e 's|@''REPLACE_FABSL''@|$(REPLACE_FABSL)|g' \
@@ -846,6 +1222,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
846 -e 's|@''REPLACE_HYPOTL''@|$(REPLACE_HYPOTL)|g' \ 1222 -e 's|@''REPLACE_HYPOTL''@|$(REPLACE_HYPOTL)|g' \
847 -e 's|@''REPLACE_ILOGB''@|$(REPLACE_ILOGB)|g' \ 1223 -e 's|@''REPLACE_ILOGB''@|$(REPLACE_ILOGB)|g' \
848 -e 's|@''REPLACE_ILOGBF''@|$(REPLACE_ILOGBF)|g' \ 1224 -e 's|@''REPLACE_ILOGBF''@|$(REPLACE_ILOGBF)|g' \
1225 -e 's|@''REPLACE_ILOGBL''@|$(REPLACE_ILOGBL)|g' \
849 -e 's|@''REPLACE_ISFINITE''@|$(REPLACE_ISFINITE)|g' \ 1226 -e 's|@''REPLACE_ISFINITE''@|$(REPLACE_ISFINITE)|g' \
850 -e 's|@''REPLACE_ISINF''@|$(REPLACE_ISINF)|g' \ 1227 -e 's|@''REPLACE_ISINF''@|$(REPLACE_ISINF)|g' \
851 -e 's|@''REPLACE_ISNAN''@|$(REPLACE_ISNAN)|g' \ 1228 -e 's|@''REPLACE_ISNAN''@|$(REPLACE_ISNAN)|g' \
@@ -873,12 +1250,18 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
873 -e 's|@''REPLACE_REMAINDER''@|$(REPLACE_REMAINDER)|g' \ 1250 -e 's|@''REPLACE_REMAINDER''@|$(REPLACE_REMAINDER)|g' \
874 -e 's|@''REPLACE_REMAINDERF''@|$(REPLACE_REMAINDERF)|g' \ 1251 -e 's|@''REPLACE_REMAINDERF''@|$(REPLACE_REMAINDERF)|g' \
875 -e 's|@''REPLACE_REMAINDERL''@|$(REPLACE_REMAINDERL)|g' \ 1252 -e 's|@''REPLACE_REMAINDERL''@|$(REPLACE_REMAINDERL)|g' \
1253 -e 's|@''REPLACE_RINTL''@|$(REPLACE_RINTL)|g' \
876 -e 's|@''REPLACE_ROUND''@|$(REPLACE_ROUND)|g' \ 1254 -e 's|@''REPLACE_ROUND''@|$(REPLACE_ROUND)|g' \
877 -e 's|@''REPLACE_ROUNDF''@|$(REPLACE_ROUNDF)|g' \ 1255 -e 's|@''REPLACE_ROUNDF''@|$(REPLACE_ROUNDF)|g' \
878 -e 's|@''REPLACE_ROUNDL''@|$(REPLACE_ROUNDL)|g' \ 1256 -e 's|@''REPLACE_ROUNDL''@|$(REPLACE_ROUNDL)|g' \
879 -e 's|@''REPLACE_SIGNBIT''@|$(REPLACE_SIGNBIT)|g' \ 1257 -e 's|@''REPLACE_SIGNBIT''@|$(REPLACE_SIGNBIT)|g' \
880 -e 's|@''REPLACE_SIGNBIT_USING_GCC''@|$(REPLACE_SIGNBIT_USING_GCC)|g' \ 1258 -e 's|@''REPLACE_SIGNBIT_USING_BUILTINS''@|$(REPLACE_SIGNBIT_USING_BUILTINS)|g' \
1259 -e 's|@''REPLACE_SINF''@|$(REPLACE_SINF)|g' \
1260 -e 's|@''REPLACE_SINHF''@|$(REPLACE_SINHF)|g' \
1261 -e 's|@''REPLACE_SQRTF''@|$(REPLACE_SQRTF)|g' \
881 -e 's|@''REPLACE_SQRTL''@|$(REPLACE_SQRTL)|g' \ 1262 -e 's|@''REPLACE_SQRTL''@|$(REPLACE_SQRTL)|g' \
1263 -e 's|@''REPLACE_TANF''@|$(REPLACE_TANF)|g' \
1264 -e 's|@''REPLACE_TANHF''@|$(REPLACE_TANHF)|g' \
882 -e 's|@''REPLACE_TRUNC''@|$(REPLACE_TRUNC)|g' \ 1265 -e 's|@''REPLACE_TRUNC''@|$(REPLACE_TRUNC)|g' \
883 -e 's|@''REPLACE_TRUNCF''@|$(REPLACE_TRUNCF)|g' \ 1266 -e 's|@''REPLACE_TRUNCF''@|$(REPLACE_TRUNCF)|g' \
884 -e 's|@''REPLACE_TRUNCL''@|$(REPLACE_TRUNCL)|g' \ 1267 -e 's|@''REPLACE_TRUNCL''@|$(REPLACE_TRUNCL)|g' \
@@ -896,9 +1279,9 @@ EXTRA_DIST += math.in.h
896## begin gnulib module mbrtowc 1279## begin gnulib module mbrtowc
897 1280
898 1281
899EXTRA_DIST += mbrtowc.c 1282EXTRA_DIST += lc-charset-dispatch.c lc-charset-dispatch.h mbrtowc-impl-utf8.h mbrtowc-impl.h mbrtowc.c mbtowc-lock.c mbtowc-lock.h windows-initguard.h
900 1283
901EXTRA_libgnu_a_SOURCES += mbrtowc.c 1284EXTRA_libgnu_a_SOURCES += lc-charset-dispatch.c mbrtowc.c mbtowc-lock.c
902 1285
903## end gnulib module mbrtowc 1286## end gnulib module mbrtowc
904 1287
@@ -929,6 +1312,12 @@ EXTRA_libgnu_a_SOURCES += memchr.c
929 1312
930## end gnulib module memchr 1313## end gnulib module memchr
931 1314
1315## begin gnulib module minmax
1316
1317libgnu_a_SOURCES += minmax.h
1318
1319## end gnulib module minmax
1320
932## begin gnulib module mktime 1321## begin gnulib module mktime
933 1322
934 1323
@@ -989,13 +1378,14 @@ netdb.h: netdb.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
989 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 1378 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
990 -e 's|@''NEXT_NETDB_H''@|$(NEXT_NETDB_H)|g' \ 1379 -e 's|@''NEXT_NETDB_H''@|$(NEXT_NETDB_H)|g' \
991 -e 's|@''HAVE_NETDB_H''@|$(HAVE_NETDB_H)|g' \ 1380 -e 's|@''HAVE_NETDB_H''@|$(HAVE_NETDB_H)|g' \
992 -e 's/@''GNULIB_GETADDRINFO''@/$(GNULIB_GETADDRINFO)/g' \ 1381 -e 's/@''GNULIB_GETADDRINFO''@/$(GL_GNULIB_GETADDRINFO)/g' \
993 -e 's|@''HAVE_STRUCT_ADDRINFO''@|$(HAVE_STRUCT_ADDRINFO)|g' \ 1382 -e 's|@''HAVE_STRUCT_ADDRINFO''@|$(HAVE_STRUCT_ADDRINFO)|g' \
994 -e 's|@''HAVE_DECL_FREEADDRINFO''@|$(HAVE_DECL_FREEADDRINFO)|g' \ 1383 -e 's|@''HAVE_DECL_FREEADDRINFO''@|$(HAVE_DECL_FREEADDRINFO)|g' \
995 -e 's|@''HAVE_DECL_GAI_STRERROR''@|$(HAVE_DECL_GAI_STRERROR)|g' \ 1384 -e 's|@''HAVE_DECL_GAI_STRERROR''@|$(HAVE_DECL_GAI_STRERROR)|g' \
996 -e 's|@''HAVE_DECL_GETADDRINFO''@|$(HAVE_DECL_GETADDRINFO)|g' \ 1385 -e 's|@''HAVE_DECL_GETADDRINFO''@|$(HAVE_DECL_GETADDRINFO)|g' \
997 -e 's|@''HAVE_DECL_GETNAMEINFO''@|$(HAVE_DECL_GETNAMEINFO)|g' \ 1386 -e 's|@''HAVE_DECL_GETNAMEINFO''@|$(HAVE_DECL_GETNAMEINFO)|g' \
998 -e 's|@''REPLACE_GAI_STRERROR''@|$(REPLACE_GAI_STRERROR)|g' \ 1387 -e 's|@''REPLACE_GAI_STRERROR''@|$(REPLACE_GAI_STRERROR)|g' \
1388 -e 's|@''REPLACE_GETADDRINFO''@|$(REPLACE_GETADDRINFO)|g' \
999 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 1389 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
1000 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ 1390 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
1001 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ 1391 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
@@ -1042,37 +1432,63 @@ EXTRA_DIST += netinet_in.in.h
1042## begin gnulib module nl_langinfo 1432## begin gnulib module nl_langinfo
1043 1433
1044 1434
1045EXTRA_DIST += nl_langinfo.c 1435EXTRA_DIST += nl_langinfo-lock.c nl_langinfo.c windows-initguard.h
1046 1436
1047EXTRA_libgnu_a_SOURCES += nl_langinfo.c 1437EXTRA_libgnu_a_SOURCES += nl_langinfo-lock.c nl_langinfo.c
1048 1438
1049## end gnulib module nl_langinfo 1439## end gnulib module nl_langinfo
1050 1440
1051## begin gnulib module read 1441## begin gnulib module open
1052 1442
1053 1443
1054EXTRA_DIST += read.c 1444EXTRA_DIST += open.c
1055 1445
1056EXTRA_libgnu_a_SOURCES += read.c 1446EXTRA_libgnu_a_SOURCES += open.c
1057 1447
1058## end gnulib module read 1448## end gnulib module open
1059 1449
1060## begin gnulib module regex 1450## begin gnulib module pathmax
1061 1451
1062 1452
1063EXTRA_DIST += regcomp.c regex.c regex.h regex_internal.c regex_internal.h regexec.c 1453EXTRA_DIST += pathmax.h
1064 1454
1065EXTRA_libgnu_a_SOURCES += regcomp.c regex.c regex_internal.c regexec.c 1455## end gnulib module pathmax
1066 1456
1067## end gnulib module regex 1457## begin gnulib module realloc-gnu
1458
1459
1460EXTRA_DIST += realloc.c
1461
1462EXTRA_libgnu_a_SOURCES += realloc.c
1463
1464## end gnulib module realloc-gnu
1465
1466## begin gnulib module realloc-posix
1068 1467
1069## begin gnulib module safe-read
1070 1468
1071libgnu_a_SOURCES += safe-read.c 1469EXTRA_DIST += realloc.c
1072 1470
1073EXTRA_DIST += safe-read.h 1471EXTRA_libgnu_a_SOURCES += realloc.c
1074 1472
1075## end gnulib module safe-read 1473## end gnulib module realloc-posix
1474
1475## begin gnulib module reallocarray
1476
1477
1478EXTRA_DIST += reallocarray.c
1479
1480EXTRA_libgnu_a_SOURCES += reallocarray.c
1481
1482## end gnulib module reallocarray
1483
1484## begin gnulib module regex
1485
1486
1487EXTRA_DIST += regcomp.c regex.c regex.h regex_internal.c regex_internal.h regexec.c
1488
1489EXTRA_libgnu_a_SOURCES += regcomp.c regex.c regex_internal.c regexec.c
1490
1491## end gnulib module regex
1076 1492
1077## begin gnulib module setenv 1493## begin gnulib module setenv
1078 1494
@@ -1083,6 +1499,16 @@ EXTRA_libgnu_a_SOURCES += setenv.c
1083 1499
1084## end gnulib module setenv 1500## end gnulib module setenv
1085 1501
1502## begin gnulib module setlocale-null
1503
1504libgnu_a_SOURCES += setlocale_null.c
1505
1506EXTRA_DIST += setlocale-lock.c setlocale_null.h windows-initguard.h
1507
1508EXTRA_libgnu_a_SOURCES += setlocale-lock.c
1509
1510## end gnulib module setlocale-null
1511
1086## begin gnulib module size_max 1512## begin gnulib module size_max
1087 1513
1088libgnu_a_SOURCES += size_max.h 1514libgnu_a_SOURCES += size_max.h
@@ -1092,81 +1518,48 @@ libgnu_a_SOURCES += size_max.h
1092## begin gnulib module snippet/_Noreturn 1518## begin gnulib module snippet/_Noreturn
1093 1519
1094# Because this Makefile snippet defines a variable used by other 1520# Because this Makefile snippet defines a variable used by other
1095# gnulib Makefile snippets, it must be present in all Makefile.am that 1521# gnulib Makefile snippets, it must be present in all makefiles that
1096# need it. This is ensured by the applicability 'all' defined above. 1522# need it. This is ensured by the applicability 'all' defined above.
1097 1523
1098_NORETURN_H=$(top_srcdir)/build-aux/snippet/_Noreturn.h 1524_NORETURN_H=$(srcdir)/_Noreturn.h
1099 1525
1100EXTRA_DIST += $(top_srcdir)/build-aux/snippet/_Noreturn.h 1526EXTRA_DIST += _Noreturn.h
1101 1527
1102## end gnulib module snippet/_Noreturn 1528## end gnulib module snippet/_Noreturn
1103 1529
1104## begin gnulib module snippet/arg-nonnull 1530## begin gnulib module snippet/arg-nonnull
1105 1531
1106# The BUILT_SOURCES created by this Makefile snippet are not used via #include 1532# Because this Makefile snippet defines a variable used by other
1107# statements but through direct file reference. Therefore this snippet must be 1533# 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 1534# 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 1535
1123ARG_NONNULL_H=arg-nonnull.h 1536ARG_NONNULL_H=$(srcdir)/arg-nonnull.h
1124 1537
1125EXTRA_DIST += $(top_srcdir)/build-aux/snippet/arg-nonnull.h 1538EXTRA_DIST += arg-nonnull.h
1126 1539
1127## end gnulib module snippet/arg-nonnull 1540## end gnulib module snippet/arg-nonnull
1128 1541
1129## begin gnulib module snippet/c++defs 1542## begin gnulib module snippet/c++defs
1130 1543
1131# The BUILT_SOURCES created by this Makefile snippet are not used via #include 1544# Because this Makefile snippet defines a variable used by other
1132# statements but through direct file reference. Therefore this snippet must be 1545# 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 1546# 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 1547
1147CXXDEFS_H=c++defs.h 1548CXXDEFS_H=$(srcdir)/c++defs.h
1148 1549
1149EXTRA_DIST += $(top_srcdir)/build-aux/snippet/c++defs.h 1550EXTRA_DIST += c++defs.h
1150 1551
1151## end gnulib module snippet/c++defs 1552## end gnulib module snippet/c++defs
1152 1553
1153## begin gnulib module snippet/warn-on-use 1554## begin gnulib module snippet/warn-on-use
1154 1555
1155BUILT_SOURCES += warn-on-use.h 1556# 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 1557# 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 1558# 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 1559
1167WARN_ON_USE_H=warn-on-use.h 1560WARN_ON_USE_H=$(srcdir)/warn-on-use.h
1168 1561
1169EXTRA_DIST += $(top_srcdir)/build-aux/snippet/warn-on-use.h 1562EXTRA_DIST += warn-on-use.h
1170 1563
1171## end gnulib module snippet/warn-on-use 1564## end gnulib module snippet/warn-on-use
1172 1565
@@ -1187,6 +1580,23 @@ EXTRA_DIST += w32sock.h
1187 1580
1188## end gnulib module sockets 1581## end gnulib module sockets
1189 1582
1583## begin gnulib module stat
1584
1585
1586EXTRA_DIST += stat-w32.c stat-w32.h stat.c
1587
1588EXTRA_libgnu_a_SOURCES += stat-w32.c stat.c
1589
1590## end gnulib module stat
1591
1592## begin gnulib module stat-time
1593
1594libgnu_a_SOURCES += stat-time.c
1595
1596EXTRA_DIST += stat-time.h
1597
1598## end gnulib module stat-time
1599
1190## begin gnulib module stdalign 1600## begin gnulib module stdalign
1191 1601
1192BUILT_SOURCES += $(STDALIGN_H) 1602BUILT_SOURCES += $(STDALIGN_H)
@@ -1248,6 +1658,7 @@ stddef.h: stddef.in.h $(top_builddir)/config.status
1248 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 1658 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1249 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 1659 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
1250 -e 's|@''NEXT_STDDEF_H''@|$(NEXT_STDDEF_H)|g' \ 1660 -e 's|@''NEXT_STDDEF_H''@|$(NEXT_STDDEF_H)|g' \
1661 -e 's|@''HAVE_MAX_ALIGN_T''@|$(HAVE_MAX_ALIGN_T)|g' \
1251 -e 's|@''HAVE_WCHAR_T''@|$(HAVE_WCHAR_T)|g' \ 1662 -e 's|@''HAVE_WCHAR_T''@|$(HAVE_WCHAR_T)|g' \
1252 -e 's|@''REPLACE_NULL''@|$(REPLACE_NULL)|g' \ 1663 -e 's|@''REPLACE_NULL''@|$(REPLACE_NULL)|g' \
1253 < $(srcdir)/stddef.in.h; \ 1664 < $(srcdir)/stddef.in.h; \
@@ -1279,13 +1690,12 @@ stdint.h: stdint.in.h $(top_builddir)/config.status
1279 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 1690 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1280 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 1691 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
1281 -e 's|@''NEXT_STDINT_H''@|$(NEXT_STDINT_H)|g' \ 1692 -e 's|@''NEXT_STDINT_H''@|$(NEXT_STDINT_H)|g' \
1693 -e 's/@''HAVE_C99_STDINT_H''@/$(HAVE_C99_STDINT_H)/g' \
1282 -e 's/@''HAVE_SYS_TYPES_H''@/$(HAVE_SYS_TYPES_H)/g' \ 1694 -e 's/@''HAVE_SYS_TYPES_H''@/$(HAVE_SYS_TYPES_H)/g' \
1283 -e 's/@''HAVE_INTTYPES_H''@/$(HAVE_INTTYPES_H)/g' \ 1695 -e 's/@''HAVE_INTTYPES_H''@/$(HAVE_INTTYPES_H)/g' \
1284 -e 's/@''HAVE_SYS_INTTYPES_H''@/$(HAVE_SYS_INTTYPES_H)/g' \ 1696 -e 's/@''HAVE_SYS_INTTYPES_H''@/$(HAVE_SYS_INTTYPES_H)/g' \
1285 -e 's/@''HAVE_SYS_BITYPES_H''@/$(HAVE_SYS_BITYPES_H)/g' \ 1697 -e 's/@''HAVE_SYS_BITYPES_H''@/$(HAVE_SYS_BITYPES_H)/g' \
1286 -e 's/@''HAVE_WCHAR_H''@/$(HAVE_WCHAR_H)/g' \ 1698 -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' \ 1699 -e 's/@''APPLE_UNIVERSAL_BUILD''@/$(APPLE_UNIVERSAL_BUILD)/g' \
1290 -e 's/@''BITSIZEOF_PTRDIFF_T''@/$(BITSIZEOF_PTRDIFF_T)/g' \ 1700 -e 's/@''BITSIZEOF_PTRDIFF_T''@/$(BITSIZEOF_PTRDIFF_T)/g' \
1291 -e 's/@''PTRDIFF_T_SUFFIX''@/$(PTRDIFF_T_SUFFIX)/g' \ 1701 -e 's/@''PTRDIFF_T_SUFFIX''@/$(PTRDIFF_T_SUFFIX)/g' \
@@ -1300,6 +1710,7 @@ stdint.h: stdint.in.h $(top_builddir)/config.status
1300 -e 's/@''BITSIZEOF_WINT_T''@/$(BITSIZEOF_WINT_T)/g' \ 1710 -e 's/@''BITSIZEOF_WINT_T''@/$(BITSIZEOF_WINT_T)/g' \
1301 -e 's/@''HAVE_SIGNED_WINT_T''@/$(HAVE_SIGNED_WINT_T)/g' \ 1711 -e 's/@''HAVE_SIGNED_WINT_T''@/$(HAVE_SIGNED_WINT_T)/g' \
1302 -e 's/@''WINT_T_SUFFIX''@/$(WINT_T_SUFFIX)/g' \ 1712 -e 's/@''WINT_T_SUFFIX''@/$(WINT_T_SUFFIX)/g' \
1713 -e 's/@''GNULIBHEADERS_OVERRIDE_WINT_T''@/$(GNULIBHEADERS_OVERRIDE_WINT_T)/g' \
1303 < $(srcdir)/stdint.in.h; \ 1714 < $(srcdir)/stdint.in.h; \
1304 } > $@-t && \ 1715 } > $@-t && \
1305 mv $@-t $@ 1716 mv $@-t $@
@@ -1327,61 +1738,68 @@ stdio.h: stdio.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
1327 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 1738 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1328 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 1739 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
1329 -e 's|@''NEXT_STDIO_H''@|$(NEXT_STDIO_H)|g' \ 1740 -e 's|@''NEXT_STDIO_H''@|$(NEXT_STDIO_H)|g' \
1330 -e 's/@''GNULIB_DPRINTF''@/$(GNULIB_DPRINTF)/g' \ 1741 -e 's/@''GNULIB_DPRINTF''@/$(GL_GNULIB_DPRINTF)/g' \
1331 -e 's/@''GNULIB_FCLOSE''@/$(GNULIB_FCLOSE)/g' \ 1742 -e 's/@''GNULIB_FCLOSE''@/$(GL_GNULIB_FCLOSE)/g' \
1332 -e 's/@''GNULIB_FDOPEN''@/$(GNULIB_FDOPEN)/g' \ 1743 -e 's/@''GNULIB_FDOPEN''@/$(GL_GNULIB_FDOPEN)/g' \
1333 -e 's/@''GNULIB_FFLUSH''@/$(GNULIB_FFLUSH)/g' \ 1744 -e 's/@''GNULIB_FFLUSH''@/$(GL_GNULIB_FFLUSH)/g' \
1334 -e 's/@''GNULIB_FGETC''@/$(GNULIB_FGETC)/g' \ 1745 -e 's/@''GNULIB_FGETC''@/$(GL_GNULIB_FGETC)/g' \
1335 -e 's/@''GNULIB_FGETS''@/$(GNULIB_FGETS)/g' \ 1746 -e 's/@''GNULIB_FGETS''@/$(GL_GNULIB_FGETS)/g' \
1336 -e 's/@''GNULIB_FOPEN''@/$(GNULIB_FOPEN)/g' \ 1747 -e 's/@''GNULIB_FOPEN''@/$(GL_GNULIB_FOPEN)/g' \
1337 -e 's/@''GNULIB_FPRINTF''@/$(GNULIB_FPRINTF)/g' \ 1748 -e 's/@''GNULIB_FPRINTF''@/$(GL_GNULIB_FPRINTF)/g' \
1338 -e 's/@''GNULIB_FPRINTF_POSIX''@/$(GNULIB_FPRINTF_POSIX)/g' \ 1749 -e 's/@''GNULIB_FPRINTF_POSIX''@/$(GL_GNULIB_FPRINTF_POSIX)/g' \
1339 -e 's/@''GNULIB_FPURGE''@/$(GNULIB_FPURGE)/g' \ 1750 -e 's/@''GNULIB_FPURGE''@/$(GL_GNULIB_FPURGE)/g' \
1340 -e 's/@''GNULIB_FPUTC''@/$(GNULIB_FPUTC)/g' \ 1751 -e 's/@''GNULIB_FPUTC''@/$(GL_GNULIB_FPUTC)/g' \
1341 -e 's/@''GNULIB_FPUTS''@/$(GNULIB_FPUTS)/g' \ 1752 -e 's/@''GNULIB_FPUTS''@/$(GL_GNULIB_FPUTS)/g' \
1342 -e 's/@''GNULIB_FREAD''@/$(GNULIB_FREAD)/g' \ 1753 -e 's/@''GNULIB_FREAD''@/$(GL_GNULIB_FREAD)/g' \
1343 -e 's/@''GNULIB_FREOPEN''@/$(GNULIB_FREOPEN)/g' \ 1754 -e 's/@''GNULIB_FREOPEN''@/$(GL_GNULIB_FREOPEN)/g' \
1344 -e 's/@''GNULIB_FSCANF''@/$(GNULIB_FSCANF)/g' \ 1755 -e 's/@''GNULIB_FSCANF''@/$(GL_GNULIB_FSCANF)/g' \
1345 -e 's/@''GNULIB_FSEEK''@/$(GNULIB_FSEEK)/g' \ 1756 -e 's/@''GNULIB_FSEEK''@/$(GL_GNULIB_FSEEK)/g' \
1346 -e 's/@''GNULIB_FSEEKO''@/$(GNULIB_FSEEKO)/g' \ 1757 -e 's/@''GNULIB_FSEEKO''@/$(GL_GNULIB_FSEEKO)/g' \
1347 -e 's/@''GNULIB_FTELL''@/$(GNULIB_FTELL)/g' \ 1758 -e 's/@''GNULIB_FTELL''@/$(GL_GNULIB_FTELL)/g' \
1348 -e 's/@''GNULIB_FTELLO''@/$(GNULIB_FTELLO)/g' \ 1759 -e 's/@''GNULIB_FTELLO''@/$(GL_GNULIB_FTELLO)/g' \
1349 -e 's/@''GNULIB_FWRITE''@/$(GNULIB_FWRITE)/g' \ 1760 -e 's/@''GNULIB_FWRITE''@/$(GL_GNULIB_FWRITE)/g' \
1350 -e 's/@''GNULIB_GETC''@/$(GNULIB_GETC)/g' \ 1761 -e 's/@''GNULIB_GETC''@/$(GL_GNULIB_GETC)/g' \
1351 -e 's/@''GNULIB_GETCHAR''@/$(GNULIB_GETCHAR)/g' \ 1762 -e 's/@''GNULIB_GETCHAR''@/$(GL_GNULIB_GETCHAR)/g' \
1352 -e 's/@''GNULIB_GETDELIM''@/$(GNULIB_GETDELIM)/g' \ 1763 -e 's/@''GNULIB_GETDELIM''@/$(GL_GNULIB_GETDELIM)/g' \
1353 -e 's/@''GNULIB_GETLINE''@/$(GNULIB_GETLINE)/g' \ 1764 -e 's/@''GNULIB_GETLINE''@/$(GL_GNULIB_GETLINE)/g' \
1354 -e 's/@''GNULIB_OBSTACK_PRINTF''@/$(GNULIB_OBSTACK_PRINTF)/g' \ 1765 -e 's/@''GNULIB_OBSTACK_PRINTF''@/$(GL_GNULIB_OBSTACK_PRINTF)/g' \
1355 -e 's/@''GNULIB_OBSTACK_PRINTF_POSIX''@/$(GNULIB_OBSTACK_PRINTF_POSIX)/g' \ 1766 -e 's/@''GNULIB_OBSTACK_PRINTF_POSIX''@/$(GL_GNULIB_OBSTACK_PRINTF_POSIX)/g' \
1356 -e 's/@''GNULIB_PCLOSE''@/$(GNULIB_PCLOSE)/g' \ 1767 -e 's/@''GNULIB_PCLOSE''@/$(GL_GNULIB_PCLOSE)/g' \
1357 -e 's/@''GNULIB_PERROR''@/$(GNULIB_PERROR)/g' \ 1768 -e 's/@''GNULIB_PERROR''@/$(GL_GNULIB_PERROR)/g' \
1358 -e 's/@''GNULIB_POPEN''@/$(GNULIB_POPEN)/g' \ 1769 -e 's/@''GNULIB_POPEN''@/$(GL_GNULIB_POPEN)/g' \
1359 -e 's/@''GNULIB_PRINTF''@/$(GNULIB_PRINTF)/g' \ 1770 -e 's/@''GNULIB_PRINTF''@/$(GL_GNULIB_PRINTF)/g' \
1360 -e 's/@''GNULIB_PRINTF_POSIX''@/$(GNULIB_PRINTF_POSIX)/g' \ 1771 -e 's/@''GNULIB_PRINTF_POSIX''@/$(GL_GNULIB_PRINTF_POSIX)/g' \
1361 -e 's/@''GNULIB_PUTC''@/$(GNULIB_PUTC)/g' \ 1772 -e 's/@''GNULIB_PUTC''@/$(GL_GNULIB_PUTC)/g' \
1362 -e 's/@''GNULIB_PUTCHAR''@/$(GNULIB_PUTCHAR)/g' \ 1773 -e 's/@''GNULIB_PUTCHAR''@/$(GL_GNULIB_PUTCHAR)/g' \
1363 -e 's/@''GNULIB_PUTS''@/$(GNULIB_PUTS)/g' \ 1774 -e 's/@''GNULIB_PUTS''@/$(GL_GNULIB_PUTS)/g' \
1364 -e 's/@''GNULIB_REMOVE''@/$(GNULIB_REMOVE)/g' \ 1775 -e 's/@''GNULIB_REMOVE''@/$(GL_GNULIB_REMOVE)/g' \
1365 -e 's/@''GNULIB_RENAME''@/$(GNULIB_RENAME)/g' \ 1776 -e 's/@''GNULIB_RENAME''@/$(GL_GNULIB_RENAME)/g' \
1366 -e 's/@''GNULIB_RENAMEAT''@/$(GNULIB_RENAMEAT)/g' \ 1777 -e 's/@''GNULIB_RENAMEAT''@/$(GL_GNULIB_RENAMEAT)/g' \
1367 -e 's/@''GNULIB_SCANF''@/$(GNULIB_SCANF)/g' \ 1778 -e 's/@''GNULIB_SCANF''@/$(GL_GNULIB_SCANF)/g' \
1368 -e 's/@''GNULIB_SNPRINTF''@/$(GNULIB_SNPRINTF)/g' \ 1779 -e 's/@''GNULIB_SNPRINTF''@/$(GL_GNULIB_SNPRINTF)/g' \
1369 -e 's/@''GNULIB_SPRINTF_POSIX''@/$(GNULIB_SPRINTF_POSIX)/g' \ 1780 -e 's/@''GNULIB_SPRINTF_POSIX''@/$(GL_GNULIB_SPRINTF_POSIX)/g' \
1370 -e 's/@''GNULIB_STDIO_H_NONBLOCKING''@/$(GNULIB_STDIO_H_NONBLOCKING)/g' \ 1781 -e 's/@''GNULIB_STDIO_H_NONBLOCKING''@/$(GL_GNULIB_STDIO_H_NONBLOCKING)/g' \
1371 -e 's/@''GNULIB_STDIO_H_SIGPIPE''@/$(GNULIB_STDIO_H_SIGPIPE)/g' \ 1782 -e 's/@''GNULIB_STDIO_H_SIGPIPE''@/$(GL_GNULIB_STDIO_H_SIGPIPE)/g' \
1372 -e 's/@''GNULIB_TMPFILE''@/$(GNULIB_TMPFILE)/g' \ 1783 -e 's/@''GNULIB_TMPFILE''@/$(GL_GNULIB_TMPFILE)/g' \
1373 -e 's/@''GNULIB_VASPRINTF''@/$(GNULIB_VASPRINTF)/g' \ 1784 -e 's/@''GNULIB_VASPRINTF''@/$(GL_GNULIB_VASPRINTF)/g' \
1374 -e 's/@''GNULIB_VDPRINTF''@/$(GNULIB_VDPRINTF)/g' \ 1785 -e 's/@''GNULIB_VDPRINTF''@/$(GL_GNULIB_VDPRINTF)/g' \
1375 -e 's/@''GNULIB_VFPRINTF''@/$(GNULIB_VFPRINTF)/g' \ 1786 -e 's/@''GNULIB_VFPRINTF''@/$(GL_GNULIB_VFPRINTF)/g' \
1376 -e 's/@''GNULIB_VFPRINTF_POSIX''@/$(GNULIB_VFPRINTF_POSIX)/g' \ 1787 -e 's/@''GNULIB_VFPRINTF_POSIX''@/$(GL_GNULIB_VFPRINTF_POSIX)/g' \
1377 -e 's/@''GNULIB_VFSCANF''@/$(GNULIB_VFSCANF)/g' \ 1788 -e 's/@''GNULIB_VFSCANF''@/$(GL_GNULIB_VFSCANF)/g' \
1378 -e 's/@''GNULIB_VSCANF''@/$(GNULIB_VSCANF)/g' \ 1789 -e 's/@''GNULIB_VSCANF''@/$(GL_GNULIB_VSCANF)/g' \
1379 -e 's/@''GNULIB_VPRINTF''@/$(GNULIB_VPRINTF)/g' \ 1790 -e 's/@''GNULIB_VPRINTF''@/$(GL_GNULIB_VPRINTF)/g' \
1380 -e 's/@''GNULIB_VPRINTF_POSIX''@/$(GNULIB_VPRINTF_POSIX)/g' \ 1791 -e 's/@''GNULIB_VPRINTF_POSIX''@/$(GL_GNULIB_VPRINTF_POSIX)/g' \
1381 -e 's/@''GNULIB_VSNPRINTF''@/$(GNULIB_VSNPRINTF)/g' \ 1792 -e 's/@''GNULIB_VSNPRINTF''@/$(GL_GNULIB_VSNPRINTF)/g' \
1382 -e 's/@''GNULIB_VSPRINTF_POSIX''@/$(GNULIB_VSPRINTF_POSIX)/g' \ 1793 -e 's/@''GNULIB_VSPRINTF_POSIX''@/$(GL_GNULIB_VSPRINTF_POSIX)/g' \
1794 -e 's/@''GNULIB_MDA_FCLOSEALL''@/$(GL_GNULIB_MDA_FCLOSEALL)/g' \
1795 -e 's/@''GNULIB_MDA_FDOPEN''@/$(GL_GNULIB_MDA_FDOPEN)/g' \
1796 -e 's/@''GNULIB_MDA_FILENO''@/$(GL_GNULIB_MDA_FILENO)/g' \
1797 -e 's/@''GNULIB_MDA_GETW''@/$(GL_GNULIB_MDA_GETW)/g' \
1798 -e 's/@''GNULIB_MDA_PUTW''@/$(GL_GNULIB_MDA_PUTW)/g' \
1799 -e 's/@''GNULIB_MDA_TEMPNAM''@/$(GL_GNULIB_MDA_TEMPNAM)/g' \
1383 < $(srcdir)/stdio.in.h | \ 1800 < $(srcdir)/stdio.in.h | \
1384 sed -e 's|@''HAVE_DECL_FPURGE''@|$(HAVE_DECL_FPURGE)|g' \ 1801 sed -e 's|@''HAVE_DECL_FCLOSEALL''@|$(HAVE_DECL_FCLOSEALL)|g' \
1802 -e 's|@''HAVE_DECL_FPURGE''@|$(HAVE_DECL_FPURGE)|g' \
1385 -e 's|@''HAVE_DECL_FSEEKO''@|$(HAVE_DECL_FSEEKO)|g' \ 1803 -e 's|@''HAVE_DECL_FSEEKO''@|$(HAVE_DECL_FSEEKO)|g' \
1386 -e 's|@''HAVE_DECL_FTELLO''@|$(HAVE_DECL_FTELLO)|g' \ 1804 -e 's|@''HAVE_DECL_FTELLO''@|$(HAVE_DECL_FTELLO)|g' \
1387 -e 's|@''HAVE_DECL_GETDELIM''@|$(HAVE_DECL_GETDELIM)|g' \ 1805 -e 's|@''HAVE_DECL_GETDELIM''@|$(HAVE_DECL_GETDELIM)|g' \
@@ -1456,80 +1874,121 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
1456 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 1874 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1457 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 1875 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
1458 -e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \ 1876 -e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \
1459 -e 's/@''GNULIB__EXIT''@/$(GNULIB__EXIT)/g' \ 1877 -e 's/@''GNULIB__EXIT''@/$(GL_GNULIB__EXIT)/g' \
1460 -e 's/@''GNULIB_ATOLL''@/$(GNULIB_ATOLL)/g' \ 1878 -e 's/@''GNULIB_ALIGNED_ALLOC''@/$(GL_GNULIB_ALIGNED_ALLOC)/g' \
1461 -e 's/@''GNULIB_CALLOC_POSIX''@/$(GNULIB_CALLOC_POSIX)/g' \ 1879 -e 's/@''GNULIB_ATOLL''@/$(GL_GNULIB_ATOLL)/g' \
1462 -e 's/@''GNULIB_CANONICALIZE_FILE_NAME''@/$(GNULIB_CANONICALIZE_FILE_NAME)/g' \ 1880 -e 's/@''GNULIB_CALLOC_POSIX''@/$(GL_GNULIB_CALLOC_POSIX)/g' \
1463 -e 's/@''GNULIB_GETLOADAVG''@/$(GNULIB_GETLOADAVG)/g' \ 1881 -e 's/@''GNULIB_CANONICALIZE_FILE_NAME''@/$(GL_GNULIB_CANONICALIZE_FILE_NAME)/g' \
1464 -e 's/@''GNULIB_GETSUBOPT''@/$(GNULIB_GETSUBOPT)/g' \ 1882 -e 's/@''GNULIB_FREE_POSIX''@/$(GL_GNULIB_FREE_POSIX)/g' \
1465 -e 's/@''GNULIB_GRANTPT''@/$(GNULIB_GRANTPT)/g' \ 1883 -e 's/@''GNULIB_GETLOADAVG''@/$(GL_GNULIB_GETLOADAVG)/g' \
1466 -e 's/@''GNULIB_MALLOC_POSIX''@/$(GNULIB_MALLOC_POSIX)/g' \ 1884 -e 's/@''GNULIB_GETSUBOPT''@/$(GL_GNULIB_GETSUBOPT)/g' \
1467 -e 's/@''GNULIB_MBTOWC''@/$(GNULIB_MBTOWC)/g' \ 1885 -e 's/@''GNULIB_GRANTPT''@/$(GL_GNULIB_GRANTPT)/g' \
1468 -e 's/@''GNULIB_MKDTEMP''@/$(GNULIB_MKDTEMP)/g' \ 1886 -e 's/@''GNULIB_MALLOC_POSIX''@/$(GL_GNULIB_MALLOC_POSIX)/g' \
1469 -e 's/@''GNULIB_MKOSTEMP''@/$(GNULIB_MKOSTEMP)/g' \ 1887 -e 's/@''GNULIB_MBTOWC''@/$(GL_GNULIB_MBTOWC)/g' \
1470 -e 's/@''GNULIB_MKOSTEMPS''@/$(GNULIB_MKOSTEMPS)/g' \ 1888 -e 's/@''GNULIB_MKDTEMP''@/$(GL_GNULIB_MKDTEMP)/g' \
1471 -e 's/@''GNULIB_MKSTEMP''@/$(GNULIB_MKSTEMP)/g' \ 1889 -e 's/@''GNULIB_MKOSTEMP''@/$(GL_GNULIB_MKOSTEMP)/g' \
1472 -e 's/@''GNULIB_MKSTEMPS''@/$(GNULIB_MKSTEMPS)/g' \ 1890 -e 's/@''GNULIB_MKOSTEMPS''@/$(GL_GNULIB_MKOSTEMPS)/g' \
1473 -e 's/@''GNULIB_POSIX_OPENPT''@/$(GNULIB_POSIX_OPENPT)/g' \ 1891 -e 's/@''GNULIB_MKSTEMP''@/$(GL_GNULIB_MKSTEMP)/g' \
1474 -e 's/@''GNULIB_PTSNAME''@/$(GNULIB_PTSNAME)/g' \ 1892 -e 's/@''GNULIB_MKSTEMPS''@/$(GL_GNULIB_MKSTEMPS)/g' \
1475 -e 's/@''GNULIB_PTSNAME_R''@/$(GNULIB_PTSNAME_R)/g' \ 1893 -e 's/@''GNULIB_POSIX_MEMALIGN''@/$(GL_GNULIB_POSIX_MEMALIGN)/g' \
1476 -e 's/@''GNULIB_PUTENV''@/$(GNULIB_PUTENV)/g' \ 1894 -e 's/@''GNULIB_POSIX_OPENPT''@/$(GL_GNULIB_POSIX_OPENPT)/g' \
1477 -e 's/@''GNULIB_RANDOM''@/$(GNULIB_RANDOM)/g' \ 1895 -e 's/@''GNULIB_PTSNAME''@/$(GL_GNULIB_PTSNAME)/g' \
1478 -e 's/@''GNULIB_RANDOM_R''@/$(GNULIB_RANDOM_R)/g' \ 1896 -e 's/@''GNULIB_PTSNAME_R''@/$(GL_GNULIB_PTSNAME_R)/g' \
1479 -e 's/@''GNULIB_REALLOC_POSIX''@/$(GNULIB_REALLOC_POSIX)/g' \ 1897 -e 's/@''GNULIB_PUTENV''@/$(GL_GNULIB_PUTENV)/g' \
1480 -e 's/@''GNULIB_REALPATH''@/$(GNULIB_REALPATH)/g' \ 1898 -e 's/@''GNULIB_QSORT_R''@/$(GL_GNULIB_QSORT_R)/g' \
1481 -e 's/@''GNULIB_RPMATCH''@/$(GNULIB_RPMATCH)/g' \ 1899 -e 's/@''GNULIB_RANDOM''@/$(GL_GNULIB_RANDOM)/g' \
1482 -e 's/@''GNULIB_SECURE_GETENV''@/$(GNULIB_SECURE_GETENV)/g' \ 1900 -e 's/@''GNULIB_RANDOM_R''@/$(GL_GNULIB_RANDOM_R)/g' \
1483 -e 's/@''GNULIB_SETENV''@/$(GNULIB_SETENV)/g' \ 1901 -e 's/@''GNULIB_REALLOC_POSIX''@/$(GL_GNULIB_REALLOC_POSIX)/g' \
1484 -e 's/@''GNULIB_STRTOD''@/$(GNULIB_STRTOD)/g' \ 1902 -e 's/@''GNULIB_REALLOCARRAY''@/$(GL_GNULIB_REALLOCARRAY)/g' \
1485 -e 's/@''GNULIB_STRTOLL''@/$(GNULIB_STRTOLL)/g' \ 1903 -e 's/@''GNULIB_REALPATH''@/$(GL_GNULIB_REALPATH)/g' \
1486 -e 's/@''GNULIB_STRTOULL''@/$(GNULIB_STRTOULL)/g' \ 1904 -e 's/@''GNULIB_RPMATCH''@/$(GL_GNULIB_RPMATCH)/g' \
1487 -e 's/@''GNULIB_SYSTEM_POSIX''@/$(GNULIB_SYSTEM_POSIX)/g' \ 1905 -e 's/@''GNULIB_SECURE_GETENV''@/$(GL_GNULIB_SECURE_GETENV)/g' \
1488 -e 's/@''GNULIB_UNLOCKPT''@/$(GNULIB_UNLOCKPT)/g' \ 1906 -e 's/@''GNULIB_SETENV''@/$(GL_GNULIB_SETENV)/g' \
1489 -e 's/@''GNULIB_UNSETENV''@/$(GNULIB_UNSETENV)/g' \ 1907 -e 's/@''GNULIB_STRTOD''@/$(GL_GNULIB_STRTOD)/g' \
1490 -e 's/@''GNULIB_WCTOMB''@/$(GNULIB_WCTOMB)/g' \ 1908 -e 's/@''GNULIB_STRTOL''@/$(GL_GNULIB_STRTOL)/g' \
1909 -e 's/@''GNULIB_STRTOLD''@/$(GL_GNULIB_STRTOLD)/g' \
1910 -e 's/@''GNULIB_STRTOLL''@/$(GL_GNULIB_STRTOLL)/g' \
1911 -e 's/@''GNULIB_STRTOUL''@/$(GL_GNULIB_STRTOUL)/g' \
1912 -e 's/@''GNULIB_STRTOULL''@/$(GL_GNULIB_STRTOULL)/g' \
1913 -e 's/@''GNULIB_SYSTEM_POSIX''@/$(GL_GNULIB_SYSTEM_POSIX)/g' \
1914 -e 's/@''GNULIB_UNLOCKPT''@/$(GL_GNULIB_UNLOCKPT)/g' \
1915 -e 's/@''GNULIB_UNSETENV''@/$(GL_GNULIB_UNSETENV)/g' \
1916 -e 's/@''GNULIB_WCTOMB''@/$(GL_GNULIB_WCTOMB)/g' \
1917 -e 's/@''GNULIB_MDA_ECVT''@/$(GL_GNULIB_MDA_ECVT)/g' \
1918 -e 's/@''GNULIB_MDA_FCVT''@/$(GL_GNULIB_MDA_FCVT)/g' \
1919 -e 's/@''GNULIB_MDA_GCVT''@/$(GL_GNULIB_MDA_GCVT)/g' \
1920 -e 's/@''GNULIB_MDA_MKTEMP''@/$(GL_GNULIB_MDA_MKTEMP)/g' \
1921 -e 's/@''GNULIB_MDA_PUTENV''@/$(GL_GNULIB_MDA_PUTENV)/g' \
1491 < $(srcdir)/stdlib.in.h | \ 1922 < $(srcdir)/stdlib.in.h | \
1492 sed -e 's|@''HAVE__EXIT''@|$(HAVE__EXIT)|g' \ 1923 sed -e 's|@''HAVE__EXIT''@|$(HAVE__EXIT)|g' \
1924 -e 's|@''HAVE_ALIGNED_ALLOC''@|$(HAVE_ALIGNED_ALLOC)|g' \
1493 -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \ 1925 -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \
1494 -e 's|@''HAVE_CANONICALIZE_FILE_NAME''@|$(HAVE_CANONICALIZE_FILE_NAME)|g' \ 1926 -e 's|@''HAVE_CANONICALIZE_FILE_NAME''@|$(HAVE_CANONICALIZE_FILE_NAME)|g' \
1927 -e 's|@''HAVE_DECL_ECVT''@|$(HAVE_DECL_ECVT)|g' \
1928 -e 's|@''HAVE_DECL_FCVT''@|$(HAVE_DECL_FCVT)|g' \
1929 -e 's|@''HAVE_DECL_GCVT''@|$(HAVE_DECL_GCVT)|g' \
1495 -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \ 1930 -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \
1496 -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \ 1931 -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \
1497 -e 's|@''HAVE_GRANTPT''@|$(HAVE_GRANTPT)|g' \ 1932 -e 's|@''HAVE_GRANTPT''@|$(HAVE_GRANTPT)|g' \
1933 -e 's|@''HAVE_INITSTATE''@|$(HAVE_INITSTATE)|g' \
1934 -e 's|@''HAVE_DECL_INITSTATE''@|$(HAVE_DECL_INITSTATE)|g' \
1935 -e 's|@''HAVE_MBTOWC''@|$(HAVE_MBTOWC)|g' \
1498 -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \ 1936 -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \
1499 -e 's|@''HAVE_MKOSTEMP''@|$(HAVE_MKOSTEMP)|g' \ 1937 -e 's|@''HAVE_MKOSTEMP''@|$(HAVE_MKOSTEMP)|g' \
1500 -e 's|@''HAVE_MKOSTEMPS''@|$(HAVE_MKOSTEMPS)|g' \ 1938 -e 's|@''HAVE_MKOSTEMPS''@|$(HAVE_MKOSTEMPS)|g' \
1501 -e 's|@''HAVE_MKSTEMP''@|$(HAVE_MKSTEMP)|g' \ 1939 -e 's|@''HAVE_MKSTEMP''@|$(HAVE_MKSTEMP)|g' \
1502 -e 's|@''HAVE_MKSTEMPS''@|$(HAVE_MKSTEMPS)|g' \ 1940 -e 's|@''HAVE_MKSTEMPS''@|$(HAVE_MKSTEMPS)|g' \
1941 -e 's|@''HAVE_POSIX_MEMALIGN''@|$(HAVE_POSIX_MEMALIGN)|g' \
1503 -e 's|@''HAVE_POSIX_OPENPT''@|$(HAVE_POSIX_OPENPT)|g' \ 1942 -e 's|@''HAVE_POSIX_OPENPT''@|$(HAVE_POSIX_OPENPT)|g' \
1504 -e 's|@''HAVE_PTSNAME''@|$(HAVE_PTSNAME)|g' \ 1943 -e 's|@''HAVE_PTSNAME''@|$(HAVE_PTSNAME)|g' \
1505 -e 's|@''HAVE_PTSNAME_R''@|$(HAVE_PTSNAME_R)|g' \ 1944 -e 's|@''HAVE_PTSNAME_R''@|$(HAVE_PTSNAME_R)|g' \
1945 -e 's|@''HAVE_QSORT_R''@|$(HAVE_QSORT_R)|g' \
1506 -e 's|@''HAVE_RANDOM''@|$(HAVE_RANDOM)|g' \ 1946 -e 's|@''HAVE_RANDOM''@|$(HAVE_RANDOM)|g' \
1507 -e 's|@''HAVE_RANDOM_H''@|$(HAVE_RANDOM_H)|g' \ 1947 -e 's|@''HAVE_RANDOM_H''@|$(HAVE_RANDOM_H)|g' \
1508 -e 's|@''HAVE_RANDOM_R''@|$(HAVE_RANDOM_R)|g' \ 1948 -e 's|@''HAVE_RANDOM_R''@|$(HAVE_RANDOM_R)|g' \
1949 -e 's|@''HAVE_REALLOCARRAY''@|$(HAVE_REALLOCARRAY)|g' \
1509 -e 's|@''HAVE_REALPATH''@|$(HAVE_REALPATH)|g' \ 1950 -e 's|@''HAVE_REALPATH''@|$(HAVE_REALPATH)|g' \
1510 -e 's|@''HAVE_RPMATCH''@|$(HAVE_RPMATCH)|g' \ 1951 -e 's|@''HAVE_RPMATCH''@|$(HAVE_RPMATCH)|g' \
1511 -e 's|@''HAVE_SECURE_GETENV''@|$(HAVE_SECURE_GETENV)|g' \ 1952 -e 's|@''HAVE_SECURE_GETENV''@|$(HAVE_SECURE_GETENV)|g' \
1512 -e 's|@''HAVE_DECL_SETENV''@|$(HAVE_DECL_SETENV)|g' \ 1953 -e 's|@''HAVE_DECL_SETENV''@|$(HAVE_DECL_SETENV)|g' \
1954 -e 's|@''HAVE_SETSTATE''@|$(HAVE_SETSTATE)|g' \
1955 -e 's|@''HAVE_DECL_SETSTATE''@|$(HAVE_DECL_SETSTATE)|g' \
1513 -e 's|@''HAVE_STRTOD''@|$(HAVE_STRTOD)|g' \ 1956 -e 's|@''HAVE_STRTOD''@|$(HAVE_STRTOD)|g' \
1957 -e 's|@''HAVE_STRTOL''@|$(HAVE_STRTOL)|g' \
1958 -e 's|@''HAVE_STRTOLD''@|$(HAVE_STRTOLD)|g' \
1514 -e 's|@''HAVE_STRTOLL''@|$(HAVE_STRTOLL)|g' \ 1959 -e 's|@''HAVE_STRTOLL''@|$(HAVE_STRTOLL)|g' \
1960 -e 's|@''HAVE_STRTOUL''@|$(HAVE_STRTOUL)|g' \
1515 -e 's|@''HAVE_STRTOULL''@|$(HAVE_STRTOULL)|g' \ 1961 -e 's|@''HAVE_STRTOULL''@|$(HAVE_STRTOULL)|g' \
1516 -e 's|@''HAVE_STRUCT_RANDOM_DATA''@|$(HAVE_STRUCT_RANDOM_DATA)|g' \ 1962 -e 's|@''HAVE_STRUCT_RANDOM_DATA''@|$(HAVE_STRUCT_RANDOM_DATA)|g' \
1517 -e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \ 1963 -e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \
1518 -e 's|@''HAVE_UNLOCKPT''@|$(HAVE_UNLOCKPT)|g' \ 1964 -e 's|@''HAVE_UNLOCKPT''@|$(HAVE_UNLOCKPT)|g' \
1519 -e 's|@''HAVE_DECL_UNSETENV''@|$(HAVE_DECL_UNSETENV)|g' \ 1965 -e 's|@''HAVE_DECL_UNSETENV''@|$(HAVE_DECL_UNSETENV)|g' \
1966 -e 's|@''REPLACE_ALIGNED_ALLOC''@|$(REPLACE_ALIGNED_ALLOC)|g' \
1520 -e 's|@''REPLACE_CALLOC''@|$(REPLACE_CALLOC)|g' \ 1967 -e 's|@''REPLACE_CALLOC''@|$(REPLACE_CALLOC)|g' \
1521 -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \ 1968 -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \
1969 -e 's|@''REPLACE_FREE''@|$(REPLACE_FREE)|g' \
1970 -e 's|@''REPLACE_INITSTATE''@|$(REPLACE_INITSTATE)|g' \
1522 -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \ 1971 -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \
1523 -e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \ 1972 -e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \
1524 -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \ 1973 -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
1974 -e 's|@''REPLACE_POSIX_MEMALIGN''@|$(REPLACE_POSIX_MEMALIGN)|g' \
1525 -e 's|@''REPLACE_PTSNAME''@|$(REPLACE_PTSNAME)|g' \ 1975 -e 's|@''REPLACE_PTSNAME''@|$(REPLACE_PTSNAME)|g' \
1526 -e 's|@''REPLACE_PTSNAME_R''@|$(REPLACE_PTSNAME_R)|g' \ 1976 -e 's|@''REPLACE_PTSNAME_R''@|$(REPLACE_PTSNAME_R)|g' \
1527 -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \ 1977 -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
1978 -e 's|@''REPLACE_QSORT_R''@|$(REPLACE_QSORT_R)|g' \
1979 -e 's|@''REPLACE_RANDOM''@|$(REPLACE_RANDOM)|g' \
1528 -e 's|@''REPLACE_RANDOM_R''@|$(REPLACE_RANDOM_R)|g' \ 1980 -e 's|@''REPLACE_RANDOM_R''@|$(REPLACE_RANDOM_R)|g' \
1529 -e 's|@''REPLACE_REALLOC''@|$(REPLACE_REALLOC)|g' \ 1981 -e 's|@''REPLACE_REALLOC''@|$(REPLACE_REALLOC)|g' \
1982 -e 's|@''REPLACE_REALLOCARRAY''@|$(REPLACE_REALLOCARRAY)|g' \
1530 -e 's|@''REPLACE_REALPATH''@|$(REPLACE_REALPATH)|g' \ 1983 -e 's|@''REPLACE_REALPATH''@|$(REPLACE_REALPATH)|g' \
1531 -e 's|@''REPLACE_SETENV''@|$(REPLACE_SETENV)|g' \ 1984 -e 's|@''REPLACE_SETENV''@|$(REPLACE_SETENV)|g' \
1985 -e 's|@''REPLACE_SETSTATE''@|$(REPLACE_SETSTATE)|g' \
1532 -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \ 1986 -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \
1987 -e 's|@''REPLACE_STRTOL''@|$(REPLACE_STRTOL)|g' \
1988 -e 's|@''REPLACE_STRTOLD''@|$(REPLACE_STRTOLD)|g' \
1989 -e 's|@''REPLACE_STRTOLL''@|$(REPLACE_STRTOLL)|g' \
1990 -e 's|@''REPLACE_STRTOUL''@|$(REPLACE_STRTOUL)|g' \
1991 -e 's|@''REPLACE_STRTOULL''@|$(REPLACE_STRTOULL)|g' \
1533 -e 's|@''REPLACE_UNSETENV''@|$(REPLACE_UNSETENV)|g' \ 1992 -e 's|@''REPLACE_UNSETENV''@|$(REPLACE_UNSETENV)|g' \
1534 -e 's|@''REPLACE_WCTOMB''@|$(REPLACE_WCTOMB)|g' \ 1993 -e 's|@''REPLACE_WCTOMB''@|$(REPLACE_WCTOMB)|g' \
1535 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 1994 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
@@ -1553,6 +2012,15 @@ EXTRA_libgnu_a_SOURCES += strcasecmp.c strncasecmp.c
1553 2012
1554## end gnulib module strcase 2013## end gnulib module strcase
1555 2014
2015## begin gnulib module strcasestr
2016
2017
2018EXTRA_DIST += strcasestr.c
2019
2020EXTRA_libgnu_a_SOURCES += strcasestr.c
2021
2022## end gnulib module strcasestr
2023
1556## begin gnulib module strcasestr-simple 2024## begin gnulib module strcasestr-simple
1557 2025
1558 2026
@@ -1601,48 +2069,55 @@ string.h: string.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
1601 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 2069 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1602 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 2070 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
1603 -e 's|@''NEXT_STRING_H''@|$(NEXT_STRING_H)|g' \ 2071 -e 's|@''NEXT_STRING_H''@|$(NEXT_STRING_H)|g' \
1604 -e 's/@''GNULIB_FFSL''@/$(GNULIB_FFSL)/g' \ 2072 -e 's/@''GNULIB_EXPLICIT_BZERO''@/$(GL_GNULIB_EXPLICIT_BZERO)/g' \
1605 -e 's/@''GNULIB_FFSLL''@/$(GNULIB_FFSLL)/g' \ 2073 -e 's/@''GNULIB_FFSL''@/$(GL_GNULIB_FFSL)/g' \
1606 -e 's/@''GNULIB_MBSLEN''@/$(GNULIB_MBSLEN)/g' \ 2074 -e 's/@''GNULIB_FFSLL''@/$(GL_GNULIB_FFSLL)/g' \
1607 -e 's/@''GNULIB_MBSNLEN''@/$(GNULIB_MBSNLEN)/g' \ 2075 -e 's/@''GNULIB_MBSLEN''@/$(GL_GNULIB_MBSLEN)/g' \
1608 -e 's/@''GNULIB_MBSCHR''@/$(GNULIB_MBSCHR)/g' \ 2076 -e 's/@''GNULIB_MBSNLEN''@/$(GL_GNULIB_MBSNLEN)/g' \
1609 -e 's/@''GNULIB_MBSRCHR''@/$(GNULIB_MBSRCHR)/g' \ 2077 -e 's/@''GNULIB_MBSCHR''@/$(GL_GNULIB_MBSCHR)/g' \
1610 -e 's/@''GNULIB_MBSSTR''@/$(GNULIB_MBSSTR)/g' \ 2078 -e 's/@''GNULIB_MBSRCHR''@/$(GL_GNULIB_MBSRCHR)/g' \
1611 -e 's/@''GNULIB_MBSCASECMP''@/$(GNULIB_MBSCASECMP)/g' \ 2079 -e 's/@''GNULIB_MBSSTR''@/$(GL_GNULIB_MBSSTR)/g' \
1612 -e 's/@''GNULIB_MBSNCASECMP''@/$(GNULIB_MBSNCASECMP)/g' \ 2080 -e 's/@''GNULIB_MBSCASECMP''@/$(GL_GNULIB_MBSCASECMP)/g' \
1613 -e 's/@''GNULIB_MBSPCASECMP''@/$(GNULIB_MBSPCASECMP)/g' \ 2081 -e 's/@''GNULIB_MBSNCASECMP''@/$(GL_GNULIB_MBSNCASECMP)/g' \
1614 -e 's/@''GNULIB_MBSCASESTR''@/$(GNULIB_MBSCASESTR)/g' \ 2082 -e 's/@''GNULIB_MBSPCASECMP''@/$(GL_GNULIB_MBSPCASECMP)/g' \
1615 -e 's/@''GNULIB_MBSCSPN''@/$(GNULIB_MBSCSPN)/g' \ 2083 -e 's/@''GNULIB_MBSCASESTR''@/$(GL_GNULIB_MBSCASESTR)/g' \
1616 -e 's/@''GNULIB_MBSPBRK''@/$(GNULIB_MBSPBRK)/g' \ 2084 -e 's/@''GNULIB_MBSCSPN''@/$(GL_GNULIB_MBSCSPN)/g' \
1617 -e 's/@''GNULIB_MBSSPN''@/$(GNULIB_MBSSPN)/g' \ 2085 -e 's/@''GNULIB_MBSPBRK''@/$(GL_GNULIB_MBSPBRK)/g' \
1618 -e 's/@''GNULIB_MBSSEP''@/$(GNULIB_MBSSEP)/g' \ 2086 -e 's/@''GNULIB_MBSSPN''@/$(GL_GNULIB_MBSSPN)/g' \
1619 -e 's/@''GNULIB_MBSTOK_R''@/$(GNULIB_MBSTOK_R)/g' \ 2087 -e 's/@''GNULIB_MBSSEP''@/$(GL_GNULIB_MBSSEP)/g' \
1620 -e 's/@''GNULIB_MEMCHR''@/$(GNULIB_MEMCHR)/g' \ 2088 -e 's/@''GNULIB_MBSTOK_R''@/$(GL_GNULIB_MBSTOK_R)/g' \
1621 -e 's/@''GNULIB_MEMMEM''@/$(GNULIB_MEMMEM)/g' \ 2089 -e 's/@''GNULIB_MEMCHR''@/$(GL_GNULIB_MEMCHR)/g' \
1622 -e 's/@''GNULIB_MEMPCPY''@/$(GNULIB_MEMPCPY)/g' \ 2090 -e 's/@''GNULIB_MEMMEM''@/$(GL_GNULIB_MEMMEM)/g' \
1623 -e 's/@''GNULIB_MEMRCHR''@/$(GNULIB_MEMRCHR)/g' \ 2091 -e 's/@''GNULIB_MEMPCPY''@/$(GL_GNULIB_MEMPCPY)/g' \
1624 -e 's/@''GNULIB_RAWMEMCHR''@/$(GNULIB_RAWMEMCHR)/g' \ 2092 -e 's/@''GNULIB_MEMRCHR''@/$(GL_GNULIB_MEMRCHR)/g' \
1625 -e 's/@''GNULIB_STPCPY''@/$(GNULIB_STPCPY)/g' \ 2093 -e 's/@''GNULIB_RAWMEMCHR''@/$(GL_GNULIB_RAWMEMCHR)/g' \
1626 -e 's/@''GNULIB_STPNCPY''@/$(GNULIB_STPNCPY)/g' \ 2094 -e 's/@''GNULIB_STPCPY''@/$(GL_GNULIB_STPCPY)/g' \
1627 -e 's/@''GNULIB_STRCHRNUL''@/$(GNULIB_STRCHRNUL)/g' \ 2095 -e 's/@''GNULIB_STPNCPY''@/$(GL_GNULIB_STPNCPY)/g' \
1628 -e 's/@''GNULIB_STRDUP''@/$(GNULIB_STRDUP)/g' \ 2096 -e 's/@''GNULIB_STRCHRNUL''@/$(GL_GNULIB_STRCHRNUL)/g' \
1629 -e 's/@''GNULIB_STRNCAT''@/$(GNULIB_STRNCAT)/g' \ 2097 -e 's/@''GNULIB_STRDUP''@/$(GL_GNULIB_STRDUP)/g' \
1630 -e 's/@''GNULIB_STRNDUP''@/$(GNULIB_STRNDUP)/g' \ 2098 -e 's/@''GNULIB_STRNCAT''@/$(GL_GNULIB_STRNCAT)/g' \
1631 -e 's/@''GNULIB_STRNLEN''@/$(GNULIB_STRNLEN)/g' \ 2099 -e 's/@''GNULIB_STRNDUP''@/$(GL_GNULIB_STRNDUP)/g' \
1632 -e 's/@''GNULIB_STRPBRK''@/$(GNULIB_STRPBRK)/g' \ 2100 -e 's/@''GNULIB_STRNLEN''@/$(GL_GNULIB_STRNLEN)/g' \
1633 -e 's/@''GNULIB_STRSEP''@/$(GNULIB_STRSEP)/g' \ 2101 -e 's/@''GNULIB_STRPBRK''@/$(GL_GNULIB_STRPBRK)/g' \
1634 -e 's/@''GNULIB_STRSTR''@/$(GNULIB_STRSTR)/g' \ 2102 -e 's/@''GNULIB_STRSEP''@/$(GL_GNULIB_STRSEP)/g' \
1635 -e 's/@''GNULIB_STRCASESTR''@/$(GNULIB_STRCASESTR)/g' \ 2103 -e 's/@''GNULIB_STRSTR''@/$(GL_GNULIB_STRSTR)/g' \
1636 -e 's/@''GNULIB_STRTOK_R''@/$(GNULIB_STRTOK_R)/g' \ 2104 -e 's/@''GNULIB_STRCASESTR''@/$(GL_GNULIB_STRCASESTR)/g' \
1637 -e 's/@''GNULIB_STRERROR''@/$(GNULIB_STRERROR)/g' \ 2105 -e 's/@''GNULIB_STRTOK_R''@/$(GL_GNULIB_STRTOK_R)/g' \
1638 -e 's/@''GNULIB_STRERROR_R''@/$(GNULIB_STRERROR_R)/g' \ 2106 -e 's/@''GNULIB_STRERROR''@/$(GL_GNULIB_STRERROR)/g' \
1639 -e 's/@''GNULIB_STRSIGNAL''@/$(GNULIB_STRSIGNAL)/g' \ 2107 -e 's/@''GNULIB_STRERROR_R''@/$(GL_GNULIB_STRERROR_R)/g' \
1640 -e 's/@''GNULIB_STRVERSCMP''@/$(GNULIB_STRVERSCMP)/g' \ 2108 -e 's/@''GNULIB_STRERRORNAME_NP''@/$(GL_GNULIB_STRERRORNAME_NP)/g' \
2109 -e 's/@''GNULIB_SIGABBREV_NP''@/$(GL_GNULIB_SIGABBREV_NP)/g' \
2110 -e 's/@''GNULIB_SIGDESCR_NP''@/$(GL_GNULIB_SIGDESCR_NP)/g' \
2111 -e 's/@''GNULIB_STRSIGNAL''@/$(GL_GNULIB_STRSIGNAL)/g' \
2112 -e 's/@''GNULIB_STRVERSCMP''@/$(GL_GNULIB_STRVERSCMP)/g' \
2113 -e 's/@''GNULIB_MDA_MEMCCPY''@/$(GL_GNULIB_MDA_MEMCCPY)/g' \
2114 -e 's/@''GNULIB_MDA_STRDUP''@/$(GL_GNULIB_MDA_STRDUP)/g' \
2115 -e 's/@''GNULIB_FREE_POSIX''@/$(GL_GNULIB_FREE_POSIX)/g' \
1641 < $(srcdir)/string.in.h | \ 2116 < $(srcdir)/string.in.h | \
1642 sed -e 's|@''HAVE_FFSL''@|$(HAVE_FFSL)|g' \ 2117 sed -e 's|@''HAVE_EXPLICIT_BZERO''@|$(HAVE_EXPLICIT_BZERO)|g' \
2118 -e 's|@''HAVE_FFSL''@|$(HAVE_FFSL)|g' \
1643 -e 's|@''HAVE_FFSLL''@|$(HAVE_FFSLL)|g' \ 2119 -e 's|@''HAVE_FFSLL''@|$(HAVE_FFSLL)|g' \
1644 -e 's|@''HAVE_MBSLEN''@|$(HAVE_MBSLEN)|g' \ 2120 -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' \ 2121 -e 's|@''HAVE_DECL_MEMMEM''@|$(HAVE_DECL_MEMMEM)|g' \
1647 -e 's|@''HAVE_MEMPCPY''@|$(HAVE_MEMPCPY)|g' \ 2122 -e 's|@''HAVE_MEMPCPY''@|$(HAVE_MEMPCPY)|g' \
1648 -e 's|@''HAVE_DECL_MEMRCHR''@|$(HAVE_DECL_MEMRCHR)|g' \ 2123 -e 's|@''HAVE_DECL_MEMRCHR''@|$(HAVE_DECL_MEMRCHR)|g' \
@@ -1658,22 +2133,28 @@ string.h: string.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
1658 -e 's|@''HAVE_STRCASESTR''@|$(HAVE_STRCASESTR)|g' \ 2133 -e 's|@''HAVE_STRCASESTR''@|$(HAVE_STRCASESTR)|g' \
1659 -e 's|@''HAVE_DECL_STRTOK_R''@|$(HAVE_DECL_STRTOK_R)|g' \ 2134 -e 's|@''HAVE_DECL_STRTOK_R''@|$(HAVE_DECL_STRTOK_R)|g' \
1660 -e 's|@''HAVE_DECL_STRERROR_R''@|$(HAVE_DECL_STRERROR_R)|g' \ 2135 -e 's|@''HAVE_DECL_STRERROR_R''@|$(HAVE_DECL_STRERROR_R)|g' \
2136 -e 's|@''HAVE_STRERRORNAME_NP''@|$(HAVE_STRERRORNAME_NP)|g' \
2137 -e 's|@''HAVE_SIGABBREV_NP''@|$(HAVE_SIGABBREV_NP)|g' \
2138 -e 's|@''HAVE_SIGDESCR_NP''@|$(HAVE_SIGDESCR_NP)|g' \
1661 -e 's|@''HAVE_DECL_STRSIGNAL''@|$(HAVE_DECL_STRSIGNAL)|g' \ 2139 -e 's|@''HAVE_DECL_STRSIGNAL''@|$(HAVE_DECL_STRSIGNAL)|g' \
1662 -e 's|@''HAVE_STRVERSCMP''@|$(HAVE_STRVERSCMP)|g' \ 2140 -e 's|@''HAVE_STRVERSCMP''@|$(HAVE_STRVERSCMP)|g' \
1663 -e 's|@''REPLACE_STPNCPY''@|$(REPLACE_STPNCPY)|g' \ 2141 -e 's|@''REPLACE_FFSLL''@|$(REPLACE_FFSLL)|g' \
1664 -e 's|@''REPLACE_MEMCHR''@|$(REPLACE_MEMCHR)|g' \ 2142 -e 's|@''REPLACE_MEMCHR''@|$(REPLACE_MEMCHR)|g' \
1665 -e 's|@''REPLACE_MEMMEM''@|$(REPLACE_MEMMEM)|g' \ 2143 -e 's|@''REPLACE_MEMMEM''@|$(REPLACE_MEMMEM)|g' \
1666 -e 's|@''REPLACE_STRCASESTR''@|$(REPLACE_STRCASESTR)|g' \ 2144 -e 's|@''REPLACE_FREE''@|$(REPLACE_FREE)|g' \
2145 -e 's|@''REPLACE_STPNCPY''@|$(REPLACE_STPNCPY)|g' \
1667 -e 's|@''REPLACE_STRCHRNUL''@|$(REPLACE_STRCHRNUL)|g' \ 2146 -e 's|@''REPLACE_STRCHRNUL''@|$(REPLACE_STRCHRNUL)|g' \
1668 -e 's|@''REPLACE_STRDUP''@|$(REPLACE_STRDUP)|g' \ 2147 -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' \ 2148 -e 's|@''REPLACE_STRNCAT''@|$(REPLACE_STRNCAT)|g' \
1673 -e 's|@''REPLACE_STRNDUP''@|$(REPLACE_STRNDUP)|g' \ 2149 -e 's|@''REPLACE_STRNDUP''@|$(REPLACE_STRNDUP)|g' \
1674 -e 's|@''REPLACE_STRNLEN''@|$(REPLACE_STRNLEN)|g' \ 2150 -e 's|@''REPLACE_STRNLEN''@|$(REPLACE_STRNLEN)|g' \
1675 -e 's|@''REPLACE_STRSIGNAL''@|$(REPLACE_STRSIGNAL)|g' \ 2151 -e 's|@''REPLACE_STRSTR''@|$(REPLACE_STRSTR)|g' \
2152 -e 's|@''REPLACE_STRCASESTR''@|$(REPLACE_STRCASESTR)|g' \
1676 -e 's|@''REPLACE_STRTOK_R''@|$(REPLACE_STRTOK_R)|g' \ 2153 -e 's|@''REPLACE_STRTOK_R''@|$(REPLACE_STRTOK_R)|g' \
2154 -e 's|@''REPLACE_STRERROR''@|$(REPLACE_STRERROR)|g' \
2155 -e 's|@''REPLACE_STRERROR_R''@|$(REPLACE_STRERROR_R)|g' \
2156 -e 's|@''REPLACE_STRERRORNAME_NP''@|$(REPLACE_STRERRORNAME_NP)|g' \
2157 -e 's|@''REPLACE_STRSIGNAL''@|$(REPLACE_STRSIGNAL)|g' \
1677 -e 's|@''UNDEFINE_STRTOK_R''@|$(UNDEFINE_STRTOK_R)|g' \ 2158 -e 's|@''UNDEFINE_STRTOK_R''@|$(UNDEFINE_STRTOK_R)|g' \
1678 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 2159 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
1679 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ 2160 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
@@ -1702,7 +2183,7 @@ strings.h: strings.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE
1702 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 2183 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1703 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 2184 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
1704 -e 's|@''NEXT_STRINGS_H''@|$(NEXT_STRINGS_H)|g' \ 2185 -e 's|@''NEXT_STRINGS_H''@|$(NEXT_STRINGS_H)|g' \
1705 -e 's|@''GNULIB_FFS''@|$(GNULIB_FFS)|g' \ 2186 -e 's/@''GNULIB_FFS''@/$(GL_GNULIB_FFS)/g' \
1706 -e 's|@''HAVE_FFS''@|$(HAVE_FFS)|g' \ 2187 -e 's|@''HAVE_FFS''@|$(HAVE_FFS)|g' \
1707 -e 's|@''HAVE_STRCASECMP''@|$(HAVE_STRCASECMP)|g' \ 2188 -e 's|@''HAVE_STRCASECMP''@|$(HAVE_STRCASECMP)|g' \
1708 -e 's|@''HAVE_DECL_STRNCASECMP''@|$(HAVE_DECL_STRNCASECMP)|g' \ 2189 -e 's|@''HAVE_DECL_STRNCASECMP''@|$(HAVE_DECL_STRNCASECMP)|g' \
@@ -1718,24 +2199,6 @@ EXTRA_DIST += strings.in.h
1718 2199
1719## end gnulib module strings 2200## end gnulib module strings
1720 2201
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 2202## begin gnulib module strsep
1740 2203
1741 2204
@@ -1771,22 +2234,22 @@ sys/socket.h: sys_socket.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_
1771 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 2234 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
1772 -e 's|@''NEXT_SYS_SOCKET_H''@|$(NEXT_SYS_SOCKET_H)|g' \ 2235 -e 's|@''NEXT_SYS_SOCKET_H''@|$(NEXT_SYS_SOCKET_H)|g' \
1773 -e 's|@''HAVE_SYS_SOCKET_H''@|$(HAVE_SYS_SOCKET_H)|g' \ 2236 -e 's|@''HAVE_SYS_SOCKET_H''@|$(HAVE_SYS_SOCKET_H)|g' \
1774 -e 's/@''GNULIB_CLOSE''@/$(GNULIB_CLOSE)/g' \ 2237 -e 's/@''GNULIB_CLOSE''@/$(GL_GNULIB_CLOSE)/g' \
1775 -e 's/@''GNULIB_SOCKET''@/$(GNULIB_SOCKET)/g' \ 2238 -e 's/@''GNULIB_SOCKET''@/$(GL_GNULIB_SOCKET)/g' \
1776 -e 's/@''GNULIB_CONNECT''@/$(GNULIB_CONNECT)/g' \ 2239 -e 's/@''GNULIB_CONNECT''@/$(GL_GNULIB_CONNECT)/g' \
1777 -e 's/@''GNULIB_ACCEPT''@/$(GNULIB_ACCEPT)/g' \ 2240 -e 's/@''GNULIB_ACCEPT''@/$(GL_GNULIB_ACCEPT)/g' \
1778 -e 's/@''GNULIB_BIND''@/$(GNULIB_BIND)/g' \ 2241 -e 's/@''GNULIB_BIND''@/$(GL_GNULIB_BIND)/g' \
1779 -e 's/@''GNULIB_GETPEERNAME''@/$(GNULIB_GETPEERNAME)/g' \ 2242 -e 's/@''GNULIB_GETPEERNAME''@/$(GL_GNULIB_GETPEERNAME)/g' \
1780 -e 's/@''GNULIB_GETSOCKNAME''@/$(GNULIB_GETSOCKNAME)/g' \ 2243 -e 's/@''GNULIB_GETSOCKNAME''@/$(GL_GNULIB_GETSOCKNAME)/g' \
1781 -e 's/@''GNULIB_GETSOCKOPT''@/$(GNULIB_GETSOCKOPT)/g' \ 2244 -e 's/@''GNULIB_GETSOCKOPT''@/$(GL_GNULIB_GETSOCKOPT)/g' \
1782 -e 's/@''GNULIB_LISTEN''@/$(GNULIB_LISTEN)/g' \ 2245 -e 's/@''GNULIB_LISTEN''@/$(GL_GNULIB_LISTEN)/g' \
1783 -e 's/@''GNULIB_RECV''@/$(GNULIB_RECV)/g' \ 2246 -e 's/@''GNULIB_RECV''@/$(GL_GNULIB_RECV)/g' \
1784 -e 's/@''GNULIB_SEND''@/$(GNULIB_SEND)/g' \ 2247 -e 's/@''GNULIB_SEND''@/$(GL_GNULIB_SEND)/g' \
1785 -e 's/@''GNULIB_RECVFROM''@/$(GNULIB_RECVFROM)/g' \ 2248 -e 's/@''GNULIB_RECVFROM''@/$(GL_GNULIB_RECVFROM)/g' \
1786 -e 's/@''GNULIB_SENDTO''@/$(GNULIB_SENDTO)/g' \ 2249 -e 's/@''GNULIB_SENDTO''@/$(GL_GNULIB_SENDTO)/g' \
1787 -e 's/@''GNULIB_SETSOCKOPT''@/$(GNULIB_SETSOCKOPT)/g' \ 2250 -e 's/@''GNULIB_SETSOCKOPT''@/$(GL_GNULIB_SETSOCKOPT)/g' \
1788 -e 's/@''GNULIB_SHUTDOWN''@/$(GNULIB_SHUTDOWN)/g' \ 2251 -e 's/@''GNULIB_SHUTDOWN''@/$(GL_GNULIB_SHUTDOWN)/g' \
1789 -e 's/@''GNULIB_ACCEPT4''@/$(GNULIB_ACCEPT4)/g' \ 2252 -e 's/@''GNULIB_ACCEPT4''@/$(GL_GNULIB_ACCEPT4)/g' \
1790 -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \ 2253 -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \
1791 -e 's|@''HAVE_WS2TCPIP_H''@|$(HAVE_WS2TCPIP_H)|g' \ 2254 -e 's|@''HAVE_WS2TCPIP_H''@|$(HAVE_WS2TCPIP_H)|g' \
1792 -e 's|@''HAVE_STRUCT_SOCKADDR_STORAGE''@|$(HAVE_STRUCT_SOCKADDR_STORAGE)|g' \ 2255 -e 's|@''HAVE_STRUCT_SOCKADDR_STORAGE''@|$(HAVE_STRUCT_SOCKADDR_STORAGE)|g' \
@@ -1806,6 +2269,79 @@ EXTRA_DIST += sys_socket.in.h
1806 2269
1807## end gnulib module sys_socket 2270## end gnulib module sys_socket
1808 2271
2272## begin gnulib module sys_stat
2273
2274BUILT_SOURCES += sys/stat.h
2275
2276# We need the following in order to create <sys/stat.h> when the system
2277# has one that is incomplete.
2278sys/stat.h: sys_stat.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
2279 $(AM_V_at)$(MKDIR_P) sys
2280 $(AM_V_GEN)rm -f $@-t $@ && \
2281 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
2282 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
2283 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
2284 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
2285 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
2286 -e 's|@''NEXT_SYS_STAT_H''@|$(NEXT_SYS_STAT_H)|g' \
2287 -e 's|@''WINDOWS_64_BIT_ST_SIZE''@|$(WINDOWS_64_BIT_ST_SIZE)|g' \
2288 -e 's|@''WINDOWS_STAT_TIMESPEC''@|$(WINDOWS_STAT_TIMESPEC)|g' \
2289 -e 's/@''GNULIB_FCHMODAT''@/$(GL_GNULIB_FCHMODAT)/g' \
2290 -e 's/@''GNULIB_FSTAT''@/$(GL_GNULIB_FSTAT)/g' \
2291 -e 's/@''GNULIB_FSTATAT''@/$(GL_GNULIB_FSTATAT)/g' \
2292 -e 's/@''GNULIB_FUTIMENS''@/$(GL_GNULIB_FUTIMENS)/g' \
2293 -e 's/@''GNULIB_GETUMASK''@/$(GL_GNULIB_GETUMASK)/g' \
2294 -e 's/@''GNULIB_LCHMOD''@/$(GL_GNULIB_LCHMOD)/g' \
2295 -e 's/@''GNULIB_LSTAT''@/$(GL_GNULIB_LSTAT)/g' \
2296 -e 's/@''GNULIB_MKDIR''@/$(GL_GNULIB_MKDIR)/g' \
2297 -e 's/@''GNULIB_MKDIRAT''@/$(GL_GNULIB_MKDIRAT)/g' \
2298 -e 's/@''GNULIB_MKFIFO''@/$(GL_GNULIB_MKFIFO)/g' \
2299 -e 's/@''GNULIB_MKFIFOAT''@/$(GL_GNULIB_MKFIFOAT)/g' \
2300 -e 's/@''GNULIB_MKNOD''@/$(GL_GNULIB_MKNOD)/g' \
2301 -e 's/@''GNULIB_MKNODAT''@/$(GL_GNULIB_MKNODAT)/g' \
2302 -e 's/@''GNULIB_STAT''@/$(GL_GNULIB_STAT)/g' \
2303 -e 's/@''GNULIB_UTIMENSAT''@/$(GL_GNULIB_UTIMENSAT)/g' \
2304 -e 's/@''GNULIB_OVERRIDES_STRUCT_STAT''@/$(GL_GNULIB_OVERRIDES_STRUCT_STAT)/g' \
2305 -e 's/@''GNULIB_MDA_CHMOD''@/$(GL_GNULIB_MDA_CHMOD)/g' \
2306 -e 's/@''GNULIB_MDA_MKDIR''@/$(GL_GNULIB_MDA_MKDIR)/g' \
2307 -e 's/@''GNULIB_MDA_UMASK''@/$(GL_GNULIB_MDA_UMASK)/g' \
2308 -e 's|@''HAVE_FCHMODAT''@|$(HAVE_FCHMODAT)|g' \
2309 -e 's|@''HAVE_FSTATAT''@|$(HAVE_FSTATAT)|g' \
2310 -e 's|@''HAVE_FUTIMENS''@|$(HAVE_FUTIMENS)|g' \
2311 -e 's|@''HAVE_GETUMASK''@|$(HAVE_GETUMASK)|g' \
2312 -e 's|@''HAVE_LCHMOD''@|$(HAVE_LCHMOD)|g' \
2313 -e 's|@''HAVE_LSTAT''@|$(HAVE_LSTAT)|g' \
2314 -e 's|@''HAVE_MKDIRAT''@|$(HAVE_MKDIRAT)|g' \
2315 -e 's|@''HAVE_MKFIFO''@|$(HAVE_MKFIFO)|g' \
2316 -e 's|@''HAVE_MKFIFOAT''@|$(HAVE_MKFIFOAT)|g' \
2317 -e 's|@''HAVE_MKNOD''@|$(HAVE_MKNOD)|g' \
2318 -e 's|@''HAVE_MKNODAT''@|$(HAVE_MKNODAT)|g' \
2319 -e 's|@''HAVE_UTIMENSAT''@|$(HAVE_UTIMENSAT)|g' \
2320 -e 's|@''REPLACE_FCHMODAT''@|$(REPLACE_FCHMODAT)|g' \
2321 -e 's|@''REPLACE_FSTAT''@|$(REPLACE_FSTAT)|g' \
2322 -e 's|@''REPLACE_FSTATAT''@|$(REPLACE_FSTATAT)|g' \
2323 -e 's|@''REPLACE_FUTIMENS''@|$(REPLACE_FUTIMENS)|g' \
2324 -e 's|@''REPLACE_LSTAT''@|$(REPLACE_LSTAT)|g' \
2325 -e 's|@''REPLACE_MKDIR''@|$(REPLACE_MKDIR)|g' \
2326 -e 's|@''REPLACE_MKFIFO''@|$(REPLACE_MKFIFO)|g' \
2327 -e 's|@''REPLACE_MKFIFOAT''@|$(REPLACE_MKFIFOAT)|g' \
2328 -e 's|@''REPLACE_MKNOD''@|$(REPLACE_MKNOD)|g' \
2329 -e 's|@''REPLACE_MKNODAT''@|$(REPLACE_MKNODAT)|g' \
2330 -e 's|@''REPLACE_STAT''@|$(REPLACE_STAT)|g' \
2331 -e 's|@''REPLACE_UTIMENSAT''@|$(REPLACE_UTIMENSAT)|g' \
2332 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
2333 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
2334 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
2335 < $(srcdir)/sys_stat.in.h; \
2336 } > $@-t && \
2337 mv $@-t $@
2338MOSTLYCLEANFILES += sys/stat.h sys/stat.h-t
2339MOSTLYCLEANDIRS += sys
2340
2341EXTRA_DIST += sys_stat.in.h
2342
2343## end gnulib module sys_stat
2344
1809## begin gnulib module sys_types 2345## begin gnulib module sys_types
1810 2346
1811BUILT_SOURCES += sys/types.h 2347BUILT_SOURCES += sys/types.h
@@ -1822,6 +2358,7 @@ sys/types.h: sys_types.in.h $(top_builddir)/config.status
1822 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 2358 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
1823 -e 's|@''NEXT_SYS_TYPES_H''@|$(NEXT_SYS_TYPES_H)|g' \ 2359 -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' \ 2360 -e 's|@''WINDOWS_64_BIT_OFF_T''@|$(WINDOWS_64_BIT_OFF_T)|g' \
2361 -e 's|@''WINDOWS_STAT_INODES''@|$(WINDOWS_STAT_INODES)|g' \
1825 < $(srcdir)/sys_types.in.h; \ 2362 < $(srcdir)/sys_types.in.h; \
1826 } > $@-t && \ 2363 } > $@-t && \
1827 mv $@-t $@ 2364 mv $@-t $@
@@ -1861,8 +2398,6 @@ EXTRA_DIST += sys_uio.in.h
1861 2398
1862libgnu_a_SOURCES += glthread/threadlib.c 2399libgnu_a_SOURCES += glthread/threadlib.c
1863 2400
1864EXTRA_DIST += $(top_srcdir)/build-aux/config.rpath
1865
1866## end gnulib module threadlib 2401## end gnulib module threadlib
1867 2402
1868## begin gnulib module time 2403## begin gnulib module time
@@ -1879,22 +2414,38 @@ time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
1879 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 2414 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
1880 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 2415 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
1881 -e 's|@''NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \ 2416 -e 's|@''NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \
1882 -e 's/@''GNULIB_MKTIME''@/$(GNULIB_MKTIME)/g' \ 2417 -e 's/@''GNULIB_CTIME''@/$(GL_GNULIB_CTIME)/g' \
1883 -e 's/@''GNULIB_NANOSLEEP''@/$(GNULIB_NANOSLEEP)/g' \ 2418 -e 's/@''GNULIB_LOCALTIME''@/$(GL_GNULIB_LOCALTIME)/g' \
1884 -e 's/@''GNULIB_STRPTIME''@/$(GNULIB_STRPTIME)/g' \ 2419 -e 's/@''GNULIB_MKTIME''@/$(GL_GNULIB_MKTIME)/g' \
1885 -e 's/@''GNULIB_TIMEGM''@/$(GNULIB_TIMEGM)/g' \ 2420 -e 's/@''GNULIB_NANOSLEEP''@/$(GL_GNULIB_NANOSLEEP)/g' \
1886 -e 's/@''GNULIB_TIME_R''@/$(GNULIB_TIME_R)/g' \ 2421 -e 's/@''GNULIB_STRFTIME''@/$(GL_GNULIB_STRFTIME)/g' \
2422 -e 's/@''GNULIB_STRPTIME''@/$(GL_GNULIB_STRPTIME)/g' \
2423 -e 's/@''GNULIB_TIMEGM''@/$(GL_GNULIB_TIMEGM)/g' \
2424 -e 's/@''GNULIB_TIMESPEC_GET''@/$(GL_GNULIB_TIMESPEC_GET)/g' \
2425 -e 's/@''GNULIB_TIME_R''@/$(GL_GNULIB_TIME_R)/g' \
2426 -e 's/@''GNULIB_TIME_RZ''@/$(GL_GNULIB_TIME_RZ)/g' \
2427 -e 's/@''GNULIB_TZSET''@/$(GL_GNULIB_TZSET)/g' \
2428 -e 's/@''GNULIB_MDA_TZSET''@/$(GL_GNULIB_MDA_TZSET)/g' \
1887 -e 's|@''HAVE_DECL_LOCALTIME_R''@|$(HAVE_DECL_LOCALTIME_R)|g' \ 2429 -e 's|@''HAVE_DECL_LOCALTIME_R''@|$(HAVE_DECL_LOCALTIME_R)|g' \
1888 -e 's|@''HAVE_NANOSLEEP''@|$(HAVE_NANOSLEEP)|g' \ 2430 -e 's|@''HAVE_NANOSLEEP''@|$(HAVE_NANOSLEEP)|g' \
1889 -e 's|@''HAVE_STRPTIME''@|$(HAVE_STRPTIME)|g' \ 2431 -e 's|@''HAVE_STRPTIME''@|$(HAVE_STRPTIME)|g' \
1890 -e 's|@''HAVE_TIMEGM''@|$(HAVE_TIMEGM)|g' \ 2432 -e 's|@''HAVE_TIMEGM''@|$(HAVE_TIMEGM)|g' \
2433 -e 's|@''HAVE_TIMESPEC_GET''@|$(HAVE_TIMESPEC_GET)|g' \
2434 -e 's|@''HAVE_TIMEZONE_T''@|$(HAVE_TIMEZONE_T)|g' \
2435 -e 's|@''REPLACE_CTIME''@|$(REPLACE_CTIME)|g' \
2436 -e 's|@''REPLACE_GMTIME''@|$(REPLACE_GMTIME)|g' \
2437 -e 's|@''REPLACE_LOCALTIME''@|$(REPLACE_LOCALTIME)|g' \
1891 -e 's|@''REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \ 2438 -e 's|@''REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \
1892 -e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \ 2439 -e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \
1893 -e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \ 2440 -e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \
2441 -e 's|@''REPLACE_STRFTIME''@|$(REPLACE_STRFTIME)|g' \
1894 -e 's|@''REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \ 2442 -e 's|@''REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \
2443 -e 's|@''REPLACE_TZSET''@|$(REPLACE_TZSET)|g' \
1895 -e 's|@''PTHREAD_H_DEFINES_STRUCT_TIMESPEC''@|$(PTHREAD_H_DEFINES_STRUCT_TIMESPEC)|g' \ 2444 -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' \ 2445 -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' \ 2446 -e 's|@''TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \
2447 -e 's|@''UNISTD_H_DEFINES_STRUCT_TIMESPEC''@|$(UNISTD_H_DEFINES_STRUCT_TIMESPEC)|g' \
2448 -e 's|@''TIME_H_DEFINES_TIME_UTC''@|$(TIME_H_DEFINES_TIME_UTC)|g' \
1898 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 2449 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
1899 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ 2450 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
1900 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ 2451 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
@@ -1942,60 +2493,95 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
1942 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 2493 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
1943 -e 's|@''NEXT_UNISTD_H''@|$(NEXT_UNISTD_H)|g' \ 2494 -e 's|@''NEXT_UNISTD_H''@|$(NEXT_UNISTD_H)|g' \
1944 -e 's|@''WINDOWS_64_BIT_OFF_T''@|$(WINDOWS_64_BIT_OFF_T)|g' \ 2495 -e 's|@''WINDOWS_64_BIT_OFF_T''@|$(WINDOWS_64_BIT_OFF_T)|g' \
1945 -e 's/@''GNULIB_CHDIR''@/$(GNULIB_CHDIR)/g' \ 2496 -e 's/@''GNULIB_ACCESS''@/$(GL_GNULIB_ACCESS)/g' \
1946 -e 's/@''GNULIB_CHOWN''@/$(GNULIB_CHOWN)/g' \ 2497 -e 's/@''GNULIB_CHDIR''@/$(GL_GNULIB_CHDIR)/g' \
1947 -e 's/@''GNULIB_CLOSE''@/$(GNULIB_CLOSE)/g' \ 2498 -e 's/@''GNULIB_CHOWN''@/$(GL_GNULIB_CHOWN)/g' \
1948 -e 's/@''GNULIB_DUP''@/$(GNULIB_DUP)/g' \ 2499 -e 's/@''GNULIB_CLOSE''@/$(GL_GNULIB_CLOSE)/g' \
1949 -e 's/@''GNULIB_DUP2''@/$(GNULIB_DUP2)/g' \ 2500 -e 's/@''GNULIB_COPY_FILE_RANGE''@/$(GL_GNULIB_COPY_FILE_RANGE)/g' \
1950 -e 's/@''GNULIB_DUP3''@/$(GNULIB_DUP3)/g' \ 2501 -e 's/@''GNULIB_DUP''@/$(GL_GNULIB_DUP)/g' \
1951 -e 's/@''GNULIB_ENVIRON''@/$(GNULIB_ENVIRON)/g' \ 2502 -e 's/@''GNULIB_DUP2''@/$(GL_GNULIB_DUP2)/g' \
1952 -e 's/@''GNULIB_EUIDACCESS''@/$(GNULIB_EUIDACCESS)/g' \ 2503 -e 's/@''GNULIB_DUP3''@/$(GL_GNULIB_DUP3)/g' \
1953 -e 's/@''GNULIB_FACCESSAT''@/$(GNULIB_FACCESSAT)/g' \ 2504 -e 's/@''GNULIB_ENVIRON''@/$(GL_GNULIB_ENVIRON)/g' \
1954 -e 's/@''GNULIB_FCHDIR''@/$(GNULIB_FCHDIR)/g' \ 2505 -e 's/@''GNULIB_EUIDACCESS''@/$(GL_GNULIB_EUIDACCESS)/g' \
1955 -e 's/@''GNULIB_FCHOWNAT''@/$(GNULIB_FCHOWNAT)/g' \ 2506 -e 's/@''GNULIB_EXECL''@/$(GL_GNULIB_EXECL)/g' \
1956 -e 's/@''GNULIB_FDATASYNC''@/$(GNULIB_FDATASYNC)/g' \ 2507 -e 's/@''GNULIB_EXECLE''@/$(GL_GNULIB_EXECLE)/g' \
1957 -e 's/@''GNULIB_FSYNC''@/$(GNULIB_FSYNC)/g' \ 2508 -e 's/@''GNULIB_EXECLP''@/$(GL_GNULIB_EXECLP)/g' \
1958 -e 's/@''GNULIB_FTRUNCATE''@/$(GNULIB_FTRUNCATE)/g' \ 2509 -e 's/@''GNULIB_EXECV''@/$(GL_GNULIB_EXECV)/g' \
1959 -e 's/@''GNULIB_GETCWD''@/$(GNULIB_GETCWD)/g' \ 2510 -e 's/@''GNULIB_EXECVE''@/$(GL_GNULIB_EXECVE)/g' \
1960 -e 's/@''GNULIB_GETDOMAINNAME''@/$(GNULIB_GETDOMAINNAME)/g' \ 2511 -e 's/@''GNULIB_EXECVP''@/$(GL_GNULIB_EXECVP)/g' \
1961 -e 's/@''GNULIB_GETDTABLESIZE''@/$(GNULIB_GETDTABLESIZE)/g' \ 2512 -e 's/@''GNULIB_EXECVPE''@/$(GL_GNULIB_EXECVPE)/g' \
1962 -e 's/@''GNULIB_GETGROUPS''@/$(GNULIB_GETGROUPS)/g' \ 2513 -e 's/@''GNULIB_FACCESSAT''@/$(GL_GNULIB_FACCESSAT)/g' \
1963 -e 's/@''GNULIB_GETHOSTNAME''@/$(GNULIB_GETHOSTNAME)/g' \ 2514 -e 's/@''GNULIB_FCHDIR''@/$(GL_GNULIB_FCHDIR)/g' \
1964 -e 's/@''GNULIB_GETLOGIN''@/$(GNULIB_GETLOGIN)/g' \ 2515 -e 's/@''GNULIB_FCHOWNAT''@/$(GL_GNULIB_FCHOWNAT)/g' \
1965 -e 's/@''GNULIB_GETLOGIN_R''@/$(GNULIB_GETLOGIN_R)/g' \ 2516 -e 's/@''GNULIB_FDATASYNC''@/$(GL_GNULIB_FDATASYNC)/g' \
1966 -e 's/@''GNULIB_GETPAGESIZE''@/$(GNULIB_GETPAGESIZE)/g' \ 2517 -e 's/@''GNULIB_FSYNC''@/$(GL_GNULIB_FSYNC)/g' \
1967 -e 's/@''GNULIB_GETUSERSHELL''@/$(GNULIB_GETUSERSHELL)/g' \ 2518 -e 's/@''GNULIB_FTRUNCATE''@/$(GL_GNULIB_FTRUNCATE)/g' \
1968 -e 's/@''GNULIB_GROUP_MEMBER''@/$(GNULIB_GROUP_MEMBER)/g' \ 2519 -e 's/@''GNULIB_GETCWD''@/$(GL_GNULIB_GETCWD)/g' \
1969 -e 's/@''GNULIB_ISATTY''@/$(GNULIB_ISATTY)/g' \ 2520 -e 's/@''GNULIB_GETDOMAINNAME''@/$(GL_GNULIB_GETDOMAINNAME)/g' \
1970 -e 's/@''GNULIB_LCHOWN''@/$(GNULIB_LCHOWN)/g' \ 2521 -e 's/@''GNULIB_GETDTABLESIZE''@/$(GL_GNULIB_GETDTABLESIZE)/g' \
1971 -e 's/@''GNULIB_LINK''@/$(GNULIB_LINK)/g' \ 2522 -e 's/@''GNULIB_GETENTROPY''@/$(GL_GNULIB_GETENTROPY)/g' \
1972 -e 's/@''GNULIB_LINKAT''@/$(GNULIB_LINKAT)/g' \ 2523 -e 's/@''GNULIB_GETGROUPS''@/$(GL_GNULIB_GETGROUPS)/g' \
1973 -e 's/@''GNULIB_LSEEK''@/$(GNULIB_LSEEK)/g' \ 2524 -e 's/@''GNULIB_GETHOSTNAME''@/$(GL_GNULIB_GETHOSTNAME)/g' \
1974 -e 's/@''GNULIB_PIPE''@/$(GNULIB_PIPE)/g' \ 2525 -e 's/@''GNULIB_GETLOGIN''@/$(GL_GNULIB_GETLOGIN)/g' \
1975 -e 's/@''GNULIB_PIPE2''@/$(GNULIB_PIPE2)/g' \ 2526 -e 's/@''GNULIB_GETLOGIN_R''@/$(GL_GNULIB_GETLOGIN_R)/g' \
1976 -e 's/@''GNULIB_PREAD''@/$(GNULIB_PREAD)/g' \ 2527 -e 's/@''GNULIB_GETOPT_POSIX''@/$(GL_GNULIB_GETOPT_POSIX)/g' \
1977 -e 's/@''GNULIB_PWRITE''@/$(GNULIB_PWRITE)/g' \ 2528 -e 's/@''GNULIB_GETPAGESIZE''@/$(GL_GNULIB_GETPAGESIZE)/g' \
1978 -e 's/@''GNULIB_READ''@/$(GNULIB_READ)/g' \ 2529 -e 's/@''GNULIB_GETPASS''@/$(GL_GNULIB_GETPASS)/g' \
1979 -e 's/@''GNULIB_READLINK''@/$(GNULIB_READLINK)/g' \ 2530 -e 's/@''GNULIB_GETUSERSHELL''@/$(GL_GNULIB_GETUSERSHELL)/g' \
1980 -e 's/@''GNULIB_READLINKAT''@/$(GNULIB_READLINKAT)/g' \ 2531 -e 's/@''GNULIB_GROUP_MEMBER''@/$(GL_GNULIB_GROUP_MEMBER)/g' \
1981 -e 's/@''GNULIB_RMDIR''@/$(GNULIB_RMDIR)/g' \ 2532 -e 's/@''GNULIB_ISATTY''@/$(GL_GNULIB_ISATTY)/g' \
1982 -e 's/@''GNULIB_SETHOSTNAME''@/$(GNULIB_SETHOSTNAME)/g' \ 2533 -e 's/@''GNULIB_LCHOWN''@/$(GL_GNULIB_LCHOWN)/g' \
1983 -e 's/@''GNULIB_SLEEP''@/$(GNULIB_SLEEP)/g' \ 2534 -e 's/@''GNULIB_LINK''@/$(GL_GNULIB_LINK)/g' \
1984 -e 's/@''GNULIB_SYMLINK''@/$(GNULIB_SYMLINK)/g' \ 2535 -e 's/@''GNULIB_LINKAT''@/$(GL_GNULIB_LINKAT)/g' \
1985 -e 's/@''GNULIB_SYMLINKAT''@/$(GNULIB_SYMLINKAT)/g' \ 2536 -e 's/@''GNULIB_LSEEK''@/$(GL_GNULIB_LSEEK)/g' \
1986 -e 's/@''GNULIB_TTYNAME_R''@/$(GNULIB_TTYNAME_R)/g' \ 2537 -e 's/@''GNULIB_PIPE''@/$(GL_GNULIB_PIPE)/g' \
1987 -e 's/@''GNULIB_UNISTD_H_GETOPT''@/0$(GNULIB_GL_UNISTD_H_GETOPT)/g' \ 2538 -e 's/@''GNULIB_PIPE2''@/$(GL_GNULIB_PIPE2)/g' \
1988 -e 's/@''GNULIB_UNISTD_H_NONBLOCKING''@/$(GNULIB_UNISTD_H_NONBLOCKING)/g' \ 2539 -e 's/@''GNULIB_PREAD''@/$(GL_GNULIB_PREAD)/g' \
1989 -e 's/@''GNULIB_UNISTD_H_SIGPIPE''@/$(GNULIB_UNISTD_H_SIGPIPE)/g' \ 2540 -e 's/@''GNULIB_PWRITE''@/$(GL_GNULIB_PWRITE)/g' \
1990 -e 's/@''GNULIB_UNLINK''@/$(GNULIB_UNLINK)/g' \ 2541 -e 's/@''GNULIB_READ''@/$(GL_GNULIB_READ)/g' \
1991 -e 's/@''GNULIB_UNLINKAT''@/$(GNULIB_UNLINKAT)/g' \ 2542 -e 's/@''GNULIB_READLINK''@/$(GL_GNULIB_READLINK)/g' \
1992 -e 's/@''GNULIB_USLEEP''@/$(GNULIB_USLEEP)/g' \ 2543 -e 's/@''GNULIB_READLINKAT''@/$(GL_GNULIB_READLINKAT)/g' \
1993 -e 's/@''GNULIB_WRITE''@/$(GNULIB_WRITE)/g' \ 2544 -e 's/@''GNULIB_RMDIR''@/$(GL_GNULIB_RMDIR)/g' \
2545 -e 's/@''GNULIB_SETHOSTNAME''@/$(GL_GNULIB_SETHOSTNAME)/g' \
2546 -e 's/@''GNULIB_SLEEP''@/$(GL_GNULIB_SLEEP)/g' \
2547 -e 's/@''GNULIB_SYMLINK''@/$(GL_GNULIB_SYMLINK)/g' \
2548 -e 's/@''GNULIB_SYMLINKAT''@/$(GL_GNULIB_SYMLINKAT)/g' \
2549 -e 's/@''GNULIB_TRUNCATE''@/$(GL_GNULIB_TRUNCATE)/g' \
2550 -e 's/@''GNULIB_TTYNAME_R''@/$(GL_GNULIB_TTYNAME_R)/g' \
2551 -e 's/@''GNULIB_UNISTD_H_GETOPT''@/0$(GL_GNULIB_UNISTD_H_GETOPT)/g' \
2552 -e 's/@''GNULIB_UNISTD_H_NONBLOCKING''@/$(GL_GNULIB_UNISTD_H_NONBLOCKING)/g' \
2553 -e 's/@''GNULIB_UNISTD_H_SIGPIPE''@/$(GL_GNULIB_UNISTD_H_SIGPIPE)/g' \
2554 -e 's/@''GNULIB_UNLINK''@/$(GL_GNULIB_UNLINK)/g' \
2555 -e 's/@''GNULIB_UNLINKAT''@/$(GL_GNULIB_UNLINKAT)/g' \
2556 -e 's/@''GNULIB_USLEEP''@/$(GL_GNULIB_USLEEP)/g' \
2557 -e 's/@''GNULIB_WRITE''@/$(GL_GNULIB_WRITE)/g' \
2558 -e 's/@''GNULIB_MDA_ACCESS''@/$(GL_GNULIB_MDA_ACCESS)/g' \
2559 -e 's/@''GNULIB_MDA_CHDIR''@/$(GL_GNULIB_MDA_CHDIR)/g' \
2560 -e 's/@''GNULIB_MDA_CLOSE''@/$(GL_GNULIB_MDA_CLOSE)/g' \
2561 -e 's/@''GNULIB_MDA_DUP''@/$(GL_GNULIB_MDA_DUP)/g' \
2562 -e 's/@''GNULIB_MDA_DUP2''@/$(GL_GNULIB_MDA_DUP2)/g' \
2563 -e 's/@''GNULIB_MDA_EXECL''@/$(GL_GNULIB_MDA_EXECL)/g' \
2564 -e 's/@''GNULIB_MDA_EXECLE''@/$(GL_GNULIB_MDA_EXECLE)/g' \
2565 -e 's/@''GNULIB_MDA_EXECLP''@/$(GL_GNULIB_MDA_EXECLP)/g' \
2566 -e 's/@''GNULIB_MDA_EXECV''@/$(GL_GNULIB_MDA_EXECV)/g' \
2567 -e 's/@''GNULIB_MDA_EXECVE''@/$(GL_GNULIB_MDA_EXECVE)/g' \
2568 -e 's/@''GNULIB_MDA_EXECVP''@/$(GL_GNULIB_MDA_EXECVP)/g' \
2569 -e 's/@''GNULIB_MDA_EXECVPE''@/$(GL_GNULIB_MDA_EXECVPE)/g' \
2570 -e 's/@''GNULIB_MDA_GETCWD''@/$(GL_GNULIB_MDA_GETCWD)/g' \
2571 -e 's/@''GNULIB_MDA_GETPID''@/$(GL_GNULIB_MDA_GETPID)/g' \
2572 -e 's/@''GNULIB_MDA_ISATTY''@/$(GL_GNULIB_MDA_ISATTY)/g' \
2573 -e 's/@''GNULIB_MDA_LSEEK''@/$(GL_GNULIB_MDA_LSEEK)/g' \
2574 -e 's/@''GNULIB_MDA_READ''@/$(GL_GNULIB_MDA_READ)/g' \
2575 -e 's/@''GNULIB_MDA_RMDIR''@/$(GL_GNULIB_MDA_RMDIR)/g' \
2576 -e 's/@''GNULIB_MDA_SWAB''@/$(GL_GNULIB_MDA_SWAB)/g' \
2577 -e 's/@''GNULIB_MDA_UNLINK''@/$(GL_GNULIB_MDA_UNLINK)/g' \
2578 -e 's/@''GNULIB_MDA_WRITE''@/$(GL_GNULIB_MDA_WRITE)/g' \
1994 < $(srcdir)/unistd.in.h | \ 2579 < $(srcdir)/unistd.in.h | \
1995 sed -e 's|@''HAVE_CHOWN''@|$(HAVE_CHOWN)|g' \ 2580 sed -e 's|@''HAVE_CHOWN''@|$(HAVE_CHOWN)|g' \
1996 -e 's|@''HAVE_DUP2''@|$(HAVE_DUP2)|g' \ 2581 -e 's|@''HAVE_COPY_FILE_RANGE''@|$(HAVE_COPY_FILE_RANGE)|g' \
1997 -e 's|@''HAVE_DUP3''@|$(HAVE_DUP3)|g' \ 2582 -e 's|@''HAVE_DUP3''@|$(HAVE_DUP3)|g' \
1998 -e 's|@''HAVE_EUIDACCESS''@|$(HAVE_EUIDACCESS)|g' \ 2583 -e 's|@''HAVE_EUIDACCESS''@|$(HAVE_EUIDACCESS)|g' \
2584 -e 's|@''HAVE_EXECVPE''@|$(HAVE_EXECVPE)|g' \
1999 -e 's|@''HAVE_FACCESSAT''@|$(HAVE_FACCESSAT)|g' \ 2585 -e 's|@''HAVE_FACCESSAT''@|$(HAVE_FACCESSAT)|g' \
2000 -e 's|@''HAVE_FCHDIR''@|$(HAVE_FCHDIR)|g' \ 2586 -e 's|@''HAVE_FCHDIR''@|$(HAVE_FCHDIR)|g' \
2001 -e 's|@''HAVE_FCHOWNAT''@|$(HAVE_FCHOWNAT)|g' \ 2587 -e 's|@''HAVE_FCHOWNAT''@|$(HAVE_FCHOWNAT)|g' \
@@ -2003,10 +2589,11 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
2003 -e 's|@''HAVE_FSYNC''@|$(HAVE_FSYNC)|g' \ 2589 -e 's|@''HAVE_FSYNC''@|$(HAVE_FSYNC)|g' \
2004 -e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \ 2590 -e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \
2005 -e 's|@''HAVE_GETDTABLESIZE''@|$(HAVE_GETDTABLESIZE)|g' \ 2591 -e 's|@''HAVE_GETDTABLESIZE''@|$(HAVE_GETDTABLESIZE)|g' \
2592 -e 's|@''HAVE_GETENTROPY''@|$(HAVE_GETENTROPY)|g' \
2006 -e 's|@''HAVE_GETGROUPS''@|$(HAVE_GETGROUPS)|g' \ 2593 -e 's|@''HAVE_GETGROUPS''@|$(HAVE_GETGROUPS)|g' \
2007 -e 's|@''HAVE_GETHOSTNAME''@|$(HAVE_GETHOSTNAME)|g' \ 2594 -e 's|@''HAVE_GETHOSTNAME''@|$(HAVE_GETHOSTNAME)|g' \
2008 -e 's|@''HAVE_GETLOGIN''@|$(HAVE_GETLOGIN)|g' \
2009 -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \ 2595 -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \
2596 -e 's|@''HAVE_GETPASS''@|$(HAVE_GETPASS)|g' \
2010 -e 's|@''HAVE_GROUP_MEMBER''@|$(HAVE_GROUP_MEMBER)|g' \ 2597 -e 's|@''HAVE_GROUP_MEMBER''@|$(HAVE_GROUP_MEMBER)|g' \
2011 -e 's|@''HAVE_LCHOWN''@|$(HAVE_LCHOWN)|g' \ 2598 -e 's|@''HAVE_LCHOWN''@|$(HAVE_LCHOWN)|g' \
2012 -e 's|@''HAVE_LINK''@|$(HAVE_LINK)|g' \ 2599 -e 's|@''HAVE_LINK''@|$(HAVE_LINK)|g' \
@@ -2024,28 +2611,42 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
2024 -e 's|@''HAVE_UNLINKAT''@|$(HAVE_UNLINKAT)|g' \ 2611 -e 's|@''HAVE_UNLINKAT''@|$(HAVE_UNLINKAT)|g' \
2025 -e 's|@''HAVE_USLEEP''@|$(HAVE_USLEEP)|g' \ 2612 -e 's|@''HAVE_USLEEP''@|$(HAVE_USLEEP)|g' \
2026 -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \ 2613 -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \
2614 -e 's|@''HAVE_DECL_EXECVPE''@|$(HAVE_DECL_EXECVPE)|g' \
2027 -e 's|@''HAVE_DECL_FCHDIR''@|$(HAVE_DECL_FCHDIR)|g' \ 2615 -e 's|@''HAVE_DECL_FCHDIR''@|$(HAVE_DECL_FCHDIR)|g' \
2028 -e 's|@''HAVE_DECL_FDATASYNC''@|$(HAVE_DECL_FDATASYNC)|g' \ 2616 -e 's|@''HAVE_DECL_FDATASYNC''@|$(HAVE_DECL_FDATASYNC)|g' \
2029 -e 's|@''HAVE_DECL_GETDOMAINNAME''@|$(HAVE_DECL_GETDOMAINNAME)|g' \ 2617 -e 's|@''HAVE_DECL_GETDOMAINNAME''@|$(HAVE_DECL_GETDOMAINNAME)|g' \
2618 -e 's|@''HAVE_DECL_GETLOGIN''@|$(HAVE_DECL_GETLOGIN)|g' \
2030 -e 's|@''HAVE_DECL_GETLOGIN_R''@|$(HAVE_DECL_GETLOGIN_R)|g' \ 2619 -e 's|@''HAVE_DECL_GETLOGIN_R''@|$(HAVE_DECL_GETLOGIN_R)|g' \
2031 -e 's|@''HAVE_DECL_GETPAGESIZE''@|$(HAVE_DECL_GETPAGESIZE)|g' \ 2620 -e 's|@''HAVE_DECL_GETPAGESIZE''@|$(HAVE_DECL_GETPAGESIZE)|g' \
2032 -e 's|@''HAVE_DECL_GETUSERSHELL''@|$(HAVE_DECL_GETUSERSHELL)|g' \ 2621 -e 's|@''HAVE_DECL_GETUSERSHELL''@|$(HAVE_DECL_GETUSERSHELL)|g' \
2033 -e 's|@''HAVE_DECL_SETHOSTNAME''@|$(HAVE_DECL_SETHOSTNAME)|g' \ 2622 -e 's|@''HAVE_DECL_SETHOSTNAME''@|$(HAVE_DECL_SETHOSTNAME)|g' \
2623 -e 's|@''HAVE_DECL_TRUNCATE''@|$(HAVE_DECL_TRUNCATE)|g' \
2034 -e 's|@''HAVE_DECL_TTYNAME_R''@|$(HAVE_DECL_TTYNAME_R)|g' \ 2624 -e 's|@''HAVE_DECL_TTYNAME_R''@|$(HAVE_DECL_TTYNAME_R)|g' \
2035 -e 's|@''HAVE_OS_H''@|$(HAVE_OS_H)|g' \ 2625 -e 's|@''HAVE_OS_H''@|$(HAVE_OS_H)|g' \
2036 -e 's|@''HAVE_SYS_PARAM_H''@|$(HAVE_SYS_PARAM_H)|g' \ 2626 -e 's|@''HAVE_SYS_PARAM_H''@|$(HAVE_SYS_PARAM_H)|g' \
2037 | \ 2627 | \
2038 sed -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \ 2628 sed -e 's|@''REPLACE_ACCESS''@|$(REPLACE_ACCESS)|g' \
2629 -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \
2039 -e 's|@''REPLACE_CLOSE''@|$(REPLACE_CLOSE)|g' \ 2630 -e 's|@''REPLACE_CLOSE''@|$(REPLACE_CLOSE)|g' \
2040 -e 's|@''REPLACE_DUP''@|$(REPLACE_DUP)|g' \ 2631 -e 's|@''REPLACE_DUP''@|$(REPLACE_DUP)|g' \
2041 -e 's|@''REPLACE_DUP2''@|$(REPLACE_DUP2)|g' \ 2632 -e 's|@''REPLACE_DUP2''@|$(REPLACE_DUP2)|g' \
2633 -e 's|@''REPLACE_EXECL''@|$(REPLACE_EXECL)|g' \
2634 -e 's|@''REPLACE_EXECLE''@|$(REPLACE_EXECLE)|g' \
2635 -e 's|@''REPLACE_EXECLP''@|$(REPLACE_EXECLP)|g' \
2636 -e 's|@''REPLACE_EXECV''@|$(REPLACE_EXECV)|g' \
2637 -e 's|@''REPLACE_EXECVE''@|$(REPLACE_EXECVE)|g' \
2638 -e 's|@''REPLACE_EXECVP''@|$(REPLACE_EXECVP)|g' \
2639 -e 's|@''REPLACE_EXECVPE''@|$(REPLACE_EXECVPE)|g' \
2640 -e 's|@''REPLACE_FACCESSAT''@|$(REPLACE_FACCESSAT)|g' \
2042 -e 's|@''REPLACE_FCHOWNAT''@|$(REPLACE_FCHOWNAT)|g' \ 2641 -e 's|@''REPLACE_FCHOWNAT''@|$(REPLACE_FCHOWNAT)|g' \
2043 -e 's|@''REPLACE_FTRUNCATE''@|$(REPLACE_FTRUNCATE)|g' \ 2642 -e 's|@''REPLACE_FTRUNCATE''@|$(REPLACE_FTRUNCATE)|g' \
2044 -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \ 2643 -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \
2045 -e 's|@''REPLACE_GETDOMAINNAME''@|$(REPLACE_GETDOMAINNAME)|g' \ 2644 -e 's|@''REPLACE_GETDOMAINNAME''@|$(REPLACE_GETDOMAINNAME)|g' \
2645 -e 's|@''REPLACE_GETDTABLESIZE''@|$(REPLACE_GETDTABLESIZE)|g' \
2046 -e 's|@''REPLACE_GETLOGIN_R''@|$(REPLACE_GETLOGIN_R)|g' \ 2646 -e 's|@''REPLACE_GETLOGIN_R''@|$(REPLACE_GETLOGIN_R)|g' \
2047 -e 's|@''REPLACE_GETGROUPS''@|$(REPLACE_GETGROUPS)|g' \ 2647 -e 's|@''REPLACE_GETGROUPS''@|$(REPLACE_GETGROUPS)|g' \
2048 -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \ 2648 -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \
2649 -e 's|@''REPLACE_GETPASS''@|$(REPLACE_GETPASS)|g' \
2049 -e 's|@''REPLACE_ISATTY''@|$(REPLACE_ISATTY)|g' \ 2650 -e 's|@''REPLACE_ISATTY''@|$(REPLACE_ISATTY)|g' \
2050 -e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \ 2651 -e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \
2051 -e 's|@''REPLACE_LINK''@|$(REPLACE_LINK)|g' \ 2652 -e 's|@''REPLACE_LINK''@|$(REPLACE_LINK)|g' \
@@ -2055,14 +2656,18 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H
2055 -e 's|@''REPLACE_PWRITE''@|$(REPLACE_PWRITE)|g' \ 2656 -e 's|@''REPLACE_PWRITE''@|$(REPLACE_PWRITE)|g' \
2056 -e 's|@''REPLACE_READ''@|$(REPLACE_READ)|g' \ 2657 -e 's|@''REPLACE_READ''@|$(REPLACE_READ)|g' \
2057 -e 's|@''REPLACE_READLINK''@|$(REPLACE_READLINK)|g' \ 2658 -e 's|@''REPLACE_READLINK''@|$(REPLACE_READLINK)|g' \
2659 -e 's|@''REPLACE_READLINKAT''@|$(REPLACE_READLINKAT)|g' \
2058 -e 's|@''REPLACE_RMDIR''@|$(REPLACE_RMDIR)|g' \ 2660 -e 's|@''REPLACE_RMDIR''@|$(REPLACE_RMDIR)|g' \
2059 -e 's|@''REPLACE_SLEEP''@|$(REPLACE_SLEEP)|g' \ 2661 -e 's|@''REPLACE_SLEEP''@|$(REPLACE_SLEEP)|g' \
2060 -e 's|@''REPLACE_SYMLINK''@|$(REPLACE_SYMLINK)|g' \ 2662 -e 's|@''REPLACE_SYMLINK''@|$(REPLACE_SYMLINK)|g' \
2663 -e 's|@''REPLACE_SYMLINKAT''@|$(REPLACE_SYMLINKAT)|g' \
2664 -e 's|@''REPLACE_TRUNCATE''@|$(REPLACE_TRUNCATE)|g' \
2061 -e 's|@''REPLACE_TTYNAME_R''@|$(REPLACE_TTYNAME_R)|g' \ 2665 -e 's|@''REPLACE_TTYNAME_R''@|$(REPLACE_TTYNAME_R)|g' \
2062 -e 's|@''REPLACE_UNLINK''@|$(REPLACE_UNLINK)|g' \ 2666 -e 's|@''REPLACE_UNLINK''@|$(REPLACE_UNLINK)|g' \
2063 -e 's|@''REPLACE_UNLINKAT''@|$(REPLACE_UNLINKAT)|g' \ 2667 -e 's|@''REPLACE_UNLINKAT''@|$(REPLACE_UNLINKAT)|g' \
2064 -e 's|@''REPLACE_USLEEP''@|$(REPLACE_USLEEP)|g' \ 2668 -e 's|@''REPLACE_USLEEP''@|$(REPLACE_USLEEP)|g' \
2065 -e 's|@''REPLACE_WRITE''@|$(REPLACE_WRITE)|g' \ 2669 -e 's|@''REPLACE_WRITE''@|$(REPLACE_WRITE)|g' \
2670 -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' \ 2671 -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' \ 2672 -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)' \ 2673 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
@@ -2076,6 +2681,13 @@ EXTRA_DIST += unistd.in.h
2076 2681
2077## end gnulib module unistd 2682## end gnulib module unistd
2078 2683
2684## begin gnulib module unlocked-io-internal
2685
2686
2687EXTRA_DIST += unlocked-io.h
2688
2689## end gnulib module unlocked-io-internal
2690
2079## begin gnulib module unsetenv 2691## begin gnulib module unsetenv
2080 2692
2081 2693
@@ -2135,45 +2747,51 @@ wchar.h: wchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
2135 -e 's|@''HAVE_FEATURES_H''@|$(HAVE_FEATURES_H)|g' \ 2747 -e 's|@''HAVE_FEATURES_H''@|$(HAVE_FEATURES_H)|g' \
2136 -e 's|@''NEXT_WCHAR_H''@|$(NEXT_WCHAR_H)|g' \ 2748 -e 's|@''NEXT_WCHAR_H''@|$(NEXT_WCHAR_H)|g' \
2137 -e 's|@''HAVE_WCHAR_H''@|$(HAVE_WCHAR_H)|g' \ 2749 -e 's|@''HAVE_WCHAR_H''@|$(HAVE_WCHAR_H)|g' \
2138 -e 's/@''GNULIB_BTOWC''@/$(GNULIB_BTOWC)/g' \ 2750 -e 's/@''HAVE_CRTDEFS_H''@/$(HAVE_CRTDEFS_H)/g' \
2139 -e 's/@''GNULIB_WCTOB''@/$(GNULIB_WCTOB)/g' \ 2751 -e 's/@''GNULIBHEADERS_OVERRIDE_WINT_T''@/$(GNULIBHEADERS_OVERRIDE_WINT_T)/g' \
2140 -e 's/@''GNULIB_MBSINIT''@/$(GNULIB_MBSINIT)/g' \ 2752 -e 's/@''GNULIB_BTOWC''@/$(GL_GNULIB_BTOWC)/g' \
2141 -e 's/@''GNULIB_MBRTOWC''@/$(GNULIB_MBRTOWC)/g' \ 2753 -e 's/@''GNULIB_WCTOB''@/$(GL_GNULIB_WCTOB)/g' \
2142 -e 's/@''GNULIB_MBRLEN''@/$(GNULIB_MBRLEN)/g' \ 2754 -e 's/@''GNULIB_MBSINIT''@/$(GL_GNULIB_MBSINIT)/g' \
2143 -e 's/@''GNULIB_MBSRTOWCS''@/$(GNULIB_MBSRTOWCS)/g' \ 2755 -e 's/@''GNULIB_MBRTOWC''@/$(GL_GNULIB_MBRTOWC)/g' \
2144 -e 's/@''GNULIB_MBSNRTOWCS''@/$(GNULIB_MBSNRTOWCS)/g' \ 2756 -e 's/@''GNULIB_MBRLEN''@/$(GL_GNULIB_MBRLEN)/g' \
2145 -e 's/@''GNULIB_WCRTOMB''@/$(GNULIB_WCRTOMB)/g' \ 2757 -e 's/@''GNULIB_MBSRTOWCS''@/$(GL_GNULIB_MBSRTOWCS)/g' \
2146 -e 's/@''GNULIB_WCSRTOMBS''@/$(GNULIB_WCSRTOMBS)/g' \ 2758 -e 's/@''GNULIB_MBSNRTOWCS''@/$(GL_GNULIB_MBSNRTOWCS)/g' \
2147 -e 's/@''GNULIB_WCSNRTOMBS''@/$(GNULIB_WCSNRTOMBS)/g' \ 2759 -e 's/@''GNULIB_WCRTOMB''@/$(GL_GNULIB_WCRTOMB)/g' \
2148 -e 's/@''GNULIB_WCWIDTH''@/$(GNULIB_WCWIDTH)/g' \ 2760 -e 's/@''GNULIB_WCSRTOMBS''@/$(GL_GNULIB_WCSRTOMBS)/g' \
2149 -e 's/@''GNULIB_WMEMCHR''@/$(GNULIB_WMEMCHR)/g' \ 2761 -e 's/@''GNULIB_WCSNRTOMBS''@/$(GL_GNULIB_WCSNRTOMBS)/g' \
2150 -e 's/@''GNULIB_WMEMCMP''@/$(GNULIB_WMEMCMP)/g' \ 2762 -e 's/@''GNULIB_WCWIDTH''@/$(GL_GNULIB_WCWIDTH)/g' \
2151 -e 's/@''GNULIB_WMEMCPY''@/$(GNULIB_WMEMCPY)/g' \ 2763 -e 's/@''GNULIB_WMEMCHR''@/$(GL_GNULIB_WMEMCHR)/g' \
2152 -e 's/@''GNULIB_WMEMMOVE''@/$(GNULIB_WMEMMOVE)/g' \ 2764 -e 's/@''GNULIB_WMEMCMP''@/$(GL_GNULIB_WMEMCMP)/g' \
2153 -e 's/@''GNULIB_WMEMSET''@/$(GNULIB_WMEMSET)/g' \ 2765 -e 's/@''GNULIB_WMEMCPY''@/$(GL_GNULIB_WMEMCPY)/g' \
2154 -e 's/@''GNULIB_WCSLEN''@/$(GNULIB_WCSLEN)/g' \ 2766 -e 's/@''GNULIB_WMEMMOVE''@/$(GL_GNULIB_WMEMMOVE)/g' \
2155 -e 's/@''GNULIB_WCSNLEN''@/$(GNULIB_WCSNLEN)/g' \ 2767 -e 's/@''GNULIB_WMEMPCPY''@/$(GL_GNULIB_WMEMPCPY)/g' \
2156 -e 's/@''GNULIB_WCSCPY''@/$(GNULIB_WCSCPY)/g' \ 2768 -e 's/@''GNULIB_WMEMSET''@/$(GL_GNULIB_WMEMSET)/g' \
2157 -e 's/@''GNULIB_WCPCPY''@/$(GNULIB_WCPCPY)/g' \ 2769 -e 's/@''GNULIB_WCSLEN''@/$(GL_GNULIB_WCSLEN)/g' \
2158 -e 's/@''GNULIB_WCSNCPY''@/$(GNULIB_WCSNCPY)/g' \ 2770 -e 's/@''GNULIB_WCSNLEN''@/$(GL_GNULIB_WCSNLEN)/g' \
2159 -e 's/@''GNULIB_WCPNCPY''@/$(GNULIB_WCPNCPY)/g' \ 2771 -e 's/@''GNULIB_WCSCPY''@/$(GL_GNULIB_WCSCPY)/g' \
2160 -e 's/@''GNULIB_WCSCAT''@/$(GNULIB_WCSCAT)/g' \ 2772 -e 's/@''GNULIB_WCPCPY''@/$(GL_GNULIB_WCPCPY)/g' \
2161 -e 's/@''GNULIB_WCSNCAT''@/$(GNULIB_WCSNCAT)/g' \ 2773 -e 's/@''GNULIB_WCSNCPY''@/$(GL_GNULIB_WCSNCPY)/g' \
2162 -e 's/@''GNULIB_WCSCMP''@/$(GNULIB_WCSCMP)/g' \ 2774 -e 's/@''GNULIB_WCPNCPY''@/$(GL_GNULIB_WCPNCPY)/g' \
2163 -e 's/@''GNULIB_WCSNCMP''@/$(GNULIB_WCSNCMP)/g' \ 2775 -e 's/@''GNULIB_WCSCAT''@/$(GL_GNULIB_WCSCAT)/g' \
2164 -e 's/@''GNULIB_WCSCASECMP''@/$(GNULIB_WCSCASECMP)/g' \ 2776 -e 's/@''GNULIB_WCSNCAT''@/$(GL_GNULIB_WCSNCAT)/g' \
2165 -e 's/@''GNULIB_WCSNCASECMP''@/$(GNULIB_WCSNCASECMP)/g' \ 2777 -e 's/@''GNULIB_WCSCMP''@/$(GL_GNULIB_WCSCMP)/g' \
2166 -e 's/@''GNULIB_WCSCOLL''@/$(GNULIB_WCSCOLL)/g' \ 2778 -e 's/@''GNULIB_WCSNCMP''@/$(GL_GNULIB_WCSNCMP)/g' \
2167 -e 's/@''GNULIB_WCSXFRM''@/$(GNULIB_WCSXFRM)/g' \ 2779 -e 's/@''GNULIB_WCSCASECMP''@/$(GL_GNULIB_WCSCASECMP)/g' \
2168 -e 's/@''GNULIB_WCSDUP''@/$(GNULIB_WCSDUP)/g' \ 2780 -e 's/@''GNULIB_WCSNCASECMP''@/$(GL_GNULIB_WCSNCASECMP)/g' \
2169 -e 's/@''GNULIB_WCSCHR''@/$(GNULIB_WCSCHR)/g' \ 2781 -e 's/@''GNULIB_WCSCOLL''@/$(GL_GNULIB_WCSCOLL)/g' \
2170 -e 's/@''GNULIB_WCSRCHR''@/$(GNULIB_WCSRCHR)/g' \ 2782 -e 's/@''GNULIB_WCSXFRM''@/$(GL_GNULIB_WCSXFRM)/g' \
2171 -e 's/@''GNULIB_WCSCSPN''@/$(GNULIB_WCSCSPN)/g' \ 2783 -e 's/@''GNULIB_WCSDUP''@/$(GL_GNULIB_WCSDUP)/g' \
2172 -e 's/@''GNULIB_WCSSPN''@/$(GNULIB_WCSSPN)/g' \ 2784 -e 's/@''GNULIB_WCSCHR''@/$(GL_GNULIB_WCSCHR)/g' \
2173 -e 's/@''GNULIB_WCSPBRK''@/$(GNULIB_WCSPBRK)/g' \ 2785 -e 's/@''GNULIB_WCSRCHR''@/$(GL_GNULIB_WCSRCHR)/g' \
2174 -e 's/@''GNULIB_WCSSTR''@/$(GNULIB_WCSSTR)/g' \ 2786 -e 's/@''GNULIB_WCSCSPN''@/$(GL_GNULIB_WCSCSPN)/g' \
2175 -e 's/@''GNULIB_WCSTOK''@/$(GNULIB_WCSTOK)/g' \ 2787 -e 's/@''GNULIB_WCSSPN''@/$(GL_GNULIB_WCSSPN)/g' \
2176 -e 's/@''GNULIB_WCSWIDTH''@/$(GNULIB_WCSWIDTH)/g' \ 2788 -e 's/@''GNULIB_WCSPBRK''@/$(GL_GNULIB_WCSPBRK)/g' \
2789 -e 's/@''GNULIB_WCSSTR''@/$(GL_GNULIB_WCSSTR)/g' \
2790 -e 's/@''GNULIB_WCSTOK''@/$(GL_GNULIB_WCSTOK)/g' \
2791 -e 's/@''GNULIB_WCSWIDTH''@/$(GL_GNULIB_WCSWIDTH)/g' \
2792 -e 's/@''GNULIB_WCSFTIME''@/$(GL_GNULIB_WCSFTIME)/g' \
2793 -e 's/@''GNULIB_MDA_WCSDUP''@/$(GL_GNULIB_MDA_WCSDUP)/g' \
2794 -e 's/@''GNULIB_FREE_POSIX''@/$(GL_GNULIB_FREE_POSIX)/g' \
2177 < $(srcdir)/wchar.in.h | \ 2795 < $(srcdir)/wchar.in.h | \
2178 sed -e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \ 2796 sed -e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \
2179 -e 's|@''HAVE_BTOWC''@|$(HAVE_BTOWC)|g' \ 2797 -e 's|@''HAVE_BTOWC''@|$(HAVE_BTOWC)|g' \
@@ -2189,6 +2807,7 @@ wchar.h: wchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
2189 -e 's|@''HAVE_WMEMCMP''@|$(HAVE_WMEMCMP)|g' \ 2807 -e 's|@''HAVE_WMEMCMP''@|$(HAVE_WMEMCMP)|g' \
2190 -e 's|@''HAVE_WMEMCPY''@|$(HAVE_WMEMCPY)|g' \ 2808 -e 's|@''HAVE_WMEMCPY''@|$(HAVE_WMEMCPY)|g' \
2191 -e 's|@''HAVE_WMEMMOVE''@|$(HAVE_WMEMMOVE)|g' \ 2809 -e 's|@''HAVE_WMEMMOVE''@|$(HAVE_WMEMMOVE)|g' \
2810 -e 's|@''HAVE_WMEMPCPY''@|$(HAVE_WMEMPCPY)|g' \
2192 -e 's|@''HAVE_WMEMSET''@|$(HAVE_WMEMSET)|g' \ 2811 -e 's|@''HAVE_WMEMSET''@|$(HAVE_WMEMSET)|g' \
2193 -e 's|@''HAVE_WCSLEN''@|$(HAVE_WCSLEN)|g' \ 2812 -e 's|@''HAVE_WCSLEN''@|$(HAVE_WCSLEN)|g' \
2194 -e 's|@''HAVE_WCSNLEN''@|$(HAVE_WCSNLEN)|g' \ 2813 -e 's|@''HAVE_WCSNLEN''@|$(HAVE_WCSNLEN)|g' \
@@ -2213,12 +2832,15 @@ wchar.h: wchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
2213 -e 's|@''HAVE_WCSSTR''@|$(HAVE_WCSSTR)|g' \ 2832 -e 's|@''HAVE_WCSSTR''@|$(HAVE_WCSSTR)|g' \
2214 -e 's|@''HAVE_WCSTOK''@|$(HAVE_WCSTOK)|g' \ 2833 -e 's|@''HAVE_WCSTOK''@|$(HAVE_WCSTOK)|g' \
2215 -e 's|@''HAVE_WCSWIDTH''@|$(HAVE_WCSWIDTH)|g' \ 2834 -e 's|@''HAVE_WCSWIDTH''@|$(HAVE_WCSWIDTH)|g' \
2835 -e 's|@''HAVE_WCSFTIME''@|$(HAVE_WCSFTIME)|g' \
2216 -e 's|@''HAVE_DECL_WCTOB''@|$(HAVE_DECL_WCTOB)|g' \ 2836 -e 's|@''HAVE_DECL_WCTOB''@|$(HAVE_DECL_WCTOB)|g' \
2837 -e 's|@''HAVE_DECL_WCSDUP''@|$(HAVE_DECL_WCSDUP)|g' \
2217 -e 's|@''HAVE_DECL_WCWIDTH''@|$(HAVE_DECL_WCWIDTH)|g' \ 2838 -e 's|@''HAVE_DECL_WCWIDTH''@|$(HAVE_DECL_WCWIDTH)|g' \
2218 | \ 2839 | \
2219 sed -e 's|@''REPLACE_MBSTATE_T''@|$(REPLACE_MBSTATE_T)|g' \ 2840 sed -e 's|@''REPLACE_MBSTATE_T''@|$(REPLACE_MBSTATE_T)|g' \
2220 -e 's|@''REPLACE_BTOWC''@|$(REPLACE_BTOWC)|g' \ 2841 -e 's|@''REPLACE_BTOWC''@|$(REPLACE_BTOWC)|g' \
2221 -e 's|@''REPLACE_WCTOB''@|$(REPLACE_WCTOB)|g' \ 2842 -e 's|@''REPLACE_WCTOB''@|$(REPLACE_WCTOB)|g' \
2843 -e 's|@''REPLACE_FREE''@|$(REPLACE_FREE)|g' \
2222 -e 's|@''REPLACE_MBSINIT''@|$(REPLACE_MBSINIT)|g' \ 2844 -e 's|@''REPLACE_MBSINIT''@|$(REPLACE_MBSINIT)|g' \
2223 -e 's|@''REPLACE_MBRTOWC''@|$(REPLACE_MBRTOWC)|g' \ 2845 -e 's|@''REPLACE_MBRTOWC''@|$(REPLACE_MBRTOWC)|g' \
2224 -e 's|@''REPLACE_MBRLEN''@|$(REPLACE_MBRLEN)|g' \ 2846 -e 's|@''REPLACE_MBRLEN''@|$(REPLACE_MBRLEN)|g' \
@@ -2229,6 +2851,8 @@ wchar.h: wchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
2229 -e 's|@''REPLACE_WCSNRTOMBS''@|$(REPLACE_WCSNRTOMBS)|g' \ 2851 -e 's|@''REPLACE_WCSNRTOMBS''@|$(REPLACE_WCSNRTOMBS)|g' \
2230 -e 's|@''REPLACE_WCWIDTH''@|$(REPLACE_WCWIDTH)|g' \ 2852 -e 's|@''REPLACE_WCWIDTH''@|$(REPLACE_WCWIDTH)|g' \
2231 -e 's|@''REPLACE_WCSWIDTH''@|$(REPLACE_WCSWIDTH)|g' \ 2853 -e 's|@''REPLACE_WCSWIDTH''@|$(REPLACE_WCSWIDTH)|g' \
2854 -e 's|@''REPLACE_WCSFTIME''@|$(REPLACE_WCSFTIME)|g' \
2855 -e 's|@''REPLACE_WCSTOK''@|$(REPLACE_WCSTOK)|g' \
2232 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 2856 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
2233 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ 2857 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
2234 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \ 2858 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \
@@ -2265,17 +2889,23 @@ wctype.h: wctype.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H
2265 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 2889 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
2266 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 2890 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
2267 -e 's|@''NEXT_WCTYPE_H''@|$(NEXT_WCTYPE_H)|g' \ 2891 -e 's|@''NEXT_WCTYPE_H''@|$(NEXT_WCTYPE_H)|g' \
2268 -e 's/@''GNULIB_ISWBLANK''@/$(GNULIB_ISWBLANK)/g' \ 2892 -e 's/@''HAVE_CRTDEFS_H''@/$(HAVE_CRTDEFS_H)/g' \
2269 -e 's/@''GNULIB_WCTYPE''@/$(GNULIB_WCTYPE)/g' \ 2893 -e 's/@''GNULIBHEADERS_OVERRIDE_WINT_T''@/$(GNULIBHEADERS_OVERRIDE_WINT_T)/g' \
2270 -e 's/@''GNULIB_ISWCTYPE''@/$(GNULIB_ISWCTYPE)/g' \ 2894 -e 's/@''GNULIB_ISWBLANK''@/$(GL_GNULIB_ISWBLANK)/g' \
2271 -e 's/@''GNULIB_WCTRANS''@/$(GNULIB_WCTRANS)/g' \ 2895 -e 's/@''GNULIB_ISWDIGIT''@/$(GL_GNULIB_ISWDIGIT)/g' \
2272 -e 's/@''GNULIB_TOWCTRANS''@/$(GNULIB_TOWCTRANS)/g' \ 2896 -e 's/@''GNULIB_ISWXDIGIT''@/$(GL_GNULIB_ISWXDIGIT)/g' \
2897 -e 's/@''GNULIB_WCTYPE''@/$(GL_GNULIB_WCTYPE)/g' \
2898 -e 's/@''GNULIB_ISWCTYPE''@/$(GL_GNULIB_ISWCTYPE)/g' \
2899 -e 's/@''GNULIB_WCTRANS''@/$(GL_GNULIB_WCTRANS)/g' \
2900 -e 's/@''GNULIB_TOWCTRANS''@/$(GL_GNULIB_TOWCTRANS)/g' \
2273 -e 's/@''HAVE_ISWBLANK''@/$(HAVE_ISWBLANK)/g' \ 2901 -e 's/@''HAVE_ISWBLANK''@/$(HAVE_ISWBLANK)/g' \
2274 -e 's/@''HAVE_ISWCNTRL''@/$(HAVE_ISWCNTRL)/g' \ 2902 -e 's/@''HAVE_ISWCNTRL''@/$(HAVE_ISWCNTRL)/g' \
2275 -e 's/@''HAVE_WCTYPE_T''@/$(HAVE_WCTYPE_T)/g' \ 2903 -e 's/@''HAVE_WCTYPE_T''@/$(HAVE_WCTYPE_T)/g' \
2276 -e 's/@''HAVE_WCTRANS_T''@/$(HAVE_WCTRANS_T)/g' \ 2904 -e 's/@''HAVE_WCTRANS_T''@/$(HAVE_WCTRANS_T)/g' \
2277 -e 's/@''HAVE_WINT_T''@/$(HAVE_WINT_T)/g' \ 2905 -e 's/@''HAVE_WINT_T''@/$(HAVE_WINT_T)/g' \
2278 -e 's/@''REPLACE_ISWBLANK''@/$(REPLACE_ISWBLANK)/g' \ 2906 -e 's/@''REPLACE_ISWBLANK''@/$(REPLACE_ISWBLANK)/g' \
2907 -e 's/@''REPLACE_ISWDIGIT''@/$(REPLACE_ISWDIGIT)/g' \
2908 -e 's/@''REPLACE_ISWXDIGIT''@/$(REPLACE_ISWXDIGIT)/g' \
2279 -e 's/@''REPLACE_ISWCNTRL''@/$(REPLACE_ISWCNTRL)/g' \ 2909 -e 's/@''REPLACE_ISWCNTRL''@/$(REPLACE_ISWCNTRL)/g' \
2280 -e 's/@''REPLACE_TOWLOWER''@/$(REPLACE_TOWLOWER)/g' \ 2910 -e 's/@''REPLACE_TOWLOWER''@/$(REPLACE_TOWLOWER)/g' \
2281 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ 2911 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
@@ -2289,6 +2919,42 @@ EXTRA_DIST += wctype.in.h
2289 2919
2290## end gnulib module wctype-h 2920## end gnulib module wctype-h
2291 2921
2922## begin gnulib module windows-mutex
2923
2924
2925EXTRA_DIST += windows-initguard.h windows-mutex.c windows-mutex.h
2926
2927EXTRA_libgnu_a_SOURCES += windows-mutex.c
2928
2929## end gnulib module windows-mutex
2930
2931## begin gnulib module windows-once
2932
2933
2934EXTRA_DIST += windows-once.c windows-once.h
2935
2936EXTRA_libgnu_a_SOURCES += windows-once.c
2937
2938## end gnulib module windows-once
2939
2940## begin gnulib module windows-recmutex
2941
2942
2943EXTRA_DIST += windows-initguard.h windows-recmutex.c windows-recmutex.h
2944
2945EXTRA_libgnu_a_SOURCES += windows-recmutex.c
2946
2947## end gnulib module windows-recmutex
2948
2949## begin gnulib module windows-rwlock
2950
2951
2952EXTRA_DIST += windows-initguard.h windows-rwlock.c windows-rwlock.h
2953
2954EXTRA_libgnu_a_SOURCES += windows-rwlock.c
2955
2956## end gnulib module windows-rwlock
2957
2292## begin gnulib module xalloc 2958## begin gnulib module xalloc
2293 2959
2294libgnu_a_SOURCES += xmalloc.c 2960libgnu_a_SOURCES += xmalloc.c
@@ -2301,6 +2967,8 @@ EXTRA_DIST += xalloc.h
2301 2967
2302libgnu_a_SOURCES += xalloc-die.c 2968libgnu_a_SOURCES += xalloc-die.c
2303 2969
2970EXTRA_DIST += xalloc.h
2971
2304## end gnulib module xalloc-die 2972## end gnulib module xalloc-die
2305 2973
2306## begin gnulib module xalloc-oversized 2974## begin gnulib module xalloc-oversized
@@ -2316,12 +2984,6 @@ libgnu_a_SOURCES += xsize.h xsize.c
2316 2984
2317## end gnulib module xsize 2985## end gnulib module xsize
2318 2986
2319## begin gnulib module xstrndup
2320
2321libgnu_a_SOURCES += xstrndup.h xstrndup.c
2322
2323## end gnulib module xstrndup
2324
2325 2987
2326mostlyclean-local: mostlyclean-generic 2988mostlyclean-local: mostlyclean-generic
2327 @for dir in '' $(MOSTLYCLEANDIRS); do \ 2989 @for dir in '' $(MOSTLYCLEANDIRS); do \
diff --git a/gl/_Noreturn.h b/gl/_Noreturn.h
new file mode 100644
index 0000000..6fed3c7
--- /dev/null
+++ b/gl/_Noreturn.h
@@ -0,0 +1,45 @@
1/* A C macro for declaring that a function does not return.
2 Copyright (C) 2011-2021 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 __cplusplus || defined __clang__) \
30 && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
31 || (!defined __STRICT_ANSI__ \
32 && (4 < __GNUC__ + (7 <= __GNUC_MINOR__) \
33 || (defined __apple_build_version__ \
34 ? 6000000 <= __apple_build_version__ \
35 : 3 < __clang_major__ + (5 <= __clang_minor__))))))
36 /* _Noreturn works as-is. */
37# elif (2 < __GNUC__ + (8 <= __GNUC_MINOR__) || defined __clang__ \
38 || 0x5110 <= __SUNPRO_C)
39# define _Noreturn __attribute__ ((__noreturn__))
40# elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
41# define _Noreturn __declspec (noreturn)
42# else
43# define _Noreturn
44# endif
45#endif
diff --git a/gl/af_alg.c b/gl/af_alg.c
new file mode 100644
index 0000000..748af70
--- /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-2021 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..f0fe7fc
--- /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-2021 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..65c2d4d 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-2021 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/arpa_inet.in.h b/gl/arpa_inet.in.h
index ba89e97..9968067 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-2021 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..c5367b2 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-2021 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..9c78c13 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-2021 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/attribute.h b/gl/attribute.h
new file mode 100644
index 0000000..eb36188
--- /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-2021 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 * C2x 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..b204cb7 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-2021 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..e58ccfb 100644
--- a/gl/base64.h
+++ b/gl/base64.h
@@ -1,25 +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-2021 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 23
24/* Get bool. */ 24/* Get bool. */
25# include <stdbool.h> 25# include <stdbool.h>
@@ -34,26 +34,26 @@ extern "C" {
34 34
35struct base64_decode_context 35struct base64_decode_context
36{ 36{
37 unsigned int i; 37 int i;
38 char buf[4]; 38 char buf[4];
39}; 39};
40 40
41extern bool isbase64 (char ch) _GL_ATTRIBUTE_CONST; 41extern bool isbase64 (char ch) _GL_ATTRIBUTE_CONST;
42 42
43extern void base64_encode (const char *restrict in, size_t inlen, 43extern void base64_encode (const char *restrict in, idx_t inlen,
44 char *restrict out, size_t outlen); 44 char *restrict out, idx_t outlen);
45 45
46extern size_t base64_encode_alloc (const char *in, size_t inlen, char **out); 46extern idx_t base64_encode_alloc (const char *in, idx_t inlen, char **out);
47 47
48extern void base64_decode_ctx_init (struct base64_decode_context *ctx); 48extern void base64_decode_ctx_init (struct base64_decode_context *ctx);
49 49
50extern bool base64_decode_ctx (struct base64_decode_context *ctx, 50extern bool base64_decode_ctx (struct base64_decode_context *ctx,
51 const char *restrict in, size_t inlen, 51 const char *restrict in, idx_t inlen,
52 char *restrict out, size_t *outlen); 52 char *restrict out, idx_t *outlen);
53 53
54extern bool base64_decode_alloc_ctx (struct base64_decode_context *ctx, 54extern bool base64_decode_alloc_ctx (struct base64_decode_context *ctx,
55 const char *in, size_t inlen, 55 const char *in, idx_t inlen,
56 char **out, size_t *outlen); 56 char **out, idx_t *outlen);
57 57
58#define base64_decode(in, inlen, out, outlen) \ 58#define base64_decode(in, inlen, out, outlen) \
59 base64_decode_ctx (NULL, in, inlen, out, outlen) 59 base64_decode_ctx (NULL, in, inlen, out, outlen)
diff --git a/gl/basename-lgpl.c b/gl/basename-lgpl.c
index 9307e83..5dbd157 100644
--- a/gl/basename-lgpl.c
+++ b/gl/basename-lgpl.c
@@ -1,37 +1,37 @@
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-2021 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
24#include <stdbool.h>
23#include <string.h> 25#include <string.h>
24 26
25/* Return the address of the last file name component of NAME. If 27#include "filename.h"
26 NAME has no relative file name components because it is a file
27 system root, return the empty string. */
28 28
29char * 29char *
30last_component (char const *name) 30last_component (char const *name)
31{ 31{
32 char const *base = name + FILE_SYSTEM_PREFIX_LEN (name); 32 char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);
33 char const *p; 33 char const *p;
34 bool saw_slash = false; 34 bool last_was_slash = false;
35 35
36 while (ISSLASH (*base)) 36 while (ISSLASH (*base))
37 base++; 37 base++;
@@ -39,21 +39,17 @@ last_component (char const *name)
39 for (p = base; *p; p++) 39 for (p = base; *p; p++)
40 { 40 {
41 if (ISSLASH (*p)) 41 if (ISSLASH (*p))
42 saw_slash = true; 42 last_was_slash = true;
43 else if (saw_slash) 43 else if (last_was_slash)
44 { 44 {
45 base = p; 45 base = p;
46 saw_slash = false; 46 last_was_slash = false;
47 } 47 }
48 } 48 }
49 49
50 return (char *) base; 50 return (char *) base;
51} 51}
52 52
53/* Return the length of the basename NAME. Typically NAME is the
54 value returned by base_name or last_component. Act like strlen
55 (NAME), except omit all trailing slashes. */
56
57size_t 53size_t
58base_len (char const *name) 54base_len (char const *name)
59{ 55{
diff --git a/gl/basename-lgpl.h b/gl/basename-lgpl.h
new file mode 100644
index 0000000..d520c09
--- /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-2021 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..1181134 100644
--- a/gl/basename.c
+++ b/gl/basename.c
@@ -1,6 +1,6 @@
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-2021 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
@@ -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..b8239af 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-2021 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..113f878
--- /dev/null
+++ b/gl/byteswap.in.h
@@ -0,0 +1,44 @@
1/* byteswap.h - Byte swapping
2 Copyright (C) 2005, 2007, 2009-2021 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/calloc.c b/gl/calloc.c
new file mode 100644
index 0000000..25064e9
--- /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-2021 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..ab57d4a
--- /dev/null
+++ b/gl/cdefs.h
@@ -0,0 +1,704 @@
1/* Copyright (C) 1992-2021 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 || 3 < __clang_major__ + (5 <= __clang_minor__)))
45# define __glibc_has_attribute(attr) __has_attribute (attr)
46#else
47# define __glibc_has_attribute(attr) 0
48#endif
49#ifdef __has_builtin
50# define __glibc_has_builtin(name) __has_builtin (name)
51#else
52# define __glibc_has_builtin(name) 0
53#endif
54#ifdef __has_extension
55# define __glibc_has_extension(ext) __has_extension (ext)
56#else
57# define __glibc_has_extension(ext) 0
58#endif
59
60#if defined __GNUC__ || defined __clang__
61
62/* All functions, except those with callbacks or those that
63 synchronize memory, are leaf functions. */
64# if __GNUC_PREREQ (4, 6) && !defined _LIBC
65# define __LEAF , __leaf__
66# define __LEAF_ATTR __attribute__ ((__leaf__))
67# else
68# define __LEAF
69# define __LEAF_ATTR
70# endif
71
72/* GCC can always grok prototypes. For C++ programs we add throw()
73 to help it optimize the function calls. But this only works with
74 gcc 2.8.x and egcs. For gcc 3.4 and up we even mark C functions
75 as non-throwing using a function attribute since programs can use
76 the -fexceptions options for C code as well. */
77# if !defined __cplusplus \
78 && (__GNUC_PREREQ (3, 4) || __glibc_has_attribute (__nothrow__))
79# define __THROW __attribute__ ((__nothrow__ __LEAF))
80# define __THROWNL __attribute__ ((__nothrow__))
81# define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct
82# define __NTHNL(fct) __attribute__ ((__nothrow__)) fct
83# else
84# if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major >= 4)
85# if __cplusplus >= 201103L
86# define __THROW noexcept (true)
87# else
88# define __THROW throw ()
89# endif
90# define __THROWNL __THROW
91# define __NTH(fct) __LEAF_ATTR fct __THROW
92# define __NTHNL(fct) fct __THROW
93# else
94# define __THROW
95# define __THROWNL
96# define __NTH(fct) fct
97# define __NTHNL(fct) fct
98# endif
99# endif
100
101#else /* Not GCC or clang. */
102
103# if (defined __cplusplus \
104 || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
105# define __inline inline
106# else
107# define __inline /* No inline functions. */
108# endif
109
110# define __THROW
111# define __THROWNL
112# define __NTH(fct) fct
113
114#endif /* GCC || clang. */
115
116/* These two macros are not used in glibc anymore. They are kept here
117 only because some other projects expect the macros to be defined. */
118#define __P(args) args
119#define __PMT(args) args
120
121/* For these things, GCC behaves the ANSI way normally,
122 and the non-ANSI way under -traditional. */
123
124#define __CONCAT(x,y) x ## y
125#define __STRING(x) #x
126
127/* This is not a typedef so `const __ptr_t' does the right thing. */
128#define __ptr_t void *
129
130
131/* C++ needs to know that types and declarations are C, not C++. */
132#ifdef __cplusplus
133# define __BEGIN_DECLS extern "C" {
134# define __END_DECLS }
135#else
136# define __BEGIN_DECLS
137# define __END_DECLS
138#endif
139
140
141/* Fortify support. */
142#define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1)
143#define __bos0(ptr) __builtin_object_size (ptr, 0)
144
145/* Use __builtin_dynamic_object_size at _FORTIFY_SOURCE=3 when available. */
146#if __USE_FORTIFY_LEVEL == 3 && __glibc_clang_prereq (9, 0)
147# define __glibc_objsize0(__o) __builtin_dynamic_object_size (__o, 0)
148# define __glibc_objsize(__o) __builtin_dynamic_object_size (__o, 1)
149#else
150# define __glibc_objsize0(__o) __bos0 (__o)
151# define __glibc_objsize(__o) __bos (__o)
152#endif
153
154/* Compile time conditions to choose between the regular, _chk and _chk_warn
155 variants. These conditions should get evaluated to constant and optimized
156 away. */
157
158#define __glibc_safe_len_cond(__l, __s, __osz) ((__l) <= (__osz) / (__s))
159#define __glibc_unsigned_or_positive(__l) \
160 ((__typeof (__l)) 0 < (__typeof (__l)) -1 \
161 || (__builtin_constant_p (__l) && (__l) > 0))
162
163/* Length is known to be safe at compile time if the __L * __S <= __OBJSZ
164 condition can be folded to a constant and if it is true. The -1 check is
165 redundant because since it implies that __glibc_safe_len_cond is true. */
166#define __glibc_safe_or_unknown_len(__l, __s, __osz) \
167 (__glibc_unsigned_or_positive (__l) \
168 && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \
169 __s, __osz)) \
170 && __glibc_safe_len_cond ((__SIZE_TYPE__) (__l), __s, __osz))
171
172/* Conversely, we know at compile time that the length is safe if the
173 __L * __S <= __OBJSZ condition can be folded to a constant and if it is
174 false. */
175#define __glibc_unsafe_len(__l, __s, __osz) \
176 (__glibc_unsigned_or_positive (__l) \
177 && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \
178 __s, __osz)) \
179 && !__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), __s, __osz))
180
181/* Fortify function f. __f_alias, __f_chk and __f_chk_warn must be
182 declared. */
183
184#define __glibc_fortify(f, __l, __s, __osz, ...) \
185 (__glibc_safe_or_unknown_len (__l, __s, __osz) \
186 ? __ ## f ## _alias (__VA_ARGS__) \
187 : (__glibc_unsafe_len (__l, __s, __osz) \
188 ? __ ## f ## _chk_warn (__VA_ARGS__, __osz) \
189 : __ ## f ## _chk (__VA_ARGS__, __osz))) \
190
191/* Fortify function f, where object size argument passed to f is the number of
192 elements and not total size. */
193
194#define __glibc_fortify_n(f, __l, __s, __osz, ...) \
195 (__glibc_safe_or_unknown_len (__l, __s, __osz) \
196 ? __ ## f ## _alias (__VA_ARGS__) \
197 : (__glibc_unsafe_len (__l, __s, __osz) \
198 ? __ ## f ## _chk_warn (__VA_ARGS__, (__osz) / (__s)) \
199 : __ ## f ## _chk (__VA_ARGS__, (__osz) / (__s)))) \
200
201#if __GNUC_PREREQ (4,3)
202# define __warnattr(msg) __attribute__((__warning__ (msg)))
203# define __errordecl(name, msg) \
204 extern void name (void) __attribute__((__error__ (msg)))
205#else
206# define __warnattr(msg)
207# define __errordecl(name, msg) extern void name (void)
208#endif
209
210/* Support for flexible arrays.
211 Headers that should use flexible arrays only if they're "real"
212 (e.g. only if they won't affect sizeof()) should test
213 #if __glibc_c99_flexarr_available. */
214#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L && !defined __HP_cc
215# define __flexarr []
216# define __glibc_c99_flexarr_available 1
217#elif __GNUC_PREREQ (2,97) || defined __clang__
218/* GCC 2.97 and clang support C99 flexible array members as an extension,
219 even when in C89 mode or compiling C++ (any version). */
220# define __flexarr []
221# define __glibc_c99_flexarr_available 1
222#elif defined __GNUC__
223/* Pre-2.97 GCC did not support C99 flexible arrays but did have
224 an equivalent extension with slightly different notation. */
225# define __flexarr [0]
226# define __glibc_c99_flexarr_available 1
227#else
228/* Some other non-C99 compiler. Approximate with [1]. */
229# define __flexarr [1]
230# define __glibc_c99_flexarr_available 0
231#endif
232
233
234/* __asm__ ("xyz") is used throughout the headers to rename functions
235 at the assembly language level. This is wrapped by the __REDIRECT
236 macro, in order to support compilers that can do this some other
237 way. When compilers don't support asm-names at all, we have to do
238 preprocessor tricks instead (which don't have exactly the right
239 semantics, but it's the best we can do).
240
241 Example:
242 int __REDIRECT(setpgrp, (__pid_t pid, __pid_t pgrp), setpgid); */
243
244#if (defined __GNUC__ && __GNUC__ >= 2) || (__clang_major__ >= 4)
245
246# define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))
247# ifdef __cplusplus
248# define __REDIRECT_NTH(name, proto, alias) \
249 name proto __THROW __asm__ (__ASMNAME (#alias))
250# define __REDIRECT_NTHNL(name, proto, alias) \
251 name proto __THROWNL __asm__ (__ASMNAME (#alias))
252# else
253# define __REDIRECT_NTH(name, proto, alias) \
254 name proto __asm__ (__ASMNAME (#alias)) __THROW
255# define __REDIRECT_NTHNL(name, proto, alias) \
256 name proto __asm__ (__ASMNAME (#alias)) __THROWNL
257# endif
258# define __ASMNAME(cname) __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
259# define __ASMNAME2(prefix, cname) __STRING (prefix) cname
260
261/*
262#elif __SOME_OTHER_COMPILER__
263
264# define __REDIRECT(name, proto, alias) name proto; \
265 _Pragma("let " #name " = " #alias)
266*/
267#endif
268
269/* GCC and clang have various useful declarations that can be made with
270 the '__attribute__' syntax. All of the ways we use this do fine if
271 they are omitted for compilers that don't understand it. */
272#if !(defined __GNUC__ || defined __clang__)
273# define __attribute__(xyz) /* Ignore */
274#endif
275
276/* At some point during the gcc 2.96 development the `malloc' attribute
277 for functions was introduced. We don't want to use it unconditionally
278 (although this would be possible) since it generates warnings. */
279#if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__malloc__)
280# define __attribute_malloc__ __attribute__ ((__malloc__))
281#else
282# define __attribute_malloc__ /* Ignore */
283#endif
284
285/* Tell the compiler which arguments to an allocation function
286 indicate the size of the allocation. */
287#if __GNUC_PREREQ (4, 3)
288# define __attribute_alloc_size__(params) \
289 __attribute__ ((__alloc_size__ params))
290#else
291# define __attribute_alloc_size__(params) /* Ignore. */
292#endif
293
294/* Tell the compiler which argument to an allocation function
295 indicates the alignment of the allocation. */
296#if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__alloc_align__)
297# define __attribute_alloc_align__(param) \
298 __attribute__ ((__alloc_align__ param))
299#else
300# define __attribute_alloc_align__(param) /* Ignore. */
301#endif
302
303/* At some point during the gcc 2.96 development the `pure' attribute
304 for functions was introduced. We don't want to use it unconditionally
305 (although this would be possible) since it generates warnings. */
306#if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__pure__)
307# define __attribute_pure__ __attribute__ ((__pure__))
308#else
309# define __attribute_pure__ /* Ignore */
310#endif
311
312/* This declaration tells the compiler that the value is constant. */
313#if __GNUC_PREREQ (2,5) || __glibc_has_attribute (__const__)
314# define __attribute_const__ __attribute__ ((__const__))
315#else
316# define __attribute_const__ /* Ignore */
317#endif
318
319#if __GNUC_PREREQ (2,7) || __glibc_has_attribute (__unused__)
320# define __attribute_maybe_unused__ __attribute__ ((__unused__))
321#else
322# define __attribute_maybe_unused__ /* Ignore */
323#endif
324
325/* At some point during the gcc 3.1 development the `used' attribute
326 for functions was introduced. We don't want to use it unconditionally
327 (although this would be possible) since it generates warnings. */
328#if __GNUC_PREREQ (3,1) || __glibc_has_attribute (__used__)
329# define __attribute_used__ __attribute__ ((__used__))
330# define __attribute_noinline__ __attribute__ ((__noinline__))
331#else
332# define __attribute_used__ __attribute__ ((__unused__))
333# define __attribute_noinline__ /* Ignore */
334#endif
335
336/* Since version 3.2, gcc allows marking deprecated functions. */
337#if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__deprecated__)
338# define __attribute_deprecated__ __attribute__ ((__deprecated__))
339#else
340# define __attribute_deprecated__ /* Ignore */
341#endif
342
343/* Since version 4.5, gcc also allows one to specify the message printed
344 when a deprecated function is used. clang claims to be gcc 4.2, but
345 may also support this feature. */
346#if __GNUC_PREREQ (4,5) \
347 || __glibc_has_extension (__attribute_deprecated_with_message__)
348# define __attribute_deprecated_msg__(msg) \
349 __attribute__ ((__deprecated__ (msg)))
350#else
351# define __attribute_deprecated_msg__(msg) __attribute_deprecated__
352#endif
353
354/* At some point during the gcc 2.8 development the `format_arg' attribute
355 for functions was introduced. We don't want to use it unconditionally
356 (although this would be possible) since it generates warnings.
357 If several `format_arg' attributes are given for the same function, in
358 gcc-3.0 and older, all but the last one are ignored. In newer gccs,
359 all designated arguments are considered. */
360#if __GNUC_PREREQ (2,8) || __glibc_has_attribute (__format_arg__)
361# define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x)))
362#else
363# define __attribute_format_arg__(x) /* Ignore */
364#endif
365
366/* At some point during the gcc 2.97 development the `strfmon' format
367 attribute for functions was introduced. We don't want to use it
368 unconditionally (although this would be possible) since it
369 generates warnings. */
370#if __GNUC_PREREQ (2,97) || __glibc_has_attribute (__format__)
371# define __attribute_format_strfmon__(a,b) \
372 __attribute__ ((__format__ (__strfmon__, a, b)))
373#else
374# define __attribute_format_strfmon__(a,b) /* Ignore */
375#endif
376
377/* The nonnull function attribute marks pointer parameters that
378 must not be NULL. This has the name __nonnull in glibc,
379 and __attribute_nonnull__ in files shared with Gnulib to avoid
380 collision with a different __nonnull in DragonFlyBSD 5.9. */
381#ifndef __attribute_nonnull__
382# if __GNUC_PREREQ (3,3) || __glibc_has_attribute (__nonnull__)
383# define __attribute_nonnull__(params) __attribute__ ((__nonnull__ params))
384# else
385# define __attribute_nonnull__(params)
386# endif
387#endif
388#ifndef __nonnull
389# define __nonnull(params) __attribute_nonnull__ (params)
390#endif
391
392/* The returns_nonnull function attribute marks the return type of the function
393 as always being non-null. */
394#ifndef __returns_nonnull
395# if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__returns_nonnull__)
396# define __returns_nonnull __attribute__ ((__returns_nonnull__))
397# else
398# define __returns_nonnull
399# endif
400#endif
401
402/* If fortification mode, we warn about unused results of certain
403 function calls which can lead to problems. */
404#if __GNUC_PREREQ (3,4) || __glibc_has_attribute (__warn_unused_result__)
405# define __attribute_warn_unused_result__ \
406 __attribute__ ((__warn_unused_result__))
407# if defined __USE_FORTIFY_LEVEL && __USE_FORTIFY_LEVEL > 0
408# define __wur __attribute_warn_unused_result__
409# endif
410#else
411# define __attribute_warn_unused_result__ /* empty */
412#endif
413#ifndef __wur
414# define __wur /* Ignore */
415#endif
416
417/* Forces a function to be always inlined. */
418#if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__always_inline__)
419/* The Linux kernel defines __always_inline in stddef.h (283d7573), and
420 it conflicts with this definition. Therefore undefine it first to
421 allow either header to be included first. */
422# undef __always_inline
423# define __always_inline __inline __attribute__ ((__always_inline__))
424#else
425# undef __always_inline
426# define __always_inline __inline
427#endif
428
429/* Associate error messages with the source location of the call site rather
430 than with the source location inside the function. */
431#if __GNUC_PREREQ (4,3) || __glibc_has_attribute (__artificial__)
432# define __attribute_artificial__ __attribute__ ((__artificial__))
433#else
434# define __attribute_artificial__ /* Ignore */
435#endif
436
437/* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
438 inline semantics, unless -fgnu89-inline is used. Using __GNUC_STDC_INLINE__
439 or __GNUC_GNU_INLINE is not a good enough check for gcc because gcc versions
440 older than 4.3 may define these macros and still not guarantee GNU inlining
441 semantics.
442
443 clang++ identifies itself as gcc-4.2, but has support for GNU inlining
444 semantics, that can be checked for by using the __GNUC_STDC_INLINE_ and
445 __GNUC_GNU_INLINE__ macro definitions. */
446#if (!defined __cplusplus || __GNUC_PREREQ (4,3) \
447 || (defined __clang__ && (defined __GNUC_STDC_INLINE__ \
448 || defined __GNUC_GNU_INLINE__)))
449# if defined __GNUC_STDC_INLINE__ || defined __cplusplus
450# define __extern_inline extern __inline __attribute__ ((__gnu_inline__))
451# define __extern_always_inline \
452 extern __always_inline __attribute__ ((__gnu_inline__))
453# else
454# define __extern_inline extern __inline
455# define __extern_always_inline extern __always_inline
456# endif
457#endif
458
459#ifdef __extern_always_inline
460# define __fortify_function __extern_always_inline __attribute_artificial__
461#endif
462
463/* GCC 4.3 and above allow passing all anonymous arguments of an
464 __extern_always_inline function to some other vararg function. */
465#if __GNUC_PREREQ (4,3)
466# define __va_arg_pack() __builtin_va_arg_pack ()
467# define __va_arg_pack_len() __builtin_va_arg_pack_len ()
468#endif
469
470/* It is possible to compile containing GCC extensions even if GCC is
471 run in pedantic mode if the uses are carefully marked using the
472 `__extension__' keyword. But this is not generally available before
473 version 2.8. */
474#if !(__GNUC_PREREQ (2,8) || defined __clang__)
475# define __extension__ /* Ignore */
476#endif
477
478/* __restrict is known in EGCS 1.2 and above, and in clang.
479 It works also in C++ mode (outside of arrays), but only when spelled
480 as '__restrict', not 'restrict'. */
481#if !(__GNUC_PREREQ (2,92) || __clang_major__ >= 3)
482# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
483# define __restrict restrict
484# else
485# define __restrict /* Ignore */
486# endif
487#endif
488
489/* ISO C99 also allows to declare arrays as non-overlapping. The syntax is
490 array_name[restrict]
491 GCC 3.1 and clang support this.
492 This syntax is not usable in C++ mode. */
493#if (__GNUC_PREREQ (3,1) || __clang_major__ >= 3) && !defined __cplusplus
494# define __restrict_arr __restrict
495#else
496# ifdef __GNUC__
497# define __restrict_arr /* Not supported in old GCC. */
498# else
499# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
500# define __restrict_arr restrict
501# else
502/* Some other non-C99 compiler. */
503# define __restrict_arr /* Not supported. */
504# endif
505# endif
506#endif
507
508#if (__GNUC__ >= 3) || __glibc_has_builtin (__builtin_expect)
509# define __glibc_unlikely(cond) __builtin_expect ((cond), 0)
510# define __glibc_likely(cond) __builtin_expect ((cond), 1)
511#else
512# define __glibc_unlikely(cond) (cond)
513# define __glibc_likely(cond) (cond)
514#endif
515
516#if (!defined _Noreturn \
517 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
518 && !(__GNUC_PREREQ (4,7) \
519 || (3 < __clang_major__ + (5 <= __clang_minor__))))
520# if __GNUC_PREREQ (2,8)
521# define _Noreturn __attribute__ ((__noreturn__))
522# else
523# define _Noreturn
524# endif
525#endif
526
527#if __GNUC_PREREQ (8, 0)
528/* Describes a char array whose address can safely be passed as the first
529 argument to strncpy and strncat, as the char array is not necessarily
530 a NUL-terminated string. */
531# define __attribute_nonstring__ __attribute__ ((__nonstring__))
532#else
533# define __attribute_nonstring__
534#endif
535
536/* Undefine (also defined in libc-symbols.h). */
537#undef __attribute_copy__
538#if __GNUC_PREREQ (9, 0)
539/* Copies attributes from the declaration or type referenced by
540 the argument. */
541# define __attribute_copy__(arg) __attribute__ ((__copy__ (arg)))
542#else
543# define __attribute_copy__(arg)
544#endif
545
546#if (!defined _Static_assert && !defined __cplusplus \
547 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
548 && (!(__GNUC_PREREQ (4, 6) || __clang_major__ >= 4) \
549 || defined __STRICT_ANSI__))
550# define _Static_assert(expr, diagnostic) \
551 extern int (*__Static_assert_function (void)) \
552 [!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })]
553#endif
554
555/* Gnulib avoids including these, as they don't work on non-glibc or
556 older glibc platforms. */
557#ifndef __GNULIB_CDEFS
558# include <bits/wordsize.h>
559# include <bits/long-double.h>
560#endif
561
562#if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
563# ifdef __REDIRECT
564
565/* Alias name defined automatically. */
566# define __LDBL_REDIR(name, proto) ... unused__ldbl_redir
567# define __LDBL_REDIR_DECL(name) \
568 extern __typeof (name) name __asm (__ASMNAME ("__" #name "ieee128"));
569
570/* Alias name defined automatically, with leading underscores. */
571# define __LDBL_REDIR2_DECL(name) \
572 extern __typeof (__##name) __##name \
573 __asm (__ASMNAME ("__" #name "ieee128"));
574
575/* Alias name defined manually. */
576# define __LDBL_REDIR1(name, proto, alias) ... unused__ldbl_redir1
577# define __LDBL_REDIR1_DECL(name, alias) \
578 extern __typeof (name) name __asm (__ASMNAME (#alias));
579
580# define __LDBL_REDIR1_NTH(name, proto, alias) \
581 __REDIRECT_NTH (name, proto, alias)
582# define __REDIRECT_NTH_LDBL(name, proto, alias) \
583 __LDBL_REDIR1_NTH (name, proto, __##alias##ieee128)
584
585/* Unused. */
586# define __REDIRECT_LDBL(name, proto, alias) ... unused__redirect_ldbl
587# define __LDBL_REDIR_NTH(name, proto) ... unused__ldbl_redir_nth
588
589# else
590_Static_assert (0, "IEEE 128-bits long double requires redirection on this platform");
591# endif
592#elif defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
593# define __LDBL_COMPAT 1
594# ifdef __REDIRECT
595# define __LDBL_REDIR1(name, proto, alias) __REDIRECT (name, proto, alias)
596# define __LDBL_REDIR(name, proto) \
597 __LDBL_REDIR1 (name, proto, __nldbl_##name)
598# define __LDBL_REDIR1_NTH(name, proto, alias) __REDIRECT_NTH (name, proto, alias)
599# define __LDBL_REDIR_NTH(name, proto) \
600 __LDBL_REDIR1_NTH (name, proto, __nldbl_##name)
601# define __LDBL_REDIR2_DECL(name) \
602 extern __typeof (__##name) __##name __asm (__ASMNAME ("__nldbl___" #name));
603# define __LDBL_REDIR1_DECL(name, alias) \
604 extern __typeof (name) name __asm (__ASMNAME (#alias));
605# define __LDBL_REDIR_DECL(name) \
606 extern __typeof (name) name __asm (__ASMNAME ("__nldbl_" #name));
607# define __REDIRECT_LDBL(name, proto, alias) \
608 __LDBL_REDIR1 (name, proto, __nldbl_##alias)
609# define __REDIRECT_NTH_LDBL(name, proto, alias) \
610 __LDBL_REDIR1_NTH (name, proto, __nldbl_##alias)
611# endif
612#endif
613#if (!defined __LDBL_COMPAT && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0) \
614 || !defined __REDIRECT
615# define __LDBL_REDIR1(name, proto, alias) name proto
616# define __LDBL_REDIR(name, proto) name proto
617# define __LDBL_REDIR1_NTH(name, proto, alias) name proto __THROW
618# define __LDBL_REDIR_NTH(name, proto) name proto __THROW
619# define __LDBL_REDIR2_DECL(name)
620# define __LDBL_REDIR_DECL(name)
621# ifdef __REDIRECT
622# define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias)
623# define __REDIRECT_NTH_LDBL(name, proto, alias) \
624 __REDIRECT_NTH (name, proto, alias)
625# endif
626#endif
627
628/* __glibc_macro_warning (MESSAGE) issues warning MESSAGE. This is
629 intended for use in preprocessor macros.
630
631 Note: MESSAGE must be a _single_ string; concatenation of string
632 literals is not supported. */
633#if __GNUC_PREREQ (4,8) || __glibc_clang_prereq (3,5)
634# define __glibc_macro_warning1(message) _Pragma (#message)
635# define __glibc_macro_warning(message) \
636 __glibc_macro_warning1 (GCC warning message)
637#else
638# define __glibc_macro_warning(msg)
639#endif
640
641/* Generic selection (ISO C11) is a C-only feature, available in GCC
642 since version 4.9. Previous versions do not provide generic
643 selection, even though they might set __STDC_VERSION__ to 201112L,
644 when in -std=c11 mode. Thus, we must check for !defined __GNUC__
645 when testing __STDC_VERSION__ for generic selection support.
646 On the other hand, Clang also defines __GNUC__, so a clang-specific
647 check is required to enable the use of generic selection. */
648#if !defined __cplusplus \
649 && (__GNUC_PREREQ (4, 9) \
650 || __glibc_has_extension (c_generic_selections) \
651 || (!defined __GNUC__ && defined __STDC_VERSION__ \
652 && __STDC_VERSION__ >= 201112L))
653# define __HAVE_GENERIC_SELECTION 1
654#else
655# define __HAVE_GENERIC_SELECTION 0
656#endif
657
658#if __GNUC_PREREQ (10, 0)
659/* Designates a 1-based positional argument ref-index of pointer type
660 that can be used to access size-index elements of the pointed-to
661 array according to access mode, or at least one element when
662 size-index is not provided:
663 access (access-mode, <ref-index> [, <size-index>]) */
664# define __attr_access(x) __attribute__ ((__access__ x))
665/* For _FORTIFY_SOURCE == 3 we use __builtin_dynamic_object_size, which may
666 use the access attribute to get object sizes from function definition
667 arguments, so we can't use them on functions we fortify. Drop the object
668 size hints for such functions. */
669# if __USE_FORTIFY_LEVEL == 3
670# define __fortified_attr_access(a, o, s) __attribute__ ((__access__ (a, o)))
671# else
672# define __fortified_attr_access(a, o, s) __attr_access ((a, o, s))
673# endif
674# if __GNUC_PREREQ (11, 0)
675# define __attr_access_none(argno) __attribute__ ((__access__ (__none__, argno)))
676# else
677# define __attr_access_none(argno)
678# endif
679#else
680# define __fortified_attr_access(a, o, s)
681# define __attr_access(x)
682# define __attr_access_none(argno)
683#endif
684
685#if __GNUC_PREREQ (11, 0)
686/* Designates dealloc as a function to call to deallocate objects
687 allocated by the declared function. */
688# define __attr_dealloc(dealloc, argno) \
689 __attribute__ ((__malloc__ (dealloc, argno)))
690# define __attr_dealloc_free __attr_dealloc (__builtin_free, 1)
691#else
692# define __attr_dealloc(dealloc, argno)
693# define __attr_dealloc_free
694#endif
695
696/* Specify that a function such as setjmp or vfork may return
697 twice. */
698#if __GNUC_PREREQ (4, 1)
699# define __attribute_returns_twice__ __attribute__ ((__returns_twice__))
700#else
701# define __attribute_returns_twice__ /* Ignore. */
702#endif
703
704#endif /* sys/cdefs.h */
diff --git a/gl/cloexec.c b/gl/cloexec.c
new file mode 100644
index 0000000..7defa93
--- /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-2021 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..97a3659
--- /dev/null
+++ b/gl/cloexec.h
@@ -0,0 +1,36 @@
1/* cloexec.c - set or clear the close-on-exec descriptor flag
2
3 Copyright (C) 2004, 2009-2021 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 <stdbool.h>
19
20/* Set the 'FD_CLOEXEC' flag of DESC if VALUE is true,
21 or clear the flag if VALUE is false.
22 Return 0 on success, or -1 on error with 'errno' set.
23
24 Note that on MingW, this function does NOT protect DESC from being
25 inherited into spawned children. Instead, either use dup_cloexec
26 followed by closing the original DESC, or use interfaces such as
27 open or pipe2 that accept flags like O_CLOEXEC to create DESC
28 non-inheritable in the first place. */
29
30int set_cloexec_flag (int desc, bool value);
31
32/* Duplicates a file handle FD, while marking the copy to be closed
33 prior to exec or spawn. Returns -1 and sets errno if FD could not
34 be duplicated. */
35
36int dup_cloexec (int fd);
diff --git a/gl/close.c b/gl/close.c
new file mode 100644
index 0000000..5b9ab6c
--- /dev/null
+++ b/gl/close.c
@@ -0,0 +1,75 @@
1/* close replacement.
2 Copyright (C) 2008-2021 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..95f9c99 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-2021 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..d8b07d3 100644
--- a/gl/dirname.c
+++ b/gl/dirname.c
@@ -1,6 +1,6 @@
1/* dirname.c -- return all but the last element in a file name 1/* dirname.c -- return all but the last element in a file name
2 2
3 Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2013 Free Software 3 Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2021 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
@@ -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..25abc7b 100644
--- a/gl/dirname.h
+++ b/gl/dirname.h
@@ -1,46 +1,54 @@
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-2021 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 <stdbool.h>
23# include <stddef.h> 23# include <stdlib.h>
24# include "dosname.h" 24# include "filename.h"
25# include "basename-lgpl.h"
25 26
26# ifndef DIRECTORY_SEPARATOR 27# ifndef DIRECTORY_SEPARATOR
27# define DIRECTORY_SEPARATOR '/' 28# define DIRECTORY_SEPARATOR '/'
28# endif 29# endif
29 30
30# ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT 31#ifdef __cplusplus
31# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0 32extern "C" {
32# endif 33#endif
33 34
34# if GNULIB_DIRNAME 35# if GNULIB_DIRNAME
35char *base_name (char const *file); 36char *base_name (char const *file)
36char *dir_name (char const *file); 37 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
38 _GL_ATTRIBUTE_RETURNS_NONNULL;
39char *dir_name (char const *file)
40 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
41 _GL_ATTRIBUTE_RETURNS_NONNULL;
37# endif 42# endif
38 43
39char *mdir_name (char const *file); 44char *mdir_name (char const *file)
40size_t base_len (char const *file) _GL_ATTRIBUTE_PURE; 45 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
41size_t dir_len (char const *file) _GL_ATTRIBUTE_PURE; 46size_t dir_len (char const *file) _GL_ATTRIBUTE_PURE;
42char *last_component (char const *file) _GL_ATTRIBUTE_PURE;
43 47
44bool strip_trailing_slashes (char *file); 48bool strip_trailing_slashes (char *file);
45 49
50#ifdef __cplusplus
51} /* extern "C" */
52#endif
53
46#endif /* not DIRNAME_H_ */ 54#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..53e5552
--- /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-2021 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..ec64273
--- /dev/null
+++ b/gl/dynarray.h
@@ -0,0 +1,284 @@
1/* Type-safe arrays which grow dynamically.
2 Copyright 2021 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..3cad9e2 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-2021 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..f89dcc5 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-2021 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..814715e 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-2021 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..ebc1f58 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-2021 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..4add9e0 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-2021 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..c744eb9
--- /dev/null
+++ b/gl/fcntl.c
@@ -0,0 +1,629 @@
1/* Provide file descriptor control.
2
3 Copyright (C) 2009-2021 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..26dedc3
--- /dev/null
+++ b/gl/fcntl.in.h
@@ -0,0 +1,441 @@
1/* Like <fcntl.h>, but with non-working flags defined to 0.
2
3 Copyright (C) 2006-2021 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
439#endif /* _@GUARD_PREFIX@_FCNTL_H */
440#endif /* _@GUARD_PREFIX@_FCNTL_H */
441#endif
diff --git a/gl/fd-hook.c b/gl/fd-hook.c
index e158a52..75b1626 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-2021 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..98e2a52 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-2021 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..8fe9d26
--- /dev/null
+++ b/gl/fflush.c
@@ -0,0 +1,233 @@
1/* fflush.c -- allow flushing input streams
2 Copyright (C) 2007-2021 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__
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..dafe3df
--- /dev/null
+++ b/gl/filename.h
@@ -0,0 +1,112 @@
1/* Basic filename support macros.
2 Copyright (C) 2001-2004, 2007-2021 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..ad891f6 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-2021 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..dd1e84a 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-2021 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..f52aba3 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-2021 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..1530300 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-2021 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..587f73b 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-2021 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..cebcdac
--- /dev/null
+++ b/gl/fopen.c
@@ -0,0 +1,230 @@
1/* Open a stream to a file.
2 Copyright (C) 2007-2021 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 <stdbool.h>
43#include <string.h>
44#include <unistd.h>
45#include <sys/types.h>
46#include <sys/stat.h>
47
48FILE *
49rpl_fopen (const char *filename, const char *mode)
50{
51 int open_direction;
52 int open_flags;
53#if GNULIB_FOPEN_GNU
54 bool open_flags_gnu;
55# define BUF_SIZE 80
56 char fdopen_mode_buf[BUF_SIZE + 1];
57#endif
58
59#if defined _WIN32 && ! defined __CYGWIN__
60 if (strcmp (filename, "/dev/null") == 0)
61 filename = "NUL";
62#endif
63
64 /* Parse the mode. */
65 open_direction = 0;
66 open_flags = 0;
67#if GNULIB_FOPEN_GNU
68 open_flags_gnu = false;
69#endif
70 {
71 const char *p = mode;
72#if GNULIB_FOPEN_GNU
73 char *q = fdopen_mode_buf;
74#endif
75
76 for (; *p != '\0'; p++)
77 {
78 switch (*p)
79 {
80 case 'r':
81 open_direction = O_RDONLY;
82#if GNULIB_FOPEN_GNU
83 if (q < fdopen_mode_buf + BUF_SIZE)
84 *q++ = *p;
85#endif
86 continue;
87 case 'w':
88 open_direction = O_WRONLY;
89 open_flags |= O_CREAT | O_TRUNC;
90#if GNULIB_FOPEN_GNU
91 if (q < fdopen_mode_buf + BUF_SIZE)
92 *q++ = *p;
93#endif
94 continue;
95 case 'a':
96 open_direction = O_WRONLY;
97 open_flags |= O_CREAT | O_APPEND;
98#if GNULIB_FOPEN_GNU
99 if (q < fdopen_mode_buf + BUF_SIZE)
100 *q++ = *p;
101#endif
102 continue;
103 case 'b':
104 /* While it is non-standard, O_BINARY is guaranteed by
105 gnulib <fcntl.h>. We can also assume that orig_fopen
106 supports the 'b' flag. */
107 open_flags |= O_BINARY;
108#if GNULIB_FOPEN_GNU
109 if (q < fdopen_mode_buf + BUF_SIZE)
110 *q++ = *p;
111#endif
112 continue;
113 case '+':
114 open_direction = O_RDWR;
115#if GNULIB_FOPEN_GNU
116 if (q < fdopen_mode_buf + BUF_SIZE)
117 *q++ = *p;
118#endif
119 continue;
120#if GNULIB_FOPEN_GNU
121 case 'x':
122 open_flags |= O_EXCL;
123 open_flags_gnu = true;
124 continue;
125 case 'e':
126 open_flags |= O_CLOEXEC;
127 open_flags_gnu = true;
128 continue;
129#endif
130 default:
131 break;
132 }
133#if GNULIB_FOPEN_GNU
134 /* The rest of the mode string can be a platform-dependent extension.
135 Copy it unmodified. */
136 {
137 size_t len = strlen (p);
138 if (len > fdopen_mode_buf + BUF_SIZE - q)
139 len = fdopen_mode_buf + BUF_SIZE - q;
140 memcpy (q, p, len);
141 q += len;
142 }
143#endif
144 break;
145 }
146#if GNULIB_FOPEN_GNU
147 *q = '\0';
148#endif
149 }
150
151#if FOPEN_TRAILING_SLASH_BUG
152 /* Fail if the mode requires write access and the filename ends in a slash,
153 as POSIX says such a filename must name a directory
154 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>:
155 "A pathname that contains at least one non-<slash> character and that
156 ends with one or more trailing <slash> characters shall not be resolved
157 successfully unless the last pathname component before the trailing
158 <slash> characters names an existing directory"
159 If the named file already exists as a directory, then if a mode that
160 requires write access is specified, fopen() must fail because POSIX
161 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/fopen.html>
162 says that it fails with errno = EISDIR in this case.
163 If the named file does not exist or does not name a directory, then
164 fopen() must fail since the file does not contain a '.' directory. */
165 {
166 size_t len = strlen (filename);
167 if (len > 0 && filename[len - 1] == '/')
168 {
169 int fd;
170 struct stat statbuf;
171 FILE *fp;
172
173 if (open_direction != O_RDONLY)
174 {
175 errno = EISDIR;
176 return NULL;
177 }
178
179 fd = open (filename, open_direction | open_flags,
180 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
181 if (fd < 0)
182 return NULL;
183
184 if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode))
185 {
186 close (fd);
187 errno = ENOTDIR;
188 return NULL;
189 }
190
191# if GNULIB_FOPEN_GNU
192 fp = fdopen (fd, fdopen_mode_buf);
193# else
194 fp = fdopen (fd, mode);
195# endif
196 if (fp == NULL)
197 {
198 int saved_errno = errno;
199 close (fd);
200 errno = saved_errno;
201 }
202 return fp;
203 }
204 }
205#endif
206
207#if GNULIB_FOPEN_GNU
208 if (open_flags_gnu)
209 {
210 int fd;
211 FILE *fp;
212
213 fd = open (filename, open_direction | open_flags,
214 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
215 if (fd < 0)
216 return NULL;
217
218 fp = fdopen (fd, fdopen_mode_buf);
219 if (fp == NULL)
220 {
221 int saved_errno = errno;
222 close (fd);
223 errno = saved_errno;
224 }
225 return fp;
226 }
227#endif
228
229 return orig_fopen (filename, mode);
230}
diff --git a/gl/fpurge.c b/gl/fpurge.c
new file mode 100644
index 0000000..6b9c17a
--- /dev/null
+++ b/gl/fpurge.c
@@ -0,0 +1,150 @@
1/* Flushing buffers of a FILE stream.
2 Copyright (C) 2007-2021 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..be4f561
--- /dev/null
+++ b/gl/freading.c
@@ -0,0 +1,76 @@
1/* Retrieve information about a FILE stream.
2 Copyright (C) 2007-2021 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..61cdbd2
--- /dev/null
+++ b/gl/freading.h
@@ -0,0 +1,55 @@
1/* Retrieve information about a FILE stream.
2 Copyright (C) 2007-2021 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 <stdbool.h>
18#include <stdio.h>
19
20/* Return true if the stream STREAM is opened read-only, or if the
21 last operation on the stream was a read operation. Return false if
22 the stream is opened write-only or append-only, or if it supports
23 writing and there is no current read operation (such as fgetc).
24
25 freading and fwriting will never both be true. If STREAM supports
26 both reads and writes, then:
27 - both freading and fwriting might be false when the stream is first
28 opened, after read encounters EOF, or after fflush,
29 - freading might be false or true and fwriting might be false
30 after repositioning (such as fseek, fsetpos, or rewind),
31 depending on the underlying implementation.
32
33 STREAM must not be wide-character oriented. */
34
35#if HAVE___FREADING && (!defined __GLIBC__ || defined __UCLIBC__ || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7))
36/* 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 */
37
38# if HAVE_STDIO_EXT_H
39# include <stdio_ext.h>
40# endif
41# define freading(stream) (__freading (stream) != 0)
42
43#else
44
45# ifdef __cplusplus
46extern "C" {
47# endif
48
49extern bool freading (FILE *stream) _GL_ATTRIBUTE_PURE;
50
51# ifdef __cplusplus
52}
53# endif
54
55#endif
diff --git a/gl/free.c b/gl/free.c
new file mode 100644
index 0000000..780f03d
--- /dev/null
+++ b/gl/free.c
@@ -0,0 +1,53 @@
1/* Make free() preserve errno.
2
3 Copyright (C) 2003, 2006, 2009-2021 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..d0df710
--- /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-2021 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..3539a36
--- /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-2021 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..512c688
--- /dev/null
+++ b/gl/fstat.c
@@ -0,0 +1,94 @@
1/* fstat() replacement.
2 Copyright (C) 2011-2021 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..740cdc2 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-2021 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..b3f58d9 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-2021 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
@@ -32,8 +32,7 @@ struct fs_usage
32 uintmax_t fsu_bavail; /* Free blocks available to non-superuser. */ 32 uintmax_t fsu_bavail; /* Free blocks available to non-superuser. */
33 bool fsu_bavail_top_bit_set; /* 1 if fsu_bavail represents a value < 0. */ 33 bool fsu_bavail_top_bit_set; /* 1 if fsu_bavail represents a value < 0. */
34 uintmax_t fsu_files; /* Total file nodes. */ 34 uintmax_t fsu_files; /* Total file nodes. */
35 uintmax_t fsu_ffree; /* Free file nodes to superuser. */ 35 uintmax_t fsu_ffree; /* Free file nodes. */
36 uintmax_t fsu_favail; /* Free file nodes to non-superuser. */
37}; 36};
38 37
39int get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp); 38int get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp);
diff --git a/gl/ftell.c b/gl/ftell.c
new file mode 100644
index 0000000..a2479c6
--- /dev/null
+++ b/gl/ftell.c
@@ -0,0 +1,37 @@
1/* An ftell() function that works around platform bugs.
2 Copyright (C) 2007-2021 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..f701aa6
--- /dev/null
+++ b/gl/ftello.c
@@ -0,0 +1,157 @@
1/* An ftello() function that works around platform bugs.
2 Copyright (C) 2007, 2009-2021 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..4874ef5 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-2021 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..0c42d1b 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-2021 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. */
@@ -54,14 +54,48 @@
54# define PF_UNSPEC 0 54# define PF_UNSPEC 0
55#endif 55#endif
56 56
57#if defined _WIN32 || defined __WIN32__ 57#if HAVE_GETADDRINFO
58# define WINDOWS_NATIVE 58
59#endif 59/* Override with cdecl calling convention. */
60
61int
62getaddrinfo (const char *restrict nodename,
63 const char *restrict servname,
64 const struct addrinfo *restrict hints,
65 struct addrinfo **restrict res)
66# undef getaddrinfo
67{
68 return getaddrinfo (nodename, servname, hints, res);
69}
70
71void
72freeaddrinfo (struct addrinfo *ai)
73# undef freeaddrinfo
74{
75 freeaddrinfo (ai);
76}
77
78#else
79
80# if defined _WIN32 && !defined __CYGWIN__
81# define WINDOWS_NATIVE
82# endif
60 83
61/* gl_sockets_startup */ 84/* gl_sockets_startup */
62#include "sockets.h" 85# include "sockets.h"
86
87# ifdef WINDOWS_NATIVE
88
89/* Don't assume that UNICODE is not defined. */
90# undef GetModuleHandle
91# define GetModuleHandle GetModuleHandleA
92
93# if !(_WIN32_WINNT >= _WIN32_WINNT_WINXP)
94
95/* Avoid warnings from gcc -Wcast-function-type. */
96# define GetProcAddress \
97 (void *) GetProcAddress
63 98
64#ifdef WINDOWS_NATIVE
65typedef int (WSAAPI *getaddrinfo_func) (const char*, const char*, 99typedef int (WSAAPI *getaddrinfo_func) (const char*, const char*,
66 const struct addrinfo*, 100 const struct addrinfo*,
67 struct addrinfo**); 101 struct addrinfo**);
@@ -107,20 +141,43 @@ use_win32_p (void)
107 141
108 return 1; 142 return 1;
109} 143}
110#endif 144
145# else
146
147static int
148use_win32_p (void)
149{
150 static int done = 0;
151
152 if (!done)
153 {
154 done = 1;
155
156 gl_sockets_startup (SOCKETS_1_1);
157 }
158
159 return 1;
160}
161
162# define getaddrinfo_ptr getaddrinfo
163# define freeaddrinfo_ptr freeaddrinfo
164# define getnameinfo_ptr getnameinfo
165
166# endif
167# endif
111 168
112static bool 169static bool
113validate_family (int family) 170validate_family (int family)
114{ 171{
115 /* FIXME: Support more families. */ 172 /* FIXME: Support more families. */
116#if HAVE_IPV4 173# if HAVE_IPV4
117 if (family == PF_INET) 174 if (family == PF_INET)
118 return true; 175 return true;
119#endif 176# endif
120#if HAVE_IPV6 177# if HAVE_IPV6
121 if (family == PF_INET6) 178 if (family == PF_INET6)
122 return true; 179 return true;
123#endif 180# endif
124 if (family == PF_UNSPEC) 181 if (family == PF_UNSPEC)
125 return true; 182 return true;
126 return false; 183 return false;
@@ -133,29 +190,30 @@ getaddrinfo (const char *restrict nodename,
133 const char *restrict servname, 190 const char *restrict servname,
134 const struct addrinfo *restrict hints, 191 const struct addrinfo *restrict hints,
135 struct addrinfo **restrict res) 192 struct addrinfo **restrict res)
193#undef getaddrinfo
136{ 194{
137 struct addrinfo *tmp; 195 struct addrinfo *tmp;
138 int port = 0; 196 int port = 0;
139 struct hostent *he; 197 struct hostent *he;
140 void *storage; 198 void *storage;
141 size_t size; 199 size_t size;
142#if HAVE_IPV6 200# if HAVE_IPV6
143 struct v6_pair { 201 struct v6_pair {
144 struct addrinfo addrinfo; 202 struct addrinfo addrinfo;
145 struct sockaddr_in6 sockaddr_in6; 203 struct sockaddr_in6 sockaddr_in6;
146 }; 204 };
147#endif 205# endif
148#if HAVE_IPV4 206# if HAVE_IPV4
149 struct v4_pair { 207 struct v4_pair {
150 struct addrinfo addrinfo; 208 struct addrinfo addrinfo;
151 struct sockaddr_in sockaddr_in; 209 struct sockaddr_in sockaddr_in;
152 }; 210 };
153#endif 211# endif
154 212
155#ifdef WINDOWS_NATIVE 213# ifdef WINDOWS_NATIVE
156 if (use_win32_p ()) 214 if (use_win32_p ())
157 return getaddrinfo_ptr (nodename, servname, hints, res); 215 return getaddrinfo_ptr (nodename, servname, hints, res);
158#endif 216# endif
159 217
160 if (hints && (hints->ai_flags & ~(AI_CANONNAME|AI_PASSIVE))) 218 if (hints && (hints->ai_flags & ~(AI_CANONNAME|AI_PASSIVE)))
161 /* FIXME: Support more flags. */ 219 /* FIXME: Support more flags. */
@@ -174,11 +232,11 @@ getaddrinfo (const char *restrict nodename,
174 if (!(hints->ai_flags & AI_PASSIVE)) 232 if (!(hints->ai_flags & AI_PASSIVE))
175 return EAI_NONAME; 233 return EAI_NONAME;
176 234
177#ifdef HAVE_IPV6 235# ifdef HAVE_IPV6
178 nodename = (hints->ai_family == AF_INET6) ? "::" : "0.0.0.0"; 236 nodename = (hints->ai_family == AF_INET6) ? "::" : "0.0.0.0";
179#else 237# else
180 nodename = "0.0.0.0"; 238 nodename = "0.0.0.0";
181#endif 239# endif
182 } 240 }
183 241
184 if (servname) 242 if (servname)
@@ -212,17 +270,17 @@ getaddrinfo (const char *restrict nodename,
212 270
213 switch (he->h_addrtype) 271 switch (he->h_addrtype)
214 { 272 {
215#if HAVE_IPV6 273# if HAVE_IPV6
216 case PF_INET6: 274 case PF_INET6:
217 size = sizeof (struct v6_pair); 275 size = sizeof (struct v6_pair);
218 break; 276 break;
219#endif 277# endif
220 278
221#if HAVE_IPV4 279# if HAVE_IPV4
222 case PF_INET: 280 case PF_INET:
223 size = sizeof (struct v4_pair); 281 size = sizeof (struct v4_pair);
224 break; 282 break;
225#endif 283# endif
226 284
227 default: 285 default:
228 return EAI_NODATA; 286 return EAI_NODATA;
@@ -234,7 +292,7 @@ getaddrinfo (const char *restrict nodename,
234 292
235 switch (he->h_addrtype) 293 switch (he->h_addrtype)
236 { 294 {
237#if HAVE_IPV6 295# if HAVE_IPV6
238 case PF_INET6: 296 case PF_INET6:
239 { 297 {
240 struct v6_pair *p = storage; 298 struct v6_pair *p = storage;
@@ -256,9 +314,9 @@ getaddrinfo (const char *restrict nodename,
256 tmp->ai_addrlen = sizeof *sinp; 314 tmp->ai_addrlen = sizeof *sinp;
257 } 315 }
258 break; 316 break;
259#endif 317# endif
260 318
261#if HAVE_IPV4 319# if HAVE_IPV4
262 case PF_INET: 320 case PF_INET:
263 { 321 {
264 struct v4_pair *p = storage; 322 struct v4_pair *p = storage;
@@ -280,7 +338,7 @@ getaddrinfo (const char *restrict nodename,
280 tmp->ai_addrlen = sizeof *sinp; 338 tmp->ai_addrlen = sizeof *sinp;
281 } 339 }
282 break; 340 break;
283#endif 341# endif
284 342
285 default: 343 default:
286 free (storage); 344 free (storage);
@@ -308,21 +366,21 @@ getaddrinfo (const char *restrict nodename,
308 tmp->ai_addr->sa_family = he->h_addrtype; 366 tmp->ai_addr->sa_family = he->h_addrtype;
309 tmp->ai_family = he->h_addrtype; 367 tmp->ai_family = he->h_addrtype;
310 368
311#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN 369# ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
312 switch (he->h_addrtype) 370 switch (he->h_addrtype)
313 { 371 {
314#if HAVE_IPV4 372# if HAVE_IPV4
315 case AF_INET: 373 case AF_INET:
316 tmp->ai_addr->sa_len = sizeof (struct sockaddr_in); 374 tmp->ai_addr->sa_len = sizeof (struct sockaddr_in);
317 break; 375 break;
318#endif 376# endif
319#if HAVE_IPV6 377# if HAVE_IPV6
320 case AF_INET6: 378 case AF_INET6:
321 tmp->ai_addr->sa_len = sizeof (struct sockaddr_in6); 379 tmp->ai_addr->sa_len = sizeof (struct sockaddr_in6);
322 break; 380 break;
323#endif 381# endif
324 } 382 }
325#endif 383# endif
326 384
327 /* FIXME: If more than one address, create linked list of addrinfo's. */ 385 /* FIXME: If more than one address, create linked list of addrinfo's. */
328 386
@@ -334,14 +392,15 @@ getaddrinfo (const char *restrict nodename,
334/* Free 'addrinfo' structure AI including associated storage. */ 392/* Free 'addrinfo' structure AI including associated storage. */
335void 393void
336freeaddrinfo (struct addrinfo *ai) 394freeaddrinfo (struct addrinfo *ai)
395#undef freeaddrinfo
337{ 396{
338#ifdef WINDOWS_NATIVE 397# ifdef WINDOWS_NATIVE
339 if (use_win32_p ()) 398 if (use_win32_p ())
340 { 399 {
341 freeaddrinfo_ptr (ai); 400 freeaddrinfo_ptr (ai);
342 return; 401 return;
343 } 402 }
344#endif 403# endif
345 404
346 while (ai) 405 while (ai)
347 { 406 {
@@ -360,12 +419,13 @@ getnameinfo (const struct sockaddr *restrict sa, socklen_t salen,
360 char *restrict node, socklen_t nodelen, 419 char *restrict node, socklen_t nodelen,
361 char *restrict service, socklen_t servicelen, 420 char *restrict service, socklen_t servicelen,
362 int flags) 421 int flags)
422#undef getnameinfo
363{ 423{
364#ifdef WINDOWS_NATIVE 424# ifdef WINDOWS_NATIVE
365 if (use_win32_p ()) 425 if (use_win32_p ())
366 return getnameinfo_ptr (sa, salen, node, nodelen, 426 return getnameinfo_ptr (sa, salen, node, nodelen,
367 service, servicelen, flags); 427 service, servicelen, flags);
368#endif 428# endif
369 429
370 /* FIXME: Support other flags. */ 430 /* FIXME: Support other flags. */
371 if ((node && nodelen > 0 && !(flags & NI_NUMERICHOST)) || 431 if ((node && nodelen > 0 && !(flags & NI_NUMERICHOST)) ||
@@ -378,18 +438,18 @@ getnameinfo (const struct sockaddr *restrict sa, socklen_t salen,
378 438
379 switch (sa->sa_family) 439 switch (sa->sa_family)
380 { 440 {
381#if HAVE_IPV4 441# if HAVE_IPV4
382 case AF_INET: 442 case AF_INET:
383 if (salen < sizeof (struct sockaddr_in)) 443 if (salen < sizeof (struct sockaddr_in))
384 return EAI_FAMILY; 444 return EAI_FAMILY;
385 break; 445 break;
386#endif 446# endif
387#if HAVE_IPV6 447# if HAVE_IPV6
388 case AF_INET6: 448 case AF_INET6:
389 if (salen < sizeof (struct sockaddr_in6)) 449 if (salen < sizeof (struct sockaddr_in6))
390 return EAI_FAMILY; 450 return EAI_FAMILY;
391 break; 451 break;
392#endif 452# endif
393 default: 453 default:
394 return EAI_FAMILY; 454 return EAI_FAMILY;
395 } 455 }
@@ -398,23 +458,23 @@ getnameinfo (const struct sockaddr *restrict sa, socklen_t salen,
398 { 458 {
399 switch (sa->sa_family) 459 switch (sa->sa_family)
400 { 460 {
401#if HAVE_IPV4 461# if HAVE_IPV4
402 case AF_INET: 462 case AF_INET:
403 if (!inet_ntop (AF_INET, 463 if (!inet_ntop (AF_INET,
404 &(((const struct sockaddr_in *) sa)->sin_addr), 464 &(((const struct sockaddr_in *) sa)->sin_addr),
405 node, nodelen)) 465 node, nodelen))
406 return EAI_SYSTEM; 466 return EAI_SYSTEM;
407 break; 467 break;
408#endif 468# endif
409 469
410#if HAVE_IPV6 470# if HAVE_IPV6
411 case AF_INET6: 471 case AF_INET6:
412 if (!inet_ntop (AF_INET6, 472 if (!inet_ntop (AF_INET6,
413 &(((const struct sockaddr_in6 *) sa)->sin6_addr), 473 &(((const struct sockaddr_in6 *) sa)->sin6_addr),
414 node, nodelen)) 474 node, nodelen))
415 return EAI_SYSTEM; 475 return EAI_SYSTEM;
416 break; 476 break;
417#endif 477# endif
418 478
419 default: 479 default:
420 return EAI_FAMILY; 480 return EAI_FAMILY;
@@ -424,12 +484,12 @@ getnameinfo (const struct sockaddr *restrict sa, socklen_t salen,
424 if (service && servicelen > 0 && flags & NI_NUMERICSERV) 484 if (service && servicelen > 0 && flags & NI_NUMERICSERV)
425 switch (sa->sa_family) 485 switch (sa->sa_family)
426 { 486 {
427#if HAVE_IPV4 487# if HAVE_IPV4
428 case AF_INET: 488 case AF_INET:
429#endif 489# endif
430#if HAVE_IPV6 490# if HAVE_IPV6
431 case AF_INET6: 491 case AF_INET6:
432#endif 492# endif
433 { 493 {
434 unsigned short int port 494 unsigned short int port
435 = ntohs (((const struct sockaddr_in *) sa)->sin_port); 495 = ntohs (((const struct sockaddr_in *) sa)->sin_port);
@@ -441,3 +501,5 @@ getnameinfo (const struct sockaddr *restrict sa, socklen_t salen,
441 501
442 return 0; 502 return 0;
443} 503}
504
505#endif
diff --git a/gl/getdelim.c b/gl/getdelim.c
new file mode 100644
index 0000000..c690b10
--- /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-2021 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..5006c2d
--- /dev/null
+++ b/gl/getdtablesize.c
@@ -0,0 +1,124 @@
1/* getdtablesize() function: Return maximum possible file descriptor value + 1.
2 Copyright (C) 2008-2021 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..028edc6 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-2021 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..47de1ba
--- /dev/null
+++ b/gl/getline.c
@@ -0,0 +1,27 @@
1/* getline.c --- Implementation of replacement getline function.
2 Copyright (C) 2005-2007, 2009-2021 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..d42d0cd 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-2021 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.
@@ -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.
@@ -97,9 +93,8 @@
97 93
98# include "intprops.h" 94# include "intprops.h"
99 95
100# if !defined (BSD) && defined (ultrix) 96# if defined _WIN32 && ! defined __CYGWIN__ && ! defined WINDOWS32
101/* Ultrix behaves like BSD on Vaxen. */ 97# define WINDOWS32
102# define BSD
103# endif 98# endif
104 99
105# ifdef NeXT 100# ifdef NeXT
@@ -141,10 +136,6 @@
141# define MORE_BSD 136# define MORE_BSD
142# endif 137# endif
143 138
144# if defined (ultrix) && defined (mips)
145# define decstation
146# endif
147
148# if defined (__SVR4) && !defined (SVR4) 139# if defined (__SVR4) && !defined (SVR4)
149# define SVR4 140# define SVR4
150# endif 141# endif
@@ -168,13 +159,6 @@
168# include <sys/table.h> 159# include <sys/table.h>
169# endif 160# endif
170 161
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 162
179/* VAX C can't handle multi-line #ifs, or lines longer than 256 chars. */ 163/* VAX C can't handle multi-line #ifs, or lines longer than 256 chars. */
180# ifndef LOAD_AVE_TYPE 164# ifndef LOAD_AVE_TYPE
@@ -187,14 +171,6 @@
187# define LOAD_AVE_TYPE long 171# define LOAD_AVE_TYPE long
188# endif 172# endif
189 173
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 174# ifdef sgi
199# define LOAD_AVE_TYPE long 175# define LOAD_AVE_TYPE long
200# endif 176# endif
@@ -203,41 +179,14 @@
203# define LOAD_AVE_TYPE long 179# define LOAD_AVE_TYPE long
204# endif 180# endif
205 181
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 182# ifdef OSF_ALPHA
215# define LOAD_AVE_TYPE long 183# define LOAD_AVE_TYPE long
216# endif 184# endif
217 185
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 186# if defined _AIX && ! defined HAVE_LIBPERFSTAT
231# define LOAD_AVE_TYPE long 187# define LOAD_AVE_TYPE long
232# endif 188# endif
233 189
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. */ 190# endif /* No LOAD_AVE_TYPE. */
242 191
243# ifdef OSF_ALPHA 192# ifdef OSF_ALPHA
@@ -247,13 +196,6 @@
247# define FSCALE 1024.0 196# define FSCALE 1024.0
248# endif 197# endif
249 198
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 199
258# ifndef FSCALE 200# ifndef FSCALE
259 201
@@ -263,25 +205,17 @@
263# define FSCALE 2048.0 205# define FSCALE 2048.0
264# endif 206# endif
265 207
266# if defined (MIPS) || defined (SVR4) || defined (decstation) 208# if defined (MIPS) || defined (SVR4)
267# define FSCALE 256 209# define FSCALE 256
268# endif 210# endif
269 211
270# if defined (sgi) || defined (sequent) 212# if defined (sgi)
271/* Sometimes both MIPS and sgi are defined, so FSCALE was just defined 213/* Sometimes both MIPS and sgi are defined, so FSCALE was just defined
272 above under #ifdef MIPS. But we want the sgi value. */ 214 above under #ifdef MIPS. But we want the sgi value. */
273# undef FSCALE 215# undef FSCALE
274# define FSCALE 1000.0 216# define FSCALE 1000.0
275# endif 217# endif
276 218
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 219# if defined _AIX && !defined HAVE_LIBPERFSTAT
286# define FSCALE 65536.0 220# define FSCALE 65536.0
287# endif 221# endif
@@ -303,28 +237,22 @@
303# endif 237# endif
304 238
305 239
306# if !defined (KERNEL_FILE) && defined (sequent)
307# define KERNEL_FILE "/dynix"
308# endif
309
310# if !defined (KERNEL_FILE) && defined (hpux) 240# if !defined (KERNEL_FILE) && defined (hpux)
311# define KERNEL_FILE "/hp-ux" 241# define KERNEL_FILE "/hp-ux"
312# endif 242# endif
313 243
314# if !defined (KERNEL_FILE) && (defined (_SEQUENT_) || defined (MIPS) || defined (SVR4) || defined (ISC) || defined (sgi) || (defined (ardent) && defined (titan))) 244# if !defined (KERNEL_FILE) && (defined (MIPS) || defined (SVR4) || defined (ISC) || defined (sgi))
315# define KERNEL_FILE "/unix" 245# define KERNEL_FILE "/unix"
316# endif 246# endif
317 247
318 248
319# if !defined (LDAV_SYMBOL) && defined (alliant) 249# 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" 250# define LDAV_SYMBOL "avenrun"
325# endif 251# endif
326 252
327# include <unistd.h> 253# ifdef HAVE_UNISTD_H
254# include <unistd.h>
255# endif
328 256
329/* LOAD_AVE_TYPE should only get defined if we're going to use the 257/* LOAD_AVE_TYPE should only get defined if we're going to use the
330 nlist method. */ 258 nlist method. */
@@ -335,7 +263,7 @@
335# ifdef LOAD_AVE_TYPE 263# ifdef LOAD_AVE_TYPE
336 264
337# ifndef __VMS 265# ifndef __VMS
338# ifndef __linux__ 266# if !(defined __linux__ || defined __ANDROID__)
339# ifndef NLIST_STRUCT 267# ifndef NLIST_STRUCT
340# include <a.out.h> 268# include <a.out.h>
341# else /* NLIST_STRUCT */ 269# else /* NLIST_STRUCT */
@@ -358,7 +286,7 @@
358# ifndef LDAV_SYMBOL 286# ifndef LDAV_SYMBOL
359# define LDAV_SYMBOL "_avenrun" 287# define LDAV_SYMBOL "_avenrun"
360# endif /* LDAV_SYMBOL */ 288# endif /* LDAV_SYMBOL */
361# endif /* __linux__ */ 289# endif /* __linux__ || __ANDROID__ */
362 290
363# else /* __VMS */ 291# else /* __VMS */
364 292
@@ -431,7 +359,8 @@
431# include <sys/dg_sys_info.h> 359# include <sys/dg_sys_info.h>
432# endif 360# endif
433 361
434# if (defined __linux__ || defined __CYGWIN__ || defined SUNOS_5 \ 362# if (defined __linux__ || defined __ANDROID__ \
363 || defined __CYGWIN__ || defined SUNOS_5 \
435 || (defined LOAD_AVE_TYPE && ! defined __VMS)) 364 || (defined LOAD_AVE_TYPE && ! defined __VMS))
436# include <fcntl.h> 365# include <fcntl.h>
437# endif 366# endif
@@ -460,7 +389,7 @@ static bool getloadavg_initialized;
460/* Offset in kmem to seek to read load average, or 0 means invalid. */ 389/* Offset in kmem to seek to read load average, or 0 means invalid. */
461static long offset; 390static long offset;
462 391
463# if ! defined __VMS && ! defined sgi && ! defined __linux__ 392# if ! defined __VMS && ! defined sgi && ! (defined __linux__ || defined __ANDROID__)
464static struct nlist name_list[2]; 393static struct nlist name_list[2];
465# endif 394# endif
466 395
@@ -495,17 +424,17 @@ getloadavg (double loadavg[], int nelem)
495 int saved_errno; 424 int saved_errno;
496 425
497 kc = kstat_open (); 426 kc = kstat_open ();
498 if (kc == 0) 427 if (kc == NULL)
499 return -1; 428 return -1;
500 ksp = kstat_lookup (kc, "unix", 0, "system_misc"); 429 ksp = kstat_lookup (kc, "unix", 0, "system_misc");
501 if (ksp == 0) 430 if (ksp == NULL)
502 return -1; 431 return -1;
503 if (kstat_read (kc, ksp, 0) == -1) 432 if (kstat_read (kc, ksp, 0) == -1)
504 return -1; 433 return -1;
505 434
506 435
507 kn = kstat_data_lookup (ksp, "avenrun_1min"); 436 kn = kstat_data_lookup (ksp, "avenrun_1min");
508 if (kn == 0) 437 if (kn == NULL)
509 { 438 {
510 /* Return -1 if no load average information is available. */ 439 /* Return -1 if no load average information is available. */
511 nelem = 0; 440 nelem = 0;
@@ -518,14 +447,14 @@ getloadavg (double loadavg[], int nelem)
518 if (nelem >= 2) 447 if (nelem >= 2)
519 { 448 {
520 kn = kstat_data_lookup (ksp, "avenrun_5min"); 449 kn = kstat_data_lookup (ksp, "avenrun_5min");
521 if (kn != 0) 450 if (kn != NULL)
522 { 451 {
523 loadavg[elem++] = (double) kn->value.ul / FSCALE; 452 loadavg[elem++] = (double) kn->value.ul / FSCALE;
524 453
525 if (nelem >= 3) 454 if (nelem >= 3)
526 { 455 {
527 kn = kstat_data_lookup (ksp, "avenrun_15min"); 456 kn = kstat_data_lookup (ksp, "avenrun_15min");
528 if (kn != 0) 457 if (kn != NULL)
529 loadavg[elem++] = (double) kn->value.ul / FSCALE; 458 loadavg[elem++] = (double) kn->value.ul / FSCALE;
530 } 459 }
531 } 460 }
@@ -570,8 +499,8 @@ getloadavg (double loadavg[], int nelem)
570 } 499 }
571# endif 500# endif
572 501
573# if !defined (LDAV_DONE) && (defined (__linux__) || defined (__CYGWIN__)) 502# if !defined (LDAV_DONE) && (defined __linux__ || defined __ANDROID__ || defined __CYGWIN__)
574 /* Linux without glibc, Cygwin */ 503 /* Linux without glibc, Android, Cygwin */
575# define LDAV_DONE 504# define LDAV_DONE
576# undef LOAD_AVE_TYPE 505# undef LOAD_AVE_TYPE
577 506
@@ -583,7 +512,7 @@ getloadavg (double loadavg[], int nelem)
583 char const *ptr = ldavgbuf; 512 char const *ptr = ldavgbuf;
584 int fd, count, saved_errno; 513 int fd, count, saved_errno;
585 514
586 fd = open (LINUX_LDAV_FILE, O_RDONLY); 515 fd = open (LINUX_LDAV_FILE, O_RDONLY | O_CLOEXEC);
587 if (fd == -1) 516 if (fd == -1)
588 return -1; 517 return -1;
589 count = read (fd, ldavgbuf, sizeof ldavgbuf - 1); 518 count = read (fd, ldavgbuf, sizeof ldavgbuf - 1);
@@ -621,12 +550,12 @@ getloadavg (double loadavg[], int nelem)
621 for (ptr++; '0' <= *ptr && *ptr <= '9'; ptr++) 550 for (ptr++; '0' <= *ptr && *ptr <= '9'; ptr++)
622 numerator = 10 * numerator + (*ptr - '0'), denominator *= 10; 551 numerator = 10 * numerator + (*ptr - '0'), denominator *= 10;
623 552
624 loadavg[elem++] = numerator / denominator; 553 loadavg[elem] = numerator / denominator;
625 } 554 }
626 555
627 return elem; 556 return elem;
628 557
629# endif /* __linux__ || __CYGWIN__ */ 558# endif /* __linux__ || __ANDROID__ || __CYGWIN__ */
630 559
631# if !defined (LDAV_DONE) && defined (__NetBSD__) /* NetBSD < 0.9 */ 560# if !defined (LDAV_DONE) && defined (__NetBSD__) /* NetBSD < 0.9 */
632# define LDAV_DONE 561# define LDAV_DONE
@@ -638,15 +567,22 @@ getloadavg (double loadavg[], int nelem)
638 567
639 unsigned long int load_ave[3], scale; 568 unsigned long int load_ave[3], scale;
640 int count; 569 int count;
641 FILE *fp; 570 char readbuf[4 * INT_BUFSIZE_BOUND (unsigned long int) + 1];
642 571 int fd = open (NETBSD_LDAV_FILE, O_RDONLY | O_CLOEXEC);
643 fp = fopen (NETBSD_LDAV_FILE, "r"); 572 if (fd < 0)
644 if (fp == NULL) 573 return fd;
645 return -1; 574 int nread = read (fd, readbuf, sizeof readbuf - 1);
646 count = fscanf (fp, "%lu %lu %lu %lu\n", 575 int err = errno;
576 close (fd);
577 if (nread < 0)
578 {
579 errno = err;
580 return -1;
581 }
582 readbuf[nread] = '\0';
583 count = sscanf (readbuf, "%lu %lu %lu %lu\n",
647 &load_ave[0], &load_ave[1], &load_ave[2], 584 &load_ave[0], &load_ave[1], &load_ave[2],
648 &scale); 585 &scale);
649 (void) fclose (fp);
650 if (count != 4) 586 if (count != 4)
651 { 587 {
652 errno = ENOTSUP; 588 errno = ENOTSUP;
@@ -915,7 +851,7 @@ getloadavg (double loadavg[], int nelem)
915 851
916# ifndef SUNOS_5 852# ifndef SUNOS_5
917 if ( 853 if (
918# if !(defined (_AIX) && !defined (ps2)) 854# if !defined (_AIX)
919 nlist (KERNEL_FILE, name_list) 855 nlist (KERNEL_FILE, name_list)
920# else /* _AIX */ 856# else /* _AIX */
921 knlist (name_list, 1, sizeof (name_list[0])) 857 knlist (name_list, 1, sizeof (name_list[0]))
@@ -940,33 +876,17 @@ getloadavg (double loadavg[], int nelem)
940 if (!getloadavg_initialized) 876 if (!getloadavg_initialized)
941 { 877 {
942# ifndef SUNOS_5 878# 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); 879 int fd = open ("/dev/kmem", O_RDONLY | O_CLOEXEC);
949 if (0 <= fd) 880 if (0 <= fd)
950 { 881 {
951# if F_DUPFD_CLOEXEC 882 channel = fd;
952 if (fd <= STDERR_FILENO) 883 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 } 884 }
965# else /* SUNOS_5 */ 885# else /* SUNOS_5 */
966 /* We pass 0 for the kernel, corefile, and swapfile names 886 /* We pass 0 for the kernel, corefile, and swapfile names
967 to use the currently running kernel. */ 887 to use the currently running kernel. */
968 kd = kvm_open (0, 0, 0, O_RDONLY, 0); 888 kd = kvm_open (0, 0, 0, O_RDONLY, 0);
969 if (kd != 0) 889 if (kd != NULL)
970 { 890 {
971 /* nlist the currently running kernel. */ 891 /* nlist the currently running kernel. */
972 kvm_nlist (kd, name_list); 892 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..33e3d4b
--- /dev/null
+++ b/gl/getopt-cdefs.in.h
@@ -0,0 +1,66 @@
1/* getopt-on-non-glibc compatibility macros.
2 Copyright (C) 1989-2021 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..ceb14d0
--- /dev/null
+++ b/gl/getopt-core.h
@@ -0,0 +1,96 @@
1/* Declarations for getopt (basic, portable features only).
2 Copyright (C) 1989-2021 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..f82a8c6
--- /dev/null
+++ b/gl/getopt-ext.h
@@ -0,0 +1,77 @@
1/* Declarations for getopt (GNU extensions).
2 Copyright (C) 1989-2021 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..b1733a3
--- /dev/null
+++ b/gl/getopt-pfx-core.h
@@ -0,0 +1,66 @@
1/* getopt (basic, portable features) gnulib wrapper header.
2 Copyright (C) 1989-2021 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..b9a14ba
--- /dev/null
+++ b/gl/getopt-pfx-ext.h
@@ -0,0 +1,70 @@
1/* getopt (GNU extensions) gnulib wrapper header.
2 Copyright (C) 1989-2021 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..7f3aa5a 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-2021 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..bf884f0 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-2021 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..5a92806 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-2021 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..91254e4 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-2021 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..9a80281
--- /dev/null
+++ b/gl/getprogname.c
@@ -0,0 +1,302 @@
1/* Program name management.
2 Copyright (C) 2016-2021 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..eb12dcd
--- /dev/null
+++ b/gl/getprogname.h
@@ -0,0 +1,40 @@
1/* Program name management.
2 Copyright (C) 2016-2021 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..f1c7a24 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-2021 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>
@@ -183,8 +184,16 @@ 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 && (((__GNUC__ >= 3 || __GNUG__ >= 2) && !defined __STRICT_ANSI__) \
195 /* || (__STDC_VERSION__ == 199901L && !defined __HP_cc)
196 || (__STDC_VERSION__ >= 201112L && !defined __STDC_NO_VLA__) */ ))
188# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 1 197# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 1
189#else 198#else
190# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 0 199# define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 0
@@ -225,15 +234,17 @@ dcpgettext_expr (const char *domain,
225 if (msg_ctxt_id != NULL) 234 if (msg_ctxt_id != NULL)
226#endif 235#endif
227 { 236 {
237 int found_translation;
228 memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); 238 memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
229 msg_ctxt_id[msgctxt_len - 1] = '\004'; 239 msg_ctxt_id[msgctxt_len - 1] = '\004';
230 memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); 240 memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
231 translation = dcgettext (domain, msg_ctxt_id, category); 241 translation = dcgettext (domain, msg_ctxt_id, category);
242 found_translation = (translation != msg_ctxt_id);
232#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 243#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
233 if (msg_ctxt_id != buf) 244 if (msg_ctxt_id != buf)
234 free (msg_ctxt_id); 245 free (msg_ctxt_id);
235#endif 246#endif
236 if (translation != msg_ctxt_id) 247 if (found_translation)
237 return translation; 248 return translation;
238 } 249 }
239 return msgid; 250 return msgid;
@@ -271,15 +282,17 @@ dcnpgettext_expr (const char *domain,
271 if (msg_ctxt_id != NULL) 282 if (msg_ctxt_id != NULL)
272#endif 283#endif
273 { 284 {
285 int found_translation;
274 memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); 286 memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
275 msg_ctxt_id[msgctxt_len - 1] = '\004'; 287 msg_ctxt_id[msgctxt_len - 1] = '\004';
276 memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); 288 memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
277 translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category); 289 translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
290 found_translation = !(translation == msg_ctxt_id || translation == msgid_plural);
278#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 291#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
279 if (msg_ctxt_id != buf) 292 if (msg_ctxt_id != buf)
280 free (msg_ctxt_id); 293 free (msg_ctxt_id);
281#endif 294#endif
282 if (!(translation == msg_ctxt_id || translation == msgid_plural)) 295 if (found_translation)
283 return translation; 296 return translation;
284 } 297 }
285 return (n == 1 ? msgid : msgid_plural); 298 return (n == 1 ? msgid : msgid_plural);
diff --git a/gl/gl_openssl.h b/gl/gl_openssl.h
new file mode 100644
index 0000000..ed98975
--- /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-2021 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..44335e3 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-2021 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..cc4c519 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-2021 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..793bc69 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-2021 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..8b6802d
--- /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-2021 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..eba6601
--- /dev/null
+++ b/gl/hard-locale.h
@@ -0,0 +1,28 @@
1/* Determine whether a locale is hard.
2
3 Copyright (C) 1999, 2003-2004, 2009-2021 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# include <stdbool.h>
22
23/* Return true if the specified CATEGORY of the current locale is hard, i.e.
24 different from the C or POSIX locale that has a fixed behavior.
25 CATEGORY must be one of the LC_* values, but not LC_ALL. */
26extern bool hard_locale (int category);
27
28#endif /* HARD_LOCALE_H_ */
diff --git a/gl/ialloc.c b/gl/ialloc.c
new file mode 100644
index 0000000..0137099
--- /dev/null
+++ b/gl/ialloc.c
@@ -0,0 +1,21 @@
1/* malloc with idx_t rather than size_t
2
3 Copyright 2021 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..d4f54ce
--- /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 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..532413a 100644
--- a/gl/idpriv-droptemp.c
+++ b/gl/idpriv-droptemp.c
@@ -1,5 +1,5 @@
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-2021 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
@@ -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..0f7e2f4 100644
--- a/gl/idpriv.h
+++ b/gl/idpriv.h
@@ -1,5 +1,5 @@
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-2021 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
@@ -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..54ad5d8
--- /dev/null
+++ b/gl/idx.h
@@ -0,0 +1,134 @@
1/* A type for indices and sizes.
2 Copyright (C) 2020-2021 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..409e88c 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-2021 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.h b/gl/intprops.h
index f57f9b4..3fe64e8 100644
--- a/gl/intprops.h
+++ b/gl/intprops.h
@@ -1,34 +1,33 @@
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-2021 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 17
18/* Written by Paul Eggert. */
19 18
20#ifndef _GL_INTPROPS_H 19#ifndef _GL_INTPROPS_H
21#define _GL_INTPROPS_H 20#define _GL_INTPROPS_H
22 21
23#include <limits.h> 22#include <limits.h>
24 23
25/* Return an integer value, converted to the same type as the integer 24/* Return a value with the common real type of E and V and the value of V.
26 expression E after integer type promotion. V is the unconverted value. */ 25 Do not evaluate E. */
27#define _GL_INT_CONVERT(e, v) (0 * (e) + (v)) 26#define _GL_INT_CONVERT(e, v) ((1 ? 0 : (e)) + (v))
28 27
29/* Act like _GL_INT_CONVERT (E, -V) but work around a bug in IRIX 6.5 cc; see 28/* 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>. */ 29 <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00406.html>. */
31#define _GL_INT_NEGATE_CONVERT(e, v) (0 * (e) - (v)) 30#define _GL_INT_NEGATE_CONVERT(e, v) ((1 ? 0 : (e)) - (v))
32 31
33/* The extra casts in the following macros work around compiler bugs, 32/* The extra casts in the following macros work around compiler bugs,
34 e.g., in Cray C 5.0.3.0. */ 33 e.g., in Cray C 5.0.3.0. */
@@ -37,67 +36,67 @@
37 an integer. */ 36 an integer. */
38#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1) 37#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1)
39 38
40/* True if negative values of the signed integer type T use two's 39/* True if the real type T is signed. */
41 complement, ones' complement, or signed magnitude representation,
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
48/* True if the signed integer expression E uses two's complement. */
49#define _GL_INT_TWOS_COMPLEMENT(e) (~ _GL_INT_CONVERT (e, 0) == -1)
50
51/* True if the arithmetic type T is signed. */
52#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) 40#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
53 41
54/* Return 1 if the integer expression E, after integer promotion, has 42/* Return 1 if the real expression E, after promotion, has a
55 a signed type. */ 43 signed or floating type. Do not evaluate E. */
56#define _GL_INT_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0) 44#define EXPR_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0)
57 45
58 46
59/* Minimum and maximum values for integer types and expressions. These 47/* Minimum and maximum values for integer types and expressions. */
60 macros have undefined behavior if T is signed and has padding bits. 48
61 If this is a problem for you, please let us know how to fix it for 49/* The width in bits of the integer type or expression T.
62 your host. */ 50 Do not evaluate T. T must not be a bit-field expression.
51 Padding bits are not supported; this is checked at compile-time below. */
52#define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT)
63 53
64/* The maximum and minimum values for the integer type T. */ 54/* The maximum and minimum values for the integer type T. */
65#define TYPE_MINIMUM(t) \ 55#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) \ 56#define TYPE_MAXIMUM(t) \
72 ((t) (! TYPE_SIGNED (t) \ 57 ((t) (! TYPE_SIGNED (t) \
73 ? (t) -1 \ 58 ? (t) -1 \
74 : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1))) 59 : ((((t) 1 << (TYPE_WIDTH (t) - 2)) - 1) * 2 + 1)))
75 60
76/* The maximum and minimum values for the type of the expression E, 61/* The maximum and minimum values for the type of the expression E,
77 after integer promotion. E should not have side effects. */ 62 after integer promotion. E is not evaluated. */
78#define _GL_INT_MINIMUM(e) \ 63#define _GL_INT_MINIMUM(e) \
79 (_GL_INT_SIGNED (e) \ 64 (EXPR_SIGNED (e) \
80 ? - _GL_INT_TWOS_COMPLEMENT (e) - _GL_SIGNED_INT_MAXIMUM (e) \ 65 ? ~ _GL_SIGNED_INT_MAXIMUM (e) \
81 : _GL_INT_CONVERT (e, 0)) 66 : _GL_INT_CONVERT (e, 0))
82#define _GL_INT_MAXIMUM(e) \ 67#define _GL_INT_MAXIMUM(e) \
83 (_GL_INT_SIGNED (e) \ 68 (EXPR_SIGNED (e) \
84 ? _GL_SIGNED_INT_MAXIMUM (e) \ 69 ? _GL_SIGNED_INT_MAXIMUM (e) \
85 : _GL_INT_NEGATE_CONVERT (e, 1)) 70 : _GL_INT_NEGATE_CONVERT (e, 1))
86#define _GL_SIGNED_INT_MAXIMUM(e) \ 71#define _GL_SIGNED_INT_MAXIMUM(e) \
87 (((_GL_INT_CONVERT (e, 1) << (sizeof ((e) + 0) * CHAR_BIT - 2)) - 1) * 2 + 1) 72 (((_GL_INT_CONVERT (e, 1) << (TYPE_WIDTH (+ (e)) - 2)) - 1) * 2 + 1)
88 73
74/* Work around OpenVMS incompatibility with C99. */
75#if !defined LLONG_MAX && defined __INT64_MAX
76# define LLONG_MAX __INT64_MAX
77# define LLONG_MIN __INT64_MIN
78#endif
79
80/* This include file assumes that signed types are two's complement without
81 padding bits; the above macros have undefined behavior otherwise.
82 If this is a problem for you, please let us know how to fix it for your host.
83 This assumption is tested by the intprops-tests module. */
89 84
90/* Return 1 if the __typeof__ keyword works. This could be done by 85/* Does the __typeof__ keyword work? This could be done by
91 'configure', but for now it's easier to do it by hand. */ 86 'configure', but for now it's easier to do it by hand. */
92#if 2 <= __GNUC__ || defined __IBM__TYPEOF__ || 0x5110 <= __SUNPRO_C 87#if (2 <= __GNUC__ \
88 || (4 <= __clang_major__) \
89 || (1210 <= __IBMC__ && defined __IBM__TYPEOF__) \
90 || (0x5110 <= __SUNPRO_C && !__STDC__))
93# define _GL_HAVE___TYPEOF__ 1 91# define _GL_HAVE___TYPEOF__ 1
94#else 92#else
95# define _GL_HAVE___TYPEOF__ 0 93# define _GL_HAVE___TYPEOF__ 0
96#endif 94#endif
97 95
98/* Return 1 if the integer type or expression T might be signed. Return 0 96/* 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, 97 if it is definitely unsigned. T must not be a bit-field expression.
100 and expands to an integer constant expression. */ 98 This macro does not evaluate its argument, and expands to an
99 integer constant expression. */
101#if _GL_HAVE___TYPEOF__ 100#if _GL_HAVE___TYPEOF__
102# define _GL_SIGNED_TYPE_OR_EXPR(t) TYPE_SIGNED (__typeof__ (t)) 101# define _GL_SIGNED_TYPE_OR_EXPR(t) TYPE_SIGNED (__typeof__ (t))
103#else 102#else
@@ -110,19 +109,20 @@
110#define INT_BITS_STRLEN_BOUND(b) (((b) * 146 + 484) / 485) 109#define INT_BITS_STRLEN_BOUND(b) (((b) * 146 + 484) / 485)
111 110
112/* Bound on length of the string representing an integer type or expression T. 111/* Bound on length of the string representing an integer type or expression T.
112 T must not be a bit-field expression.
113
113 Subtract 1 for the sign bit if T is signed, and then add 1 more for 114 Subtract 1 for the sign bit if T is signed, and then add 1 more for
114 a minus sign if needed. 115 a minus sign if needed.
115 116
116 Because _GL_SIGNED_TYPE_OR_EXPR sometimes returns 0 when its argument is 117 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 118 unsigned, this macro may overestimate the true bound by one byte when
118 applied to unsigned types of size 2, 4, 16, ... bytes. */ 119 applied to unsigned types of size 2, 4, 16, ... bytes. */
119#define INT_STRLEN_BOUND(t) \ 120#define INT_STRLEN_BOUND(t) \
120 (INT_BITS_STRLEN_BOUND (sizeof (t) * CHAR_BIT \ 121 (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)) 122 + _GL_SIGNED_TYPE_OR_EXPR (t))
123 123
124/* Bound on buffer size needed to represent an integer type or expression T, 124/* Bound on buffer size needed to represent an integer type or expression T,
125 including the terminating null. */ 125 including the terminating null. T must not be a bit-field expression. */
126#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1) 126#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1)
127 127
128 128
@@ -132,7 +132,8 @@
132 operators might not yield numerically correct answers due to 132 operators might not yield numerically correct answers due to
133 arithmetic overflow. They do not rely on undefined or 133 arithmetic overflow. They do not rely on undefined or
134 implementation-defined behavior. Their implementations are simple 134 implementation-defined behavior. Their implementations are simple
135 and straightforward, but they are a bit harder to use than the 135 and straightforward, but they are harder to use and may be less
136 efficient than the INT_<op>_WRAPV, INT_<op>_OK, and
136 INT_<op>_OVERFLOW macros described below. 137 INT_<op>_OVERFLOW macros described below.
137 138
138 Example usage: 139 Example usage:
@@ -157,6 +158,9 @@
157 must have minimum value MIN and maximum MAX. Unsigned types should 158 must have minimum value MIN and maximum MAX. Unsigned types should
158 use a zero MIN of the proper type. 159 use a zero MIN of the proper type.
159 160
161 Because all arguments are subject to integer promotions, these
162 macros typically do not work on types narrower than 'int'.
163
160 These macros are tuned for constant MIN and MAX. For commutative 164 These macros are tuned for constant MIN and MAX. For commutative
161 operations such as A + B, they are also tuned for constant B. */ 165 operations such as A + B, they are also tuned for constant B. */
162 166
@@ -184,7 +188,7 @@
184/* Return 1 if A * B would overflow in [MIN,MAX] arithmetic. 188/* Return 1 if A * B would overflow in [MIN,MAX] arithmetic.
185 See above for restrictions. Avoid && and || as they tickle 189 See above for restrictions. Avoid && and || as they tickle
186 bugs in Sun C 5.11 2010/08/13 and other compilers; see 190 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>. */ 191 <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00401.html>. */
188#define INT_MULTIPLY_RANGE_OVERFLOW(a, b, min, max) \ 192#define INT_MULTIPLY_RANGE_OVERFLOW(a, b, min, max) \
189 ((b) < 0 \ 193 ((b) < 0 \
190 ? ((a) < 0 \ 194 ? ((a) < 0 \
@@ -223,24 +227,66 @@
223 ? (a) < (min) >> (b) \ 227 ? (a) < (min) >> (b) \
224 : (max) >> (b) < (a)) 228 : (max) >> (b) < (a))
225 229
230/* True if __builtin_add_overflow (A, B, P) and __builtin_sub_overflow
231 (A, B, P) work when P is non-null. */
232/* __builtin_{add,sub}_overflow exists but is not reliable in GCC 5.x and 6.x,
233 see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98269>. */
234#if 7 <= __GNUC__ && !defined __ICC
235# define _GL_HAS_BUILTIN_ADD_OVERFLOW 1
236#elif defined __has_builtin
237# define _GL_HAS_BUILTIN_ADD_OVERFLOW __has_builtin (__builtin_add_overflow)
238#else
239# define _GL_HAS_BUILTIN_ADD_OVERFLOW 0
240#endif
241
242/* True if __builtin_mul_overflow (A, B, P) works when P is non-null. */
243#ifdef __clang__
244/* Work around Clang bug <https://bugs.llvm.org/show_bug.cgi?id=16404>. */
245# define _GL_HAS_BUILTIN_MUL_OVERFLOW 0
246#else
247# define _GL_HAS_BUILTIN_MUL_OVERFLOW _GL_HAS_BUILTIN_ADD_OVERFLOW
248#endif
249
250/* True if __builtin_add_overflow_p (A, B, C) works, and similarly for
251 __builtin_sub_overflow_p and __builtin_mul_overflow_p. */
252#if defined __clang__ || defined __ICC
253/* Clang 11 lacks __builtin_mul_overflow_p, and even if it did it
254 would presumably run afoul of Clang bug 16404. ICC 2021.1's
255 __builtin_add_overflow_p etc. are not treated as integral constant
256 expressions even when all arguments are. */
257# define _GL_HAS_BUILTIN_OVERFLOW_P 0
258#elif defined __has_builtin
259# define _GL_HAS_BUILTIN_OVERFLOW_P __has_builtin (__builtin_mul_overflow_p)
260#else
261# define _GL_HAS_BUILTIN_OVERFLOW_P (7 <= __GNUC__)
262#endif
226 263
227/* The _GL*_OVERFLOW macros have the same restrictions as the 264/* The _GL*_OVERFLOW macros have the same restrictions as the
228 *_RANGE_OVERFLOW macros, except that they do not assume that operands 265 *_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 266 (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. */ 267 that the result (e.g., A + B) has that type. */
231#define _GL_ADD_OVERFLOW(a, b, min, max) \ 268#if _GL_HAS_BUILTIN_OVERFLOW_P
232 ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max) \ 269# define _GL_ADD_OVERFLOW(a, b, min, max) \
233 : (a) < 0 ? (b) <= (a) + (b) \ 270 __builtin_add_overflow_p (a, b, (__typeof__ ((a) + (b))) 0)
234 : (b) < 0 ? (a) <= (a) + (b) \ 271# define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \
235 : (a) + (b) < (b)) 272 __builtin_sub_overflow_p (a, b, (__typeof__ ((a) - (b))) 0)
236#define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \ 273# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \
237 ((min) < 0 ? INT_SUBTRACT_RANGE_OVERFLOW (a, b, min, max) \ 274 __builtin_mul_overflow_p (a, b, (__typeof__ ((a) * (b))) 0)
238 : (a) < 0 ? 1 \ 275#else
239 : (b) < 0 ? (a) - (b) <= (a) \ 276# define _GL_ADD_OVERFLOW(a, b, min, max) \
240 : (a) < (b)) 277 ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max) \
241#define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \ 278 : (a) < 0 ? (b) <= (a) + (b) \
242 (((min) == 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a)))) \ 279 : (b) < 0 ? (a) <= (a) + (b) \
243 || INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max)) 280 : (a) + (b) < (b))
281# define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \
282 ((min) < 0 ? INT_SUBTRACT_RANGE_OVERFLOW (a, b, min, max) \
283 : (a) < 0 ? 1 \
284 : (b) < 0 ? (a) - (b) <= (a) \
285 : (a) < (b))
286# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \
287 (((min) == 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a)))) \
288 || INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max))
289#endif
244#define _GL_DIVIDE_OVERFLOW(a, b, min, max) \ 290#define _GL_DIVIDE_OVERFLOW(a, b, min, max) \
245 ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \ 291 ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \
246 : (a) < 0 ? (b) <= (a) + (b) - 1 \ 292 : (a) < 0 ? (b) <= (a) + (b) - 1 \
@@ -262,22 +308,31 @@
262 : (a) % - (b)) \ 308 : (a) % - (b)) \
263 == 0) 309 == 0)
264 310
265 311/* Check for integer overflow, and report low order bits of answer.
266/* Integer overflow checks.
267 312
268 The INT_<op>_OVERFLOW macros return 1 if the corresponding C operators 313 The INT_<op>_OVERFLOW macros return 1 if the corresponding C operators
269 might not yield numerically correct answers due to arithmetic overflow. 314 might not yield numerically correct answers due to arithmetic overflow.
270 They work correctly on all known practical hosts, and do not rely 315 The INT_<op>_WRAPV macros compute the low-order bits of the sum,
316 difference, and product of two C integers, and return 1 if these
317 low-order bits are not numerically correct.
318 These macros work correctly on all known practical hosts, and do not rely
271 on undefined behavior due to signed arithmetic overflow. 319 on undefined behavior due to signed arithmetic overflow.
272 320
273 Example usage: 321 Example usage, assuming A and B are long int:
274 322
275 long int i = ...; 323 if (INT_MULTIPLY_OVERFLOW (a, b))
276 long int j = ...; 324 printf ("result would overflow\n");
277 if (INT_MULTIPLY_OVERFLOW (i, j))
278 printf ("multiply would overflow");
279 else 325 else
280 printf ("product is %ld", i * j); 326 printf ("result is %ld (no overflow)\n", a * b);
327
328 Example usage with WRAPV flavor:
329
330 long int result;
331 bool overflow = INT_MULTIPLY_WRAPV (a, b, &result);
332 printf ("result is %ld (%s)\n", result,
333 overflow ? "after overflow" : "no overflow");
334
335 Restrictions on these macros:
281 336
282 These macros do not check for all possible numerical problems or 337 These macros do not check for all possible numerical problems or
283 undefined or unspecified behavior: they do not check for division 338 undefined or unspecified behavior: they do not check for division
@@ -286,7 +341,18 @@
286 These macros may evaluate their arguments zero or multiple times, so the 341 These macros may evaluate their arguments zero or multiple times, so the
287 arguments should not have side effects. 342 arguments should not have side effects.
288 343
289 These macros are tuned for their last argument being a constant. 344 The WRAPV macros are not constant expressions. They support only
345 +, binary -, and *.
346
347 Because the WRAPV macros convert the result, they report overflow
348 in different circumstances than the OVERFLOW macros do. For
349 example, in the typical case with 16-bit 'short' and 32-bit 'int',
350 if A, B and R are all of type 'short' then INT_ADD_OVERFLOW (A, B)
351 returns false because the addition cannot overflow after A and B
352 are converted to 'int', whereas INT_ADD_WRAPV (A, B, &R) returns
353 true or false depending on whether the sum fits into 'short'.
354
355 These macros are tuned for their last input argument being a constant.
290 356
291 Return 1 if the integer expressions A * B, A - B, -A, A * B, A / B, 357 Return 1 if the integer expressions A * B, A - B, -A, A * B, A / B,
292 A % B, and A << B would overflow, respectively. */ 358 A % B, and A << B would overflow, respectively. */
@@ -295,8 +361,12 @@
295 _GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW) 361 _GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW)
296#define INT_SUBTRACT_OVERFLOW(a, b) \ 362#define INT_SUBTRACT_OVERFLOW(a, b) \
297 _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW) 363 _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW)
298#define INT_NEGATE_OVERFLOW(a) \ 364#if _GL_HAS_BUILTIN_OVERFLOW_P
299 INT_NEGATE_RANGE_OVERFLOW (a, _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a)) 365# define INT_NEGATE_OVERFLOW(a) INT_SUBTRACT_OVERFLOW (0, a)
366#else
367# define INT_NEGATE_OVERFLOW(a) \
368 INT_NEGATE_RANGE_OVERFLOW (a, _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a))
369#endif
300#define INT_MULTIPLY_OVERFLOW(a, b) \ 370#define INT_MULTIPLY_OVERFLOW(a, b) \
301 _GL_BINARY_OP_OVERFLOW (a, b, _GL_MULTIPLY_OVERFLOW) 371 _GL_BINARY_OP_OVERFLOW (a, b, _GL_MULTIPLY_OVERFLOW)
302#define INT_DIVIDE_OVERFLOW(a, b) \ 372#define INT_DIVIDE_OVERFLOW(a, b) \
@@ -313,7 +383,257 @@
313 Arguments should be free of side effects. */ 383 Arguments should be free of side effects. */
314#define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \ 384#define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \
315 op_result_overflow (a, b, \ 385 op_result_overflow (a, b, \
316 _GL_INT_MINIMUM (0 * (b) + (a)), \ 386 _GL_INT_MINIMUM (_GL_INT_CONVERT (a, b)), \
317 _GL_INT_MAXIMUM (0 * (b) + (a))) 387 _GL_INT_MAXIMUM (_GL_INT_CONVERT (a, b)))
388
389/* Store the low-order bits of A + B, A - B, A * B, respectively, into *R.
390 Return 1 if the result overflows. See above for restrictions. */
391#if _GL_HAS_BUILTIN_ADD_OVERFLOW
392# define INT_ADD_WRAPV(a, b, r) __builtin_add_overflow (a, b, r)
393# define INT_SUBTRACT_WRAPV(a, b, r) __builtin_sub_overflow (a, b, r)
394#else
395# define INT_ADD_WRAPV(a, b, r) \
396 _GL_INT_OP_WRAPV (a, b, r, +, _GL_INT_ADD_RANGE_OVERFLOW)
397# define INT_SUBTRACT_WRAPV(a, b, r) \
398 _GL_INT_OP_WRAPV (a, b, r, -, _GL_INT_SUBTRACT_RANGE_OVERFLOW)
399#endif
400#if _GL_HAS_BUILTIN_MUL_OVERFLOW
401# if ((9 < __GNUC__ + (3 <= __GNUC_MINOR__) \
402 || (__GNUC__ == 8 && 4 <= __GNUC_MINOR__)) \
403 && !defined __ICC)
404# define INT_MULTIPLY_WRAPV(a, b, r) __builtin_mul_overflow (a, b, r)
405# else
406 /* Work around GCC bug 91450. */
407# define INT_MULTIPLY_WRAPV(a, b, r) \
408 ((!_GL_SIGNED_TYPE_OR_EXPR (*(r)) && EXPR_SIGNED (a) && EXPR_SIGNED (b) \
409 && _GL_INT_MULTIPLY_RANGE_OVERFLOW (a, b, 0, (__typeof__ (*(r))) -1)) \
410 ? ((void) __builtin_mul_overflow (a, b, r), 1) \
411 : __builtin_mul_overflow (a, b, r))
412# endif
413#else
414# define INT_MULTIPLY_WRAPV(a, b, r) \
415 _GL_INT_OP_WRAPV (a, b, r, *, _GL_INT_MULTIPLY_RANGE_OVERFLOW)
416#endif
417
418/* Nonzero if this compiler has GCC bug 68193 or Clang bug 25390. See:
419 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68193
420 https://llvm.org/bugs/show_bug.cgi?id=25390
421 For now, assume all versions of GCC-like compilers generate bogus
422 warnings for _Generic. This matters only for compilers that
423 lack relevant builtins. */
424#if __GNUC__ || defined __clang__
425# define _GL__GENERIC_BOGUS 1
426#else
427# define _GL__GENERIC_BOGUS 0
428#endif
429
430/* Store the low-order bits of A <op> B into *R, where OP specifies
431 the operation and OVERFLOW the overflow predicate. Return 1 if the
432 result overflows. See above for restrictions. */
433#if 201112 <= __STDC_VERSION__ && !_GL__GENERIC_BOGUS
434# define _GL_INT_OP_WRAPV(a, b, r, op, overflow) \
435 (_Generic \
436 (*(r), \
437 signed char: \
438 _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
439 signed char, SCHAR_MIN, SCHAR_MAX), \
440 unsigned char: \
441 _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
442 unsigned char, 0, UCHAR_MAX), \
443 short int: \
444 _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
445 short int, SHRT_MIN, SHRT_MAX), \
446 unsigned short int: \
447 _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
448 unsigned short int, 0, USHRT_MAX), \
449 int: \
450 _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
451 int, INT_MIN, INT_MAX), \
452 unsigned int: \
453 _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
454 unsigned int, 0, UINT_MAX), \
455 long int: \
456 _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
457 long int, LONG_MIN, LONG_MAX), \
458 unsigned long int: \
459 _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
460 unsigned long int, 0, ULONG_MAX), \
461 long long int: \
462 _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \
463 long long int, LLONG_MIN, LLONG_MAX), \
464 unsigned long long int: \
465 _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \
466 unsigned long long int, 0, ULLONG_MAX)))
467#else
468/* Store the low-order bits of A <op> B into *R, where OP specifies
469 the operation and OVERFLOW the overflow predicate. If *R is
470 signed, its type is ST with bounds SMIN..SMAX; otherwise its type
471 is UT with bounds U..UMAX. ST and UT are narrower than int.
472 Return 1 if the result overflows. See above for restrictions. */
473# if _GL_HAVE___TYPEOF__
474# define _GL_INT_OP_WRAPV_SMALLISH(a,b,r,op,overflow,st,smin,smax,ut,umax) \
475 (TYPE_SIGNED (__typeof__ (*(r))) \
476 ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, st, smin, smax) \
477 : _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, ut, 0, umax))
478# else
479# define _GL_INT_OP_WRAPV_SMALLISH(a,b,r,op,overflow,st,smin,smax,ut,umax) \
480 (overflow (a, b, smin, smax) \
481 ? (overflow (a, b, 0, umax) \
482 ? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a,b,op,unsigned,st), 1) \
483 : (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a,b,op,unsigned,st)) < 0) \
484 : (overflow (a, b, 0, umax) \
485 ? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a,b,op,unsigned,st)) >= 0 \
486 : (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a,b,op,unsigned,st), 0)))
487# endif
488
489# define _GL_INT_OP_WRAPV(a, b, r, op, overflow) \
490 (sizeof *(r) == sizeof (signed char) \
491 ? _GL_INT_OP_WRAPV_SMALLISH (a, b, r, op, overflow, \
492 signed char, SCHAR_MIN, SCHAR_MAX, \
493 unsigned char, UCHAR_MAX) \
494 : sizeof *(r) == sizeof (short int) \
495 ? _GL_INT_OP_WRAPV_SMALLISH (a, b, r, op, overflow, \
496 short int, SHRT_MIN, SHRT_MAX, \
497 unsigned short int, USHRT_MAX) \
498 : sizeof *(r) == sizeof (int) \
499 ? (EXPR_SIGNED (*(r)) \
500 ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
501 int, INT_MIN, INT_MAX) \
502 : _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \
503 unsigned int, 0, UINT_MAX)) \
504 : _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow))
505# ifdef LLONG_MAX
506# define _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow) \
507 (sizeof *(r) == sizeof (long int) \
508 ? (EXPR_SIGNED (*(r)) \
509 ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
510 long int, LONG_MIN, LONG_MAX) \
511 : _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
512 unsigned long int, 0, ULONG_MAX)) \
513 : (EXPR_SIGNED (*(r)) \
514 ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \
515 long long int, LLONG_MIN, LLONG_MAX) \
516 : _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \
517 unsigned long long int, 0, ULLONG_MAX)))
518# else
519# define _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow) \
520 (EXPR_SIGNED (*(r)) \
521 ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
522 long int, LONG_MIN, LONG_MAX) \
523 : _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
524 unsigned long int, 0, ULONG_MAX))
525# endif
526#endif
527
528/* Store the low-order bits of A <op> B into *R, where the operation
529 is given by OP. Use the unsigned type UT for calculation to avoid
530 overflow problems. *R's type is T, with extrema TMIN and TMAX.
531 T must be a signed integer type. Return 1 if the result overflows. */
532#define _GL_INT_OP_CALC(a, b, r, op, overflow, ut, t, tmin, tmax) \
533 (overflow (a, b, tmin, tmax) \
534 ? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t), 1) \
535 : (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t), 0))
536
537/* Return the low-order bits of A <op> B, where the operation is given
538 by OP. Use the unsigned type UT for calculation to avoid undefined
539 behavior on signed integer overflow, and convert the result to type T.
540 UT is at least as wide as T and is no narrower than unsigned int,
541 T is two's complement, and there is no padding or trap representations.
542 Assume that converting UT to T yields the low-order bits, as is
543 done in all known two's-complement C compilers. E.g., see:
544 https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html
545
546 According to the C standard, converting UT to T yields an
547 implementation-defined result or signal for values outside T's
548 range. However, code that works around this theoretical problem
549 runs afoul of a compiler bug in Oracle Studio 12.3 x86. See:
550 https://lists.gnu.org/r/bug-gnulib/2017-04/msg00049.html
551 As the compiler bug is real, don't try to work around the
552 theoretical problem. */
553
554#define _GL_INT_OP_WRAPV_VIA_UNSIGNED(a, b, op, ut, t) \
555 ((t) ((ut) (a) op (ut) (b)))
556
557/* Return true if the numeric values A + B, A - B, A * B fall outside
558 the range TMIN..TMAX. Arguments should be integer expressions
559 without side effects. TMIN should be signed and nonpositive.
560 TMAX should be positive, and should be signed unless TMIN is zero. */
561#define _GL_INT_ADD_RANGE_OVERFLOW(a, b, tmin, tmax) \
562 ((b) < 0 \
563 ? (((tmin) \
564 ? ((EXPR_SIGNED (_GL_INT_CONVERT (a, (tmin) - (b))) || (b) < (tmin)) \
565 && (a) < (tmin) - (b)) \
566 : (a) <= -1 - (b)) \
567 || ((EXPR_SIGNED (a) ? 0 <= (a) : (tmax) < (a)) && (tmax) < (a) + (b))) \
568 : (a) < 0 \
569 ? (((tmin) \
570 ? ((EXPR_SIGNED (_GL_INT_CONVERT (b, (tmin) - (a))) || (a) < (tmin)) \
571 && (b) < (tmin) - (a)) \
572 : (b) <= -1 - (a)) \
573 || ((EXPR_SIGNED (_GL_INT_CONVERT (a, b)) || (tmax) < (b)) \
574 && (tmax) < (a) + (b))) \
575 : (tmax) < (b) || (tmax) - (b) < (a))
576#define _GL_INT_SUBTRACT_RANGE_OVERFLOW(a, b, tmin, tmax) \
577 (((a) < 0) == ((b) < 0) \
578 ? ((a) < (b) \
579 ? !(tmin) || -1 - (tmin) < (b) - (a) - 1 \
580 : (tmax) < (a) - (b)) \
581 : (a) < 0 \
582 ? ((!EXPR_SIGNED (_GL_INT_CONVERT ((a) - (tmin), b)) && (a) - (tmin) < 0) \
583 || (a) - (tmin) < (b)) \
584 : ((! (EXPR_SIGNED (_GL_INT_CONVERT (tmax, b)) \
585 && EXPR_SIGNED (_GL_INT_CONVERT ((tmax) + (b), a))) \
586 && (tmax) <= -1 - (b)) \
587 || (tmax) + (b) < (a)))
588#define _GL_INT_MULTIPLY_RANGE_OVERFLOW(a, b, tmin, tmax) \
589 ((b) < 0 \
590 ? ((a) < 0 \
591 ? (EXPR_SIGNED (_GL_INT_CONVERT (tmax, b)) \
592 ? (a) < (tmax) / (b) \
593 : ((INT_NEGATE_OVERFLOW (b) \
594 ? _GL_INT_CONVERT (b, tmax) >> (TYPE_WIDTH (+ (b)) - 1) \
595 : (tmax) / -(b)) \
596 <= -1 - (a))) \
597 : INT_NEGATE_OVERFLOW (_GL_INT_CONVERT (b, tmin)) && (b) == -1 \
598 ? (EXPR_SIGNED (a) \
599 ? 0 < (a) + (tmin) \
600 : 0 < (a) && -1 - (tmin) < (a) - 1) \
601 : (tmin) / (b) < (a)) \
602 : (b) == 0 \
603 ? 0 \
604 : ((a) < 0 \
605 ? (INT_NEGATE_OVERFLOW (_GL_INT_CONVERT (a, tmin)) && (a) == -1 \
606 ? (EXPR_SIGNED (b) ? 0 < (b) + (tmin) : -1 - (tmin) < (b) - 1) \
607 : (tmin) / (a) < (b)) \
608 : (tmax) / (b) < (a)))
609
610/* The following macros compute A + B, A - B, and A * B, respectively.
611 If no overflow occurs, they set *R to the result and return 1;
612 otherwise, they return 0 and may modify *R.
613
614 Example usage:
615
616 long int result;
617 if (INT_ADD_OK (a, b, &result))
618 printf ("result is %ld\n", result);
619 else
620 printf ("overflow\n");
621
622 A, B, and *R should be integers; they need not be the same type,
623 and they need not be all signed or all unsigned.
624
625 These macros work correctly on all known practical hosts, and do not rely
626 on undefined behavior due to signed arithmetic overflow.
627
628 These macros are not constant expressions.
629
630 These macros may evaluate their arguments zero or multiple times, so the
631 arguments should not have side effects.
632
633 These macros are tuned for B being a constant. */
634
635#define INT_ADD_OK(a, b, r) ! INT_ADD_WRAPV (a, b, r)
636#define INT_SUBTRACT_OK(a, b, r) ! INT_SUBTRACT_WRAPV (a, b, r)
637#define INT_MULTIPLY_OK(a, b, r) ! INT_MULTIPLY_WRAPV (a, b, r)
318 638
319#endif /* _GL_INTPROPS_H */ 639#endif /* _GL_INTPROPS_H */
diff --git a/gl/inttypes.in.h b/gl/inttypes.in.h
new file mode 100644
index 0000000..41cb422
--- /dev/null
+++ b/gl/inttypes.in.h
@@ -0,0 +1,1002 @@
1/* Copyright (C) 2006-2021 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..7984866 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-2021 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..4873899 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-2021 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..88a0bd3
--- /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-2021 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..59b485d
--- /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-2021 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..886c11f
--- /dev/null
+++ b/gl/libc-config.h
@@ -0,0 +1,191 @@
1/* System definitions for code taken from the GNU C Library
2
3 Copyright 2017-2021 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_size__
125# undef __attribute_artificial__
126# undef __attribute_const__
127# undef __attribute_deprecated__
128# undef __attribute_deprecated_msg__
129# undef __attribute_format_arg__
130# undef __attribute_format_strfmon__
131# undef __attribute_malloc__
132# undef __attribute_noinline__
133# undef __attribute_nonstring__
134# undef __attribute_pure__
135# undef __attribute_returns_twice__
136# undef __attribute_used__
137# undef __attribute_warn_unused_result__
138# undef __bos
139# undef __bos0
140# undef __errordecl
141# undef __extension__
142# undef __extern_always_inline
143# undef __extern_inline
144# undef __flexarr
145# undef __fortify_function
146# undef __glibc_c99_flexarr_available
147# undef __glibc_has_attribute
148# undef __glibc_has_builtin
149# undef __glibc_has_extension
150# undef __glibc_macro_warning
151# undef __glibc_macro_warning1
152# undef __glibc_objsize
153# undef __glibc_objsize0
154# undef __glibc_unlikely
155# undef __inline
156# undef __ptr_t
157# undef __restrict
158# undef __restrict_arr
159# undef __va_arg_pack
160# undef __va_arg_pack_len
161# undef __warnattr
162
163/* Include our copy of glibc <sys/cdefs.h>. */
164# include <cdefs.h>
165
166/* <cdefs.h> __inline is too pessimistic for non-GCC. */
167# undef __inline
168# ifndef HAVE___INLINE
169# if 199901 <= __STDC_VERSION__ || defined inline
170# define __inline inline
171# else
172# define __inline
173# endif
174# endif
175
176#endif /* defined __glibc_likely */
177
178
179/* A substitute for glibc <libc-symbols.h>, good enough for Gnulib. */
180#define attribute_hidden
181#define libc_hidden_proto(name)
182#define libc_hidden_def(name)
183#define libc_hidden_weak(name)
184#define libc_hidden_ver(local, name)
185#define strong_alias(name, aliasname)
186#define weak_alias(name, aliasname)
187
188/* A substitute for glibc <shlib-compat.h>, good enough for Gnulib. */
189#define SHLIB_COMPAT(lib, introduced, obsoleted) 0
190#define compat_symbol(lib, local, symbol, version) extern int dummy
191#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..2ecafeb
--- /dev/null
+++ b/gl/limits.in.h
@@ -0,0 +1,131 @@
1/* A GNU-like <limits.h>.
2
3 Copyright 2016-2021 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 C2x 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 C2x. */
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..3c50858 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-2021 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..0ff4954 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-2021 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..1063070 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-2021 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..25e95a1 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-2021 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..e9a96ad
--- /dev/null
+++ b/gl/lseek.c
@@ -0,0 +1,89 @@
1/* An lseek() function that detects pipes.
2 Copyright (C) 2007, 2009-2021 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..9ba1743 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-2021 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..b28cc6a
--- /dev/null
+++ b/gl/m4/__inline.m4
@@ -0,0 +1,22 @@
1# Test for __inline keyword
2dnl Copyright 2017-2021 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..52d80d0
--- /dev/null
+++ b/gl/m4/absolute-header.m4
@@ -0,0 +1,100 @@
1# absolute-header.m4 serial 17
2dnl Copyright (C) 2006-2021 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..601cf67
--- /dev/null
+++ b/gl/m4/af_alg.m4
@@ -0,0 +1,57 @@
1# af_alg.m4 serial 6
2dnl Copyright 2018-2021 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..ba2f679 100644
--- a/gl/m4/alloca.m4
+++ b/gl/m4/alloca.m4
@@ -1,5 +1,5 @@
1# alloca.m4 serial 14 1# alloca.m4 serial 20
2dnl Copyright (C) 2002-2004, 2006-2007, 2009-2013 Free Software Foundation, 2dnl Copyright (C) 2002-2004, 2006-2007, 2009-2021 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,
@@ -37,19 +37,26 @@ AC_DEFUN([gl_FUNC_ALLOCA],
37 fi 37 fi
38 AC_SUBST([ALLOCA_H]) 38 AC_SUBST([ALLOCA_H])
39 AM_CONDITIONAL([GL_GENERATE_ALLOCA_H], [test -n "$ALLOCA_H"]) 39 AM_CONDITIONAL([GL_GENERATE_ALLOCA_H], [test -n "$ALLOCA_H"])
40
41 if test $ac_cv_working_alloca_h = yes; then
42 HAVE_ALLOCA_H=1
43 else
44 HAVE_ALLOCA_H=0
45 fi
46 AC_SUBST([HAVE_ALLOCA_H])
40]) 47])
41 48
42# Prerequisites of lib/alloca.c. 49# Prerequisites of lib/alloca.c.
43# STACK_DIRECTION is already handled by AC_FUNC_ALLOCA. 50# STACK_DIRECTION is already handled by AC_FUNC_ALLOCA.
44AC_DEFUN([gl_PREREQ_ALLOCA], [:]) 51AC_DEFUN([gl_PREREQ_ALLOCA], [:])
45 52
46# This works around a bug in autoconf <= 2.68. 53m4_version_prereq([2.70], [], [
47# See <http://lists.gnu.org/archive/html/bug-gnulib/2011-06/msg00277.html>.
48 54
49m4_version_prereq([2.69], [] ,[ 55# This works around a bug in autoconf <= 2.68 and has simplifications
50 56# from 2.70. See:
51# This is taken from the following Autoconf patch: 57# https://lists.gnu.org/r/bug-gnulib/2011-06/msg00277.html
52# http://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=6cd9f12520b0d6f76d3230d7565feba1ecf29497 58# https://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=6cd9f12520b0d6f76d3230d7565feba1ecf29497
59# https://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=15edf7fd8094fd14a89d9891dd72a9624762597a
53 60
54# _AC_LIBOBJ_ALLOCA 61# _AC_LIBOBJ_ALLOCA
55# ----------------- 62# -----------------
@@ -65,26 +72,6 @@ AC_LIBSOURCES(alloca.c)
65AC_SUBST([ALLOCA], [\${LIBOBJDIR}alloca.$ac_objext])dnl 72AC_SUBST([ALLOCA], [\${LIBOBJDIR}alloca.$ac_objext])dnl
66AC_DEFINE(C_ALLOCA, 1, [Define to 1 if using 'alloca.c'.]) 73AC_DEFINE(C_ALLOCA, 1, [Define to 1 if using 'alloca.c'.])
67 74
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], 75AC_CACHE_CHECK([stack direction for C alloca],
89 [ac_cv_c_stack_direction], 76 [ac_cv_c_stack_direction],
90[AC_RUN_IFELSE([AC_LANG_SOURCE( 77[AC_RUN_IFELSE([AC_LANG_SOURCE(
@@ -115,7 +102,7 @@ AH_VERBATIM([STACK_DIRECTION],
115 STACK_DIRECTION > 0 => grows toward higher addresses 102 STACK_DIRECTION > 0 => grows toward higher addresses
116 STACK_DIRECTION < 0 => grows toward lower addresses 103 STACK_DIRECTION < 0 => grows toward lower addresses
117 STACK_DIRECTION = 0 => direction of growth unknown */ 104 STACK_DIRECTION = 0 => direction of growth unknown */
118@%:@undef STACK_DIRECTION])dnl 105#undef STACK_DIRECTION])dnl
119AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction) 106AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction)
120])# _AC_LIBOBJ_ALLOCA 107])# _AC_LIBOBJ_ALLOCA
121]) 108])
diff --git a/gl/m4/arpa_inet_h.m4 b/gl/m4/arpa_inet_h.m4
index ea69af5..a3ba256 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-2021 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/base64.m4 b/gl/m4/base64.m4
index fc19893..ab95081 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-2021 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..d2b2fe8 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-2021 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..c584116
--- /dev/null
+++ b/gl/m4/builtin-expect.m4
@@ -0,0 +1,49 @@
1dnl Check for __builtin_expect.
2
3dnl Copyright 2016-2021 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..1083b4c
--- /dev/null
+++ b/gl/m4/byteswap.m4
@@ -0,0 +1,19 @@
1# byteswap.m4 serial 4
2dnl Copyright (C) 2005, 2007, 2009-2021 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 BYTESWAP_H=''
14 ], [
15 BYTESWAP_H='byteswap.h'
16 ])
17 AC_SUBST([BYTESWAP_H])
18 AM_CONDITIONAL([GL_GENERATE_BYTESWAP_H], [test -n "$BYTESWAP_H"])
19])
diff --git a/gl/m4/calloc.m4 b/gl/m4/calloc.m4
new file mode 100644
index 0000000..fe12b15
--- /dev/null
+++ b/gl/m4/calloc.m4
@@ -0,0 +1,82 @@
1# calloc.m4 serial 27
2
3# Copyright (C) 2004-2021 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 if test $REPLACE_CALLOC = 0; then
62 _AC_FUNC_CALLOC_IF([], [REPLACE_CALLOC=1])
63 fi
64])# gl_FUNC_CALLOC_GNU
65
66# gl_FUNC_CALLOC_POSIX
67# --------------------
68# Test whether 'calloc' is POSIX compliant (sets errno to ENOMEM when it
69# fails, and doesn't mess up with ptrdiff_t or size_t overflow),
70# and replace calloc if it is not.
71AC_DEFUN([gl_FUNC_CALLOC_POSIX],
72[
73 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
74 AC_REQUIRE([gl_FUNC_MALLOC_POSIX])
75 if test $REPLACE_MALLOC = 1; then
76 REPLACE_CALLOC=1
77 fi
78 dnl Although in theory we should also test for size_t overflow,
79 dnl in practice testing for ptrdiff_t overflow suffices
80 dnl since PTRDIFF_MAX <= SIZE_MAX on all known Gnulib porting targets.
81 dnl A separate size_t test would slow down 'configure'.
82])
diff --git a/gl/m4/close.m4 b/gl/m4/close.m4
new file mode 100644
index 0000000..77a5047
--- /dev/null
+++ b/gl/m4/close.m4
@@ -0,0 +1,35 @@
1# close.m4 serial 9
2dnl Copyright (C) 2008-2021 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..629f4ee 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-2021 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..c9bbcef 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-2021 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..0753a32
--- /dev/null
+++ b/gl/m4/dup2.m4
@@ -0,0 +1,105 @@
1#serial 27
2dnl Copyright (C) 2002, 2005, 2007, 2009-2021 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..002f0c8 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-2021 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..ae53291 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-2021 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..51dfe92 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 13
2dnl Copyright (C) 2004, 2006, 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2004, 2006, 2008-2021 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])
@@ -129,9 +131,3 @@ yes
129 AC_SUBST($1[_VALUE]) 131 AC_SUBST($1[_VALUE])
130 fi 132 fi
131]) 133])
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..8e3cf95 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-2021 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..fb136f4 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-2021 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..5792a95 100644
--- a/gl/m4/extensions.m4
+++ b/gl/m4/extensions.m4
@@ -1,14 +1,19 @@
1# serial 13 -*- Autoconf -*- 1# serial 22 -*- 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-2021 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,121 @@
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.70.1], [], [
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 ISO/IEC TS 18661-4:2015. */
117#ifndef __STDC_WANT_IEC_60559_FUNCS_EXT__
118# undef __STDC_WANT_IEC_60559_FUNCS_EXT__
119#endif
120/* Enable extensions specified by ISO/IEC TS 18661-3:2015. */
121#ifndef __STDC_WANT_IEC_60559_TYPES_EXT__
122# undef __STDC_WANT_IEC_60559_TYPES_EXT__
123#endif
124/* Enable extensions specified by ISO/IEC TR 24731-2:2010. */
125#ifndef __STDC_WANT_LIB_EXT2__
126# undef __STDC_WANT_LIB_EXT2__
127#endif
128/* Enable extensions specified by ISO/IEC 24747:2009. */
129#ifndef __STDC_WANT_MATH_SPEC_FUNCS__
130# undef __STDC_WANT_MATH_SPEC_FUNCS__
131#endif
75/* Enable extensions on HP NonStop. */ 132/* Enable extensions on HP NonStop. */
76#ifndef _TANDEM_SOURCE 133#ifndef _TANDEM_SOURCE
77# undef _TANDEM_SOURCE 134# undef _TANDEM_SOURCE
78#endif 135#endif
79/* Enable X/Open extensions if necessary. HP-UX 11.11 defines 136/* Enable X/Open extensions. Define to 500 only if necessary
80 mbstate_t only if _XOPEN_SOURCE is defined to 500, regardless of 137 to make mbstate_t available. */
81 whether compiling with -Ae or -D_HPUX_SOURCE=1. */
82#ifndef _XOPEN_SOURCE 138#ifndef _XOPEN_SOURCE
83# undef _XOPEN_SOURCE 139# undef _XOPEN_SOURCE
84#endif 140#endif
85/* Enable general extensions on Solaris. */ 141])dnl
86#ifndef __EXTENSIONS__ 142
87# undef __EXTENSIONS__ 143 AC_REQUIRE([AC_CHECK_INCLUDES_DEFAULT])dnl
88#endif 144 _AC_CHECK_HEADER_ONCE([wchar.h])
89]) 145 _AC_CHECK_HEADER_ONCE([minix/config.h])
146
147dnl Defining __EXTENSIONS__ may break the system headers on some systems.
148dnl (FIXME: Which ones?)
90 AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__], 149 AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__],
91 [ac_cv_safe_to_define___extensions__], 150 [ac_cv_safe_to_define___extensions__],
92 [AC_COMPILE_IFELSE( 151 [AC_COMPILE_IFELSE(
@@ -95,30 +154,56 @@ dnl configure.ac when using autoheader 2.62.
95 ]AC_INCLUDES_DEFAULT])], 154 ]AC_INCLUDES_DEFAULT])],
96 [ac_cv_safe_to_define___extensions__=yes], 155 [ac_cv_safe_to_define___extensions__=yes],
97 [ac_cv_safe_to_define___extensions__=no])]) 156 [ac_cv_safe_to_define___extensions__=no])])
98 test $ac_cv_safe_to_define___extensions__ = yes && 157
99 AC_DEFINE([__EXTENSIONS__]) 158dnl HP-UX 11.11 defines mbstate_t only if _XOPEN_SOURCE is defined to
100 AC_DEFINE([_ALL_SOURCE]) 159dnl 500, regardless of whether compiling with -Ae or -D_HPUX_SOURCE=1.
101 AC_DEFINE([_DARWIN_C_SOURCE]) 160dnl But defining _XOPEN_SOURCE may turn *off* extensions on platforms
102 AC_DEFINE([_GNU_SOURCE]) 161dnl not covered by turn-on-extensions macros (notably Dragonfly, Free,
103 AC_DEFINE([_POSIX_PTHREAD_SEMANTICS]) 162dnl and OpenBSD, which don't have any equivalent of _NETBSD_SOURCE) so
104 AC_DEFINE([_TANDEM_SOURCE]) 163dnl it should only be defined when necessary.
105 AC_CACHE_CHECK([whether _XOPEN_SOURCE should be defined], 164 AC_CACHE_CHECK([whether _XOPEN_SOURCE should be defined],
106 [ac_cv_should_define__xopen_source], 165 [ac_cv_should_define__xopen_source],
107 [ac_cv_should_define__xopen_source=no 166 [ac_cv_should_define__xopen_source=no
108 AC_COMPILE_IFELSE( 167 AS_IF([test $ac_cv_header_wchar_h = yes],
109 [AC_LANG_PROGRAM([[ 168 [AC_COMPILE_IFELSE(
169 [AC_LANG_PROGRAM([[
110 #include <wchar.h> 170 #include <wchar.h>
111 mbstate_t x;]])], 171 mbstate_t x;]])],
112 [], 172 [],
113 [AC_COMPILE_IFELSE( 173 [AC_COMPILE_IFELSE(
114 [AC_LANG_PROGRAM([[ 174 [AC_LANG_PROGRAM([[
115 #define _XOPEN_SOURCE 500 175 #define _XOPEN_SOURCE 500
116 #include <wchar.h> 176 #include <wchar.h>
117 mbstate_t x;]])], 177 mbstate_t x;]])],
118 [ac_cv_should_define__xopen_source=yes])])]) 178 [ac_cv_should_define__xopen_source=yes])])])])
119 test $ac_cv_should_define__xopen_source = yes && 179
120 AC_DEFINE([_XOPEN_SOURCE], [500]) 180 AC_DEFINE([_ALL_SOURCE])
181 AC_DEFINE([_DARWIN_C_SOURCE])
182 AC_DEFINE([_GNU_SOURCE])
183 AC_DEFINE([_HPUX_ALT_XOPEN_SOCKET_API])
184 AC_DEFINE([_NETBSD_SOURCE])
185 AC_DEFINE([_OPENBSD_SOURCE])
186 AC_DEFINE([_POSIX_PTHREAD_SEMANTICS])
187 AC_DEFINE([__STDC_WANT_IEC_60559_ATTRIBS_EXT__])
188 AC_DEFINE([__STDC_WANT_IEC_60559_BFP_EXT__])
189 AC_DEFINE([__STDC_WANT_IEC_60559_DFP_EXT__])
190 AC_DEFINE([__STDC_WANT_IEC_60559_FUNCS_EXT__])
191 AC_DEFINE([__STDC_WANT_IEC_60559_TYPES_EXT__])
192 AC_DEFINE([__STDC_WANT_LIB_EXT2__])
193 AC_DEFINE([__STDC_WANT_MATH_SPEC_FUNCS__])
194 AC_DEFINE([_TANDEM_SOURCE])
195 AS_IF([test $ac_cv_header_minix_config_h = yes],
196 [MINIX=yes
197 AC_DEFINE([_MINIX])
198 AC_DEFINE([_POSIX_SOURCE])
199 AC_DEFINE([_POSIX_1_SOURCE], [2])],
200 [MINIX=])
201 AS_IF([test $ac_cv_safe_to_define___extensions__ = yes],
202 [AC_DEFINE([__EXTENSIONS__])])
203 AS_IF([test $ac_cv_should_define__xopen_source = yes],
204 [AC_DEFINE([_XOPEN_SOURCE], [500])])
121])# AC_USE_SYSTEM_EXTENSIONS 205])# AC_USE_SYSTEM_EXTENSIONS
206])
122 207
123# gl_USE_SYSTEM_EXTENSIONS 208# gl_USE_SYSTEM_EXTENSIONS
124# ------------------------ 209# ------------------------
@@ -126,13 +211,17 @@ dnl configure.ac when using autoheader 2.62.
126# typically due to standards-conformance issues. 211# typically due to standards-conformance issues.
127AC_DEFUN_ONCE([gl_USE_SYSTEM_EXTENSIONS], 212AC_DEFUN_ONCE([gl_USE_SYSTEM_EXTENSIONS],
128[ 213[
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]) 214 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
215
216 dnl On OpenBSD 6.8 with GCC, the include files contain a couple of
217 dnl definitions that are only activated with an explicit -D_ISOC11_SOURCE.
218 dnl That's because this version of GCC (4.2.1) supports the option
219 dnl '-std=gnu99' but not the option '-std=gnu11'.
220 AC_REQUIRE([AC_CANONICAL_HOST])
221 case "$host_os" in
222 openbsd*)
223 AC_DEFINE([_ISOC11_SOURCE], [1],
224 [Define to enable the declarations of ISO C 11 types and functions.])
225 ;;
226 esac
138]) 227])
diff --git a/gl/m4/extern-inline.m4 b/gl/m4/extern-inline.m4
index c4c5e7f..a4ac5ea 100644
--- a/gl/m4/extern-inline.m4
+++ b/gl/m4/extern-inline.m4
@@ -1,6 +1,6 @@
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-2021 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.
@@ -11,51 +11,96 @@ AC_DEFUN([gl_EXTERN_INLINE],
11[/* Please see the Gnulib manual for how to use these macros. 11[/* Please see the Gnulib manual for how to use these macros.
12 12
13 Suppress extern inline with HP-UX cc, as it appears to be broken; see 13 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>. 14 <https://lists.gnu.org/r/bug-texinfo/2013-02/msg00030.html>.
15 15
16 Suppress extern inline with Sun C in standards-conformance mode, as it 16 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 17 mishandles inline functions that call each other. E.g., for 'inline void f
18 (void) { } inline void g (void) { f (); }', c99 incorrectly complains 18 (void) { } inline void g (void) { f (); }', c99 incorrectly complains
19 'reference to static identifier "f" in extern inline function'. 19 'reference to static identifier "f" in extern inline function'.
20 This bug was observed with Sun C 5.12 SunOS_i386 2011/11/16. 20 This bug was observed with Oracle Developer Studio 12.6
21 (Sun C 5.15 SunOS_sparc 2017/05/30).
21 22
22 Suppress the use of extern inline on Apple's platforms, as Libc at least 23 Suppress extern inline (with or without __attribute__ ((__gnu_inline__)))
23 through Libc-825.26 (2013-04-09) is incompatible with it; see, e.g., 24 on configurations that mistakenly use 'static inline' to implement
24 <http://lists.gnu.org/archive/html/bug-gnulib/2012-12/msg00023.html>. 25 functions or macros in standard C headers like <ctype.h>. For example,
25 Perhaps Apple will fix this some day. */ 26 if isdigit is mistakenly implemented via a static inline function,
27 a program containing an extern inline function that calls isdigit
28 may not work since the C standard prohibits extern inline functions
29 from calling static functions (ISO C 99 section 6.7.4.(3).
30 This bug is known to occur on:
31
32 OS X 10.8 and earlier; see:
33 https://lists.gnu.org/r/bug-gnulib/2012-12/msg00023.html
34
35 DragonFly; see
36 http://muscles.dragonflybsd.org/bulk/clang-master-potential/20141111_102002/logs/ah-tty-0.3.12.log
37
38 FreeBSD; see:
39 https://lists.gnu.org/r/bug-gnulib/2014-07/msg00104.html
40
41 OS X 10.9 has a macro __header_inline indicating the bug is fixed for C and
42 for clang but remains for g++; see <https://trac.macports.org/ticket/41033>.
43 Assume DragonFly and FreeBSD will be similar.
44
45 GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
46 inline semantics, unless -fgnu89-inline is used. It defines a macro
47 __GNUC_STDC_INLINE__ to indicate this situation or a macro
48 __GNUC_GNU_INLINE__ to indicate the opposite situation.
49 GCC 4.2 with -std=c99 or -std=gnu99 implements the GNU C inline
50 semantics but warns, unless -fgnu89-inline is used:
51 warning: C99 inline functions are not supported; using GNU89
52 warning: to disable this warning use -fgnu89-inline or the gnu_inline function attribute
53 It defines a macro __GNUC_GNU_INLINE__ to indicate this situation.
54 */
55#if (((defined __APPLE__ && defined __MACH__) \
56 || defined __DragonFly__ || defined __FreeBSD__) \
57 && (defined __header_inline \
58 ? (defined __cplusplus && defined __GNUC_STDC_INLINE__ \
59 && ! defined __clang__) \
60 : ((! defined _DONT_USE_CTYPE_INLINE_ \
61 && (defined __GNUC__ || defined __cplusplus)) \
62 || (defined _FORTIFY_SOURCE && 0 < _FORTIFY_SOURCE \
63 && defined __GNUC__ && ! defined __cplusplus))))
64# define _GL_EXTERN_INLINE_STDHEADER_BUG
65#endif
26#if ((__GNUC__ \ 66#if ((__GNUC__ \
27 ? defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ \ 67 ? defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ \
28 : (199901L <= __STDC_VERSION__ \ 68 : (199901L <= __STDC_VERSION__ \
29 && !defined __HP_cc \ 69 && !defined __HP_cc \
70 && !defined __PGI \
30 && !(defined __SUNPRO_C && __STDC__))) \ 71 && !(defined __SUNPRO_C && __STDC__))) \
31 && !defined __APPLE__) 72 && !defined _GL_EXTERN_INLINE_STDHEADER_BUG)
32# define _GL_INLINE inline 73# define _GL_INLINE inline
33# define _GL_EXTERN_INLINE extern inline 74# define _GL_EXTERN_INLINE extern inline
75# define _GL_EXTERN_INLINE_IN_USE
34#elif (2 < __GNUC__ + (7 <= __GNUC_MINOR__) && !defined __STRICT_ANSI__ \ 76#elif (2 < __GNUC__ + (7 <= __GNUC_MINOR__) && !defined __STRICT_ANSI__ \
35 && !defined __APPLE__) 77 && !defined _GL_EXTERN_INLINE_STDHEADER_BUG)
36# if __GNUC_GNU_INLINE__ 78# if defined __GNUC_GNU_INLINE__ && __GNUC_GNU_INLINE__
37 /* __gnu_inline__ suppresses a GCC 4.2 diagnostic. */ 79 /* __gnu_inline__ suppresses a GCC 4.2 diagnostic. */
38# define _GL_INLINE extern inline __attribute__ ((__gnu_inline__)) 80# define _GL_INLINE extern inline __attribute__ ((__gnu_inline__))
39# else 81# else
40# define _GL_INLINE extern inline 82# define _GL_INLINE extern inline
41# endif 83# endif
42# define _GL_EXTERN_INLINE extern 84# define _GL_EXTERN_INLINE extern
85# define _GL_EXTERN_INLINE_IN_USE
43#else 86#else
44# define _GL_INLINE static _GL_UNUSED 87# define _GL_INLINE _GL_UNUSED static
45# define _GL_EXTERN_INLINE static _GL_UNUSED 88# define _GL_EXTERN_INLINE _GL_UNUSED static
46#endif 89#endif
47 90
48#if 4 < __GNUC__ + (6 <= __GNUC_MINOR__) 91/* In GCC 4.6 (inclusive) to 5.1 (exclusive),
92 suppress bogus "no previous prototype for 'FOO'"
93 and "no previous declaration for 'FOO'" diagnostics,
94 when FOO is an inline function in the header; see
95 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54113> and
96 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63877>. */
97#if __GNUC__ == 4 && 6 <= __GNUC_MINOR__
49# if defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ 98# if defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__
50# define _GL_INLINE_HEADER_CONST_PRAGMA 99# define _GL_INLINE_HEADER_CONST_PRAGMA
51# else 100# else
52# define _GL_INLINE_HEADER_CONST_PRAGMA \ 101# define _GL_INLINE_HEADER_CONST_PRAGMA \
53 _Pragma ("GCC diagnostic ignored \"-Wsuggest-attribute=const\"") 102 _Pragma ("GCC diagnostic ignored \"-Wsuggest-attribute=const\"")
54# endif 103# 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 \ 104# define _GL_INLINE_HEADER_BEGIN \
60 _Pragma ("GCC diagnostic push") \ 105 _Pragma ("GCC diagnostic push") \
61 _Pragma ("GCC diagnostic ignored \"-Wmissing-prototypes\"") \ 106 _Pragma ("GCC diagnostic ignored \"-Wmissing-prototypes\"") \
diff --git a/gl/m4/fcntl-o.m4 b/gl/m4/fcntl-o.m4
index 87cc4bd..7c459ad 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-2021 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..f626434
--- /dev/null
+++ b/gl/m4/fcntl.m4
@@ -0,0 +1,151 @@
1# fcntl.m4 serial 11
2dnl Copyright (C) 2009-2021 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..aba4473
--- /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-2021 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..43266ef
--- /dev/null
+++ b/gl/m4/fflush.m4
@@ -0,0 +1,100 @@
1# fflush.m4 serial 18
2
3# Copyright (C) 2007-2021 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..ba38a28 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 12
2dnl Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2007, 2009-2021 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,7 +14,7 @@ AC_DEFUN([gl_FLOAT_H],
14 aix* | beos* | openbsd* | mirbsd* | irix*) 14 aix* | beos* | openbsd* | mirbsd* | irix*)
15 FLOAT_H=float.h 15 FLOAT_H=float.h
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 )
@@ -24,10 +24,14 @@ changequote([,])dnl
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 [FLOAT_H=float.h])
33 ;; 37 ;;
@@ -42,7 +46,7 @@ changequote([,])dnl
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 test -n "$FLOAT_H"; then
47 REPLACE_FLOAT_LDBL=1 51 REPLACE_FLOAT_LDBL=1
48 fi 52 fi
@@ -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 ])
diff --git a/gl/m4/floorf.m4 b/gl/m4/floorf.m4
index c892ff9..f521437 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-2021 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..4ed7dce
--- /dev/null
+++ b/gl/m4/fopen.m4
@@ -0,0 +1,148 @@
1# fopen.m4 serial 12
2dnl Copyright (C) 2007-2021 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 case "$gl_cv_func_fopen_mode_x" in
140 *no) REPLACE_FOPEN=1 ;;
141 esac
142 case "$gl_cv_func_fopen_mode_e" in
143 *no) REPLACE_FOPEN=1 ;;
144 esac
145])
146
147# Prerequisites of lib/fopen.c.
148AC_DEFUN([gl_PREREQ_FOPEN], [:])
diff --git a/gl/m4/fpurge.m4 b/gl/m4/fpurge.m4
new file mode 100644
index 0000000..275c9d0
--- /dev/null
+++ b/gl/m4/fpurge.m4
@@ -0,0 +1,73 @@
1# fpurge.m4 serial 12
2dnl Copyright (C) 2007, 2009-2021 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/freading.m4 b/gl/m4/freading.m4
new file mode 100644
index 0000000..6cc660f
--- /dev/null
+++ b/gl/m4/freading.m4
@@ -0,0 +1,11 @@
1# freading.m4 serial 2
2dnl Copyright (C) 2007, 2009-2021 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_FREADING],
8[
9 AC_CHECK_HEADERS_ONCE([stdio_ext.h])
10 AC_CHECK_FUNCS_ONCE([__freading])
11])
diff --git a/gl/m4/free.m4 b/gl/m4/free.m4
new file mode 100644
index 0000000..a7923b9
--- /dev/null
+++ b/gl/m4/free.m4
@@ -0,0 +1,52 @@
1# free.m4 serial 6
2# Copyright (C) 2003-2005, 2009-2021 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..2e90afc
--- /dev/null
+++ b/gl/m4/fseek.m4
@@ -0,0 +1,15 @@
1# fseek.m4 serial 4
2dnl Copyright (C) 2007, 2009-2021 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..531e442
--- /dev/null
+++ b/gl/m4/fseeko.m4
@@ -0,0 +1,77 @@
1# fseeko.m4 serial 20
2dnl Copyright (C) 2007-2021 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..cdaca80
--- /dev/null
+++ b/gl/m4/fstat.m4
@@ -0,0 +1,40 @@
1# fstat.m4 serial 8
2dnl Copyright (C) 2011-2021 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..895c4f0 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-2021 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..d005579 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-2021 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..f9cc619
--- /dev/null
+++ b/gl/m4/ftell.m4
@@ -0,0 +1,15 @@
1# ftell.m4 serial 3
2dnl Copyright (C) 2007, 2009-2021 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..65bec39
--- /dev/null
+++ b/gl/m4/ftello.m4
@@ -0,0 +1,151 @@
1# ftello.m4 serial 14
2dnl Copyright (C) 2007-2021 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..3f8e04f 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-2021 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..244a731
--- /dev/null
+++ b/gl/m4/getdelim.m4
@@ -0,0 +1,99 @@
1# getdelim.m4 serial 15
2
3dnl Copyright (C) 2005-2007, 2009-2021 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]) dnl for cross-compiles
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 [echo fooNbarN | tr -d '\012' | tr N '\012' > conftest.data
28 AC_RUN_IFELSE([AC_LANG_SOURCE([[
29# include <stdio.h>
30# include <stdlib.h>
31# include <string.h>
32 int main ()
33 {
34 FILE *in = fopen ("./conftest.data", "r");
35 if (!in)
36 return 1;
37 {
38 /* Test result for a NULL buffer and a zero size.
39 Based on a test program from Karl Heuer. */
40 char *line = NULL;
41 size_t siz = 0;
42 int len = getdelim (&line, &siz, '\n', in);
43 if (!(len == 4 && line && strcmp (line, "foo\n") == 0))
44 { free (line); fclose (in); return 2; }
45 free (line);
46 }
47 {
48 /* Test result for a NULL buffer and a non-zero size.
49 This crashes on FreeBSD 8.0. */
50 char *line = NULL;
51 size_t siz = (size_t)(~0) / 4;
52 if (getdelim (&line, &siz, '\n', in) == -1)
53 { fclose (in); return 3; }
54 free (line);
55 }
56 fclose (in);
57 return 0;
58 }
59 ]])],
60 [gl_cv_func_working_getdelim=yes],
61 [gl_cv_func_working_getdelim=no],
62 [dnl We're cross compiling.
63 dnl Guess it works on glibc2 systems and musl systems.
64 AC_EGREP_CPP([Lucky GNU user],
65 [
66#include <features.h>
67#ifdef __GNU_LIBRARY__
68 #if (__GLIBC__ >= 2) && !defined __UCLIBC__
69 Lucky GNU user
70 #endif
71#endif
72 ],
73 [gl_cv_func_working_getdelim="guessing yes"],
74 [case "$host_os" in
75 *-musl*) gl_cv_func_working_getdelim="guessing yes" ;;
76 *) gl_cv_func_working_getdelim="$gl_cross_guess_normal" ;;
77 esac
78 ])
79 ])
80 ])
81 case "$gl_cv_func_working_getdelim" in
82 *yes) ;;
83 *) REPLACE_GETDELIM=1 ;;
84 esac
85 else
86 HAVE_GETDELIM=0
87 fi
88
89 if test $ac_cv_have_decl_getdelim = no; then
90 HAVE_DECL_GETDELIM=0
91 fi
92])
93
94# Prerequisites of lib/getdelim.c.
95AC_DEFUN([gl_PREREQ_GETDELIM],
96[
97 AC_CHECK_FUNCS([flockfile funlockfile])
98 AC_CHECK_DECLS([getc_unlocked])
99])
diff --git a/gl/m4/getdtablesize.m4 b/gl/m4/getdtablesize.m4
new file mode 100644
index 0000000..8fbc941
--- /dev/null
+++ b/gl/m4/getdtablesize.m4
@@ -0,0 +1,63 @@
1# getdtablesize.m4 serial 8
2dnl Copyright (C) 2008-2021 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..25e9eb2 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-2021 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..58b27c7
--- /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-2021 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..bba2216 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-2021 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..bb95c5e 100644
--- a/gl/m4/getopt.m4
+++ b/gl/m4/getopt.m4
@@ -1,5 +1,5 @@
1# getopt.m4 serial 44 1# getopt.m4 serial 47
2dnl Copyright (C) 2002-2006, 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2006, 2008-2021 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,9 +32,16 @@ AC_DEFUN([gl_FUNC_GETOPT_POSIX],
32# getopt_long_only. 32# getopt_long_only.
33AC_DEFUN([gl_FUNC_GETOPT_GNU], 33AC_DEFUN([gl_FUNC_GETOPT_GNU],
34[ 34[
35 dnl Set the variable gl_getopt_required, so that all invocations of
36 dnl gl_GETOPT_CHECK_HEADERS in the scope of the current configure file
37 dnl will check for getopt with GNU extensions.
38 dnl This means that if one gnulib-tool invocation requests getopt-posix
39 dnl and another gnulib-tool invocation requests getopt-gnu, it is as if
40 dnl both had requested getopt-gnu.
35 m4_divert_text([INIT_PREPARE], [gl_getopt_required=GNU]) 41 m4_divert_text([INIT_PREPARE], [gl_getopt_required=GNU])
36 42
37 AC_REQUIRE([gl_FUNC_GETOPT_POSIX]) 43 dnl No need to invoke gl_FUNC_GETOPT_POSIX here; this is automatically
44 dnl done through the module dependency getopt-gnu -> getopt-posix.
38]) 45])
39 46
40# Determine whether to replace the entire getopt facility. 47# Determine whether to replace the entire getopt facility.
@@ -295,8 +302,10 @@ dnl is ambiguous with environment values that contain newlines.
295 ]])], 302 ]])],
296 [gl_cv_func_getopt_gnu=yes], 303 [gl_cv_func_getopt_gnu=yes],
297 [gl_cv_func_getopt_gnu=no], 304 [gl_cv_func_getopt_gnu=no],
298 [dnl Cross compiling. Assume the worst, even on glibc platforms. 305 [dnl Cross compiling.
299 gl_cv_func_getopt_gnu="guessing no" 306 dnl Assume the worst, even on glibc platforms.
307 dnl But obey --enable-cross-guesses.
308 gl_cv_func_getopt_gnu="$gl_cross_guess_normal"
300 ]) 309 ])
301 case $gl_had_POSIXLY_CORRECT in 310 case $gl_had_POSIXLY_CORRECT in
302 exported) ;; 311 exported) ;;
@@ -354,15 +363,19 @@ dnl is ambiguous with environment values that contain newlines.
354 363
355AC_DEFUN([gl_GETOPT_SUBSTITUTE_HEADER], 364AC_DEFUN([gl_GETOPT_SUBSTITUTE_HEADER],
356[ 365[
357 GETOPT_H=getopt.h 366 AC_CHECK_HEADERS_ONCE([sys/cdefs.h])
367 if test $ac_cv_header_sys_cdefs_h = yes; then
368 HAVE_SYS_CDEFS_H=1
369 else
370 HAVE_SYS_CDEFS_H=0
371 fi
372 AC_SUBST([HAVE_SYS_CDEFS_H])
373
358 AC_DEFINE([__GETOPT_PREFIX], [[rpl_]], 374 AC_DEFINE([__GETOPT_PREFIX], [[rpl_]],
359 [Define to rpl_ if the getopt replacement functions and variables 375 [Define to rpl_ if the getopt replacement functions and variables
360 should be used.]) 376 should be used.])
377 GETOPT_H=getopt.h
378 GETOPT_CDEFS_H=getopt-cdefs.h
361 AC_SUBST([GETOPT_H]) 379 AC_SUBST([GETOPT_H])
362]) 380 AC_SUBST([GETOPT_CDEFS_H])
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..65917d6
--- /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-2021 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
index 8d1f066..c7f5460 100644
--- a/gl/m4/gettext.m4
+++ b/gl/m4/gettext.m4
@@ -1,16 +1,16 @@
1# gettext.m4 serial 66 (gettext-0.18.2) 1# gettext.m4 serial 71 (gettext-0.20.2)
2dnl Copyright (C) 1995-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 1995-2014, 2016, 2018-2021 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.
6dnl 6dnl
7dnl This file can can be used in projects which are not available under 7dnl This file can be used in projects which are not available under
8dnl the GNU General Public License or the GNU Library General Public 8dnl the GNU General Public License or the GNU Lesser General Public
9dnl License but which still want to provide support for the GNU gettext 9dnl License but which still want to provide support for the GNU gettext
10dnl functionality. 10dnl functionality.
11dnl Please note that the actual code of the GNU gettext library is covered 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 12dnl by the GNU Lesser General Public License, and the rest of the GNU
13dnl gettext package package is covered by the GNU General Public License. 13dnl gettext package is covered by the GNU General Public License.
14dnl They are *not* in the public domain. 14dnl They are *not* in the public domain.
15 15
16dnl Authors: 16dnl Authors:
@@ -20,15 +20,13 @@ dnl Bruno Haible <haible@clisp.cons.org>, 2000-2006, 2008-2010.
20dnl Macro to add for using GNU gettext. 20dnl Macro to add for using GNU gettext.
21 21
22dnl Usage: AM_GNU_GETTEXT([INTLSYMBOL], [NEEDSYMBOL], [INTLDIR]). 22dnl Usage: AM_GNU_GETTEXT([INTLSYMBOL], [NEEDSYMBOL], [INTLDIR]).
23dnl INTLSYMBOL can be one of 'external', 'no-libtool', 'use-libtool'. The 23dnl INTLSYMBOL must be one of 'external', 'use-libtool'.
24dnl default (if it is not specified or empty) is 'no-libtool'. 24dnl INTLSYMBOL should be 'external' for packages other than GNU gettext, and
25dnl INTLSYMBOL should be 'external' for packages with no intl directory, 25dnl 'use-libtool' for the packages 'gettext-runtime' and 'gettext-tools'.
26dnl and 'no-libtool' or 'use-libtool' for packages with an intl directory.
27dnl If INTLSYMBOL is 'use-libtool', then a libtool library 26dnl If INTLSYMBOL is 'use-libtool', then a libtool library
28dnl $(top_builddir)/intl/libintl.la will be created (shared and/or static, 27dnl $(top_builddir)/intl/libintl.la will be created (shared and/or static,
29dnl depending on --{enable,disable}-{shared,static} and on the presence of 28dnl depending on --{enable,disable}-{shared,static} and on the presence of
30dnl AM-DISABLE-SHARED). If INTLSYMBOL is 'no-libtool', a static library 29dnl AM-DISABLE-SHARED).
31dnl $(top_builddir)/intl/libintl.a will be created.
32dnl If NEEDSYMBOL is specified and is 'need-ngettext', then GNU gettext 30dnl If NEEDSYMBOL is specified and is 'need-ngettext', then GNU gettext
33dnl implementations (in libc or libintl) without the ngettext() function 31dnl implementations (in libc or libintl) without the ngettext() function
34dnl will be ignored. If NEEDSYMBOL is specified and is 32dnl will be ignored. If NEEDSYMBOL is specified and is
@@ -57,19 +55,17 @@ dnl
57AC_DEFUN([AM_GNU_GETTEXT], 55AC_DEFUN([AM_GNU_GETTEXT],
58[ 56[
59 dnl Argument checking. 57 dnl Argument checking.
60 ifelse([$1], [], , [ifelse([$1], [external], , [ifelse([$1], [no-libtool], , [ifelse([$1], [use-libtool], , 58 ifelse([$1], [], , [ifelse([$1], [external], , [ifelse([$1], [use-libtool], ,
61 [errprint([ERROR: invalid first argument to AM_GNU_GETTEXT 59 [errprint([ERROR: invalid first argument to AM_GNU_GETTEXT
62])])])])]) 60])])])])
63 ifelse(ifelse([$1], [], [old])[]ifelse([$1], [no-libtool], [old]), [old], 61 ifelse(ifelse([$1], [], [old])[]ifelse([$1], [no-libtool], [old]), [old],
64 [AC_DIAGNOSE([obsolete], [Use of AM_GNU_GETTEXT without [external] argument is deprecated.])]) 62 [errprint([ERROR: Use of AM_GNU_GETTEXT without [external] argument is no longer supported.
63])])
65 ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], , 64 ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], ,
66 [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT 65 [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT
67])])])]) 66])])])])
68 define([gt_included_intl], 67 define([gt_included_intl],
69 ifelse([$1], [external], 68 ifelse([$1], [external], [no], [yes]))
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 69 gt_NEEDS_INIT
74 AM_GNU_GETTEXT_NEED([$2]) 70 AM_GNU_GETTEXT_NEED([$2])
75 71
@@ -91,8 +87,7 @@ AC_DEFUN([AM_GNU_GETTEXT],
91 dnl again, outside any 'if'. There are two solutions: 87 dnl again, outside any 'if'. There are two solutions:
92 dnl - Invoke AM_ICONV_LINKFLAGS_BODY here, outside any 'if'. 88 dnl - Invoke AM_ICONV_LINKFLAGS_BODY here, outside any 'if'.
93 dnl - Control the expansions in more detail using AC_PROVIDE_IFELSE. 89 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 90 dnl Since AC_PROVIDE_IFELSE is not documented, we avoid it.
95 dnl documented, we avoid it.
96 ifelse(gt_included_intl, yes, , [ 91 ifelse(gt_included_intl, yes, , [
97 AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY]) 92 AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
98 ]) 93 ])
@@ -161,13 +156,18 @@ changequote([,])dnl
161 [AC_LANG_PROGRAM( 156 [AC_LANG_PROGRAM(
162 [[ 157 [[
163#include <libintl.h> 158#include <libintl.h>
164$gt_revision_test_code 159#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
165extern int _nl_msg_cat_cntr; 160extern int _nl_msg_cat_cntr;
166extern int *_nl_domain_bindings; 161extern int *_nl_domain_bindings;
162#define __GNU_GETTEXT_SYMBOL_EXPRESSION (_nl_msg_cat_cntr + *_nl_domain_bindings)
163#else
164#define __GNU_GETTEXT_SYMBOL_EXPRESSION 0
165#endif
166$gt_revision_test_code
167 ]], 167 ]],
168 [[ 168 [[
169bindtextdomain ("", ""); 169bindtextdomain ("", "");
170return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_domain_bindings 170return * gettext ("")$gt_expression_test_code + __GNU_GETTEXT_SYMBOL_EXPRESSION
171 ]])], 171 ]])],
172 [eval "$gt_func_gnugettext_libc=yes"], 172 [eval "$gt_func_gnugettext_libc=yes"],
173 [eval "$gt_func_gnugettext_libc=no"])]) 173 [eval "$gt_func_gnugettext_libc=no"])])
@@ -193,17 +193,22 @@ return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_domain_b
193 [AC_LANG_PROGRAM( 193 [AC_LANG_PROGRAM(
194 [[ 194 [[
195#include <libintl.h> 195#include <libintl.h>
196$gt_revision_test_code 196#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
197extern int _nl_msg_cat_cntr; 197extern int _nl_msg_cat_cntr;
198extern 198extern
199#ifdef __cplusplus 199#ifdef __cplusplus
200"C" 200"C"
201#endif 201#endif
202const char *_nl_expand_alias (const char *); 202const char *_nl_expand_alias (const char *);
203#define __GNU_GETTEXT_SYMBOL_EXPRESSION (_nl_msg_cat_cntr + *_nl_expand_alias (""))
204#else
205#define __GNU_GETTEXT_SYMBOL_EXPRESSION 0
206#endif
207$gt_revision_test_code
203 ]], 208 ]],
204 [[ 209 [[
205bindtextdomain ("", ""); 210bindtextdomain ("", "");
206return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("") 211return * gettext ("")$gt_expression_test_code + __GNU_GETTEXT_SYMBOL_EXPRESSION
207 ]])], 212 ]])],
208 [eval "$gt_func_gnugettext_libintl=yes"], 213 [eval "$gt_func_gnugettext_libintl=yes"],
209 [eval "$gt_func_gnugettext_libintl=no"]) 214 [eval "$gt_func_gnugettext_libintl=no"])
@@ -214,17 +219,22 @@ return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_a
214 [AC_LANG_PROGRAM( 219 [AC_LANG_PROGRAM(
215 [[ 220 [[
216#include <libintl.h> 221#include <libintl.h>
217$gt_revision_test_code 222#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
218extern int _nl_msg_cat_cntr; 223extern int _nl_msg_cat_cntr;
219extern 224extern
220#ifdef __cplusplus 225#ifdef __cplusplus
221"C" 226"C"
222#endif 227#endif
223const char *_nl_expand_alias (const char *); 228const char *_nl_expand_alias (const char *);
229#define __GNU_GETTEXT_SYMBOL_EXPRESSION (_nl_msg_cat_cntr + *_nl_expand_alias (""))
230#else
231#define __GNU_GETTEXT_SYMBOL_EXPRESSION 0
232#endif
233$gt_revision_test_code
224 ]], 234 ]],
225 [[ 235 [[
226bindtextdomain ("", ""); 236bindtextdomain ("", "");
227return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_alias ("") 237return * gettext ("")$gt_expression_test_code + __GNU_GETTEXT_SYMBOL_EXPRESSION
228 ]])], 238 ]])],
229 [LIBINTL="$LIBINTL $LIBICONV" 239 [LIBINTL="$LIBINTL $LIBICONV"
230 LTLIBINTL="$LTLIBINTL $LTLIBICONV" 240 LTLIBINTL="$LTLIBINTL $LTLIBICONV"
@@ -263,8 +273,8 @@ return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_a
263 dnl Mark actions used to generate GNU NLS library. 273 dnl Mark actions used to generate GNU NLS library.
264 BUILD_INCLUDED_LIBINTL=yes 274 BUILD_INCLUDED_LIBINTL=yes
265 USE_INCLUDED_LIBINTL=yes 275 USE_INCLUDED_LIBINTL=yes
266 LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LIBICONV $LIBTHREAD" 276 LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.la $LIBICONV $LIBTHREAD"
267 LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.[]gt_libtool_suffix_prefix[]a $LTLIBICONV $LTLIBTHREAD" 277 LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.la $LTLIBICONV $LTLIBTHREAD"
268 LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'` 278 LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'`
269 fi 279 fi
270 280
@@ -332,43 +342,14 @@ return * gettext ("")$gt_expression_test_code + _nl_msg_cat_cntr + *_nl_expand_a
332 fi 342 fi
333 343
334 ifelse(gt_included_intl, yes, [ 344 ifelse(gt_included_intl, yes, [
335 dnl If this is used in GNU gettext we have to set BUILD_INCLUDED_LIBINTL 345 dnl In GNU gettext we have to set BUILD_INCLUDED_LIBINTL to 'yes'
336 dnl to 'yes' because some of the testsuite requires it. 346 dnl because some of the testsuite requires it.
337 if test "$PACKAGE" = gettext-runtime || test "$PACKAGE" = gettext-tools; then 347 BUILD_INCLUDED_LIBINTL=yes
338 BUILD_INCLUDED_LIBINTL=yes
339 fi
340 348
341 dnl Make all variables we use known to autoconf. 349 dnl Make all variables we use known to autoconf.
342 AC_SUBST([BUILD_INCLUDED_LIBINTL]) 350 AC_SUBST([BUILD_INCLUDED_LIBINTL])
343 AC_SUBST([USE_INCLUDED_LIBINTL]) 351 AC_SUBST([USE_INCLUDED_LIBINTL])
344 AC_SUBST([CATOBJEXT]) 352 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 ]) 353 ])
373 354
374 dnl For backward compatibility. Some Makefiles may be using this. 355 dnl For backward compatibility. Some Makefiles may be using this.
@@ -399,3 +380,7 @@ AC_DEFUN([AM_GNU_GETTEXT_NEED],
399 380
400dnl Usage: AM_GNU_GETTEXT_VERSION([gettext-version]) 381dnl Usage: AM_GNU_GETTEXT_VERSION([gettext-version])
401AC_DEFUN([AM_GNU_GETTEXT_VERSION], []) 382AC_DEFUN([AM_GNU_GETTEXT_VERSION], [])
383
384
385dnl Usage: AM_GNU_GETTEXT_REQUIRE_VERSION([gettext-version])
386AC_DEFUN([AM_GNU_GETTEXT_REQUIRE_VERSION], [])
diff --git a/gl/m4/gl-openssl.m4 b/gl/m4/gl-openssl.m4
new file mode 100644
index 0000000..c968eb6
--- /dev/null
+++ b/gl/m4/gl-openssl.m4
@@ -0,0 +1,76 @@
1# gl-openssl.m4 serial 6
2dnl Copyright (C) 2013-2021 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..2471be2 100644
--- a/gl/m4/gnulib-cache.m4
+++ b/gl/m4/gnulib-cache.m4
@@ -1,4 +1,4 @@
1# Copyright (C) 2002-2013 Free Software Foundation, Inc. 1# Copyright (C) 2002-2021 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
@@ -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,7 +27,39 @@
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/sha1 \
43# dirname \
44# environ \
45# floorf \
46# fsusage \
47# getaddrinfo \
48# gethostname \
49# getloadavg \
50# getopt-gnu \
51# gettext \
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([])
diff --git a/gl/m4/gnulib-common.m4 b/gl/m4/gnulib-common.m4
index 0ae5a9e..12b19db 100644
--- a/gl/m4/gnulib-common.m4
+++ b/gl/m4/gnulib-common.m4
@@ -1,25 +1,54 @@
1# gnulib-common.m4 serial 33 1# gnulib-common.m4 serial 67
2dnl Copyright (C) 2007-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2007-2021 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 __cplusplus || defined __clang__) \
42 && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
43 || (!defined __STRICT_ANSI__ \
44 && (_GL_GNUC_PREREQ (4, 7) \
45 || (defined __apple_build_version__ \
46 ? 6000000 <= __apple_build_version__ \
47 : 3 < __clang_major__ + (5 <= __clang_minor__))))))
48 /* _Noreturn works as-is. */
49# elif _GL_GNUC_PREREQ (2, 8) || defined __clang__ || 0x5110 <= __SUNPRO_C
21# define _Noreturn __attribute__ ((__noreturn__)) 50# define _Noreturn __attribute__ ((__noreturn__))
22# elif defined _MSC_VER && 1200 <= _MSC_VER 51# elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
23# define _Noreturn __declspec (noreturn) 52# define _Noreturn __declspec (noreturn)
24# else 53# else
25# define _Noreturn 54# define _Noreturn
@@ -36,33 +65,437 @@ AC_DEFUN([gl_COMMON_BODY], [
36#if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__ 65#if defined __APPLE__ && defined __MACH__ && __APPLE_CC__ >= 5465 && !defined __cplusplus && __STDC_VERSION__ >= 199901L && !defined __GNUC_STDC_INLINE__
37# define __GNUC_STDC_INLINE__ 1 66# define __GNUC_STDC_INLINE__ 1
38#endif]) 67#endif])
39 AH_VERBATIM([unused_parameter], 68 AH_VERBATIM([attribute],
40[/* Define as a marker that can be attached to declarations that might not 69[/* Attributes. */
41 be used. This helps to reduce warnings, such as from 70#if (defined __has_attribute \
42 GCC -Wunused-parameter. */ 71 && (!defined __clang_minor__ \
43#if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) 72 || 3 < __clang_major__ + (5 <= __clang_minor__)))
44# define _GL_UNUSED __attribute__ ((__unused__)) 73# define _GL_HAS_ATTRIBUTE(attr) __has_attribute (__##attr##__)
45#else 74#else
46# define _GL_UNUSED 75# define _GL_HAS_ATTRIBUTE(attr) _GL_ATTR_##attr
76# define _GL_ATTR_alloc_size _GL_GNUC_PREREQ (4, 3)
77# define _GL_ATTR_always_inline _GL_GNUC_PREREQ (3, 2)
78# define _GL_ATTR_artificial _GL_GNUC_PREREQ (4, 3)
79# define _GL_ATTR_cold _GL_GNUC_PREREQ (4, 3)
80# define _GL_ATTR_const _GL_GNUC_PREREQ (2, 95)
81# define _GL_ATTR_deprecated _GL_GNUC_PREREQ (3, 1)
82# define _GL_ATTR_diagnose_if 0
83# define _GL_ATTR_error _GL_GNUC_PREREQ (4, 3)
84# define _GL_ATTR_externally_visible _GL_GNUC_PREREQ (4, 1)
85# define _GL_ATTR_fallthrough _GL_GNUC_PREREQ (7, 0)
86# define _GL_ATTR_format _GL_GNUC_PREREQ (2, 7)
87# define _GL_ATTR_leaf _GL_GNUC_PREREQ (4, 6)
88# define _GL_ATTR_malloc _GL_GNUC_PREREQ (3, 0)
89# ifdef _ICC
90# define _GL_ATTR_may_alias 0
91# else
92# define _GL_ATTR_may_alias _GL_GNUC_PREREQ (3, 3)
93# endif
94# define _GL_ATTR_noinline _GL_GNUC_PREREQ (3, 1)
95# define _GL_ATTR_nonnull _GL_GNUC_PREREQ (3, 3)
96# define _GL_ATTR_nonstring _GL_GNUC_PREREQ (8, 0)
97# define _GL_ATTR_nothrow _GL_GNUC_PREREQ (3, 3)
98# define _GL_ATTR_packed _GL_GNUC_PREREQ (2, 7)
99# define _GL_ATTR_pure _GL_GNUC_PREREQ (2, 96)
100# define _GL_ATTR_returns_nonnull _GL_GNUC_PREREQ (4, 9)
101# define _GL_ATTR_sentinel _GL_GNUC_PREREQ (4, 0)
102# define _GL_ATTR_unused _GL_GNUC_PREREQ (2, 7)
103# define _GL_ATTR_warn_unused_result _GL_GNUC_PREREQ (3, 4)
47#endif 104#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 105
52/* The __pure__ attribute was added in gcc 2.96. */ 106#ifdef __has_c_attribute
53#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) 107# define _GL_HAS_C_ATTRIBUTE(attr) __has_c_attribute (__##attr##__)
54# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) 108#else
109# define _GL_HAS_C_ATTRIBUTE(attr) 0
110#endif
111
112]dnl There is no _GL_ATTRIBUTE_ALIGNED; use stdalign's _Alignas instead.
113[
114/* _GL_ATTRIBUTE_ALLOC_SIZE ((N)) declares that the Nth argument of the function
115 is the size of the returned memory block.
116 _GL_ATTRIBUTE_ALLOC_SIZE ((M, N)) declares that the Mth argument multiplied
117 by the Nth argument of the function is the size of the returned memory block.
118 */
119/* Applies to: function, pointer to function, function types. */
120#if _GL_HAS_ATTRIBUTE (alloc_size)
121# define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
122#else
123# define _GL_ATTRIBUTE_ALLOC_SIZE(args)
124#endif
125
126/* _GL_ATTRIBUTE_ALWAYS_INLINE tells that the compiler should always inline the
127 function and report an error if it cannot do so. */
128/* Applies to: function. */
129#if _GL_HAS_ATTRIBUTE (always_inline)
130# define _GL_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((__always_inline__))
131#else
132# define _GL_ATTRIBUTE_ALWAYS_INLINE
133#endif
134
135/* _GL_ATTRIBUTE_ARTIFICIAL declares that the function is not important to show
136 in stack traces when debugging. The compiler should omit the function from
137 stack traces. */
138/* Applies to: function. */
139#if _GL_HAS_ATTRIBUTE (artificial)
140# define _GL_ATTRIBUTE_ARTIFICIAL __attribute__ ((__artificial__))
141#else
142# define _GL_ATTRIBUTE_ARTIFICIAL
143#endif
144
145/* _GL_ATTRIBUTE_COLD declares that the function is rarely executed. */
146/* Applies to: functions. */
147/* Avoid __attribute__ ((cold)) on MinGW; see thread starting at
148 <https://lists.gnu.org/r/emacs-devel/2019-04/msg01152.html>.
149 Also, Oracle Studio 12.6 requires 'cold' not '__cold__'. */
150#if _GL_HAS_ATTRIBUTE (cold) && !defined __MINGW32__
151# ifndef __SUNPRO_C
152# define _GL_ATTRIBUTE_COLD __attribute__ ((__cold__))
153# else
154# define _GL_ATTRIBUTE_COLD __attribute__ ((cold))
155# endif
55#else 156#else
56# define _GL_ATTRIBUTE_PURE /* empty */ 157# define _GL_ATTRIBUTE_COLD
57#endif 158#endif
58 159
59/* The __const__ attribute was added in gcc 2.95. */ 160/* _GL_ATTRIBUTE_CONST declares that it is OK for a compiler to omit duplicate
60#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) 161 calls to the function with the same arguments.
162 This attribute is safe for a function that neither depends on nor affects
163 observable state, and always returns exactly once - e.g., does not loop
164 forever, and does not call longjmp.
165 (This attribute is stricter than _GL_ATTRIBUTE_PURE.) */
166/* Applies to: functions. */
167#if _GL_HAS_ATTRIBUTE (const)
61# define _GL_ATTRIBUTE_CONST __attribute__ ((__const__)) 168# define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
62#else 169#else
63# define _GL_ATTRIBUTE_CONST /* empty */ 170# define _GL_ATTRIBUTE_CONST
171#endif
172
173/* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
174 that can be freed by passing them as the Ith argument to the
175 function F.
176 _GL_ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that
177 can be freed via 'free'; it can be used only after declaring 'free'. */
178/* Applies to: functions. Cannot be used on inline functions. */
179#if _GL_GNUC_PREREQ (11, 0)
180# define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
181#else
182# define _GL_ATTRIBUTE_DEALLOC(f, i)
183#endif
184#define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (free, 1)
185
186/* _GL_ATTRIBUTE_DEPRECATED: Declares that an entity is deprecated.
187 The compiler may warn if the entity is used. */
188/* Applies to:
189 - function, variable,
190 - struct, union, struct/union member,
191 - enumeration, enumeration item,
192 - typedef,
193 in C++ also: namespace, class, template specialization. */
194#if _GL_HAS_C_ATTRIBUTE (deprecated)
195# define _GL_ATTRIBUTE_DEPRECATED [[__deprecated__]]
196#elif _GL_HAS_ATTRIBUTE (deprecated)
197# define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__))
198#else
199# define _GL_ATTRIBUTE_DEPRECATED
200#endif
201
202/* _GL_ATTRIBUTE_ERROR(msg) requests an error if a function is called and
203 the function call is not optimized away.
204 _GL_ATTRIBUTE_WARNING(msg) requests a warning if a function is called and
205 the function call is not optimized away. */
206/* Applies to: functions. */
207#if _GL_HAS_ATTRIBUTE (error)
208# define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__error__ (msg)))
209# define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__warning__ (msg)))
210#elif _GL_HAS_ATTRIBUTE (diagnose_if)
211# define _GL_ATTRIBUTE_ERROR(msg) __attribute__ ((__diagnose_if__ (1, msg, "error")))
212# define _GL_ATTRIBUTE_WARNING(msg) __attribute__ ((__diagnose_if__ (1, msg, "warning")))
213#else
214# define _GL_ATTRIBUTE_ERROR(msg)
215# define _GL_ATTRIBUTE_WARNING(msg)
216#endif
217
218/* _GL_ATTRIBUTE_EXTERNALLY_VISIBLE declares that the entity should remain
219 visible to debuggers etc., even with '-fwhole-program'. */
220/* Applies to: functions, variables. */
221#if _GL_HAS_ATTRIBUTE (externally_visible)
222# define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE __attribute__ ((externally_visible))
223#else
224# define _GL_ATTRIBUTE_EXTERNALLY_VISIBLE
225#endif
226
227/* _GL_ATTRIBUTE_FALLTHROUGH declares that it is not a programming mistake if
228 the control flow falls through to the immediately following 'case' or
229 'default' label. The compiler should not warn in this case. */
230/* Applies to: Empty statement (;), inside a 'switch' statement. */
231/* Always expands to something. */
232#if _GL_HAS_C_ATTRIBUTE (fallthrough)
233# define _GL_ATTRIBUTE_FALLTHROUGH [[__fallthrough__]]
234#elif _GL_HAS_ATTRIBUTE (fallthrough)
235# define _GL_ATTRIBUTE_FALLTHROUGH __attribute__ ((__fallthrough__))
236#else
237# define _GL_ATTRIBUTE_FALLTHROUGH ((void) 0)
238#endif
239
240/* _GL_ATTRIBUTE_FORMAT ((ARCHETYPE, STRING-INDEX, FIRST-TO-CHECK))
241 declares that the STRING-INDEXth function argument is a format string of
242 style ARCHETYPE, which is one of:
243 printf, gnu_printf
244 scanf, gnu_scanf,
245 strftime, gnu_strftime,
246 strfmon,
247 or the same thing prefixed and suffixed with '__'.
248 If FIRST-TO-CHECK is not 0, arguments starting at FIRST-TO_CHECK
249 are suitable for the format string. */
250/* Applies to: functions. */
251#if _GL_HAS_ATTRIBUTE (format)
252# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
253#else
254# define _GL_ATTRIBUTE_FORMAT(spec)
255#endif
256
257/* _GL_ATTRIBUTE_LEAF declares that if the function is called from some other
258 compilation unit, it executes code from that unit only by return or by
259 exception handling. This declaration lets the compiler optimize that unit
260 more aggressively. */
261/* Applies to: functions. */
262#if _GL_HAS_ATTRIBUTE (leaf)
263# define _GL_ATTRIBUTE_LEAF __attribute__ ((__leaf__))
264#else
265# define _GL_ATTRIBUTE_LEAF
266#endif
267
268/* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly
269 allocated memory. */
270/* Applies to: functions. */
271#if _GL_HAS_ATTRIBUTE (malloc)
272# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
273#else
274# define _GL_ATTRIBUTE_MALLOC
275#endif
276
277/* _GL_ATTRIBUTE_MAY_ALIAS declares that pointers to the type may point to the
278 same storage as pointers to other types. Thus this declaration disables
279 strict aliasing optimization. */
280/* Applies to: types. */
281/* Oracle Studio 12.6 mishandles may_alias despite __has_attribute OK. */
282#if _GL_HAS_ATTRIBUTE (may_alias) && !defined __SUNPRO_C
283# define _GL_ATTRIBUTE_MAY_ALIAS __attribute__ ((__may_alias__))
284#else
285# define _GL_ATTRIBUTE_MAY_ALIAS
286#endif
287
288/* _GL_ATTRIBUTE_MAYBE_UNUSED declares that it is not a programming mistake if
289 the entity is not used. The compiler should not warn if the entity is not
290 used. */
291/* Applies to:
292 - function, variable,
293 - struct, union, struct/union member,
294 - enumeration, enumeration item,
295 - typedef,
296 in C++ also: class. */
297/* In C++ and C2x, this is spelled [[__maybe_unused__]].
298 GCC's syntax is __attribute__ ((__unused__)).
299 clang supports both syntaxes. */
300#if _GL_HAS_C_ATTRIBUTE (maybe_unused)
301# define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]]
302#else
303# define _GL_ATTRIBUTE_MAYBE_UNUSED _GL_ATTRIBUTE_UNUSED
304#endif
305/* Alternative spelling of this macro, for convenience. */
306#define _GL_UNUSED _GL_ATTRIBUTE_MAYBE_UNUSED
307/* Earlier spellings of this macro. */
308#define _UNUSED_PARAMETER_ _GL_ATTRIBUTE_MAYBE_UNUSED
309
310/* _GL_ATTRIBUTE_NODISCARD declares that the caller of the function should not
311 discard the return value. The compiler may warn if the caller does not use
312 the return value, unless the caller uses something like ignore_value. */
313/* Applies to: function, enumeration, class. */
314#if _GL_HAS_C_ATTRIBUTE (nodiscard)
315# define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
316#elif _GL_HAS_ATTRIBUTE (warn_unused_result)
317# define _GL_ATTRIBUTE_NODISCARD __attribute__ ((__warn_unused_result__))
318#else
319# define _GL_ATTRIBUTE_NODISCARD
320#endif
321
322/* _GL_ATTRIBUTE_NOINLINE tells that the compiler should not inline the
323 function. */
324/* Applies to: functions. */
325#if _GL_HAS_ATTRIBUTE (noinline)
326# define _GL_ATTRIBUTE_NOINLINE __attribute__ ((__noinline__))
327#else
328# define _GL_ATTRIBUTE_NOINLINE
329#endif
330
331/* _GL_ATTRIBUTE_NONNULL ((N1, N2,...)) declares that the arguments N1, N2,...
332 must not be NULL.
333 _GL_ATTRIBUTE_NONNULL () declares that all pointer arguments must not be
334 null. */
335/* Applies to: functions. */
336#if _GL_HAS_ATTRIBUTE (nonnull)
337# define _GL_ATTRIBUTE_NONNULL(args) __attribute__ ((__nonnull__ args))
338#else
339# define _GL_ATTRIBUTE_NONNULL(args)
340#endif
341
342/* _GL_ATTRIBUTE_NONSTRING declares that the contents of a character array is
343 not meant to be NUL-terminated. */
344/* Applies to: struct/union members and variables that are arrays of element
345 type '[[un]signed] char'. */
346#if _GL_HAS_ATTRIBUTE (nonstring)
347# define _GL_ATTRIBUTE_NONSTRING __attribute__ ((__nonstring__))
348#else
349# define _GL_ATTRIBUTE_NONSTRING
350#endif
351
352/* There is no _GL_ATTRIBUTE_NORETURN; use _Noreturn instead. */
353
354/* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions.
355 */
356/* Applies to: functions. */
357#if _GL_HAS_ATTRIBUTE (nothrow) && !defined __cplusplus
358# define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__))
359#else
360# define _GL_ATTRIBUTE_NOTHROW
361#endif
362
363/* _GL_ATTRIBUTE_PACKED declares:
364 For struct members: The member has the smallest possible alignment.
365 For struct, union, class: All members have the smallest possible alignment,
366 minimizing the memory required. */
367/* Applies to: struct members, struct, union,
368 in C++ also: class. */
369#if _GL_HAS_ATTRIBUTE (packed)
370# define _GL_ATTRIBUTE_PACKED __attribute__ ((__packed__))
371#else
372# define _GL_ATTRIBUTE_PACKED
373#endif
374
375/* _GL_ATTRIBUTE_PURE declares that It is OK for a compiler to omit duplicate
376 calls to the function with the same arguments if observable state is not
377 changed between calls.
378 This attribute is safe for a function that does not affect
379 observable state, and always returns exactly once.
380 (This attribute is looser than _GL_ATTRIBUTE_CONST.) */
381/* Applies to: functions. */
382#if _GL_HAS_ATTRIBUTE (pure)
383# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
384#else
385# define _GL_ATTRIBUTE_PURE
386#endif
387
388/* _GL_ATTRIBUTE_RETURNS_NONNULL declares that the function's return value is
389 a non-NULL pointer. */
390/* Applies to: functions. */
391#if _GL_HAS_ATTRIBUTE (returns_nonnull)
392# define _GL_ATTRIBUTE_RETURNS_NONNULL __attribute__ ((__returns_nonnull__))
393#else
394# define _GL_ATTRIBUTE_RETURNS_NONNULL
395#endif
396
397/* _GL_ATTRIBUTE_SENTINEL(pos) declares that the variadic function expects a
398 trailing NULL argument.
399 _GL_ATTRIBUTE_SENTINEL () - The last argument is NULL (requires C99).
400 _GL_ATTRIBUTE_SENTINEL ((N)) - The (N+1)st argument from the end is NULL. */
401/* Applies to: functions. */
402#if _GL_HAS_ATTRIBUTE (sentinel)
403# define _GL_ATTRIBUTE_SENTINEL(pos) __attribute__ ((__sentinel__ pos))
404#else
405# define _GL_ATTRIBUTE_SENTINEL(pos)
406#endif
407
408/* A helper macro. Don't use it directly. */
409#if _GL_HAS_ATTRIBUTE (unused)
410# define _GL_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
411#else
412# define _GL_ATTRIBUTE_UNUSED
413#endif
414
415]dnl There is no _GL_ATTRIBUTE_VISIBILITY; see m4/visibility.m4 instead.
416[
417/* _GL_UNUSED_LABEL; declares that it is not a programming mistake if the
418 immediately preceding label is not used. The compiler should not warn
419 if the label is not used. */
420/* Applies to: label (both in C and C++). */
421/* Note that g++ < 4.5 does not support the '__attribute__ ((__unused__)) ;'
422 syntax. But clang does. */
423#if !(defined __cplusplus && !_GL_GNUC_PREREQ (4, 5)) || defined __clang__
424# define _GL_UNUSED_LABEL _GL_ATTRIBUTE_UNUSED
425#else
426# define _GL_UNUSED_LABEL
64#endif 427#endif
65]) 428])
429 AH_VERBATIM([async_safe],
430[/* The _GL_ASYNC_SAFE marker should be attached to functions that are
431 signal handlers (for signals other than SIGABRT, SIGPIPE) or can be
432 invoked from such signal handlers. Such functions have some restrictions:
433 * All functions that it calls should be marked _GL_ASYNC_SAFE as well,
434 or should be listed as async-signal-safe in POSIX
435 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04>
436 section 2.4.3. Note that malloc(), sprintf(), and fwrite(), in
437 particular, are NOT async-signal-safe.
438 * All memory locations (variables and struct fields) that these functions
439 access must be marked 'volatile'. This holds for both read and write
440 accesses. Otherwise the compiler might optimize away stores to and
441 reads from such locations that occur in the program, depending on its
442 data flow analysis. For example, when the program contains a loop
443 that is intended to inspect a variable set from within a signal handler
444 while (!signal_occurred)
445 ;
446 the compiler is allowed to transform this into an endless loop if the
447 variable 'signal_occurred' is not declared 'volatile'.
448 Additionally, recall that:
449 * A signal handler should not modify errno (except if it is a handler
450 for a fatal signal and ends by raising the same signal again, thus
451 provoking the termination of the process). If it invokes a function
452 that may clobber errno, it needs to save and restore the value of
453 errno. */
454#define _GL_ASYNC_SAFE
455])
456 AH_VERBATIM([micro_optimizations],
457[/* _GL_CMP (n1, n2) performs a three-valued comparison on n1 vs. n2, where
458 n1 and n2 are expressions without side effects, that evaluate to real
459 numbers (excluding NaN).
460 It returns
461 1 if n1 > n2
462 0 if n1 == n2
463 -1 if n1 < n2
464 The naïve code (n1 > n2 ? 1 : n1 < n2 ? -1 : 0) produces a conditional
465 jump with nearly all GCC versions up to GCC 10.
466 This variant (n1 < n2 ? -1 : n1 > n2) produces a conditional with many
467 GCC versions up to GCC 9.
468 The better code (n1 > n2) - (n1 < n2) from Hacker's Delight § 2-9
469 avoids conditional jumps in all GCC versions >= 3.4. */
470#define _GL_CMP(n1, n2) (((n1) > (n2)) - ((n1) < (n2)))
471])
472 dnl Hint which direction to take regarding cross-compilation guesses:
473 dnl When a user installs a program on a platform they are not intimately
474 dnl familiar with, --enable-cross-guesses=conservative is the appropriate
475 dnl choice. It implements the "If we don't know, assume the worst" principle.
476 dnl However, when an operating system developer (on a platform which is not
477 dnl yet known to gnulib) builds packages for their platform, they want to
478 dnl expose, not hide, possible platform bugs; in this case,
479 dnl --enable-cross-guesses=risky is the appropriate choice.
480 dnl Sets the variables
481 dnl gl_cross_guess_normal (to be used when 'yes' is good and 'no' is bad),
482 dnl gl_cross_guess_inverted (to be used when 'no' is good and 'yes' is bad).
483 AC_ARG_ENABLE([cross-guesses],
484 [AS_HELP_STRING([--enable-cross-guesses={conservative|risky}],
485 [specify policy for cross-compilation guesses])],
486 [if test "x$enableval" != xconservative && test "x$enableval" != xrisky; then
487 AC_MSG_WARN([invalid argument supplied to --enable-cross-guesses])
488 enableval=conservative
489 fi
490 gl_cross_guesses="$enableval"],
491 [gl_cross_guesses=conservative])
492 if test $gl_cross_guesses = risky; then
493 gl_cross_guess_normal="guessing yes"
494 gl_cross_guess_inverted="guessing no"
495 else
496 gl_cross_guess_normal="guessing no"
497 gl_cross_guess_inverted="guessing yes"
498 fi
66 dnl Preparation for running test programs: 499 dnl Preparation for running test programs:
67 dnl Tell glibc to write diagnostics from -D_FORTIFY_SOURCE=2 to stderr, not 500 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 501 dnl to /dev/tty, so they can be redirected to log files. Such diagnostics
@@ -71,6 +504,16 @@ AC_DEFUN([gl_COMMON_BODY], [
71 export LIBC_FATAL_STDERR_ 504 export LIBC_FATAL_STDERR_
72]) 505])
73 506
507# gl_MODULE_INDICATOR_INIT_VARIABLE([variablename])
508# gl_MODULE_INDICATOR_INIT_VARIABLE([variablename], [initialvalue])
509# initializes the shell variable that indicates the presence of the given module
510# as a C preprocessor expression.
511AC_DEFUN([gl_MODULE_INDICATOR_INIT_VARIABLE],
512[
513 GL_MODULE_INDICATOR_PREFIX[]_[$1]=m4_if([$2], , [0], [$2])
514 AC_SUBST(GL_MODULE_INDICATOR_PREFIX[]_[$1])
515])
516
74# gl_MODULE_INDICATOR_CONDITION 517# gl_MODULE_INDICATOR_CONDITION
75# expands to a C preprocessor expression that evaluates to 1 or 0, depending 518# 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 519# whether a gnulib module that has been requested shall be considered present
@@ -83,9 +526,9 @@ m4_define([gl_MODULE_INDICATOR_CONDITION], [1])
83AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE], 526AC_DEFUN([gl_MODULE_INDICATOR_SET_VARIABLE],
84[ 527[
85 gl_MODULE_INDICATOR_SET_VARIABLE_AUX( 528 gl_MODULE_INDICATOR_SET_VARIABLE_AUX(
86 [GNULIB_[]m4_translit([[$1]], 529 [GL_MODULE_INDICATOR_PREFIX[]_GNULIB_[]m4_translit([[$1]],
87 [abcdefghijklmnopqrstuvwxyz./-], 530 [abcdefghijklmnopqrstuvwxyz./-],
88 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])], 531 [ABCDEFGHIJKLMNOPQRSTUVWXYZ___])],
89 [gl_MODULE_INDICATOR_CONDITION]) 532 [gl_MODULE_INDICATOR_CONDITION])
90]) 533])
91 534
@@ -197,42 +640,20 @@ AC_DEFUN([gl_FEATURES_H],
197 AC_SUBST([HAVE_FEATURES_H]) 640 AC_SUBST([HAVE_FEATURES_H])
198]) 641])
199 642
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 643# gl_PROG_CC_C99
216# Modifies the value of the shell variable CC in an attempt to make $CC 644# Modifies the value of the shell variable CC in an attempt to make $CC
217# understand ISO C99 source code. 645# 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], 646AC_DEFUN([gl_PROG_CC_C99],
230[ 647[
231 dnl Change that version number to the minimum Autoconf version that supports 648 dnl Just use AC_PROG_CC_C99.
232 dnl mixing AC_PROG_CC_C99 calls with AC_PROG_CC_STDC calls. 649 dnl When AC_PROG_CC_C99 and AC_PROG_CC_STDC are used together, the substituted
233 m4_version_prereq([9.0], 650 dnl value of CC will contain the C99 enabling options twice. But this is only
234 [AC_REQUIRE([AC_PROG_CC_C99])], 651 dnl a cosmetic problem.
235 [AC_REQUIRE([AC_PROG_CC_STDC])]) 652 dnl With Autoconf >= 2.70, use AC_PROG_CC since it implies AC_PROG_CC_C99;
653 dnl this avoids a "warning: The macro `AC_PROG_CC_C99' is obsolete."
654 m4_version_prereq([2.70],
655 [AC_REQUIRE([AC_PROG_CC])],
656 [AC_REQUIRE([AC_PROG_CC_C99])])
236]) 657])
237 658
238# gl_PROG_AR_RANLIB 659# gl_PROG_AR_RANLIB
@@ -243,9 +664,11 @@ AC_DEFUN([gl_PROG_AR_RANLIB],
243[ 664[
244 dnl Minix 3 comes with two toolchains: The Amsterdam Compiler Kit compiler 665 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 666 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 667 dnl library formats. In particular, the GNU binutils programs ar and ranlib
247 dnl produce libraries that work only with gcc, not with cc. 668 dnl produce libraries that work only with gcc, not with cc.
248 AC_REQUIRE([AC_PROG_CC]) 669 AC_REQUIRE([AC_PROG_CC])
670 dnl The '][' hides this use from 'aclocal'.
671 AC_BEFORE([$0], [A][M_PROG_AR])
249 AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler], 672 AC_CACHE_CHECK([for Minix Amsterdam compiler], [gl_cv_c_amsterdam_compiler],
250 [ 673 [
251 AC_EGREP_CPP([Amsterdam], 674 AC_EGREP_CPP([Amsterdam],
@@ -257,25 +680,39 @@ Amsterdam
257 [gl_cv_c_amsterdam_compiler=yes], 680 [gl_cv_c_amsterdam_compiler=yes],
258 [gl_cv_c_amsterdam_compiler=no]) 681 [gl_cv_c_amsterdam_compiler=no])
259 ]) 682 ])
260 if test -z "$AR"; then 683
261 if test $gl_cv_c_amsterdam_compiler = yes; then 684 dnl Don't compete with AM_PROG_AR's decision about AR/ARFLAGS if we are not
685 dnl building with __ACK__.
686 if test $gl_cv_c_amsterdam_compiler = yes; then
687 if test -z "$AR"; then
262 AR='cc -c.a' 688 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 689 fi
274 else
275 if test -z "$ARFLAGS"; then 690 if test -z "$ARFLAGS"; then
276 ARFLAGS='cru' 691 ARFLAGS='-o'
277 fi 692 fi
693 else
694 dnl AM_PROG_AR was added in automake v1.11.2. AM_PROG_AR does not AC_SUBST
695 dnl ARFLAGS variable (it is filed into Makefile.in directly by automake
696 dnl script on-demand, if not specified by ./configure of course).
697 dnl Don't AC_REQUIRE the AM_PROG_AR otherwise the code for __ACK__ above
698 dnl will be ignored. Also, pay attention to call AM_PROG_AR in else block
699 dnl because AM_PROG_AR is written so it could re-set AR variable even for
700 dnl __ACK__. It may seem like its easier to avoid calling the macro here,
701 dnl but we need to AC_SUBST both AR/ARFLAGS (thus those must have some good
702 dnl default value and automake should usually know them).
703 dnl
704 dnl The '][' hides this use from 'aclocal'.
705 m4_ifdef([A][M_PROG_AR], [A][M_PROG_AR], [:])
706 fi
707
708 dnl In case the code above has not helped with setting AR/ARFLAGS, use
709 dnl Automake-documented default values for AR and ARFLAGS, but prefer
710 dnl ${host}-ar over ar (useful for cross-compiling).
711 AC_CHECK_TOOL([AR], [ar], [ar])
712 if test -z "$ARFLAGS"; then
713 ARFLAGS='cr'
278 fi 714 fi
715
279 AC_SUBST([AR]) 716 AC_SUBST([AR])
280 AC_SUBST([ARFLAGS]) 717 AC_SUBST([ARFLAGS])
281 if test -z "$RANLIB"; then 718 if test -z "$RANLIB"; then
@@ -289,46 +726,29 @@ Amsterdam
289 AC_SUBST([RANLIB]) 726 AC_SUBST([RANLIB])
290]) 727])
291 728
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 729# AC_C_RESTRICT
312# This definition overrides the AC_C_RESTRICT macro from autoconf 2.60..2.61, 730# 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++ 731# AC_C_RESTRICT macro from autoconf 2.60..2.70.
314# works. 732m4_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], 733AC_DEFUN([AC_C_RESTRICT],
319[AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict], 734[AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict],
320 [ac_cv_c_restrict=no 735 [ac_cv_c_restrict=no
321 # The order here caters to the fact that C++ does not require restrict. 736 # Put '__restrict__' first, to avoid problems with glibc and non-GCC; see:
322 for ac_kw in __restrict __restrict__ _Restrict restrict; do 737 # https://lists.gnu.org/archive/html/bug-autoconf/2016-02/msg00006.html
323 AC_COMPILE_IFELSE([AC_LANG_PROGRAM( 738 # Put 'restrict' last, because C++ lacks it.
324 [[typedef int * int_ptr; 739 for ac_kw in __restrict__ __restrict _Restrict restrict; do
325 int foo (int_ptr $ac_kw ip) { 740 AC_COMPILE_IFELSE(
326 return ip[0]; 741 [AC_LANG_PROGRAM(
327 }]], 742 [[typedef int *int_ptr;
328 [[int s[1]; 743 int foo (int_ptr $ac_kw ip) { return ip[0]; }
329 int * $ac_kw t = s; 744 int bar (int [$ac_kw]); /* Catch GCC bug 14050. */
330 t[0] = 0; 745 int bar (int ip[$ac_kw]) { return ip[0]; }
331 return foo(t)]])], 746 ]],
747 [[int s[1];
748 int *$ac_kw t = s;
749 t[0] = 0;
750 return foo (t) + bar (t);
751 ]])],
332 [ac_cv_c_restrict=$ac_kw]) 752 [ac_cv_c_restrict=$ac_kw])
333 test "$ac_cv_c_restrict" != no && break 753 test "$ac_cv_c_restrict" != no && break
334 done 754 done
@@ -336,22 +756,24 @@ AC_DEFUN([AC_C_RESTRICT],
336 AH_VERBATIM([restrict], 756 AH_VERBATIM([restrict],
337[/* Define to the equivalent of the C99 'restrict' keyword, or to 757[/* Define to the equivalent of the C99 'restrict' keyword, or to
338 nothing if this is not supported. Do not define if restrict is 758 nothing if this is not supported. Do not define if restrict is
339 supported directly. */ 759 supported only directly. */
340#undef restrict 760#undef restrict
341/* Work around a bug in Sun C++: it does not support _Restrict, even 761/* Work around a bug in older versions of Sun C++, which did not
342 though the corresponding Sun C compiler does, which causes 762 #define __restrict__ or support _Restrict or __restrict__
343 "#define restrict _Restrict" in the previous line. Perhaps some future 763 even though the corresponding Sun C compiler ended up with
344 version of Sun C++ will work with _Restrict; if so, it'll probably 764 "#define restrict _Restrict" or "#define restrict __restrict__"
345 define __RESTRICT, just as Sun C does. */ 765 in the previous line. This workaround can be removed once
346#if defined __SUNPRO_CC && !defined __RESTRICT 766 we assume Oracle Developer Studio 12.5 (2016) or later. */
767#if defined __SUNPRO_CC && !defined __RESTRICT && !defined __restrict__
347# define _Restrict 768# define _Restrict
769# define __restrict__
348#endif]) 770#endif])
349 case $ac_cv_c_restrict in 771 case $ac_cv_c_restrict in
350 restrict) ;; 772 restrict) ;;
351 no) AC_DEFINE([restrict], []) ;; 773 no) AC_DEFINE([restrict], []) ;;
352 *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;; 774 *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
353 esac 775 esac
354]) 776])# AC_C_RESTRICT
355]) 777])
356 778
357# gl_BIGENDIAN 779# gl_BIGENDIAN
@@ -363,6 +785,22 @@ AC_DEFUN([gl_BIGENDIAN],
363 AC_C_BIGENDIAN 785 AC_C_BIGENDIAN
364]) 786])
365 787
788# A temporary file descriptor.
789# Must be less than 10, because dash 0.5.8 does not support redirections
790# with multi-digit file descriptors.
791m4_define([GL_TMP_FD], 9)
792
793# gl_SILENT(command)
794# executes command, but without the normal configure output.
795# This is useful when you want to invoke AC_CACHE_CHECK (or AC_CHECK_FUNC etc.)
796# inside another AC_CACHE_CHECK.
797AC_DEFUN([gl_SILENT],
798[
799 exec GL_TMP_FD>&AS_MESSAGE_FD AS_MESSAGE_FD>/dev/null
800 $1
801 exec AS_MESSAGE_FD>&GL_TMP_FD GL_TMP_FD>&-
802])
803
366# gl_CACHE_VAL_SILENT(cache-id, command-to-set-it) 804# 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 805# 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. 806# output a spurious "(cached)" mark in the midst of other configure output.
@@ -370,8 +808,143 @@ AC_DEFUN([gl_BIGENDIAN],
370# by an AC_MSG_CHECKING/AC_MSG_RESULT pair. 808# by an AC_MSG_CHECKING/AC_MSG_RESULT pair.
371AC_DEFUN([gl_CACHE_VAL_SILENT], 809AC_DEFUN([gl_CACHE_VAL_SILENT],
372[ 810[
373 saved_as_echo_n="$as_echo_n" 811 gl_SILENT([
374 as_echo_n=':' 812 AC_CACHE_VAL([$1], [$2])
375 AC_CACHE_VAL([$1], [$2]) 813 ])
376 as_echo_n="$saved_as_echo_n" 814])
815
816# gl_CC_ALLOW_WARNINGS
817# sets and substitutes a variable GL_CFLAG_ALLOW_WARNINGS, to a $(CC) option
818# that reverts a preceding '-Werror' option, if available.
819# This is expected to be '-Wno-error' on gcc, clang (except clang/MSVC), xlclang
820# and empty otherwise.
821AC_DEFUN([gl_CC_ALLOW_WARNINGS],
822[
823 AC_REQUIRE([AC_PROG_CC])
824 AC_CACHE_CHECK([for C compiler option to allow warnings],
825 [gl_cv_cc_wallow],
826 [rm -f conftest*
827 echo 'int dummy;' > conftest.c
828 AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -c conftest.c 2>conftest1.err]) >/dev/null
829 AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -Wno-error -c conftest.c 2>conftest2.err]) >/dev/null
830 dnl Test the number of error output lines, because AIX xlc accepts the
831 dnl option '-Wno-error', just to produce a warning
832 dnl "Option -Wno-error was incorrectly specified. The option will be ignored."
833 dnl afterwards.
834 if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
835 gl_cv_cc_wallow='-Wno-error'
836 else
837 gl_cv_cc_wallow=none
838 fi
839 rm -f conftest*
840 ])
841 case "$gl_cv_cc_wallow" in
842 none) GL_CFLAG_ALLOW_WARNINGS='' ;;
843 *) GL_CFLAG_ALLOW_WARNINGS="$gl_cv_cc_wallow" ;;
844 esac
845 AC_SUBST([GL_CFLAG_ALLOW_WARNINGS])
846])
847
848# gl_CXX_ALLOW_WARNINGS
849# sets and substitutes a variable GL_CXXFLAG_ALLOW_WARNINGS, to a $(CC) option
850# that reverts a preceding '-Werror' option, if available.
851AC_DEFUN([gl_CXX_ALLOW_WARNINGS],
852[
853 dnl Requires AC_PROG_CXX or gl_PROG_ANSI_CXX.
854 if test -n "$CXX" && test "$CXX" != no; then
855 AC_CACHE_CHECK([for C++ compiler option to allow warnings],
856 [gl_cv_cxx_wallow],
857 [rm -f conftest*
858 echo 'int dummy;' > conftest.cc
859 AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -c conftest.cc 2>conftest1.err]) >/dev/null
860 AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -Wno-error -c conftest.cc 2>conftest2.err]) >/dev/null
861 dnl Test the number of error output lines, because AIX xlC accepts the
862 dnl option '-Wno-error', just to produce a warning
863 dnl "Option -Wno-error was incorrectly specified. The option will be ignored."
864 dnl afterwards.
865 if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; then
866 gl_cv_cxx_wallow='-Wno-error'
867 else
868 gl_cv_cxx_wallow=none
869 fi
870 rm -f conftest*
871 ])
872 case "$gl_cv_cxx_wallow" in
873 none) GL_CXXFLAG_ALLOW_WARNINGS='' ;;
874 *) GL_CXXFLAG_ALLOW_WARNINGS="$gl_cv_cxx_wallow" ;;
875 esac
876 else
877 GL_CXXFLAG_ALLOW_WARNINGS=''
878 fi
879 AC_SUBST([GL_CXXFLAG_ALLOW_WARNINGS])
880])
881
882dnl Expands to some code for use in .c programs that, on native Windows, defines
883dnl the Microsoft deprecated alias function names to the underscore-prefixed
884dnl actual function names. With this macro, these function names are available
885dnl without linking with '-loldnames' and without generating warnings.
886dnl Usage: Use it after all system header files are included.
887dnl #include <...>
888dnl #include <...>
889dnl ]GL_MDA_DEFINES[
890dnl ...
891AC_DEFUN([GL_MDA_DEFINES],[
892AC_REQUIRE([_GL_MDA_DEFINES])
893[$gl_mda_defines]
894])
895AC_DEFUN([_GL_MDA_DEFINES],
896[gl_mda_defines='
897#if defined _WIN32 && !defined __CYGWIN__
898#define access _access
899#define chdir _chdir
900#define chmod _chmod
901#define close _close
902#define creat _creat
903#define dup _dup
904#define dup2 _dup2
905#define ecvt _ecvt
906#define execl _execl
907#define execle _execle
908#define execlp _execlp
909#define execv _execv
910#define execve _execve
911#define execvp _execvp
912#define execvpe _execvpe
913#define fcloseall _fcloseall
914#define fcvt _fcvt
915#define fdopen _fdopen
916#define fileno _fileno
917#define gcvt _gcvt
918#define getcwd _getcwd
919#define getpid _getpid
920#define getw _getw
921#define isatty _isatty
922#define j0 _j0
923#define j1 _j1
924#define jn _jn
925#define lfind _lfind
926#define lsearch _lsearch
927#define lseek _lseek
928#define memccpy _memccpy
929#define mkdir _mkdir
930#define mktemp _mktemp
931#define open _open
932#define putenv _putenv
933#define putw _putw
934#define read _read
935#define rmdir _rmdir
936#define strdup _strdup
937#define swab _swab
938#define tempnam _tempnam
939#define tzset _tzset
940#define umask _umask
941#define unlink _unlink
942#define utime _utime
943#define wcsdup _wcsdup
944#define write _write
945#define y0 _y0
946#define y1 _y1
947#define yn _yn
948#endif
949'
377]) 950])
diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4
index 9a4f502..219b81e 100644
--- a/gl/m4/gnulib-comp.m4
+++ b/gl/m4/gnulib-comp.m4
@@ -1,5 +1,5 @@
1# DO NOT EDIT! GENERATED AUTOMATICALLY! 1# DO NOT EDIT! GENERATED AUTOMATICALLY!
2# Copyright (C) 2002-2013 Free Software Foundation, Inc. 2# Copyright (C) 2002-2021 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
@@ -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,93 @@ 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])
44
41 AC_REQUIRE([AM_PROG_CC_C_O]) 45 AC_REQUIRE([AM_PROG_CC_C_O])
46 # Code from module absolute-header:
42 # Code from module alloca-opt: 47 # Code from module alloca-opt:
43 # Code from module arpa_inet: 48 # Code from module arpa_inet:
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:
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:
47 # Code from module crypto/sha1: 61 # Code from module crypto/sha1:
62 # Code from module crypto/sha1-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:
67 # Code from module dynarray:
52 # Code from module environ: 68 # Code from module environ:
53 # Code from module errno: 69 # Code from module errno:
54 # Code from module error: 70 # Code from module error:
55 # Code from module exitfail: 71 # Code from module exitfail:
56 # Code from module extensions: 72 # Code from module extensions:
57 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
58 # Code from module extern-inline: 73 # Code from module extern-inline:
74 # Code from module fcntl:
75 # Code from module fcntl-h:
59 # Code from module fd-hook: 76 # Code from module fd-hook:
77 # Code from module fflush:
78 AC_REQUIRE([gl_SET_LARGEFILE_SOURCE])
79 # Code from module filename:
60 # Code from module float: 80 # Code from module float:
61 # Code from module floorf: 81 # Code from module floorf:
82 # Code from module fopen:
83 # Code from module fopen-gnu:
84 # Code from module fpurge:
85 # Code from module freading:
86 # Code from module free-posix:
87 # Code from module fseek:
88 # Code from module fseeko:
89 AC_REQUIRE([gl_SET_LARGEFILE_SOURCE])
90 # Code from module fstat:
62 # Code from module fsusage: 91 # Code from module fsusage:
63 # Code from module full-read: 92 # Code from module ftell:
93 # Code from module ftello:
94 AC_REQUIRE([gl_SET_LARGEFILE_SOURCE])
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:
103 # Code from module getprogname:
69 # Code from module gettext: 104 # Code from module gettext:
70 # Code from module gettext-h: 105 # Code from module gettext-h:
106 # Code from module hard-locale:
71 # Code from module havelib: 107 # Code from module havelib:
72 # Code from module hostent: 108 # Code from module hostent:
109 # Code from module ialloc:
73 # Code from module idpriv-droptemp: 110 # Code from module idpriv-droptemp:
111 # Code from module idx:
74 # Code from module include_next: 112 # Code from module include_next:
75 # Code from module inet_ntop: 113 # Code from module inet_ntop:
76 # Code from module intprops: 114 # Code from module intprops:
115 # Code from module inttypes-incomplete:
77 # Code from module langinfo: 116 # Code from module langinfo:
78 # Code from module largefile: 117 # Code from module largefile:
79 AC_REQUIRE([AC_SYS_LARGEFILE]) 118 AC_REQUIRE([AC_SYS_LARGEFILE])
119 AC_REQUIRE([gl_YEAR2038_EARLY])
120 # Code from module libc-config:
121 # Code from module limits-h:
80 # Code from module localcharset: 122 # Code from module localcharset:
81 # Code from module locale: 123 # Code from module locale:
82 # Code from module localeconv: 124 # Code from module localeconv:
83 # Code from module lock: 125 # Code from module lock:
126 # Code from module lseek:
84 # Code from module malloc-gnu: 127 # Code from module malloc-gnu:
85 # Code from module malloc-posix: 128 # Code from module malloc-posix:
86 # Code from module malloca: 129 # Code from module malloca:
@@ -89,6 +132,7 @@ AC_DEFUN([gl_EARLY],
89 # Code from module mbsinit: 132 # Code from module mbsinit:
90 # Code from module mbtowc: 133 # Code from module mbtowc:
91 # Code from module memchr: 134 # Code from module memchr:
135 # Code from module minmax:
92 # Code from module mktime: 136 # Code from module mktime:
93 # Code from module mktime-internal: 137 # Code from module mktime-internal:
94 # Code from module mountlist: 138 # Code from module mountlist:
@@ -99,11 +143,15 @@ AC_DEFUN([gl_EARLY],
99 # Code from module netinet_in: 143 # Code from module netinet_in:
100 # Code from module nl_langinfo: 144 # Code from module nl_langinfo:
101 # Code from module nocrash: 145 # Code from module nocrash:
102 # Code from module read: 146 # Code from module open:
147 # Code from module pathmax:
148 # Code from module realloc-gnu:
149 # Code from module realloc-posix:
150 # Code from module reallocarray:
103 # Code from module regex: 151 # Code from module regex:
104 # Code from module safe-read:
105 # Code from module servent: 152 # Code from module servent:
106 # Code from module setenv: 153 # Code from module setenv:
154 # Code from module setlocale-null:
107 # Code from module size_max: 155 # Code from module size_max:
108 # Code from module snippet/_Noreturn: 156 # Code from module snippet/_Noreturn:
109 # Code from module snippet/arg-nonnull: 157 # Code from module snippet/arg-nonnull:
@@ -114,6 +162,9 @@ AC_DEFUN([gl_EARLY],
114 # Code from module sockets: 162 # Code from module sockets:
115 # Code from module socklen: 163 # Code from module socklen:
116 # Code from module ssize_t: 164 # Code from module ssize_t:
165 # Code from module stat:
166 # Code from module stat-time:
167 # Code from module std-gnu11:
117 # Code from module stdalign: 168 # Code from module stdalign:
118 # Code from module stdbool: 169 # Code from module stdbool:
119 # Code from module stddef: 170 # Code from module stddef:
@@ -128,11 +179,10 @@ AC_DEFUN([gl_EARLY],
128 # Code from module strerror-override: 179 # Code from module strerror-override:
129 # Code from module string: 180 # Code from module string:
130 # Code from module strings: 181 # Code from module strings:
131 # Code from module strndup:
132 # Code from module strnlen:
133 # Code from module strsep: 182 # Code from module strsep:
134 # Code from module strstr-simple: 183 # Code from module strstr-simple:
135 # Code from module sys_socket: 184 # Code from module sys_socket:
185 # Code from module sys_stat:
136 # Code from module sys_types: 186 # Code from module sys_types:
137 # Code from module sys_uio: 187 # Code from module sys_uio:
138 # Code from module threadlib: 188 # Code from module threadlib:
@@ -141,6 +191,7 @@ AC_DEFUN([gl_EARLY],
141 # Code from module time_r: 191 # Code from module time_r:
142 # Code from module timegm: 192 # Code from module timegm:
143 # Code from module unistd: 193 # Code from module unistd:
194 # Code from module unlocked-io-internal:
144 # Code from module unsetenv: 195 # Code from module unsetenv:
145 # Code from module vasnprintf: 196 # Code from module vasnprintf:
146 # Code from module vasprintf: 197 # Code from module vasprintf:
@@ -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,10 +224,13 @@ 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'
175 gl_FUNC_ALLOCA 231 gl_FUNC_ALLOCA
176 gl_HEADER_ARPA_INET 232 gl_ARPA_INET_H
233 gl_ARPA_INET_H_REQUIRE_DEFAULTS
177 AC_PROG_MKDIR_P 234 AC_PROG_MKDIR_P
178 gl_FUNC_BASE64 235 gl_FUNC_BASE64
179 gl_FUNC_BTOWC 236 gl_FUNC_BTOWC
@@ -182,24 +239,61 @@ AC_DEFUN([gl_INIT],
182 gl_PREREQ_BTOWC 239 gl_PREREQ_BTOWC
183 fi 240 fi
184 gl_WCHAR_MODULE_INDICATOR([btowc]) 241 gl_WCHAR_MODULE_INDICATOR([btowc])
185 gl_CONFIGMAKE_PREP 242 gl___BUILTIN_EXPECT
243 gl_BYTESWAP
244 gl_FUNC_CALLOC_GNU
245 if test $REPLACE_CALLOC = 1; then
246 AC_LIBOBJ([calloc])
247 fi
248 gl_FUNC_CALLOC_POSIX
249 if test $REPLACE_CALLOC = 1; then
250 AC_LIBOBJ([calloc])
251 fi
252 gl_STDLIB_MODULE_INDICATOR([calloc-posix])
253 gl_MODULE_INDICATOR_FOR_TESTS([cloexec])
254 gl_FUNC_CLOSE
255 if test $REPLACE_CLOSE = 1; then
256 AC_LIBOBJ([close])
257 fi
258 gl_UNISTD_MODULE_INDICATOR([close])
259 gl_AF_ALG
260 AC_REQUIRE([AC_C_RESTRICT])
186 gl_SHA1 261 gl_SHA1
187 gl_DIRNAME
188 gl_MODULE_INDICATOR([dirname]) 262 gl_MODULE_INDICATOR([dirname])
189 gl_DIRNAME_LGPL
190 gl_DOUBLE_SLASH_ROOT 263 gl_DOUBLE_SLASH_ROOT
264 gl_FUNC_DUP2
265 if test $REPLACE_DUP2 = 1; then
266 AC_LIBOBJ([dup2])
267 gl_PREREQ_DUP2
268 fi
269 gl_UNISTD_MODULE_INDICATOR([dup2])
270 AC_PROG_MKDIR_P
191 gl_ENVIRON 271 gl_ENVIRON
192 gl_UNISTD_MODULE_INDICATOR([environ]) 272 gl_UNISTD_MODULE_INDICATOR([environ])
193 gl_HEADER_ERRNO_H 273 gl_HEADER_ERRNO_H
194 gl_ERROR 274 gl_ERROR
195 if test $ac_cv_lib_error_at_line = no; then 275 AS_IF([test "$ac_cv_lib_error_at_line" = no], [
196 AC_LIBOBJ([error]) 276 AC_LIBOBJ([error])
197 gl_PREREQ_ERROR 277 gl_PREREQ_ERROR
198 fi 278 ])
199 m4_ifdef([AM_XGETTEXT_OPTION], 279 m4_ifdef([AM_XGETTEXT_OPTION],
200 [AM_][XGETTEXT_OPTION([--flag=error:3:c-format]) 280 [AM_][XGETTEXT_OPTION([--flag=error:3:c-format])
201 AM_][XGETTEXT_OPTION([--flag=error_at_line:5:c-format])]) 281 AM_][XGETTEXT_OPTION([--flag=error_at_line:5:c-format])])
202 AC_REQUIRE([gl_EXTERN_INLINE]) 282 AC_REQUIRE([gl_EXTERN_INLINE])
283 gl_FUNC_FCNTL
284 if test $HAVE_FCNTL = 0 || test $REPLACE_FCNTL = 1; then
285 AC_LIBOBJ([fcntl])
286 fi
287 gl_FCNTL_MODULE_INDICATOR([fcntl])
288 gl_FCNTL_H
289 gl_FCNTL_H_REQUIRE_DEFAULTS
290 gl_FUNC_FFLUSH
291 if test $REPLACE_FFLUSH = 1; then
292 AC_LIBOBJ([fflush])
293 gl_PREREQ_FFLUSH
294 fi
295 gl_MODULE_INDICATOR([fflush])
296 gl_STDIO_MODULE_INDICATOR([fflush])
203 gl_FLOAT_H 297 gl_FLOAT_H
204 if test $REPLACE_FLOAT_LDBL = 1; then 298 if test $REPLACE_FLOAT_LDBL = 1; then
205 AC_LIBOBJ([float]) 299 AC_LIBOBJ([float])
@@ -212,25 +306,101 @@ AC_DEFUN([gl_INIT],
212 AC_LIBOBJ([floorf]) 306 AC_LIBOBJ([floorf])
213 fi 307 fi
214 gl_MATH_MODULE_INDICATOR([floorf]) 308 gl_MATH_MODULE_INDICATOR([floorf])
309 gl_FUNC_FOPEN
310 if test $REPLACE_FOPEN = 1; then
311 AC_LIBOBJ([fopen])
312 gl_PREREQ_FOPEN
313 fi
314 gl_STDIO_MODULE_INDICATOR([fopen])
315 gl_FUNC_FOPEN_GNU
316 if test $REPLACE_FOPEN = 1; then
317 AC_LIBOBJ([fopen])
318 gl_PREREQ_FOPEN
319 fi
320 gl_MODULE_INDICATOR([fopen-gnu])
321 gl_FUNC_FPURGE
322 if test $HAVE_FPURGE = 0 || test $REPLACE_FPURGE = 1; then
323 AC_LIBOBJ([fpurge])
324 fi
325 gl_STDIO_MODULE_INDICATOR([fpurge])
326 gl_FUNC_FREADING
327 gl_FUNC_FREE
328 if test $REPLACE_FREE = 1; then
329 AC_LIBOBJ([free])
330 gl_PREREQ_FREE
331 fi
332 gl_STDLIB_MODULE_INDICATOR([free-posix])
333 gl_FUNC_FSEEK
334 if test $REPLACE_FSEEK = 1; then
335 AC_LIBOBJ([fseek])
336 fi
337 gl_STDIO_MODULE_INDICATOR([fseek])
338 gl_FUNC_FSEEKO
339 if test $HAVE_FSEEKO = 0 || test $REPLACE_FSEEKO = 1; then
340 AC_LIBOBJ([fseeko])
341 gl_PREREQ_FSEEKO
342 fi
343 gl_STDIO_MODULE_INDICATOR([fseeko])
344 gl_FUNC_FSTAT
345 if test $REPLACE_FSTAT = 1; then
346 AC_LIBOBJ([fstat])
347 case "$host_os" in
348 mingw*)
349 AC_LIBOBJ([stat-w32])
350 ;;
351 esac
352 gl_PREREQ_FSTAT
353 fi
354 gl_SYS_STAT_MODULE_INDICATOR([fstat])
215 gl_FSUSAGE 355 gl_FSUSAGE
216 if test $gl_cv_fs_space = yes; then 356 if test $gl_cv_fs_space = yes; then
217 AC_LIBOBJ([fsusage]) 357 AC_LIBOBJ([fsusage])
218 gl_PREREQ_FSUSAGE_EXTRA 358 gl_PREREQ_FSUSAGE_EXTRA
219 fi 359 fi
360 gl_FUNC_FTELL
361 if test $REPLACE_FTELL = 1; then
362 AC_LIBOBJ([ftell])
363 fi
364 gl_STDIO_MODULE_INDICATOR([ftell])
365 gl_FUNC_FTELLO
366 if test $HAVE_FTELLO = 0 || test $REPLACE_FTELLO = 1; then
367 AC_LIBOBJ([ftello])
368 gl_PREREQ_FTELLO
369 fi
370 gl_STDIO_MODULE_INDICATOR([ftello])
220 gl_GETADDRINFO 371 gl_GETADDRINFO
221 if test $HAVE_GETADDRINFO = 0; then 372 if test $HAVE_GETADDRINFO = 0 || test $REPLACE_GETADDRINFO = 1; then
222 AC_LIBOBJ([getaddrinfo]) 373 AC_LIBOBJ([getaddrinfo])
223 fi 374 fi
224 if test $HAVE_DECL_GAI_STRERROR = 0 || test $REPLACE_GAI_STRERROR = 1; then 375 if test $HAVE_DECL_GAI_STRERROR = 0 || test $REPLACE_GAI_STRERROR = 1; then
225 AC_LIBOBJ([gai_strerror]) 376 AC_LIBOBJ([gai_strerror])
226 fi 377 fi
227 gl_NETDB_MODULE_INDICATOR([getaddrinfo]) 378 gl_NETDB_MODULE_INDICATOR([getaddrinfo])
379 gl_FUNC_GETDELIM
380 if test $HAVE_GETDELIM = 0 || test $REPLACE_GETDELIM = 1; then
381 AC_LIBOBJ([getdelim])
382 gl_PREREQ_GETDELIM
383 fi
384 gl_STDIO_MODULE_INDICATOR([getdelim])
385 gl_FUNC_GETDTABLESIZE
386 if test $HAVE_GETDTABLESIZE = 0 || test $REPLACE_GETDTABLESIZE = 1; then
387 AC_LIBOBJ([getdtablesize])
388 gl_PREREQ_GETDTABLESIZE
389 fi
390 gl_UNISTD_MODULE_INDICATOR([getdtablesize])
228 gl_FUNC_GETHOSTNAME 391 gl_FUNC_GETHOSTNAME
229 if test $HAVE_GETHOSTNAME = 0; then 392 if test $HAVE_GETHOSTNAME = 0; then
230 AC_LIBOBJ([gethostname]) 393 AC_LIBOBJ([gethostname])
231 gl_PREREQ_GETHOSTNAME 394 gl_PREREQ_GETHOSTNAME
232 fi 395 fi
233 gl_UNISTD_MODULE_INDICATOR([gethostname]) 396 gl_UNISTD_MODULE_INDICATOR([gethostname])
397 gl_FUNC_GETLINE
398 if test $REPLACE_GETLINE = 1; then
399 AC_LIBOBJ([getline])
400 gl_PREREQ_GETLINE
401 fi
402 gl_STDIO_MODULE_INDICATOR([getline])
403 AC_REQUIRE([AC_CANONICAL_HOST])
234 gl_GETLOADAVG 404 gl_GETLOADAVG
235 if test $HAVE_GETLOADAVG = 0; then 405 if test $HAVE_GETLOADAVG = 0; then
236 AC_LIBOBJ([getloadavg]) 406 AC_LIBOBJ([getloadavg])
@@ -238,28 +408,27 @@ AC_DEFUN([gl_INIT],
238 fi 408 fi
239 gl_STDLIB_MODULE_INDICATOR([getloadavg]) 409 gl_STDLIB_MODULE_INDICATOR([getloadavg])
240 gl_FUNC_GETOPT_GNU 410 gl_FUNC_GETOPT_GNU
241 if test $REPLACE_GETOPT = 1; then 411 dnl Because of the way gl_FUNC_GETOPT_GNU is implemented (the gl_getopt_required
242 AC_LIBOBJ([getopt]) 412 dnl mechanism), there is no need to do any AC_LIBOBJ or AC_SUBST here; they are
243 AC_LIBOBJ([getopt1]) 413 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 414 gl_FUNC_GETOPT_POSIX
251 if test $REPLACE_GETOPT = 1; then 415 if test $REPLACE_GETOPT = 1; then
252 AC_LIBOBJ([getopt]) 416 AC_LIBOBJ([getopt])
253 AC_LIBOBJ([getopt1]) 417 AC_LIBOBJ([getopt1])
254 gl_PREREQ_GETOPT 418 dnl Define the substituted variable GNULIB_UNISTD_H_GETOPT to 1.
255 dnl Arrange for unistd.h to include getopt.h. 419 gl_UNISTD_H_REQUIRE_DEFAULTS
256 GNULIB_GL_UNISTD_H_GETOPT=1 420 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_UNISTD_H_GETOPT], [1])
257 fi 421 fi
258 AC_SUBST([GNULIB_GL_UNISTD_H_GETOPT]) 422 gl_UNISTD_MODULE_INDICATOR([getopt-posix])
423 gl_FUNC_GETPROGNAME
259 dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac. 424 dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac.
260 AM_GNU_GETTEXT_VERSION([0.18.1]) 425 AM_GNU_GETTEXT_VERSION([0.20])
261 AC_SUBST([LIBINTL]) 426 AC_SUBST([LIBINTL])
262 AC_SUBST([LTLIBINTL]) 427 AC_SUBST([LTLIBINTL])
428 AC_REQUIRE([gl_FUNC_SETLOCALE_NULL])
429 LIB_HARD_LOCALE="$LIB_SETLOCALE_NULL"
430 AC_SUBST([LIB_HARD_LOCALE])
431 AC_DEFUN([gl_HAVE_MODULE_HAVELIB])
263 gl_HOSTENT 432 gl_HOSTENT
264 gl_IDPRIV 433 gl_IDPRIV
265 gl_FUNC_INET_NTOP 434 gl_FUNC_INET_NTOP
@@ -268,12 +437,19 @@ AC_DEFUN([gl_INIT],
268 gl_PREREQ_INET_NTOP 437 gl_PREREQ_INET_NTOP
269 fi 438 fi
270 gl_ARPA_INET_MODULE_INDICATOR([inet_ntop]) 439 gl_ARPA_INET_MODULE_INDICATOR([inet_ntop])
440 gl_INTTYPES_INCOMPLETE
441 gl_INTTYPES_H_REQUIRE_DEFAULTS
271 gl_LANGINFO_H 442 gl_LANGINFO_H
443 gl_LANGINFO_H_REQUIRE_DEFAULTS
272 AC_REQUIRE([gl_LARGEFILE]) 444 AC_REQUIRE([gl_LARGEFILE])
445 gl___INLINE
446 gl_LIMITS_H
273 gl_LOCALCHARSET 447 gl_LOCALCHARSET
274 LOCALCHARSET_TESTS_ENVIRONMENT="CHARSETALIASDIR=\"\$(abs_top_builddir)/$gl_source_base\"" 448 dnl For backward compatibility. Some packages still use this.
449 LOCALCHARSET_TESTS_ENVIRONMENT=
275 AC_SUBST([LOCALCHARSET_TESTS_ENVIRONMENT]) 450 AC_SUBST([LOCALCHARSET_TESTS_ENVIRONMENT])
276 gl_LOCALE_H 451 gl_LOCALE_H
452 gl_LOCALE_H_REQUIRE_DEFAULTS
277 gl_FUNC_LOCALECONV 453 gl_FUNC_LOCALECONV
278 if test $REPLACE_LOCALECONV = 1; then 454 if test $REPLACE_LOCALECONV = 1; then
279 AC_LIBOBJ([localeconv]) 455 AC_LIBOBJ([localeconv])
@@ -282,21 +458,31 @@ AC_DEFUN([gl_INIT],
282 gl_LOCALE_MODULE_INDICATOR([localeconv]) 458 gl_LOCALE_MODULE_INDICATOR([localeconv])
283 gl_LOCK 459 gl_LOCK
284 gl_MODULE_INDICATOR([lock]) 460 gl_MODULE_INDICATOR([lock])
461 gl_FUNC_LSEEK
462 if test $REPLACE_LSEEK = 1; then
463 AC_LIBOBJ([lseek])
464 fi
465 gl_UNISTD_MODULE_INDICATOR([lseek])
285 gl_FUNC_MALLOC_GNU 466 gl_FUNC_MALLOC_GNU
286 if test $REPLACE_MALLOC = 1; then 467 if test $REPLACE_MALLOC = 1; then
287 AC_LIBOBJ([malloc]) 468 AC_LIBOBJ([malloc])
288 fi 469 fi
289 gl_MODULE_INDICATOR([malloc-gnu]) 470 AC_REQUIRE([gl_FUNC_MALLOC_POSIX])
290 gl_FUNC_MALLOC_POSIX
291 if test $REPLACE_MALLOC = 1; then 471 if test $REPLACE_MALLOC = 1; then
292 AC_LIBOBJ([malloc]) 472 AC_LIBOBJ([malloc])
293 fi 473 fi
294 gl_STDLIB_MODULE_INDICATOR([malloc-posix]) 474 gl_STDLIB_MODULE_INDICATOR([malloc-posix])
295 gl_MALLOCA 475 gl_MALLOCA
296 gl_MATH_H 476 gl_MATH_H
477 gl_MATH_H_REQUIRE_DEFAULTS
297 gl_FUNC_MBRTOWC 478 gl_FUNC_MBRTOWC
298 if test $HAVE_MBRTOWC = 0 || test $REPLACE_MBRTOWC = 1; then 479 if test $HAVE_MBRTOWC = 0 || test $REPLACE_MBRTOWC = 1; then
299 AC_LIBOBJ([mbrtowc]) 480 AC_LIBOBJ([mbrtowc])
481 if test $REPLACE_MBSTATE_T = 1; then
482 AC_LIBOBJ([lc-charset-dispatch])
483 AC_LIBOBJ([mbtowc-lock])
484 gl_PREREQ_MBTOWC_LOCK
485 fi
300 gl_PREREQ_MBRTOWC 486 gl_PREREQ_MBRTOWC
301 fi 487 fi
302 gl_WCHAR_MODULE_INDICATOR([mbrtowc]) 488 gl_WCHAR_MODULE_INDICATOR([mbrtowc])
@@ -307,17 +493,18 @@ AC_DEFUN([gl_INIT],
307 fi 493 fi
308 gl_WCHAR_MODULE_INDICATOR([mbsinit]) 494 gl_WCHAR_MODULE_INDICATOR([mbsinit])
309 gl_FUNC_MBTOWC 495 gl_FUNC_MBTOWC
310 if test $REPLACE_MBTOWC = 1; then 496 if test $HAVE_MBTOWC = 0 || test $REPLACE_MBTOWC = 1; then
311 AC_LIBOBJ([mbtowc]) 497 AC_LIBOBJ([mbtowc])
312 gl_PREREQ_MBTOWC 498 gl_PREREQ_MBTOWC
313 fi 499 fi
314 gl_STDLIB_MODULE_INDICATOR([mbtowc]) 500 gl_STDLIB_MODULE_INDICATOR([mbtowc])
315 gl_FUNC_MEMCHR 501 gl_FUNC_MEMCHR
316 if test $HAVE_MEMCHR = 0 || test $REPLACE_MEMCHR = 1; then 502 if test $REPLACE_MEMCHR = 1; then
317 AC_LIBOBJ([memchr]) 503 AC_LIBOBJ([memchr])
318 gl_PREREQ_MEMCHR 504 gl_PREREQ_MEMCHR
319 fi 505 fi
320 gl_STRING_MODULE_INDICATOR([memchr]) 506 gl_STRING_MODULE_INDICATOR([memchr])
507 gl_MINMAX
321 gl_FUNC_MKTIME 508 gl_FUNC_MKTIME
322 if test $REPLACE_MKTIME = 1; then 509 if test $REPLACE_MKTIME = 1; then
323 AC_LIBOBJ([mktime]) 510 AC_LIBOBJ([mktime])
@@ -325,7 +512,7 @@ AC_DEFUN([gl_INIT],
325 fi 512 fi
326 gl_TIME_MODULE_INDICATOR([mktime]) 513 gl_TIME_MODULE_INDICATOR([mktime])
327 gl_FUNC_MKTIME_INTERNAL 514 gl_FUNC_MKTIME_INTERNAL
328 if test $REPLACE_MKTIME = 1; then 515 if test $WANT_MKTIME_INTERNAL = 1; then
329 AC_LIBOBJ([mktime]) 516 AC_LIBOBJ([mktime])
330 gl_PREREQ_MKTIME 517 gl_PREREQ_MKTIME
331 fi 518 fi
@@ -334,55 +521,122 @@ AC_DEFUN([gl_INIT],
334 AC_LIBOBJ([mountlist]) 521 AC_LIBOBJ([mountlist])
335 gl_PREREQ_MOUNTLIST_EXTRA 522 gl_PREREQ_MOUNTLIST_EXTRA
336 fi 523 fi
337 gl_MSVC_INVAL 524 AC_REQUIRE([gl_MSVC_INVAL])
338 if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then 525 if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
339 AC_LIBOBJ([msvc-inval]) 526 AC_LIBOBJ([msvc-inval])
340 fi 527 fi
341 gl_MSVC_NOTHROW 528 AC_REQUIRE([gl_MSVC_NOTHROW])
342 if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then 529 if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
343 AC_LIBOBJ([msvc-nothrow]) 530 AC_LIBOBJ([msvc-nothrow])
344 fi 531 fi
532 gl_MODULE_INDICATOR([msvc-nothrow])
345 gl_MULTIARCH 533 gl_MULTIARCH
346 gl_HEADER_NETDB 534 gl_NETDB_H
535 gl_NETDB_H_REQUIRE_DEFAULTS
347 gl_HEADER_NETINET_IN 536 gl_HEADER_NETINET_IN
348 AC_PROG_MKDIR_P 537 AC_PROG_MKDIR_P
349 gl_FUNC_NL_LANGINFO 538 gl_FUNC_NL_LANGINFO
350 if test $HAVE_NL_LANGINFO = 0 || test $REPLACE_NL_LANGINFO = 1; then 539 if test $HAVE_NL_LANGINFO = 0 || test $REPLACE_NL_LANGINFO = 1; then
351 AC_LIBOBJ([nl_langinfo]) 540 AC_LIBOBJ([nl_langinfo])
352 fi 541 fi
542 if test $REPLACE_NL_LANGINFO = 1 && test $NL_LANGINFO_MTSAFE = 0; then
543 AC_LIBOBJ([nl_langinfo-lock])
544 gl_PREREQ_NL_LANGINFO_LOCK
545 fi
353 gl_LANGINFO_MODULE_INDICATOR([nl_langinfo]) 546 gl_LANGINFO_MODULE_INDICATOR([nl_langinfo])
354 gl_FUNC_READ 547 gl_FUNC_OPEN
355 if test $REPLACE_READ = 1; then 548 if test $REPLACE_OPEN = 1; then
356 AC_LIBOBJ([read]) 549 AC_LIBOBJ([open])
357 gl_PREREQ_READ 550 gl_PREREQ_OPEN
551 fi
552 gl_FCNTL_MODULE_INDICATOR([open])
553 gl_PATHMAX
554 gl_FUNC_REALLOC_GNU
555 if test $REPLACE_REALLOC = 1; then
556 AC_LIBOBJ([realloc])
557 fi
558 gl_FUNC_REALLOC_POSIX
559 if test $REPLACE_REALLOC = 1; then
560 AC_LIBOBJ([realloc])
561 fi
562 gl_STDLIB_MODULE_INDICATOR([realloc-posix])
563 gl_FUNC_REALLOCARRAY
564 if test $HAVE_REALLOCARRAY = 0 || test $REPLACE_REALLOCARRAY = 1; then
565 AC_LIBOBJ([reallocarray])
566 gl_PREREQ_REALLOCARRAY
358 fi 567 fi
359 gl_UNISTD_MODULE_INDICATOR([read]) 568 gl_MODULE_INDICATOR([reallocarray])
569 gl_STDLIB_MODULE_INDICATOR([reallocarray])
360 gl_REGEX 570 gl_REGEX
361 if test $ac_use_included_regex = yes; then 571 if test $ac_use_included_regex = yes; then
362 AC_LIBOBJ([regex]) 572 AC_LIBOBJ([regex])
363 gl_PREREQ_REGEX 573 gl_PREREQ_REGEX
364 fi 574 fi
365 gl_PREREQ_SAFE_READ
366 gl_SERVENT 575 gl_SERVENT
367 gl_FUNC_SETENV 576 gl_FUNC_SETENV
368 if test $HAVE_SETENV = 0 || test $REPLACE_SETENV = 1; then 577 if test $HAVE_SETENV = 0 || test $REPLACE_SETENV = 1; then
369 AC_LIBOBJ([setenv]) 578 AC_LIBOBJ([setenv])
370 fi 579 fi
371 gl_STDLIB_MODULE_INDICATOR([setenv]) 580 gl_STDLIB_MODULE_INDICATOR([setenv])
581 gl_FUNC_SETLOCALE_NULL
582 if test $SETLOCALE_NULL_ALL_MTSAFE = 0 || test $SETLOCALE_NULL_ONE_MTSAFE = 0; then
583 AC_LIBOBJ([setlocale-lock])
584 gl_PREREQ_SETLOCALE_LOCK
585 fi
586 gl_LOCALE_MODULE_INDICATOR([setlocale_null])
372 gl_SIZE_MAX 587 gl_SIZE_MAX
373 gl_FUNC_SNPRINTF 588 gl_FUNC_SNPRINTF
374 gl_STDIO_MODULE_INDICATOR([snprintf]) 589 gl_STDIO_MODULE_INDICATOR([snprintf])
375 gl_MODULE_INDICATOR([snprintf]) 590 gl_MODULE_INDICATOR([snprintf])
376 gl_SOCKETLIB 591 AC_REQUIRE([gl_SOCKETLIB])
377 gl_SOCKETS 592 AC_REQUIRE([gl_SOCKETS])
378 gl_TYPE_SOCKLEN_T 593 gl_TYPE_SOCKLEN_T
379 gt_TYPE_SSIZE_T 594 gt_TYPE_SSIZE_T
595 gl_FUNC_STAT
596 if test $REPLACE_STAT = 1; then
597 AC_LIBOBJ([stat])
598 case "$host_os" in
599 mingw*)
600 AC_LIBOBJ([stat-w32])
601 ;;
602 esac
603 gl_PREREQ_STAT
604 fi
605 gl_SYS_STAT_MODULE_INDICATOR([stat])
606 gl_STAT_TIME
607 gl_STAT_BIRTHTIME
380 gl_STDALIGN_H 608 gl_STDALIGN_H
381 AM_STDBOOL_H 609 AM_STDBOOL_H
382 gl_STDDEF_H 610 gl_STDDEF_H
611 gl_STDDEF_H_REQUIRE_DEFAULTS
383 gl_STDINT_H 612 gl_STDINT_H
384 gl_STDIO_H 613 gl_STDIO_H
614 gl_STDIO_H_REQUIRE_DEFAULTS
615 dnl No need to create extra modules for these functions. Everyone who uses
616 dnl <stdio.h> likely needs them.
617 gl_STDIO_MODULE_INDICATOR([fscanf])
618 gl_MODULE_INDICATOR([fscanf])
619 gl_STDIO_MODULE_INDICATOR([scanf])
620 gl_MODULE_INDICATOR([scanf])
621 gl_STDIO_MODULE_INDICATOR([fgetc])
622 gl_STDIO_MODULE_INDICATOR([getc])
623 gl_STDIO_MODULE_INDICATOR([getchar])
624 gl_STDIO_MODULE_INDICATOR([fgets])
625 gl_STDIO_MODULE_INDICATOR([fread])
626 dnl No need to create extra modules for these functions. Everyone who uses
627 dnl <stdio.h> likely needs them.
628 gl_STDIO_MODULE_INDICATOR([fprintf])
629 gl_STDIO_MODULE_INDICATOR([printf])
630 gl_STDIO_MODULE_INDICATOR([vfprintf])
631 gl_STDIO_MODULE_INDICATOR([vprintf])
632 gl_STDIO_MODULE_INDICATOR([fputc])
633 gl_STDIO_MODULE_INDICATOR([putc])
634 gl_STDIO_MODULE_INDICATOR([putchar])
635 gl_STDIO_MODULE_INDICATOR([fputs])
636 gl_STDIO_MODULE_INDICATOR([puts])
637 gl_STDIO_MODULE_INDICATOR([fwrite])
385 gl_STDLIB_H 638 gl_STDLIB_H
639 gl_STDLIB_H_REQUIRE_DEFAULTS
386 gl_STRCASE 640 gl_STRCASE
387 if test $HAVE_STRCASECMP = 0; then 641 if test $HAVE_STRCASECMP = 0; then
388 AC_LIBOBJ([strcasecmp]) 642 AC_LIBOBJ([strcasecmp])
@@ -415,19 +669,10 @@ AC_DEFUN([gl_INIT],
415 AC_LIBOBJ([strerror-override]) 669 AC_LIBOBJ([strerror-override])
416 gl_PREREQ_SYS_H_WINSOCK2 670 gl_PREREQ_SYS_H_WINSOCK2
417 fi 671 fi
418 gl_HEADER_STRING_H 672 gl_STRING_H
419 gl_HEADER_STRINGS_H 673 gl_STRING_H_REQUIRE_DEFAULTS
420 gl_FUNC_STRNDUP 674 gl_STRINGS_H
421 if test $HAVE_STRNDUP = 0 || test $REPLACE_STRNDUP = 1; then 675 gl_STRINGS_H_REQUIRE_DEFAULTS
422 AC_LIBOBJ([strndup])
423 fi
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 676 gl_FUNC_STRSEP
432 if test $HAVE_STRSEP = 0; then 677 if test $HAVE_STRSEP = 0; then
433 AC_LIBOBJ([strsep]) 678 AC_LIBOBJ([strsep])
@@ -439,14 +684,21 @@ AC_DEFUN([gl_INIT],
439 AC_LIBOBJ([strstr]) 684 AC_LIBOBJ([strstr])
440 fi 685 fi
441 gl_STRING_MODULE_INDICATOR([strstr]) 686 gl_STRING_MODULE_INDICATOR([strstr])
442 gl_HEADER_SYS_SOCKET 687 gl_SYS_SOCKET_H
688 gl_SYS_SOCKET_H_REQUIRE_DEFAULTS
689 AC_PROG_MKDIR_P
690 gl_SYS_STAT_H
691 gl_SYS_STAT_H_REQUIRE_DEFAULTS
443 AC_PROG_MKDIR_P 692 AC_PROG_MKDIR_P
444 gl_SYS_TYPES_H 693 gl_SYS_TYPES_H
694 gl_SYS_TYPES_H_REQUIRE_DEFAULTS
445 AC_PROG_MKDIR_P 695 AC_PROG_MKDIR_P
446 gl_HEADER_SYS_UIO 696 gl_SYS_UIO_H
697 gl_SYS_UIO_H_REQUIRE_DEFAULTS
447 AC_PROG_MKDIR_P 698 AC_PROG_MKDIR_P
448 gl_THREADLIB 699 AC_REQUIRE([gl_THREADLIB])
449 gl_HEADER_TIME_H 700 gl_TIME_H
701 gl_TIME_H_REQUIRE_DEFAULTS
450 gl_TIME_R 702 gl_TIME_R
451 if test $HAVE_LOCALTIME_R = 0 || test $REPLACE_LOCALTIME_R = 1; then 703 if test $HAVE_LOCALTIME_R = 0 || test $REPLACE_LOCALTIME_R = 1; then
452 AC_LIBOBJ([time_r]) 704 AC_LIBOBJ([time_r])
@@ -460,12 +712,15 @@ AC_DEFUN([gl_INIT],
460 fi 712 fi
461 gl_TIME_MODULE_INDICATOR([timegm]) 713 gl_TIME_MODULE_INDICATOR([timegm])
462 gl_UNISTD_H 714 gl_UNISTD_H
715 gl_UNISTD_H_REQUIRE_DEFAULTS
716 gl_FUNC_GLIBC_UNLOCKED_IO
463 gl_FUNC_UNSETENV 717 gl_FUNC_UNSETENV
464 if test $HAVE_UNSETENV = 0 || test $REPLACE_UNSETENV = 1; then 718 if test $HAVE_UNSETENV = 0 || test $REPLACE_UNSETENV = 1; then
465 AC_LIBOBJ([unsetenv]) 719 AC_LIBOBJ([unsetenv])
466 gl_PREREQ_UNSETENV 720 gl_PREREQ_UNSETENV
467 fi 721 fi
468 gl_STDLIB_MODULE_INDICATOR([unsetenv]) 722 gl_STDLIB_MODULE_INDICATOR([unsetenv])
723 AC_REQUIRE([AC_C_RESTRICT])
469 gl_FUNC_VASNPRINTF 724 gl_FUNC_VASNPRINTF
470 gl_FUNC_VASPRINTF 725 gl_FUNC_VASPRINTF
471 gl_STDIO_MODULE_INDICATOR([vasprintf]) 726 gl_STDIO_MODULE_INDICATOR([vasprintf])
@@ -475,6 +730,7 @@ AC_DEFUN([gl_INIT],
475 gl_FUNC_VSNPRINTF 730 gl_FUNC_VSNPRINTF
476 gl_STDIO_MODULE_INDICATOR([vsnprintf]) 731 gl_STDIO_MODULE_INDICATOR([vsnprintf])
477 gl_WCHAR_H 732 gl_WCHAR_H
733 gl_WCHAR_H_REQUIRE_DEFAULTS
478 gl_FUNC_WCRTOMB 734 gl_FUNC_WCRTOMB
479 if test $HAVE_WCRTOMB = 0 || test $REPLACE_WCRTOMB = 1; then 735 if test $HAVE_WCRTOMB = 0 || test $REPLACE_WCRTOMB = 1; then
480 AC_LIBOBJ([wcrtomb]) 736 AC_LIBOBJ([wcrtomb])
@@ -482,9 +738,35 @@ AC_DEFUN([gl_INIT],
482 fi 738 fi
483 gl_WCHAR_MODULE_INDICATOR([wcrtomb]) 739 gl_WCHAR_MODULE_INDICATOR([wcrtomb])
484 gl_WCTYPE_H 740 gl_WCTYPE_H
741 gl_WCTYPE_H_REQUIRE_DEFAULTS
742 AC_REQUIRE([AC_CANONICAL_HOST])
743 case "$host_os" in
744 mingw*)
745 AC_LIBOBJ([windows-mutex])
746 ;;
747 esac
748 AC_REQUIRE([AC_CANONICAL_HOST])
749 case "$host_os" in
750 mingw*)
751 AC_LIBOBJ([windows-once])
752 ;;
753 esac
754 AC_REQUIRE([AC_CANONICAL_HOST])
755 case "$host_os" in
756 mingw*)
757 AC_LIBOBJ([windows-recmutex])
758 ;;
759 esac
760 AC_REQUIRE([AC_CANONICAL_HOST])
761 case "$host_os" in
762 mingw*)
763 AC_LIBOBJ([windows-rwlock])
764 ;;
765 esac
485 gl_XALLOC 766 gl_XALLOC
767 gl_MODULE_INDICATOR([xalloc])
768 gl_MODULE_INDICATOR([xalloc-die])
486 gl_XSIZE 769 gl_XSIZE
487 gl_XSTRNDUP
488 # End of code from modules 770 # End of code from modules
489 m4_ifval(gl_LIBSOURCES_LIST, [ 771 m4_ifval(gl_LIBSOURCES_LIST, [
490 m4_syscmd([test ! -d ]m4_defn([gl_LIBSOURCES_DIR])[ || 772 m4_syscmd([test ! -d ]m4_defn([gl_LIBSOURCES_DIR])[ ||
@@ -497,6 +779,8 @@ AC_DEFUN([gl_INIT],
497 m4_if(m4_sysval, [0], [], 779 m4_if(m4_sysval, [0], [],
498 [AC_FATAL([expected source file, required through AC_LIBSOURCES, not found])]) 780 [AC_FATAL([expected source file, required through AC_LIBSOURCES, not found])])
499 ]) 781 ])
782 m4_popdef([GL_MODULE_INDICATOR_PREFIX])
783 m4_popdef([GL_MACRO_PREFIX])
500 m4_popdef([gl_LIBSOURCES_DIR]) 784 m4_popdef([gl_LIBSOURCES_DIR])
501 m4_popdef([gl_LIBSOURCES_LIST]) 785 m4_popdef([gl_LIBSOURCES_LIST])
502 m4_popdef([AC_LIBSOURCES]) 786 m4_popdef([AC_LIBSOURCES])
@@ -523,6 +807,8 @@ AC_DEFUN([gl_INIT],
523 m4_pushdef([AC_LIBSOURCES], m4_defn([gltests_LIBSOURCES])) 807 m4_pushdef([AC_LIBSOURCES], m4_defn([gltests_LIBSOURCES]))
524 m4_pushdef([gltests_LIBSOURCES_LIST], []) 808 m4_pushdef([gltests_LIBSOURCES_LIST], [])
525 m4_pushdef([gltests_LIBSOURCES_DIR], []) 809 m4_pushdef([gltests_LIBSOURCES_DIR], [])
810 m4_pushdef([GL_MACRO_PREFIX], [gltests])
811 m4_pushdef([GL_MODULE_INDICATOR_PREFIX], [GL])
526 gl_COMMON 812 gl_COMMON
527 gl_source_base='tests' 813 gl_source_base='tests'
528changequote(,)dnl 814changequote(,)dnl
@@ -543,6 +829,8 @@ changequote([, ])dnl
543 m4_if(m4_sysval, [0], [], 829 m4_if(m4_sysval, [0], [],
544 [AC_FATAL([expected source file, required through AC_LIBSOURCES, not found])]) 830 [AC_FATAL([expected source file, required through AC_LIBSOURCES, not found])])
545 ]) 831 ])
832 m4_popdef([GL_MODULE_INDICATOR_PREFIX])
833 m4_popdef([GL_MACRO_PREFIX])
546 m4_popdef([gltests_LIBSOURCES_DIR]) 834 m4_popdef([gltests_LIBSOURCES_DIR])
547 m4_popdef([gltests_LIBSOURCES_LIST]) 835 m4_popdef([gltests_LIBSOURCES_LIST])
548 m4_popdef([AC_LIBSOURCES]) 836 m4_popdef([AC_LIBSOURCES])
@@ -626,75 +914,128 @@ AC_DEFUN([gltests_LIBSOURCES], [
626# gnulib-tool and may be removed by future gnulib-tool invocations. 914# gnulib-tool and may be removed by future gnulib-tool invocations.
627AC_DEFUN([gl_FILE_LIST], [ 915AC_DEFUN([gl_FILE_LIST], [
628 build-aux/config.rpath 916 build-aux/config.rpath
629 build-aux/snippet/_Noreturn.h 917 lib/_Noreturn.h
630 build-aux/snippet/arg-nonnull.h 918 lib/af_alg.c
631 build-aux/snippet/c++defs.h 919 lib/af_alg.h
632 build-aux/snippet/warn-on-use.h
633 lib/alloca.in.h 920 lib/alloca.in.h
921 lib/arg-nonnull.h
634 lib/arpa_inet.in.h 922 lib/arpa_inet.in.h
635 lib/asnprintf.c 923 lib/asnprintf.c
636 lib/asprintf.c 924 lib/asprintf.c
925 lib/attribute.h
637 lib/base64.c 926 lib/base64.c
638 lib/base64.h 927 lib/base64.h
639 lib/basename-lgpl.c 928 lib/basename-lgpl.c
929 lib/basename-lgpl.h
640 lib/basename.c 930 lib/basename.c
641 lib/btowc.c 931 lib/btowc.c
642 lib/config.charset 932 lib/byteswap.in.h
933 lib/c++defs.h
934 lib/calloc.c
935 lib/cdefs.h
936 lib/cloexec.c
937 lib/cloexec.h
938 lib/close.c
643 lib/dirname-lgpl.c 939 lib/dirname-lgpl.c
644 lib/dirname.c 940 lib/dirname.c
645 lib/dirname.h 941 lib/dirname.h
646 lib/dosname.h 942 lib/dup2.c
943 lib/dynarray.h
647 lib/errno.in.h 944 lib/errno.in.h
648 lib/error.c 945 lib/error.c
649 lib/error.h 946 lib/error.h
650 lib/exitfail.c 947 lib/exitfail.c
651 lib/exitfail.h 948 lib/exitfail.h
949 lib/fcntl.c
950 lib/fcntl.in.h
652 lib/fd-hook.c 951 lib/fd-hook.c
653 lib/fd-hook.h 952 lib/fd-hook.h
953 lib/fflush.c
954 lib/filename.h
654 lib/float+.h 955 lib/float+.h
655 lib/float.c 956 lib/float.c
656 lib/float.in.h 957 lib/float.in.h
657 lib/floor.c 958 lib/floor.c
658 lib/floorf.c 959 lib/floorf.c
960 lib/fopen.c
961 lib/fpurge.c
962 lib/freading.c
963 lib/freading.h
964 lib/free.c
965 lib/fseek.c
966 lib/fseeko.c
967 lib/fstat.c
659 lib/fsusage.c 968 lib/fsusage.c
660 lib/fsusage.h 969 lib/fsusage.h
661 lib/full-read.c 970 lib/ftell.c
662 lib/full-read.h 971 lib/ftello.c
663 lib/full-write.c
664 lib/gai_strerror.c 972 lib/gai_strerror.c
665 lib/getaddrinfo.c 973 lib/getaddrinfo.c
974 lib/getdelim.c
975 lib/getdtablesize.c
666 lib/gethostname.c 976 lib/gethostname.c
977 lib/getline.c
667 lib/getloadavg.c 978 lib/getloadavg.c
979 lib/getopt-cdefs.in.h
980 lib/getopt-core.h
981 lib/getopt-ext.h
982 lib/getopt-pfx-core.h
983 lib/getopt-pfx-ext.h
668 lib/getopt.c 984 lib/getopt.c
669 lib/getopt.in.h 985 lib/getopt.in.h
670 lib/getopt1.c 986 lib/getopt1.c
671 lib/getopt_int.h 987 lib/getopt_int.h
988 lib/getprogname.c
989 lib/getprogname.h
672 lib/gettext.h 990 lib/gettext.h
991 lib/gl_openssl.h
673 lib/glthread/lock.c 992 lib/glthread/lock.c
674 lib/glthread/lock.h 993 lib/glthread/lock.h
675 lib/glthread/threadlib.c 994 lib/glthread/threadlib.c
995 lib/hard-locale.c
996 lib/hard-locale.h
997 lib/ialloc.c
998 lib/ialloc.h
676 lib/idpriv-droptemp.c 999 lib/idpriv-droptemp.c
677 lib/idpriv.h 1000 lib/idpriv.h
1001 lib/idx.h
678 lib/inet_ntop.c 1002 lib/inet_ntop.c
679 lib/intprops.h 1003 lib/intprops.h
1004 lib/inttypes.in.h
680 lib/itold.c 1005 lib/itold.c
681 lib/langinfo.in.h 1006 lib/langinfo.in.h
1007 lib/lc-charset-dispatch.c
1008 lib/lc-charset-dispatch.h
1009 lib/libc-config.h
1010 lib/limits.in.h
682 lib/localcharset.c 1011 lib/localcharset.c
683 lib/localcharset.h 1012 lib/localcharset.h
684 lib/locale.in.h 1013 lib/locale.in.h
685 lib/localeconv.c 1014 lib/localeconv.c
1015 lib/lseek.c
686 lib/malloc.c 1016 lib/malloc.c
1017 lib/malloc/dynarray-skeleton.c
1018 lib/malloc/dynarray.h
1019 lib/malloc/dynarray_at_failure.c
1020 lib/malloc/dynarray_emplace_enlarge.c
1021 lib/malloc/dynarray_finalize.c
1022 lib/malloc/dynarray_resize.c
1023 lib/malloc/dynarray_resize_clear.c
687 lib/malloca.c 1024 lib/malloca.c
688 lib/malloca.h 1025 lib/malloca.h
689 lib/malloca.valgrind
690 lib/math.c 1026 lib/math.c
691 lib/math.in.h 1027 lib/math.in.h
1028 lib/mbrtowc-impl-utf8.h
1029 lib/mbrtowc-impl.h
692 lib/mbrtowc.c 1030 lib/mbrtowc.c
693 lib/mbsinit.c 1031 lib/mbsinit.c
694 lib/mbtowc-impl.h 1032 lib/mbtowc-impl.h
1033 lib/mbtowc-lock.c
1034 lib/mbtowc-lock.h
695 lib/mbtowc.c 1035 lib/mbtowc.c
696 lib/memchr.c 1036 lib/memchr.c
697 lib/memchr.valgrind 1037 lib/memchr.valgrind
1038 lib/minmax.h
698 lib/mktime-internal.h 1039 lib/mktime-internal.h
699 lib/mktime.c 1040 lib/mktime.c
700 lib/mountlist.c 1041 lib/mountlist.c
@@ -705,33 +1046,43 @@ AC_DEFUN([gl_FILE_LIST], [
705 lib/msvc-nothrow.h 1046 lib/msvc-nothrow.h
706 lib/netdb.in.h 1047 lib/netdb.in.h
707 lib/netinet_in.in.h 1048 lib/netinet_in.in.h
1049 lib/nl_langinfo-lock.c
708 lib/nl_langinfo.c 1050 lib/nl_langinfo.c
1051 lib/open.c
1052 lib/pathmax.h
709 lib/printf-args.c 1053 lib/printf-args.c
710 lib/printf-args.h 1054 lib/printf-args.h
711 lib/printf-parse.c 1055 lib/printf-parse.c
712 lib/printf-parse.h 1056 lib/printf-parse.h
713 lib/read.c 1057 lib/realloc.c
714 lib/ref-add.sin 1058 lib/reallocarray.c
715 lib/ref-del.sin
716 lib/regcomp.c 1059 lib/regcomp.c
717 lib/regex.c 1060 lib/regex.c
718 lib/regex.h 1061 lib/regex.h
719 lib/regex_internal.c 1062 lib/regex_internal.c
720 lib/regex_internal.h 1063 lib/regex_internal.h
721 lib/regexec.c 1064 lib/regexec.c
722 lib/safe-read.c
723 lib/safe-read.h
724 lib/setenv.c 1065 lib/setenv.c
1066 lib/setlocale-lock.c
1067 lib/setlocale_null.c
1068 lib/setlocale_null.h
1069 lib/sha1-stream.c
725 lib/sha1.c 1070 lib/sha1.c
726 lib/sha1.h 1071 lib/sha1.h
727 lib/size_max.h 1072 lib/size_max.h
728 lib/snprintf.c 1073 lib/snprintf.c
729 lib/sockets.c 1074 lib/sockets.c
730 lib/sockets.h 1075 lib/sockets.h
1076 lib/stat-time.c
1077 lib/stat-time.h
1078 lib/stat-w32.c
1079 lib/stat-w32.h
1080 lib/stat.c
731 lib/stdalign.in.h 1081 lib/stdalign.in.h
732 lib/stdbool.in.h 1082 lib/stdbool.in.h
733 lib/stddef.in.h 1083 lib/stddef.in.h
734 lib/stdint.in.h 1084 lib/stdint.in.h
1085 lib/stdio-impl.h
735 lib/stdio.in.h 1086 lib/stdio.in.h
736 lib/stdlib.in.h 1087 lib/stdlib.in.h
737 lib/str-two-way.h 1088 lib/str-two-way.h
@@ -745,12 +1096,12 @@ AC_DEFUN([gl_FILE_LIST], [
745 lib/strings.in.h 1096 lib/strings.in.h
746 lib/stripslash.c 1097 lib/stripslash.c
747 lib/strncasecmp.c 1098 lib/strncasecmp.c
748 lib/strndup.c
749 lib/strnlen.c
750 lib/strsep.c 1099 lib/strsep.c
751 lib/strstr.c 1100 lib/strstr.c
1101 lib/sys-limits.h
752 lib/sys_socket.c 1102 lib/sys_socket.c
753 lib/sys_socket.in.h 1103 lib/sys_socket.in.h
1104 lib/sys_stat.in.h
754 lib/sys_types.in.h 1105 lib/sys_types.in.h
755 lib/sys_uio.in.h 1106 lib/sys_uio.in.h
756 lib/time.in.h 1107 lib/time.in.h
@@ -758,6 +1109,7 @@ AC_DEFUN([gl_FILE_LIST], [
758 lib/timegm.c 1109 lib/timegm.c
759 lib/unistd.c 1110 lib/unistd.c
760 lib/unistd.in.h 1111 lib/unistd.in.h
1112 lib/unlocked-io.h
761 lib/unsetenv.c 1113 lib/unsetenv.c
762 lib/vasnprintf.c 1114 lib/vasnprintf.c
763 lib/vasnprintf.h 1115 lib/vasnprintf.h
@@ -765,27 +1117,41 @@ AC_DEFUN([gl_FILE_LIST], [
765 lib/verify.h 1117 lib/verify.h
766 lib/vsnprintf.c 1118 lib/vsnprintf.c
767 lib/w32sock.h 1119 lib/w32sock.h
1120 lib/warn-on-use.h
768 lib/wchar.in.h 1121 lib/wchar.in.h
769 lib/wcrtomb.c 1122 lib/wcrtomb.c
770 lib/wctype-h.c 1123 lib/wctype-h.c
771 lib/wctype.in.h 1124 lib/wctype.in.h
1125 lib/windows-initguard.h
1126 lib/windows-mutex.c
1127 lib/windows-mutex.h
1128 lib/windows-once.c
1129 lib/windows-once.h
1130 lib/windows-recmutex.c
1131 lib/windows-recmutex.h
1132 lib/windows-rwlock.c
1133 lib/windows-rwlock.h
772 lib/xalloc-die.c 1134 lib/xalloc-die.c
773 lib/xalloc-oversized.h 1135 lib/xalloc-oversized.h
774 lib/xalloc.h 1136 lib/xalloc.h
775 lib/xmalloc.c 1137 lib/xmalloc.c
776 lib/xsize.c 1138 lib/xsize.c
777 lib/xsize.h 1139 lib/xsize.h
778 lib/xstrndup.c
779 lib/xstrndup.h
780 m4/00gnulib.m4 1140 m4/00gnulib.m4
1141 m4/__inline.m4
1142 m4/absolute-header.m4
1143 m4/af_alg.m4
781 m4/alloca.m4 1144 m4/alloca.m4
782 m4/arpa_inet_h.m4 1145 m4/arpa_inet_h.m4
783 m4/base64.m4 1146 m4/base64.m4
784 m4/btowc.m4 1147 m4/btowc.m4
1148 m4/builtin-expect.m4
1149 m4/byteswap.m4
1150 m4/calloc.m4
1151 m4/close.m4
785 m4/codeset.m4 1152 m4/codeset.m4
786 m4/configmake.m4
787 m4/dirname.m4
788 m4/double-slash-root.m4 1153 m4/double-slash-root.m4
1154 m4/dup2.m4
789 m4/eealloc.m4 1155 m4/eealloc.m4
790 m4/environ.m4 1156 m4/environ.m4
791 m4/errno_h.m4 1157 m4/errno_h.m4
@@ -794,37 +1160,50 @@ AC_DEFUN([gl_FILE_LIST], [
794 m4/extensions.m4 1160 m4/extensions.m4
795 m4/extern-inline.m4 1161 m4/extern-inline.m4
796 m4/fcntl-o.m4 1162 m4/fcntl-o.m4
1163 m4/fcntl.m4
1164 m4/fcntl_h.m4
1165 m4/fflush.m4
797 m4/float_h.m4 1166 m4/float_h.m4
798 m4/floorf.m4 1167 m4/floorf.m4
1168 m4/fopen.m4
1169 m4/fpurge.m4
1170 m4/freading.m4
1171 m4/free.m4
1172 m4/fseek.m4
1173 m4/fseeko.m4
1174 m4/fstat.m4
799 m4/fstypename.m4 1175 m4/fstypename.m4
800 m4/fsusage.m4 1176 m4/fsusage.m4
1177 m4/ftell.m4
1178 m4/ftello.m4
801 m4/getaddrinfo.m4 1179 m4/getaddrinfo.m4
1180 m4/getdelim.m4
1181 m4/getdtablesize.m4
802 m4/gethostname.m4 1182 m4/gethostname.m4
1183 m4/getline.m4
803 m4/getloadavg.m4 1184 m4/getloadavg.m4
804 m4/getopt.m4 1185 m4/getopt.m4
1186 m4/getprogname.m4
805 m4/gettext.m4 1187 m4/gettext.m4
806 m4/glibc2.m4 1188 m4/gl-openssl.m4
807 m4/glibc21.m4
808 m4/gnulib-common.m4 1189 m4/gnulib-common.m4
1190 m4/host-cpu-c-abi.m4
809 m4/hostent.m4 1191 m4/hostent.m4
810 m4/iconv.m4 1192 m4/iconv.m4
811 m4/idpriv.m4 1193 m4/idpriv.m4
812 m4/include_next.m4 1194 m4/include_next.m4
813 m4/inet_ntop.m4 1195 m4/inet_ntop.m4
814 m4/intdiv0.m4 1196 m4/intl-thread-locale.m4
815 m4/intl.m4
816 m4/intldir.m4
817 m4/intlmacosx.m4 1197 m4/intlmacosx.m4
818 m4/intmax.m4
819 m4/intmax_t.m4 1198 m4/intmax_t.m4
820 m4/inttypes-pri.m4 1199 m4/inttypes.m4
821 m4/inttypes_h.m4 1200 m4/inttypes_h.m4
822 m4/langinfo_h.m4 1201 m4/langinfo_h.m4
823 m4/largefile.m4 1202 m4/largefile.m4
824 m4/lcmessage.m4
825 m4/lib-ld.m4 1203 m4/lib-ld.m4
826 m4/lib-link.m4 1204 m4/lib-link.m4
827 m4/lib-prefix.m4 1205 m4/lib-prefix.m4
1206 m4/limits-h.m4
828 m4/localcharset.m4 1207 m4/localcharset.m4
829 m4/locale-fr.m4 1208 m4/locale-fr.m4
830 m4/locale-ja.m4 1209 m4/locale-ja.m4
@@ -832,8 +1211,7 @@ AC_DEFUN([gl_FILE_LIST], [
832 m4/locale_h.m4 1211 m4/locale_h.m4
833 m4/localeconv.m4 1212 m4/localeconv.m4
834 m4/lock.m4 1213 m4/lock.m4
835 m4/longlong.m4 1214 m4/lseek.m4
836 m4/ls-mntd-fs.m4
837 m4/malloc.m4 1215 m4/malloc.m4
838 m4/malloca.m4 1216 m4/malloca.m4
839 m4/math_h.m4 1217 m4/math_h.m4
@@ -842,8 +1220,10 @@ AC_DEFUN([gl_FILE_LIST], [
842 m4/mbstate_t.m4 1220 m4/mbstate_t.m4
843 m4/mbtowc.m4 1221 m4/mbtowc.m4
844 m4/memchr.m4 1222 m4/memchr.m4
1223 m4/minmax.m4
845 m4/mktime.m4 1224 m4/mktime.m4
846 m4/mmap-anon.m4 1225 m4/mmap-anon.m4
1226 m4/mode_t.m4
847 m4/mountlist.m4 1227 m4/mountlist.m4
848 m4/msvc-inval.m4 1228 m4/msvc-inval.m4
849 m4/msvc-nothrow.m4 1229 m4/msvc-nothrow.m4
@@ -854,16 +1234,21 @@ AC_DEFUN([gl_FILE_LIST], [
854 m4/nls.m4 1234 m4/nls.m4
855 m4/nocrash.m4 1235 m4/nocrash.m4
856 m4/off_t.m4 1236 m4/off_t.m4
857 m4/onceonly.m4 1237 m4/open-cloexec.m4
1238 m4/open-slash.m4
1239 m4/open.m4
1240 m4/pathmax.m4
1241 m4/pid_t.m4
858 m4/po.m4 1242 m4/po.m4
859 m4/printf-posix.m4
860 m4/printf.m4 1243 m4/printf.m4
861 m4/progtest.m4 1244 m4/progtest.m4
862 m4/read.m4 1245 m4/pthread_rwlock_rdlock.m4
1246 m4/realloc.m4
1247 m4/reallocarray.m4
863 m4/regex.m4 1248 m4/regex.m4
864 m4/safe-read.m4
865 m4/servent.m4 1249 m4/servent.m4
866 m4/setenv.m4 1250 m4/setenv.m4
1251 m4/setlocale_null.m4
867 m4/sha1.m4 1252 m4/sha1.m4
868 m4/size_max.m4 1253 m4/size_max.m4
869 m4/snprintf.m4 1254 m4/snprintf.m4
@@ -872,6 +1257,9 @@ AC_DEFUN([gl_FILE_LIST], [
872 m4/socklen.m4 1257 m4/socklen.m4
873 m4/sockpfaf.m4 1258 m4/sockpfaf.m4
874 m4/ssize_t.m4 1259 m4/ssize_t.m4
1260 m4/stat-time.m4
1261 m4/stat.m4
1262 m4/std-gnu11.m4
875 m4/stdalign.m4 1263 m4/stdalign.m4
876 m4/stdbool.m4 1264 m4/stdbool.m4
877 m4/stddef_h.m4 1265 m4/stddef_h.m4
@@ -884,19 +1272,19 @@ AC_DEFUN([gl_FILE_LIST], [
884 m4/strerror.m4 1272 m4/strerror.m4
885 m4/string_h.m4 1273 m4/string_h.m4
886 m4/strings_h.m4 1274 m4/strings_h.m4
887 m4/strndup.m4
888 m4/strnlen.m4
889 m4/strsep.m4 1275 m4/strsep.m4
890 m4/strstr.m4 1276 m4/strstr.m4
891 m4/sys_socket_h.m4 1277 m4/sys_socket_h.m4
1278 m4/sys_stat_h.m4
892 m4/sys_types_h.m4 1279 m4/sys_types_h.m4
893 m4/sys_uio_h.m4 1280 m4/sys_uio_h.m4
894 m4/threadlib.m4 1281 m4/threadlib.m4
895 m4/time_h.m4 1282 m4/time_h.m4
896 m4/time_r.m4 1283 m4/time_r.m4
897 m4/timegm.m4 1284 m4/timegm.m4
898 m4/uintmax_t.m4 1285 m4/ungetc.m4
899 m4/unistd_h.m4 1286 m4/unistd_h.m4
1287 m4/unlocked-io.m4
900 m4/vasnprintf.m4 1288 m4/vasnprintf.m4
901 m4/vasprintf.m4 1289 m4/vasprintf.m4
902 m4/visibility.m4 1290 m4/visibility.m4
@@ -909,5 +1297,6 @@ AC_DEFUN([gl_FILE_LIST], [
909 m4/wint_t.m4 1297 m4/wint_t.m4
910 m4/xalloc.m4 1298 m4/xalloc.m4
911 m4/xsize.m4 1299 m4/xsize.m4
912 m4/xstrndup.m4 1300 m4/year2038.m4
1301 m4/zzgnulib.m4
913]) 1302])
diff --git a/gl/m4/gnulib-tool.m4 b/gl/m4/gnulib-tool.m4
index f3dea1a..3d56d83 100644
--- a/gl/m4/gnulib-tool.m4
+++ b/gl/m4/gnulib-tool.m4
@@ -1,5 +1,5 @@
1# gnulib-tool.m4 serial 2 1# gnulib-tool.m4 serial 2
2dnl Copyright (C) 2004-2005, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2004-2005, 2009-2021 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/host-cpu-c-abi.m4 b/gl/m4/host-cpu-c-abi.m4
new file mode 100644
index 0000000..64e28b1
--- /dev/null
+++ b/gl/m4/host-cpu-c-abi.m4
@@ -0,0 +1,675 @@
1# host-cpu-c-abi.m4 serial 14
2dnl Copyright (C) 2002-2021 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 and Sam Steingold.
8
9dnl Sets the HOST_CPU variable to the canonical name of the CPU.
10dnl Sets the HOST_CPU_C_ABI variable to the canonical name of the CPU with its
11dnl C language ABI (application binary interface).
12dnl Also defines __${HOST_CPU}__ and __${HOST_CPU_C_ABI}__ as C macros in
13dnl config.h.
14dnl
15dnl This canonical name can be used to select a particular assembly language
16dnl source file that will interoperate with C code on the given host.
17dnl
18dnl For example:
19dnl * 'i386' and 'sparc' are different canonical names, because code for i386
20dnl will not run on SPARC CPUs and vice versa. They have different
21dnl instruction sets.
22dnl * 'sparc' and 'sparc64' are different canonical names, because code for
23dnl 'sparc' and code for 'sparc64' cannot be linked together: 'sparc' code
24dnl contains 32-bit instructions, whereas 'sparc64' code contains 64-bit
25dnl instructions. A process on a SPARC CPU can be in 32-bit mode or in 64-bit
26dnl mode, but not both.
27dnl * 'mips' and 'mipsn32' are different canonical names, because they use
28dnl different argument passing and return conventions for C functions, and
29dnl although the instruction set of 'mips' is a large subset of the
30dnl instruction set of 'mipsn32'.
31dnl * 'mipsn32' and 'mips64' are different canonical names, because they use
32dnl different sizes for the C types like 'int' and 'void *', and although
33dnl the instruction sets of 'mipsn32' and 'mips64' are the same.
34dnl * The same canonical name is used for different endiannesses. You can
35dnl determine the endianness through preprocessor symbols:
36dnl - 'arm': test __ARMEL__.
37dnl - 'mips', 'mipsn32', 'mips64': test _MIPSEB vs. _MIPSEL.
38dnl - 'powerpc64': test _BIG_ENDIAN vs. _LITTLE_ENDIAN.
39dnl * The same name 'i386' is used for CPUs of type i386, i486, i586
40dnl (Pentium), AMD K7, Pentium II, Pentium IV, etc., because
41dnl - Instructions that do not exist on all of these CPUs (cmpxchg,
42dnl MMX, SSE, SSE2, 3DNow! etc.) are not frequently used. If your
43dnl assembly language source files use such instructions, you will
44dnl need to make the distinction.
45dnl - Speed of execution of the common instruction set is reasonable across
46dnl the entire family of CPUs. If you have assembly language source files
47dnl that are optimized for particular CPU types (like GNU gmp has), you
48dnl will need to make the distinction.
49dnl See <https://en.wikipedia.org/wiki/X86_instruction_listings>.
50AC_DEFUN([gl_HOST_CPU_C_ABI],
51[
52 AC_REQUIRE([AC_CANONICAL_HOST])
53 AC_REQUIRE([gl_C_ASM])
54 AC_CACHE_CHECK([host CPU and C ABI], [gl_cv_host_cpu_c_abi],
55 [case "$host_cpu" in
56
57changequote(,)dnl
58 i[34567]86 )
59changequote([,])dnl
60 gl_cv_host_cpu_c_abi=i386
61 ;;
62
63 x86_64 )
64 # On x86_64 systems, the C compiler may be generating code in one of
65 # these ABIs:
66 # - 64-bit instruction set, 64-bit pointers, 64-bit 'long': x86_64.
67 # - 64-bit instruction set, 64-bit pointers, 32-bit 'long': x86_64
68 # with native Windows (mingw, MSVC).
69 # - 64-bit instruction set, 32-bit pointers, 32-bit 'long': x86_64-x32.
70 # - 32-bit instruction set, 32-bit pointers, 32-bit 'long': i386.
71 AC_COMPILE_IFELSE(
72 [AC_LANG_SOURCE(
73 [[#if (defined __x86_64__ || defined __amd64__ \
74 || defined _M_X64 || defined _M_AMD64)
75 int ok;
76 #else
77 error fail
78 #endif
79 ]])],
80 [AC_COMPILE_IFELSE(
81 [AC_LANG_SOURCE(
82 [[#if defined __ILP32__ || defined _ILP32
83 int ok;
84 #else
85 error fail
86 #endif
87 ]])],
88 [gl_cv_host_cpu_c_abi=x86_64-x32],
89 [gl_cv_host_cpu_c_abi=x86_64])],
90 [gl_cv_host_cpu_c_abi=i386])
91 ;;
92
93changequote(,)dnl
94 alphaev[4-8] | alphaev56 | alphapca5[67] | alphaev6[78] )
95changequote([,])dnl
96 gl_cv_host_cpu_c_abi=alpha
97 ;;
98
99 arm* | aarch64 )
100 # Assume arm with EABI.
101 # On arm64 systems, the C compiler may be generating code in one of
102 # these ABIs:
103 # - aarch64 instruction set, 64-bit pointers, 64-bit 'long': arm64.
104 # - aarch64 instruction set, 32-bit pointers, 32-bit 'long': arm64-ilp32.
105 # - 32-bit instruction set, 32-bit pointers, 32-bit 'long': arm or armhf.
106 AC_COMPILE_IFELSE(
107 [AC_LANG_SOURCE(
108 [[#ifdef __aarch64__
109 int ok;
110 #else
111 error fail
112 #endif
113 ]])],
114 [AC_COMPILE_IFELSE(
115 [AC_LANG_SOURCE(
116 [[#if defined __ILP32__ || defined _ILP32
117 int ok;
118 #else
119 error fail
120 #endif
121 ]])],
122 [gl_cv_host_cpu_c_abi=arm64-ilp32],
123 [gl_cv_host_cpu_c_abi=arm64])],
124 [# Don't distinguish little-endian and big-endian arm, since they
125 # don't require different machine code for simple operations and
126 # since the user can distinguish them through the preprocessor
127 # defines __ARMEL__ vs. __ARMEB__.
128 # But distinguish arm which passes floating-point arguments and
129 # return values in integer registers (r0, r1, ...) - this is
130 # gcc -mfloat-abi=soft or gcc -mfloat-abi=softfp - from arm which
131 # passes them in float registers (s0, s1, ...) and double registers
132 # (d0, d1, ...) - this is gcc -mfloat-abi=hard. GCC 4.6 or newer
133 # sets the preprocessor defines __ARM_PCS (for the first case) and
134 # __ARM_PCS_VFP (for the second case), but older GCC does not.
135 echo 'double ddd; void func (double dd) { ddd = dd; }' > conftest.c
136 # Look for a reference to the register d0 in the .s file.
137 AC_TRY_COMMAND(${CC-cc} $CFLAGS $CPPFLAGS $gl_c_asm_opt conftest.c) >/dev/null 2>&1
138 if LC_ALL=C grep 'd0,' conftest.$gl_asmext >/dev/null; then
139 gl_cv_host_cpu_c_abi=armhf
140 else
141 gl_cv_host_cpu_c_abi=arm
142 fi
143 rm -f conftest*
144 ])
145 ;;
146
147 hppa1.0 | hppa1.1 | hppa2.0* | hppa64 )
148 # On hppa, the C compiler may be generating 32-bit code or 64-bit
149 # code. In the latter case, it defines _LP64 and __LP64__.
150 AC_COMPILE_IFELSE(
151 [AC_LANG_SOURCE(
152 [[#ifdef __LP64__
153 int ok;
154 #else
155 error fail
156 #endif
157 ]])],
158 [gl_cv_host_cpu_c_abi=hppa64],
159 [gl_cv_host_cpu_c_abi=hppa])
160 ;;
161
162 ia64* )
163 # On ia64 on HP-UX, the C compiler may be generating 64-bit code or
164 # 32-bit code. In the latter case, it defines _ILP32.
165 AC_COMPILE_IFELSE(
166 [AC_LANG_SOURCE(
167 [[#ifdef _ILP32
168 int ok;
169 #else
170 error fail
171 #endif
172 ]])],
173 [gl_cv_host_cpu_c_abi=ia64-ilp32],
174 [gl_cv_host_cpu_c_abi=ia64])
175 ;;
176
177 mips* )
178 # We should also check for (_MIPS_SZPTR == 64), but gcc keeps this
179 # at 32.
180 AC_COMPILE_IFELSE(
181 [AC_LANG_SOURCE(
182 [[#if defined _MIPS_SZLONG && (_MIPS_SZLONG == 64)
183 int ok;
184 #else
185 error fail
186 #endif
187 ]])],
188 [gl_cv_host_cpu_c_abi=mips64],
189 [# In the n32 ABI, _ABIN32 is defined, _ABIO32 is not defined (but
190 # may later get defined by <sgidefs.h>), and _MIPS_SIM == _ABIN32.
191 # In the 32 ABI, _ABIO32 is defined, _ABIN32 is not defined (but
192 # may later get defined by <sgidefs.h>), and _MIPS_SIM == _ABIO32.
193 AC_COMPILE_IFELSE(
194 [AC_LANG_SOURCE(
195 [[#if (_MIPS_SIM == _ABIN32)
196 int ok;
197 #else
198 error fail
199 #endif
200 ]])],
201 [gl_cv_host_cpu_c_abi=mipsn32],
202 [gl_cv_host_cpu_c_abi=mips])])
203 ;;
204
205 powerpc* )
206 # Different ABIs are in use on AIX vs. Mac OS X vs. Linux,*BSD.
207 # No need to distinguish them here; the caller may distinguish
208 # them based on the OS.
209 # On powerpc64 systems, the C compiler may still be generating
210 # 32-bit code. And on powerpc-ibm-aix systems, the C compiler may
211 # be generating 64-bit code.
212 AC_COMPILE_IFELSE(
213 [AC_LANG_SOURCE(
214 [[#if defined __powerpc64__ || defined __LP64__
215 int ok;
216 #else
217 error fail
218 #endif
219 ]])],
220 [# On powerpc64, there are two ABIs on Linux: The AIX compatible
221 # one and the ELFv2 one. The latter defines _CALL_ELF=2.
222 AC_COMPILE_IFELSE(
223 [AC_LANG_SOURCE(
224 [[#if defined _CALL_ELF && _CALL_ELF == 2
225 int ok;
226 #else
227 error fail
228 #endif
229 ]])],
230 [gl_cv_host_cpu_c_abi=powerpc64-elfv2],
231 [gl_cv_host_cpu_c_abi=powerpc64])
232 ],
233 [gl_cv_host_cpu_c_abi=powerpc])
234 ;;
235
236 rs6000 )
237 gl_cv_host_cpu_c_abi=powerpc
238 ;;
239
240 riscv32 | riscv64 )
241 # There are 2 architectures (with variants): rv32* and rv64*.
242 AC_COMPILE_IFELSE(
243 [AC_LANG_SOURCE(
244 [[#if __riscv_xlen == 64
245 int ok;
246 #else
247 error fail
248 #endif
249 ]])],
250 [cpu=riscv64],
251 [cpu=riscv32])
252 # There are 6 ABIs: ilp32, ilp32f, ilp32d, lp64, lp64f, lp64d.
253 # Size of 'long' and 'void *':
254 AC_COMPILE_IFELSE(
255 [AC_LANG_SOURCE(
256 [[#if defined __LP64__
257 int ok;
258 #else
259 error fail
260 #endif
261 ]])],
262 [main_abi=lp64],
263 [main_abi=ilp32])
264 # Float ABIs:
265 # __riscv_float_abi_double:
266 # 'float' and 'double' are passed in floating-point registers.
267 # __riscv_float_abi_single:
268 # 'float' are passed in floating-point registers.
269 # __riscv_float_abi_soft:
270 # No values are passed in floating-point registers.
271 AC_COMPILE_IFELSE(
272 [AC_LANG_SOURCE(
273 [[#if defined __riscv_float_abi_double
274 int ok;
275 #else
276 error fail
277 #endif
278 ]])],
279 [float_abi=d],
280 [AC_COMPILE_IFELSE(
281 [AC_LANG_SOURCE(
282 [[#if defined __riscv_float_abi_single
283 int ok;
284 #else
285 error fail
286 #endif
287 ]])],
288 [float_abi=f],
289 [float_abi=''])
290 ])
291 gl_cv_host_cpu_c_abi="${cpu}-${main_abi}${float_abi}"
292 ;;
293
294 s390* )
295 # On s390x, the C compiler may be generating 64-bit (= s390x) code
296 # or 31-bit (= s390) code.
297 AC_COMPILE_IFELSE(
298 [AC_LANG_SOURCE(
299 [[#if defined __LP64__ || defined __s390x__
300 int ok;
301 #else
302 error fail
303 #endif
304 ]])],
305 [gl_cv_host_cpu_c_abi=s390x],
306 [gl_cv_host_cpu_c_abi=s390])
307 ;;
308
309 sparc | sparc64 )
310 # UltraSPARCs running Linux have `uname -m` = "sparc64", but the
311 # C compiler still generates 32-bit code.
312 AC_COMPILE_IFELSE(
313 [AC_LANG_SOURCE(
314 [[#if defined __sparcv9 || defined __arch64__
315 int ok;
316 #else
317 error fail
318 #endif
319 ]])],
320 [gl_cv_host_cpu_c_abi=sparc64],
321 [gl_cv_host_cpu_c_abi=sparc])
322 ;;
323
324 *)
325 gl_cv_host_cpu_c_abi="$host_cpu"
326 ;;
327 esac
328 ])
329
330 dnl In most cases, $HOST_CPU and $HOST_CPU_C_ABI are the same.
331 HOST_CPU=`echo "$gl_cv_host_cpu_c_abi" | sed -e 's/-.*//'`
332 HOST_CPU_C_ABI="$gl_cv_host_cpu_c_abi"
333 AC_SUBST([HOST_CPU])
334 AC_SUBST([HOST_CPU_C_ABI])
335
336 # This was
337 # AC_DEFINE_UNQUOTED([__${HOST_CPU}__])
338 # AC_DEFINE_UNQUOTED([__${HOST_CPU_C_ABI}__])
339 # earlier, but KAI C++ 3.2d doesn't like this.
340 sed -e 's/-/_/g' >> confdefs.h <<EOF
341#ifndef __${HOST_CPU}__
342#define __${HOST_CPU}__ 1
343#endif
344#ifndef __${HOST_CPU_C_ABI}__
345#define __${HOST_CPU_C_ABI}__ 1
346#endif
347EOF
348 AH_TOP([/* CPU and C ABI indicator */
349#ifndef __i386__
350#undef __i386__
351#endif
352#ifndef __x86_64_x32__
353#undef __x86_64_x32__
354#endif
355#ifndef __x86_64__
356#undef __x86_64__
357#endif
358#ifndef __alpha__
359#undef __alpha__
360#endif
361#ifndef __arm__
362#undef __arm__
363#endif
364#ifndef __armhf__
365#undef __armhf__
366#endif
367#ifndef __arm64_ilp32__
368#undef __arm64_ilp32__
369#endif
370#ifndef __arm64__
371#undef __arm64__
372#endif
373#ifndef __hppa__
374#undef __hppa__
375#endif
376#ifndef __hppa64__
377#undef __hppa64__
378#endif
379#ifndef __ia64_ilp32__
380#undef __ia64_ilp32__
381#endif
382#ifndef __ia64__
383#undef __ia64__
384#endif
385#ifndef __m68k__
386#undef __m68k__
387#endif
388#ifndef __mips__
389#undef __mips__
390#endif
391#ifndef __mipsn32__
392#undef __mipsn32__
393#endif
394#ifndef __mips64__
395#undef __mips64__
396#endif
397#ifndef __powerpc__
398#undef __powerpc__
399#endif
400#ifndef __powerpc64__
401#undef __powerpc64__
402#endif
403#ifndef __powerpc64_elfv2__
404#undef __powerpc64_elfv2__
405#endif
406#ifndef __riscv32__
407#undef __riscv32__
408#endif
409#ifndef __riscv64__
410#undef __riscv64__
411#endif
412#ifndef __riscv32_ilp32__
413#undef __riscv32_ilp32__
414#endif
415#ifndef __riscv32_ilp32f__
416#undef __riscv32_ilp32f__
417#endif
418#ifndef __riscv32_ilp32d__
419#undef __riscv32_ilp32d__
420#endif
421#ifndef __riscv64_ilp32__
422#undef __riscv64_ilp32__
423#endif
424#ifndef __riscv64_ilp32f__
425#undef __riscv64_ilp32f__
426#endif
427#ifndef __riscv64_ilp32d__
428#undef __riscv64_ilp32d__
429#endif
430#ifndef __riscv64_lp64__
431#undef __riscv64_lp64__
432#endif
433#ifndef __riscv64_lp64f__
434#undef __riscv64_lp64f__
435#endif
436#ifndef __riscv64_lp64d__
437#undef __riscv64_lp64d__
438#endif
439#ifndef __s390__
440#undef __s390__
441#endif
442#ifndef __s390x__
443#undef __s390x__
444#endif
445#ifndef __sh__
446#undef __sh__
447#endif
448#ifndef __sparc__
449#undef __sparc__
450#endif
451#ifndef __sparc64__
452#undef __sparc64__
453#endif
454])
455
456])
457
458
459dnl Sets the HOST_CPU_C_ABI_32BIT variable to 'yes' if the C language ABI
460dnl (application binary interface) is a 32-bit one, to 'no' if it is a 64-bit
461dnl one, or to 'unknown' if unknown.
462dnl This is a simplified variant of gl_HOST_CPU_C_ABI.
463AC_DEFUN([gl_HOST_CPU_C_ABI_32BIT],
464[
465 AC_REQUIRE([AC_CANONICAL_HOST])
466 AC_CACHE_CHECK([32-bit host C ABI], [gl_cv_host_cpu_c_abi_32bit],
467 [if test -n "$gl_cv_host_cpu_c_abi"; then
468 case "$gl_cv_host_cpu_c_abi" in
469 i386 | x86_64-x32 | arm | armhf | arm64-ilp32 | hppa | ia64-ilp32 | mips | mipsn32 | powerpc | riscv*-ilp32* | s390 | sparc)
470 gl_cv_host_cpu_c_abi_32bit=yes ;;
471 x86_64 | alpha | arm64 | hppa64 | ia64 | mips64 | powerpc64 | powerpc64-elfv2 | riscv*-lp64* | s390x | sparc64 )
472 gl_cv_host_cpu_c_abi_32bit=no ;;
473 *)
474 gl_cv_host_cpu_c_abi_32bit=unknown ;;
475 esac
476 else
477 case "$host_cpu" in
478
479 # CPUs that only support a 32-bit ABI.
480 arc \
481 | bfin \
482 | cris* \
483 | csky \
484 | epiphany \
485 | ft32 \
486 | h8300 \
487 | m68k \
488 | microblaze | microblazeel \
489 | nds32 | nds32le | nds32be \
490 | nios2 | nios2eb | nios2el \
491 | or1k* \
492 | or32 \
493 | sh | sh[1234] | sh[1234]e[lb] \
494 | tic6x \
495 | xtensa* )
496 gl_cv_host_cpu_c_abi_32bit=yes
497 ;;
498
499 # CPUs that only support a 64-bit ABI.
500changequote(,)dnl
501 alpha | alphaev[4-8] | alphaev56 | alphapca5[67] | alphaev6[78] \
502 | mmix )
503changequote([,])dnl
504 gl_cv_host_cpu_c_abi_32bit=no
505 ;;
506
507changequote(,)dnl
508 i[34567]86 )
509changequote([,])dnl
510 gl_cv_host_cpu_c_abi_32bit=yes
511 ;;
512
513 x86_64 )
514 # On x86_64 systems, the C compiler may be generating code in one of
515 # these ABIs:
516 # - 64-bit instruction set, 64-bit pointers, 64-bit 'long': x86_64.
517 # - 64-bit instruction set, 64-bit pointers, 32-bit 'long': x86_64
518 # with native Windows (mingw, MSVC).
519 # - 64-bit instruction set, 32-bit pointers, 32-bit 'long': x86_64-x32.
520 # - 32-bit instruction set, 32-bit pointers, 32-bit 'long': i386.
521 AC_COMPILE_IFELSE(
522 [AC_LANG_SOURCE(
523 [[#if (defined __x86_64__ || defined __amd64__ \
524 || defined _M_X64 || defined _M_AMD64) \
525 && !(defined __ILP32__ || defined _ILP32)
526 int ok;
527 #else
528 error fail
529 #endif
530 ]])],
531 [gl_cv_host_cpu_c_abi_32bit=no],
532 [gl_cv_host_cpu_c_abi_32bit=yes])
533 ;;
534
535 arm* | aarch64 )
536 # Assume arm with EABI.
537 # On arm64 systems, the C compiler may be generating code in one of
538 # these ABIs:
539 # - aarch64 instruction set, 64-bit pointers, 64-bit 'long': arm64.
540 # - aarch64 instruction set, 32-bit pointers, 32-bit 'long': arm64-ilp32.
541 # - 32-bit instruction set, 32-bit pointers, 32-bit 'long': arm or armhf.
542 AC_COMPILE_IFELSE(
543 [AC_LANG_SOURCE(
544 [[#if defined __aarch64__ && !(defined __ILP32__ || defined _ILP32)
545 int ok;
546 #else
547 error fail
548 #endif
549 ]])],
550 [gl_cv_host_cpu_c_abi_32bit=no],
551 [gl_cv_host_cpu_c_abi_32bit=yes])
552 ;;
553
554 hppa1.0 | hppa1.1 | hppa2.0* | hppa64 )
555 # On hppa, the C compiler may be generating 32-bit code or 64-bit
556 # code. In the latter case, it defines _LP64 and __LP64__.
557 AC_COMPILE_IFELSE(
558 [AC_LANG_SOURCE(
559 [[#ifdef __LP64__
560 int ok;
561 #else
562 error fail
563 #endif
564 ]])],
565 [gl_cv_host_cpu_c_abi_32bit=no],
566 [gl_cv_host_cpu_c_abi_32bit=yes])
567 ;;
568
569 ia64* )
570 # On ia64 on HP-UX, the C compiler may be generating 64-bit code or
571 # 32-bit code. In the latter case, it defines _ILP32.
572 AC_COMPILE_IFELSE(
573 [AC_LANG_SOURCE(
574 [[#ifdef _ILP32
575 int ok;
576 #else
577 error fail
578 #endif
579 ]])],
580 [gl_cv_host_cpu_c_abi_32bit=yes],
581 [gl_cv_host_cpu_c_abi_32bit=no])
582 ;;
583
584 mips* )
585 # We should also check for (_MIPS_SZPTR == 64), but gcc keeps this
586 # at 32.
587 AC_COMPILE_IFELSE(
588 [AC_LANG_SOURCE(
589 [[#if defined _MIPS_SZLONG && (_MIPS_SZLONG == 64)
590 int ok;
591 #else
592 error fail
593 #endif
594 ]])],
595 [gl_cv_host_cpu_c_abi_32bit=no],
596 [gl_cv_host_cpu_c_abi_32bit=yes])
597 ;;
598
599 powerpc* )
600 # Different ABIs are in use on AIX vs. Mac OS X vs. Linux,*BSD.
601 # No need to distinguish them here; the caller may distinguish
602 # them based on the OS.
603 # On powerpc64 systems, the C compiler may still be generating
604 # 32-bit code. And on powerpc-ibm-aix systems, the C compiler may
605 # be generating 64-bit code.
606 AC_COMPILE_IFELSE(
607 [AC_LANG_SOURCE(
608 [[#if defined __powerpc64__ || defined __LP64__
609 int ok;
610 #else
611 error fail
612 #endif
613 ]])],
614 [gl_cv_host_cpu_c_abi_32bit=no],
615 [gl_cv_host_cpu_c_abi_32bit=yes])
616 ;;
617
618 rs6000 )
619 gl_cv_host_cpu_c_abi_32bit=yes
620 ;;
621
622 riscv32 | riscv64 )
623 # There are 6 ABIs: ilp32, ilp32f, ilp32d, lp64, lp64f, lp64d.
624 # Size of 'long' and 'void *':
625 AC_COMPILE_IFELSE(
626 [AC_LANG_SOURCE(
627 [[#if defined __LP64__
628 int ok;
629 #else
630 error fail
631 #endif
632 ]])],
633 [gl_cv_host_cpu_c_abi_32bit=no],
634 [gl_cv_host_cpu_c_abi_32bit=yes])
635 ;;
636
637 s390* )
638 # On s390x, the C compiler may be generating 64-bit (= s390x) code
639 # or 31-bit (= s390) code.
640 AC_COMPILE_IFELSE(
641 [AC_LANG_SOURCE(
642 [[#if defined __LP64__ || defined __s390x__
643 int ok;
644 #else
645 error fail
646 #endif
647 ]])],
648 [gl_cv_host_cpu_c_abi_32bit=no],
649 [gl_cv_host_cpu_c_abi_32bit=yes])
650 ;;
651
652 sparc | sparc64 )
653 # UltraSPARCs running Linux have `uname -m` = "sparc64", but the
654 # C compiler still generates 32-bit code.
655 AC_COMPILE_IFELSE(
656 [AC_LANG_SOURCE(
657 [[#if defined __sparcv9 || defined __arch64__
658 int ok;
659 #else
660 error fail
661 #endif
662 ]])],
663 [gl_cv_host_cpu_c_abi_32bit=no],
664 [gl_cv_host_cpu_c_abi_32bit=yes])
665 ;;
666
667 *)
668 gl_cv_host_cpu_c_abi_32bit=unknown
669 ;;
670 esac
671 fi
672 ])
673
674 HOST_CPU_C_ABI_32BIT="$gl_cv_host_cpu_c_abi_32bit"
675])
diff --git a/gl/m4/hostent.m4 b/gl/m4/hostent.m4
index 72be876..f1390a3 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-2021 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
index a503646..d0e61de 100644
--- a/gl/m4/iconv.m4
+++ b/gl/m4/iconv.m4
@@ -1,11 +1,18 @@
1# iconv.m4 serial 18 (gettext-0.18.2) 1# iconv.m4 serial 24
2dnl Copyright (C) 2000-2002, 2007-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2000-2002, 2007-2014, 2016-2021 Free Software Foundation,
3dnl Inc.
3dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
6 7
7dnl From Bruno Haible. 8dnl From Bruno Haible.
8 9
10AC_PREREQ([2.64])
11
12dnl Note: AM_ICONV is documented in the GNU gettext manual
13dnl <https://www.gnu.org/software/gettext/manual/html_node/AM_005fICONV.html>.
14dnl Don't make changes that are incompatible with that documentation!
15
9AC_DEFUN([AM_ICONV_LINKFLAGS_BODY], 16AC_DEFUN([AM_ICONV_LINKFLAGS_BODY],
10[ 17[
11 dnl Prerequisites of AC_LIB_LINKFLAGS_BODY. 18 dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
@@ -72,27 +79,34 @@ AC_DEFUN([AM_ICONV_LINK],
72 if test $am_cv_lib_iconv = yes; then 79 if test $am_cv_lib_iconv = yes; then
73 LIBS="$LIBS $LIBICONV" 80 LIBS="$LIBS $LIBICONV"
74 fi 81 fi
75 AC_RUN_IFELSE( 82 am_cv_func_iconv_works=no
76 [AC_LANG_SOURCE([[ 83 for ac_iconv_const in '' 'const'; do
84 AC_RUN_IFELSE(
85 [AC_LANG_PROGRAM(
86 [[
77#include <iconv.h> 87#include <iconv.h>
78#include <string.h> 88#include <string.h>
79int main () 89
80{ 90#ifndef ICONV_CONST
81 int result = 0; 91# define ICONV_CONST $ac_iconv_const
82 /* Test against AIX 5.1 bug: Failures are not distinguishable from successful 92#endif
83 returns. */ 93 ]],
94 [[int result = 0;
95 /* Test against AIX 5.1...7.2 bug: Failures are not distinguishable from
96 successful returns. This is even documented in
97 <https://www.ibm.com/support/knowledgecenter/ssw_aix_72/i_bostechref/iconv.html> */
84 { 98 {
85 iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8"); 99 iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8");
86 if (cd_utf8_to_88591 != (iconv_t)(-1)) 100 if (cd_utf8_to_88591 != (iconv_t)(-1))
87 { 101 {
88 static const char input[] = "\342\202\254"; /* EURO SIGN */ 102 static ICONV_CONST char input[] = "\342\202\254"; /* EURO SIGN */
89 char buf[10]; 103 char buf[10];
90 const char *inptr = input; 104 ICONV_CONST char *inptr = input;
91 size_t inbytesleft = strlen (input); 105 size_t inbytesleft = strlen (input);
92 char *outptr = buf; 106 char *outptr = buf;
93 size_t outbytesleft = sizeof (buf); 107 size_t outbytesleft = sizeof (buf);
94 size_t res = iconv (cd_utf8_to_88591, 108 size_t res = iconv (cd_utf8_to_88591,
95 (char **) &inptr, &inbytesleft, 109 &inptr, &inbytesleft,
96 &outptr, &outbytesleft); 110 &outptr, &outbytesleft);
97 if (res == 0) 111 if (res == 0)
98 result |= 1; 112 result |= 1;
@@ -105,14 +119,14 @@ int main ()
105 iconv_t cd_ascii_to_88591 = iconv_open ("ISO8859-1", "646"); 119 iconv_t cd_ascii_to_88591 = iconv_open ("ISO8859-1", "646");
106 if (cd_ascii_to_88591 != (iconv_t)(-1)) 120 if (cd_ascii_to_88591 != (iconv_t)(-1))
107 { 121 {
108 static const char input[] = "\263"; 122 static ICONV_CONST char input[] = "\263";
109 char buf[10]; 123 char buf[10];
110 const char *inptr = input; 124 ICONV_CONST char *inptr = input;
111 size_t inbytesleft = strlen (input); 125 size_t inbytesleft = strlen (input);
112 char *outptr = buf; 126 char *outptr = buf;
113 size_t outbytesleft = sizeof (buf); 127 size_t outbytesleft = sizeof (buf);
114 size_t res = iconv (cd_ascii_to_88591, 128 size_t res = iconv (cd_ascii_to_88591,
115 (char **) &inptr, &inbytesleft, 129 &inptr, &inbytesleft,
116 &outptr, &outbytesleft); 130 &outptr, &outbytesleft);
117 if (res == 0) 131 if (res == 0)
118 result |= 2; 132 result |= 2;
@@ -124,14 +138,14 @@ int main ()
124 iconv_t cd_88591_to_utf8 = iconv_open ("UTF-8", "ISO-8859-1"); 138 iconv_t cd_88591_to_utf8 = iconv_open ("UTF-8", "ISO-8859-1");
125 if (cd_88591_to_utf8 != (iconv_t)(-1)) 139 if (cd_88591_to_utf8 != (iconv_t)(-1))
126 { 140 {
127 static const char input[] = "\304"; 141 static ICONV_CONST char input[] = "\304";
128 static char buf[2] = { (char)0xDE, (char)0xAD }; 142 static char buf[2] = { (char)0xDE, (char)0xAD };
129 const char *inptr = input; 143 ICONV_CONST char *inptr = input;
130 size_t inbytesleft = 1; 144 size_t inbytesleft = 1;
131 char *outptr = buf; 145 char *outptr = buf;
132 size_t outbytesleft = 1; 146 size_t outbytesleft = 1;
133 size_t res = iconv (cd_88591_to_utf8, 147 size_t res = iconv (cd_88591_to_utf8,
134 (char **) &inptr, &inbytesleft, 148 &inptr, &inbytesleft,
135 &outptr, &outbytesleft); 149 &outptr, &outbytesleft);
136 if (res != (size_t)(-1) || outptr - buf > 1 || buf[1] != (char)0xAD) 150 if (res != (size_t)(-1) || outptr - buf > 1 || buf[1] != (char)0xAD)
137 result |= 4; 151 result |= 4;
@@ -144,14 +158,14 @@ int main ()
144 iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591"); 158 iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591");
145 if (cd_88591_to_utf8 != (iconv_t)(-1)) 159 if (cd_88591_to_utf8 != (iconv_t)(-1))
146 { 160 {
147 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337"; 161 static ICONV_CONST char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
148 char buf[50]; 162 char buf[50];
149 const char *inptr = input; 163 ICONV_CONST char *inptr = input;
150 size_t inbytesleft = strlen (input); 164 size_t inbytesleft = strlen (input);
151 char *outptr = buf; 165 char *outptr = buf;
152 size_t outbytesleft = sizeof (buf); 166 size_t outbytesleft = sizeof (buf);
153 size_t res = iconv (cd_88591_to_utf8, 167 size_t res = iconv (cd_88591_to_utf8,
154 (char **) &inptr, &inbytesleft, 168 &inptr, &inbytesleft,
155 &outptr, &outbytesleft); 169 &outptr, &outbytesleft);
156 if ((int)res > 0) 170 if ((int)res > 0)
157 result |= 8; 171 result |= 8;
@@ -161,27 +175,36 @@ int main ()
161#endif 175#endif
162 /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is 176 /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is
163 provided. */ 177 provided. */
164 if (/* Try standardized names. */ 178 {
165 iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1) 179 /* Try standardized names. */
166 /* Try IRIX, OSF/1 names. */ 180 iconv_t cd1 = iconv_open ("UTF-8", "EUC-JP");
167 && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1) 181 /* Try IRIX, OSF/1 names. */
168 /* Try AIX names. */ 182 iconv_t cd2 = iconv_open ("UTF-8", "eucJP");
169 && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1) 183 /* Try AIX names. */
170 /* Try HP-UX names. */ 184 iconv_t cd3 = iconv_open ("UTF-8", "IBM-eucJP");
171 && iconv_open ("utf8", "eucJP") == (iconv_t)(-1)) 185 /* Try HP-UX names. */
172 result |= 16; 186 iconv_t cd4 = iconv_open ("utf8", "eucJP");
187 if (cd1 == (iconv_t)(-1) && cd2 == (iconv_t)(-1)
188 && cd3 == (iconv_t)(-1) && cd4 == (iconv_t)(-1))
189 result |= 16;
190 if (cd1 != (iconv_t)(-1))
191 iconv_close (cd1);
192 if (cd2 != (iconv_t)(-1))
193 iconv_close (cd2);
194 if (cd3 != (iconv_t)(-1))
195 iconv_close (cd3);
196 if (cd4 != (iconv_t)(-1))
197 iconv_close (cd4);
198 }
173 return result; 199 return result;
174}]])], 200]])],
175 [am_cv_func_iconv_works=yes], 201 [am_cv_func_iconv_works=yes], ,
176 [am_cv_func_iconv_works=no], 202 [case "$host_os" in
177 [ 203 aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
178changequote(,)dnl 204 *) am_cv_func_iconv_works="guessing yes" ;;
179 case "$host_os" in 205 esac])
180 aix* | hpux*) am_cv_func_iconv_works="guessing no" ;; 206 test "$am_cv_func_iconv_works" = no || break
181 *) am_cv_func_iconv_works="guessing yes" ;; 207 done
182 esac
183changequote([,])dnl
184 ])
185 LIBS="$am_save_LIBS" 208 LIBS="$am_save_LIBS"
186 ]) 209 ])
187 case "$am_cv_func_iconv_works" in 210 case "$am_cv_func_iconv_works" in
@@ -209,8 +232,7 @@ changequote([,])dnl
209 AC_SUBST([LTLIBICONV]) 232 AC_SUBST([LTLIBICONV])
210]) 233])
211 234
212dnl Define AM_ICONV using AC_DEFUN_ONCE for Autoconf >= 2.64, in order to 235dnl Define AM_ICONV using AC_DEFUN_ONCE, in order to avoid warnings like
213dnl avoid warnings like
214dnl "warning: AC_REQUIRE: `AM_ICONV' was expanded before it was required". 236dnl "warning: AC_REQUIRE: `AM_ICONV' was expanded before it was required".
215dnl This is tricky because of the way 'aclocal' is implemented: 237dnl This is tricky because of the way 'aclocal' is implemented:
216dnl - It requires defining an auxiliary macro whose name ends in AC_DEFUN. 238dnl - It requires defining an auxiliary macro whose name ends in AC_DEFUN.
@@ -218,51 +240,44 @@ dnl 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. 240dnl - 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" 241dnl Otherwise aclocal would emit many "Use of uninitialized value $1"
220dnl warnings. 242dnl warnings.
221m4_define([gl_iconv_AC_DEFUN], 243AC_DEFUN_ONCE([AM_ICONV],
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[ 244[
232 AM_ICONV_LINK 245 AM_ICONV_LINK
233 if test "$am_cv_func_iconv" = yes; then 246 if test "$am_cv_func_iconv" = yes; then
234 AC_MSG_CHECKING([for iconv declaration]) 247 AC_CACHE_CHECK([whether iconv is compatible with its POSIX signature],
235 AC_CACHE_VAL([am_cv_proto_iconv], [ 248 [gl_cv_iconv_nonconst],
236 AC_COMPILE_IFELSE( 249 [AC_COMPILE_IFELSE(
237 [AC_LANG_PROGRAM( 250 [AC_LANG_PROGRAM(
238 [[ 251 [[
239#include <stdlib.h> 252#include <stdlib.h>
240#include <iconv.h> 253#include <iconv.h>
241extern 254extern
242#ifdef __cplusplus 255#ifdef __cplusplus
243"C" 256"C"
244#endif 257#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); 258size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
247#else 259 ]],
248size_t iconv(); 260 [[]])],
249#endif 261 [gl_cv_iconv_nonconst=yes],
250 ]], 262 [gl_cv_iconv_nonconst=no])
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 ]) 263 ])
264 else
265 dnl When compiling GNU libiconv on a system that does not have iconv yet,
266 dnl pick the POSIX compliant declaration without 'const'.
267 gl_cv_iconv_nonconst=yes
267 fi 268 fi
269 if test $gl_cv_iconv_nonconst = yes; then
270 iconv_arg1=""
271 else
272 iconv_arg1="const"
273 fi
274 AC_DEFINE_UNQUOTED([ICONV_CONST], [$iconv_arg1],
275 [Define as const if the declaration of iconv() needs const.])
276 dnl Also substitute ICONV_CONST in the gnulib generated <iconv.h>.
277 m4_ifdef([gl_ICONV_H_DEFAULTS],
278 [AC_REQUIRE([gl_ICONV_H_DEFAULTS])
279 if test $gl_cv_iconv_nonconst != yes; then
280 ICONV_CONST="const"
281 fi
282 ])
268]) 283])
diff --git a/gl/m4/idpriv.m4 b/gl/m4/idpriv.m4
index 167f523..d96fdd1 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-2021 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..bdd542b 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-2021 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..171f53e 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-2021 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-thread-locale.m4 b/gl/m4/intl-thread-locale.m4
new file mode 100644
index 0000000..890fec0
--- /dev/null
+++ b/gl/m4/intl-thread-locale.m4
@@ -0,0 +1,219 @@
1# intl-thread-locale.m4 serial 9
2dnl Copyright (C) 2015-2021 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 be used in projects which are not available under
8dnl the GNU General Public License or the GNU Lesser 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 Lesser General Public License, and the rest of the GNU
13dnl gettext package is covered by the GNU General Public License.
14dnl They are *not* in the public domain.
15
16dnl Check how to retrieve the name of a per-thread locale (POSIX locale_t).
17dnl Sets gt_nameless_locales.
18AC_DEFUN([gt_INTL_THREAD_LOCALE_NAME],
19[
20 AC_REQUIRE([AC_CANONICAL_HOST])
21
22 dnl Persuade Solaris <locale.h> to define 'locale_t'.
23 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
24
25 dnl Test whether uselocale() exists and works at all.
26 gt_FUNC_USELOCALE
27
28 dnl On OpenBSD >= 6.2, the locale_t type and the uselocale(), newlocale(),
29 dnl duplocale(), freelocale() functions exist but are effectively useless,
30 dnl because the locale_t value depends only on the LC_CTYPE category of the
31 dnl locale and furthermore contains only one bit of information (it
32 dnl distinguishes the "C" locale from the *.UTF-8 locales). See
33 dnl <https://cvsweb.openbsd.org/src/lib/libc/locale/newlocale.c?rev=1.1&content-type=text/x-cvsweb-markup>.
34 dnl In the setlocale() implementation they have thought about the programs
35 dnl that use the API ("Even though only LC_CTYPE has any effect in the
36 dnl OpenBSD base system, store complete information about the global locale,
37 dnl such that third-party software can access it"), but for uselocale()
38 dnl they did not think about the programs.
39 dnl In this situation, even the HAVE_NAMELESS_LOCALES support does not work.
40 dnl So, define HAVE_FAKE_LOCALES and disable all locale_t support.
41 case "$gt_cv_func_uselocale_works" in
42 *yes)
43 AC_CHECK_HEADERS_ONCE([xlocale.h])
44 AC_CACHE_CHECK([for fake locale system (OpenBSD)],
45 [gt_cv_locale_fake],
46 [AC_RUN_IFELSE(
47 [AC_LANG_SOURCE([[
48#include <locale.h>
49#if HAVE_XLOCALE_H
50# include <xlocale.h>
51#endif
52int main ()
53{
54 locale_t loc1, loc2;
55 if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL) return 1;
56 if (setlocale (LC_ALL, "fr_FR.UTF-8") == NULL) return 1;
57 loc1 = newlocale (LC_ALL_MASK, "de_DE.UTF-8", (locale_t)0);
58 loc2 = newlocale (LC_ALL_MASK, "fr_FR.UTF-8", (locale_t)0);
59 return !(loc1 == loc2);
60}]])],
61 [gt_cv_locale_fake=yes],
62 [gt_cv_locale_fake=no],
63 [dnl Guess the locale system is fake only on OpenBSD.
64 case "$host_os" in
65 openbsd*) gt_cv_locale_fake="guessing yes" ;;
66 *) gt_cv_locale_fake="guessing no" ;;
67 esac
68 ])
69 ])
70 ;;
71 *) gt_cv_locale_fake=no ;;
72 esac
73 case "$gt_cv_locale_fake" in
74 *yes)
75 gt_fake_locales=yes
76 AC_DEFINE([HAVE_FAKE_LOCALES], [1],
77 [Define if the locale_t type contains insufficient information, as on OpenBSD.])
78 ;;
79 *)
80 gt_fake_locales=no
81 ;;
82 esac
83
84 case "$gt_cv_func_uselocale_works" in
85 *yes)
86 AC_CACHE_CHECK([for Solaris 11.4 locale system],
87 [gt_cv_locale_solaris114],
88 [case "$host_os" in
89 solaris*)
90 dnl Test whether <locale.h> defines locale_t as a typedef of
91 dnl 'struct _LC_locale_t **' (whereas Illumos defines it as a
92 dnl typedef of 'struct _locale *').
93 dnl Another possible test would be to include <sys/localedef.h>
94 dnl and test whether it defines the _LC_core_data_locale_t type.
95 dnl This type was added in Solaris 11.4.
96 AC_COMPILE_IFELSE(
97 [AC_LANG_PROGRAM([[
98 #include <locale.h>
99 struct _LC_locale_t *x;
100 locale_t y;
101 ]],
102 [[*y = x;]])],
103 [gt_cv_locale_solaris114=yes],
104 [gt_cv_locale_solaris114=no])
105 ;;
106 *) gt_cv_locale_solaris114=no ;;
107 esac
108 ])
109 ;;
110 *) gt_cv_locale_solaris114=no ;;
111 esac
112 if test $gt_cv_locale_solaris114 = yes; then
113 AC_DEFINE([HAVE_SOLARIS114_LOCALES], [1],
114 [Define if the locale_t type is as on Solaris 11.4.])
115 fi
116
117 dnl Solaris 12 will maybe provide getlocalename_l. If it does, it will
118 dnl improve the implementation of gl_locale_name_thread(), by removing
119 dnl the use of undocumented structures.
120 case "$gt_cv_func_uselocale_works" in
121 *yes)
122 AC_CHECK_FUNCS([getlocalename_l])
123 ;;
124 esac
125
126 dnl This code is for platforms where the locale_t type does not provide access
127 dnl to the name of each locale category. This code has the drawback that it
128 dnl requires the gnulib overrides of 'newlocale', 'duplocale', 'freelocale',
129 dnl which is a problem for GNU libunistring. Therefore try hard to avoid
130 dnl enabling this code!
131 gt_nameless_locales=no
132 case "$host_os" in
133 dnl It's needed on AIX 7.2.
134 aix*)
135 gt_nameless_locales=yes
136 AC_DEFINE([HAVE_NAMELESS_LOCALES], [1],
137 [Define if the locale_t type does not contain the name of each locale category.])
138 ;;
139 esac
140
141 dnl We cannot support uselocale() on platforms where the locale_t type is
142 dnl fake. So, set
143 dnl gt_good_uselocale = gt_working_uselocale && !gt_fake_locales.
144 if test $gt_working_uselocale = yes && test $gt_fake_locales = no; then
145 gt_good_uselocale=yes
146 AC_DEFINE([HAVE_GOOD_USELOCALE], [1],
147 [Define if the uselocale exists, may be safely called, and returns sufficient information.])
148 else
149 gt_good_uselocale=no
150 fi
151
152 dnl Set gt_localename_enhances_locale_funcs to indicate whether localename.c
153 dnl overrides newlocale(), duplocale(), freelocale() to keep track of locale
154 dnl names.
155 if test $gt_good_uselocale = yes && test $gt_nameless_locales = yes; then
156 gt_localename_enhances_locale_funcs=yes
157 LOCALENAME_ENHANCE_LOCALE_FUNCS=1
158 AC_DEFINE([LOCALENAME_ENHANCE_LOCALE_FUNCS], [1],
159 [Define if localename.c overrides newlocale(), duplocale(), freelocale().])
160 else
161 gt_localename_enhances_locale_funcs=no
162 fi
163])
164
165dnl Tests whether uselocale() exists and is usable.
166dnl Sets gt_working_uselocale and defines HAVE_WORKING_USELOCALE.
167AC_DEFUN([gt_FUNC_USELOCALE],
168[
169 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
170
171 dnl Persuade glibc and Solaris <locale.h> to define 'locale_t'.
172 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
173
174 AC_CHECK_FUNCS_ONCE([uselocale])
175
176 dnl On AIX 7.2, the uselocale() function is not documented and leads to
177 dnl crashes in subsequent setlocale() invocations.
178 dnl In 2019, some versions of z/OS lack the locale_t type and have a broken
179 dnl uselocale function.
180 if test $ac_cv_func_uselocale = yes; then
181 AC_CHECK_HEADERS_ONCE([xlocale.h])
182 AC_CACHE_CHECK([whether uselocale works],
183 [gt_cv_func_uselocale_works],
184 [AC_RUN_IFELSE(
185 [AC_LANG_SOURCE([[
186#include <locale.h>
187#if HAVE_XLOCALE_H
188# include <xlocale.h>
189#endif
190locale_t loc1;
191int main ()
192{
193 uselocale (NULL);
194 setlocale (LC_ALL, "en_US.UTF-8");
195 return 0;
196}]])],
197 [gt_cv_func_uselocale_works=yes],
198 [gt_cv_func_uselocale_works=no],
199 [# Guess no on AIX and z/OS, yes otherwise.
200 case "$host_os" in
201 aix* | openedition*) gt_cv_func_uselocale_works="guessing no" ;;
202 *) gt_cv_func_uselocale_works="guessing yes" ;;
203 esac
204 ])
205 ])
206 else
207 gt_cv_func_uselocale_works=no
208 fi
209 case "$gt_cv_func_uselocale_works" in
210 *yes)
211 gt_working_uselocale=yes
212 AC_DEFINE([HAVE_WORKING_USELOCALE], [1],
213 [Define if the uselocale function exists and may safely be called.])
214 ;;
215 *)
216 gt_working_uselocale=no
217 ;;
218 esac
219])
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
index ab97d39..4ae0d12 100644
--- a/gl/m4/intlmacosx.m4
+++ b/gl/m4/intlmacosx.m4
@@ -1,23 +1,23 @@
1# intlmacosx.m4 serial 5 (gettext-0.18.2) 1# intlmacosx.m4 serial 8 (gettext-0.20.2)
2dnl Copyright (C) 2004-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2004-2014, 2016, 2019-2021 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.
6dnl 6dnl
7dnl This file can can be used in projects which are not available under 7dnl This file can be used in projects which are not available under
8dnl the GNU General Public License or the GNU Library General Public 8dnl the GNU General Public License or the GNU Lesser General Public
9dnl License but which still want to provide support for the GNU gettext 9dnl License but which still want to provide support for the GNU gettext
10dnl functionality. 10dnl functionality.
11dnl Please note that the actual code of the GNU gettext library is covered 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 12dnl by the GNU Lesser General Public License, and the rest of the GNU
13dnl gettext package package is covered by the GNU General Public License. 13dnl gettext package is covered by the GNU General Public License.
14dnl They are *not* in the public domain. 14dnl They are *not* in the public domain.
15 15
16dnl Checks for special options needed on Mac OS X. 16dnl Checks for special options needed on Mac OS X.
17dnl Defines INTL_MACOSX_LIBS. 17dnl Defines INTL_MACOSX_LIBS.
18AC_DEFUN([gt_INTL_MACOSX], 18AC_DEFUN([gt_INTL_MACOSX],
19[ 19[
20 dnl Check for API introduced in Mac OS X 10.2. 20 dnl Check for API introduced in Mac OS X 10.4.
21 AC_CACHE_CHECK([for CFPreferencesCopyAppValue], 21 AC_CACHE_CHECK([for CFPreferencesCopyAppValue],
22 [gt_cv_func_CFPreferencesCopyAppValue], 22 [gt_cv_func_CFPreferencesCopyAppValue],
23 [gt_save_LIBS="$LIBS" 23 [gt_save_LIBS="$LIBS"
@@ -33,23 +33,32 @@ AC_DEFUN([gt_INTL_MACOSX],
33 AC_DEFINE([HAVE_CFPREFERENCESCOPYAPPVALUE], [1], 33 AC_DEFINE([HAVE_CFPREFERENCESCOPYAPPVALUE], [1],
34 [Define to 1 if you have the Mac OS X function CFPreferencesCopyAppValue in the CoreFoundation framework.]) 34 [Define to 1 if you have the Mac OS X function CFPreferencesCopyAppValue in the CoreFoundation framework.])
35 fi 35 fi
36 dnl Check for API introduced in Mac OS X 10.3. 36 dnl Don't check for the API introduced in Mac OS X 10.5, CFLocaleCopyCurrent,
37 AC_CACHE_CHECK([for CFLocaleCopyCurrent], [gt_cv_func_CFLocaleCopyCurrent], 37 dnl because in macOS 10.13.4 it has the following behaviour:
38 dnl When two or more languages are specified in the
39 dnl "System Preferences > Language & Region > Preferred Languages" panel,
40 dnl it returns en_CC where CC is the territory (even when English is not among
41 dnl the preferred languages!). What we want instead is what
42 dnl CFLocaleCopyCurrent returned in earlier macOS releases and what
43 dnl CFPreferencesCopyAppValue still returns, namely ll_CC where ll is the
44 dnl first among the preferred languages and CC is the territory.
45 AC_CACHE_CHECK([for CFLocaleCopyPreferredLanguages], [gt_cv_func_CFLocaleCopyPreferredLanguages],
38 [gt_save_LIBS="$LIBS" 46 [gt_save_LIBS="$LIBS"
39 LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation" 47 LIBS="$LIBS -Wl,-framework -Wl,CoreFoundation"
40 AC_LINK_IFELSE( 48 AC_LINK_IFELSE(
41 [AC_LANG_PROGRAM( 49 [AC_LANG_PROGRAM(
42 [[#include <CoreFoundation/CFLocale.h>]], 50 [[#include <CoreFoundation/CFLocale.h>]],
43 [[CFLocaleCopyCurrent();]])], 51 [[CFLocaleCopyPreferredLanguages();]])],
44 [gt_cv_func_CFLocaleCopyCurrent=yes], 52 [gt_cv_func_CFLocaleCopyPreferredLanguages=yes],
45 [gt_cv_func_CFLocaleCopyCurrent=no]) 53 [gt_cv_func_CFLocaleCopyPreferredLanguages=no])
46 LIBS="$gt_save_LIBS"]) 54 LIBS="$gt_save_LIBS"])
47 if test $gt_cv_func_CFLocaleCopyCurrent = yes; then 55 if test $gt_cv_func_CFLocaleCopyPreferredLanguages = yes; then
48 AC_DEFINE([HAVE_CFLOCALECOPYCURRENT], [1], 56 AC_DEFINE([HAVE_CFLOCALECOPYPREFERREDLANGUAGES], [1],
49 [Define to 1 if you have the Mac OS X function CFLocaleCopyCurrent in the CoreFoundation framework.]) 57 [Define to 1 if you have the Mac OS X function CFLocaleCopyPreferredLanguages in the CoreFoundation framework.])
50 fi 58 fi
51 INTL_MACOSX_LIBS= 59 INTL_MACOSX_LIBS=
52 if test $gt_cv_func_CFPreferencesCopyAppValue = yes || test $gt_cv_func_CFLocaleCopyCurrent = yes; then 60 if test $gt_cv_func_CFPreferencesCopyAppValue = yes \
61 || test $gt_cv_func_CFLocaleCopyPreferredLanguages = yes; then
53 INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation" 62 INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation"
54 fi 63 fi
55 AC_SUBST([INTL_MACOSX_LIBS]) 64 AC_SUBST([INTL_MACOSX_LIBS])
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..63c4b41 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-2021 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..64b1de5
--- /dev/null
+++ b/gl/m4/inttypes.m4
@@ -0,0 +1,180 @@
1# inttypes.m4 serial 35
2dnl Copyright (C) 2006-2021 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 test -n "$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..672a93e 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-2021 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..87959f7 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-2021 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..fbde5e6 100644
--- a/gl/m4/largefile.m4
+++ b/gl/m4/largefile.m4
@@ -1,28 +1,47 @@
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-2021 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.
13AC_DEFUN([gl_SET_LARGEFILE_SOURCE],
14[
15 AC_REQUIRE([AC_CANONICAL_HOST])
16 AC_FUNC_FSEEKO
17 case "$host_os" in
18 hpux*)
19 AC_DEFINE([_LARGEFILE_SOURCE], [1],
20 [Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2).])
21 ;;
22 esac
23])
24
25# Work around a problem in Autoconf through at least 2.71 on glibc 2.34+
26# with _TIME_BITS. Also, work around a problem in autoconf <= 2.69:
9# AC_SYS_LARGEFILE does not configure for large inodes on Mac OS X 10.5, 27# AC_SYS_LARGEFILE does not configure for large inodes on Mac OS X 10.5,
10# or configures them incorrectly in some cases. 28# or configures them incorrectly in some cases.
11m4_version_prereq([2.70], [] ,[ 29m4_version_prereq([2.70], [], [
12 30
13# _AC_SYS_LARGEFILE_TEST_INCLUDES 31# _AC_SYS_LARGEFILE_TEST_INCLUDES
14# ------------------------------- 32# -------------------------------
15m4_define([_AC_SYS_LARGEFILE_TEST_INCLUDES], 33m4_define([_AC_SYS_LARGEFILE_TEST_INCLUDES],
16[@%:@include <sys/types.h> 34[#include <sys/types.h>
17 /* Check that off_t can represent 2**63 - 1 correctly. 35 /* Check that off_t can represent 2**63 - 1 correctly.
18 We can't simply define LARGE_OFF_T to be 9223372036854775807, 36 We can't simply define LARGE_OFF_T to be 9223372036854775807,
19 since some C++ compilers masquerading as C compilers 37 since some C++ compilers masquerading as C compilers
20 incorrectly reject 9223372036854775807. */ 38 incorrectly reject 9223372036854775807. */
21@%:@define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) 39#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 40 int off_t_is_large[[(LARGE_OFF_T % 2147483629 == 721
23 && LARGE_OFF_T % 2147483647 == 1) 41 && LARGE_OFF_T % 2147483647 == 1)
24 ? 1 : -1]];[]dnl 42 ? 1 : -1]];[]dnl
25]) 43])
44])# m4_version_prereq 2.70
26 45
27 46
28# _AC_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE, 47# _AC_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE,
@@ -37,7 +56,8 @@ m4_define([_AC_SYS_LARGEFILE_MACRO_VALUE],
37 [AC_LANG_PROGRAM([$5], [$6])], 56 [AC_LANG_PROGRAM([$5], [$6])],
38 [$3=no; break]) 57 [$3=no; break])
39 m4_ifval([$6], [AC_LINK_IFELSE], [AC_COMPILE_IFELSE])( 58 m4_ifval([$6], [AC_LINK_IFELSE], [AC_COMPILE_IFELSE])(
40 [AC_LANG_PROGRAM([@%:@define $1 $2 59 [AC_LANG_PROGRAM([#undef $1
60#define $1 $2
41$5], [$6])], 61$5], [$6])],
42 [$3=$2; break]) 62 [$3=$2; break])
43 $3=unknown 63 $3=unknown
@@ -56,13 +76,15 @@ rm -rf conftest*[]dnl
56# By default, many hosts won't let programs access large files; 76# 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. 77# one must use special compiler options to get large-file access to work.
58# For more details about this brain damage please see: 78# For more details about this brain damage please see:
59# http://www.unix-systems.org/version2/whatsnew/lfs20mar.html 79# http://www.unix.org/version2/whatsnew/lfs20mar.html
80# Additionally, on Linux file systems with 64-bit inodes a file that happens
81# to have a 64-bit inode number cannot be accessed by 32-bit applications on
82# Linux x86/x86_64. This can occur with file systems such as XFS and NFS.
60AC_DEFUN([AC_SYS_LARGEFILE], 83AC_DEFUN([AC_SYS_LARGEFILE],
61[AC_ARG_ENABLE(largefile, 84[AC_ARG_ENABLE(largefile,
62 [ --disable-largefile omit support for large files]) 85 [ --disable-largefile omit support for large files])
63if test "$enable_largefile" != no; then 86AS_IF([test "$enable_largefile" != no],
64 87 [AC_CACHE_CHECK([for special C compiler options needed for large files],
65 AC_CACHE_CHECK([for special C compiler options needed for large files],
66 ac_cv_sys_largefile_CC, 88 ac_cv_sys_largefile_CC,
67 [ac_cv_sys_largefile_CC=no 89 [ac_cv_sys_largefile_CC=no
68 if test "$GCC" != yes; then 90 if test "$GCC" != yes; then
@@ -87,18 +109,15 @@ if test "$enable_largefile" != no; then
87 ac_cv_sys_file_offset_bits, 109 ac_cv_sys_file_offset_bits,
88 [Number of bits in a file offset, on hosts where this is settable.], 110 [Number of bits in a file offset, on hosts where this is settable.],
89 [_AC_SYS_LARGEFILE_TEST_INCLUDES]) 111 [_AC_SYS_LARGEFILE_TEST_INCLUDES])
90 if test $ac_cv_sys_file_offset_bits = unknown; then 112 AS_CASE([$ac_cv_sys_file_offset_bits],
91 _AC_SYS_LARGEFILE_MACRO_VALUE(_LARGE_FILES, 1, 113 [unknown],
92 ac_cv_sys_large_files, 114 [_AC_SYS_LARGEFILE_MACRO_VALUE([_LARGE_FILES], [1],
93 [Define for large files, on AIX-style hosts.], 115 [ac_cv_sys_large_files],
94 [_AC_SYS_LARGEFILE_TEST_INCLUDES]) 116 [Define for large files, on AIX-style hosts.],
95 fi 117 [_AC_SYS_LARGEFILE_TEST_INCLUDES])],
96 118 [64],
97 AC_DEFINE([_DARWIN_USE_64_BIT_INODE], [1], 119 [gl_YEAR2038_BODY([])])])
98 [Enable large inode numbers on Mac OS X 10.5.])
99fi
100])# AC_SYS_LARGEFILE 120])# AC_SYS_LARGEFILE
101])# m4_version_prereq 2.70
102 121
103# Enable large files on systems where this is implemented by Gnulib, not by the 122# Enable large files on systems where this is implemented by Gnulib, not by the
104# system headers. 123# system headers.
@@ -126,9 +145,24 @@ AC_DEFUN([gl_LARGEFILE],
126 else 145 else
127 WINDOWS_64_BIT_OFF_T=0 146 WINDOWS_64_BIT_OFF_T=0
128 fi 147 fi
129 dnl But all native Windows platforms (including mingw64) have a 32-bit 148 dnl Some mingw versions define, if _FILE_OFFSET_BITS=64, 'struct stat'
130 dnl st_size member in 'struct stat'. 149 dnl to 'struct _stat32i64' or 'struct _stat64' (depending on
131 WINDOWS_64_BIT_ST_SIZE=1 150 dnl _USE_32BIT_TIME_T), which has a 32-bit st_size member.
151 AC_CACHE_CHECK([for 64-bit st_size], [gl_cv_member_st_size_64],
152 [AC_COMPILE_IFELSE(
153 [AC_LANG_PROGRAM(
154 [[#include <sys/types.h>
155 struct stat buf;
156 int verify_st_size_size[sizeof (buf.st_size) >= 8 ? 1 : -1];
157 ]],
158 [[]])],
159 [gl_cv_member_st_size_64=yes], [gl_cv_member_st_size_64=no])
160 ])
161 if test $gl_cv_member_st_size_64 = no; then
162 WINDOWS_64_BIT_ST_SIZE=1
163 else
164 WINDOWS_64_BIT_ST_SIZE=0
165 fi
132 ;; 166 ;;
133 *) 167 *)
134 dnl Nothing to do on gnulib's side. 168 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
index c145e47..076358d 100644
--- a/gl/m4/lib-ld.m4
+++ b/gl/m4/lib-ld.m4
@@ -1,5 +1,5 @@
1# lib-ld.m4 serial 6 1# lib-ld.m4 serial 10
2dnl Copyright (C) 1996-2003, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 1996-2003, 2009-2021 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.
@@ -47,73 +47,122 @@ if test "${PATH_SEPARATOR+set}" != set; then
47 } 47 }
48fi 48fi
49 49
50ac_prog=ld 50if test -n "$LD"; then
51if test "$GCC" = yes; then 51 AC_MSG_CHECKING([for ld])
52 # Check if gcc -print-prog-name=ld gives a path. 52elif test "$GCC" = yes; then
53 AC_MSG_CHECKING([for ld used by $CC]) 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 54elif test "$with_gnu_ld" = yes; then
82 AC_MSG_CHECKING([for GNU ld]) 55 AC_MSG_CHECKING([for GNU ld])
83else 56else
84 AC_MSG_CHECKING([for non-GNU ld]) 57 AC_MSG_CHECKING([for non-GNU ld])
85fi 58fi
86AC_CACHE_VAL([acl_cv_path_LD], 59if test -n "$LD"; then
87[if test -z "$LD"; then 60 # Let the user override the test with a path.
88 acl_save_ifs="$IFS"; IFS=$PATH_SEPARATOR 61 :
89 for ac_dir in $PATH; do 62else
90 IFS="$acl_save_ifs" 63 AC_CACHE_VAL([acl_cv_path_LD],
91 test -z "$ac_dir" && ac_dir=. 64 [
92 if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then 65 acl_cv_path_LD= # Final result of this test
93 acl_cv_path_LD="$ac_dir/$ac_prog" 66 ac_prog=ld # Program to search in $PATH
94 # Check to see if the program is GNU ld. I'd rather use --version, 67 if test "$GCC" = yes; then
95 # but apparently some variants of GNU ld only accept -v. 68 # Check if gcc -print-prog-name=ld gives a path.
96 # Break only if it was the GNU/non-GNU ld that we prefer. 69 case $host in
97 case `"$acl_cv_path_LD" -v 2>&1 </dev/null` in 70 *-*-mingw*)
98 *GNU* | *'with BFD'*) 71 # gcc leaves a trailing carriage return which upsets mingw
99 test "$with_gnu_ld" != no && break 72 acl_output=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
100 ;; 73 *)
101 *) 74 acl_output=`($CC -print-prog-name=ld) 2>&5` ;;
102 test "$with_gnu_ld" != yes && break 75 esac
103 ;; 76 case $acl_output in
77 # Accept absolute paths.
78 [[\\/]]* | ?:[[\\/]]*)
79 re_direlt='/[[^/]][[^/]]*/\.\./'
80 # Canonicalize the pathname of ld
81 acl_output=`echo "$acl_output" | sed 's%\\\\%/%g'`
82 while echo "$acl_output" | grep "$re_direlt" > /dev/null 2>&1; do
83 acl_output=`echo $acl_output | sed "s%$re_direlt%/%"`
84 done
85 # Got the pathname. No search in PATH is needed.
86 acl_cv_path_LD="$acl_output"
87 ac_prog=
88 ;;
89 "")
90 # If it fails, then pretend we aren't using GCC.
91 ;;
92 *)
93 # If it is relative, then search for the first ld in PATH.
94 with_gnu_ld=unknown
95 ;;
104 esac 96 esac
105 fi 97 fi
106 done 98 if test -n "$ac_prog"; then
107 IFS="$acl_save_ifs" 99 # Search for $ac_prog in $PATH.
108else 100 acl_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
109 acl_cv_path_LD="$LD" # Let the user override the test with a path. 101 for ac_dir in $PATH; do
110fi]) 102 IFS="$acl_save_ifs"
111LD="$acl_cv_path_LD" 103 test -z "$ac_dir" && ac_dir=.
104 if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
105 acl_cv_path_LD="$ac_dir/$ac_prog"
106 # Check to see if the program is GNU ld. I'd rather use --version,
107 # but apparently some variants of GNU ld only accept -v.
108 # Break only if it was the GNU/non-GNU ld that we prefer.
109 case `"$acl_cv_path_LD" -v 2>&1 </dev/null` in
110 *GNU* | *'with BFD'*)
111 test "$with_gnu_ld" != no && break
112 ;;
113 *)
114 test "$with_gnu_ld" != yes && break
115 ;;
116 esac
117 fi
118 done
119 IFS="$acl_save_ifs"
120 fi
121 case $host in
122 *-*-aix*)
123 AC_COMPILE_IFELSE(
124 [AC_LANG_SOURCE(
125 [[#if defined __powerpc64__ || defined __LP64__
126 int ok;
127 #else
128 error fail
129 #endif
130 ]])],
131 [# The compiler produces 64-bit code. Add option '-b64' so that the
132 # linker groks 64-bit object files.
133 case "$acl_cv_path_LD " in
134 *" -b64 "*) ;;
135 *) acl_cv_path_LD="$acl_cv_path_LD -b64" ;;
136 esac
137 ], [])
138 ;;
139 sparc64-*-netbsd*)
140 AC_COMPILE_IFELSE(
141 [AC_LANG_SOURCE(
142 [[#if defined __sparcv9 || defined __arch64__
143 int ok;
144 #else
145 error fail
146 #endif
147 ]])],
148 [],
149 [# The compiler produces 32-bit code. Add option '-m elf32_sparc'
150 # so that the linker groks 32-bit object files.
151 case "$acl_cv_path_LD " in
152 *" -m elf32_sparc "*) ;;
153 *) acl_cv_path_LD="$acl_cv_path_LD -m elf32_sparc" ;;
154 esac
155 ])
156 ;;
157 esac
158 ])
159 LD="$acl_cv_path_LD"
160fi
112if test -n "$LD"; then 161if test -n "$LD"; then
113 AC_MSG_RESULT([$LD]) 162 AC_MSG_RESULT([$LD])
114else 163else
115 AC_MSG_RESULT([no]) 164 AC_MSG_RESULT([no])
165 AC_MSG_ERROR([no acceptable ld found in \$PATH])
116fi 166fi
117test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
118AC_LIB_PROG_LD_GNU 167AC_LIB_PROG_LD_GNU
119]) 168])
diff --git a/gl/m4/lib-link.m4 b/gl/m4/lib-link.m4
index 073f040..787efab 100644
--- a/gl/m4/lib-link.m4
+++ b/gl/m4/lib-link.m4
@@ -1,12 +1,12 @@
1# lib-link.m4 serial 26 (gettext-0.18.2) 1# lib-link.m4 serial 32
2dnl Copyright (C) 2001-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2001-2021 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.54]) 9AC_PREREQ([2.61])
10 10
11dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and 11dnl AC_LIB_LINKFLAGS(name [, dependencies]) searches for libname and
12dnl the libraries corresponding to explicit and implicit dependencies. 12dnl the libraries corresponding to explicit and implicit dependencies.
@@ -124,8 +124,8 @@ dnl acl_hardcode_direct,
124dnl acl_hardcode_minus_L. 124dnl acl_hardcode_minus_L.
125AC_DEFUN([AC_LIB_RPATH], 125AC_DEFUN([AC_LIB_RPATH],
126[ 126[
127 dnl Tell automake >= 1.10 to complain if config.rpath is missing. 127 dnl Complain if config.rpath is missing.
128 m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([config.rpath])]) 128 AC_REQUIRE_AUX_FILE([config.rpath])
129 AC_REQUIRE([AC_PROG_CC]) dnl we use $CC, $GCC, $LDFLAGS 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 130 AC_REQUIRE([AC_LIB_PROG_LD]) dnl we use $LD, $with_gnu_ld
131 AC_REQUIRE([AC_CANONICAL_HOST]) dnl we use $host 131 AC_REQUIRE([AC_CANONICAL_HOST]) dnl we use $host
@@ -187,17 +187,17 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
187 pushdef([PACKUP],[m4_translit(PACK,[abcdefghijklmnopqrstuvwxyz./+-], 187 pushdef([PACKUP],[m4_translit(PACK,[abcdefghijklmnopqrstuvwxyz./+-],
188 [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])]) 188 [ABCDEFGHIJKLMNOPQRSTUVWXYZ____])])
189 pushdef([PACKLIBS],[m4_ifdef([acl_frompackage_]NAME, [acl_libsinpackage_]PACKUP, lib[$1])]) 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. 190 dnl By default, look in $includedir and $libdir.
193 use_additional=yes 191 use_additional=yes
194 AC_LIB_WITH_FINAL_PREFIX([ 192 AC_LIB_WITH_FINAL_PREFIX([
195 eval additional_includedir=\"$includedir\" 193 eval additional_includedir=\"$includedir\"
196 eval additional_libdir=\"$libdir\" 194 eval additional_libdir=\"$libdir\"
195 eval additional_libdir2=\"$exec_prefix/$acl_libdirstem2\"
196 eval additional_libdir3=\"$exec_prefix/$acl_libdirstem3\"
197 ]) 197 ])
198 AC_ARG_WITH(P_A_C_K[-prefix], 198 AC_ARG_WITH(PACK[-prefix],
199[[ --with-]]P_A_C_K[[-prefix[=DIR] search for ]PACKLIBS[ in DIR/include and DIR/lib 199[[ --with-]]PACK[[-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]], 200 --without-]]PACK[[-prefix don't search for ]PACKLIBS[ in includedir and libdir]],
201[ 201[
202 if test "X$withval" = "Xno"; then 202 if test "X$withval" = "Xno"; then
203 use_additional=no 203 use_additional=no
@@ -206,17 +206,23 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
206 AC_LIB_WITH_FINAL_PREFIX([ 206 AC_LIB_WITH_FINAL_PREFIX([
207 eval additional_includedir=\"$includedir\" 207 eval additional_includedir=\"$includedir\"
208 eval additional_libdir=\"$libdir\" 208 eval additional_libdir=\"$libdir\"
209 eval additional_libdir2=\"$exec_prefix/$acl_libdirstem2\"
210 eval additional_libdir3=\"$exec_prefix/$acl_libdirstem3\"
209 ]) 211 ])
210 else 212 else
211 additional_includedir="$withval/include" 213 additional_includedir="$withval/include"
212 additional_libdir="$withval/$acl_libdirstem" 214 additional_libdir="$withval/$acl_libdirstem"
213 if test "$acl_libdirstem2" != "$acl_libdirstem" \ 215 additional_libdir2="$withval/$acl_libdirstem2"
214 && ! test -d "$withval/$acl_libdirstem"; then 216 additional_libdir3="$withval/$acl_libdirstem3"
215 additional_libdir="$withval/$acl_libdirstem2"
216 fi
217 fi 217 fi
218 fi 218 fi
219]) 219])
220 if test "X$additional_libdir2" = "X$additional_libdir"; then
221 additional_libdir2=
222 fi
223 if test "X$additional_libdir3" = "X$additional_libdir"; then
224 additional_libdir3=
225 fi
220 dnl Search the library and its dependencies in $additional_libdir and 226 dnl Search the library and its dependencies in $additional_libdir and
221 dnl $LDFLAGS. Using breadth-first-seach. 227 dnl $LDFLAGS. Using breadth-first-seach.
222 LIB[]NAME= 228 LIB[]NAME=
@@ -272,48 +278,54 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
272 shrext= 278 shrext=
273 fi 279 fi
274 if test $use_additional = yes; then 280 if test $use_additional = yes; then
275 dir="$additional_libdir" 281 for additional_libdir_variable in additional_libdir additional_libdir2 additional_libdir3; do
276 dnl The same code as in the loop below: 282 if test "X$found_dir" = "X"; then
277 dnl First look for a shared library. 283 eval dir=\$$additional_libdir_variable
278 if test -n "$acl_shlibext"; then 284 if test -n "$dir"; then
279 if test -f "$dir/$libname$shrext"; then 285 dnl The same code as in the loop below:
280 found_dir="$dir" 286 dnl First look for a shared library.
281 found_so="$dir/$libname$shrext" 287 if test -n "$acl_shlibext"; then
282 else 288 if test -f "$dir/$libname$shrext" && acl_is_expected_elfclass < "$dir/$libname$shrext"; then
283 if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then 289 found_dir="$dir"
284 ver=`(cd "$dir" && \ 290 found_so="$dir/$libname$shrext"
285 for f in "$libname$shrext".*; do echo "$f"; done \ 291 else
286 | sed -e "s,^$libname$shrext\\\\.,," \ 292 if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then
287 | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ 293 ver=`(cd "$dir" && \
288 | sed 1q ) 2>/dev/null` 294 for f in "$libname$shrext".*; do echo "$f"; done \
289 if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then 295 | sed -e "s,^$libname$shrext\\\\.,," \
290 found_dir="$dir" 296 | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \
291 found_so="$dir/$libname$shrext.$ver" 297 | sed 1q ) 2>/dev/null`
298 if test -n "$ver" && test -f "$dir/$libname$shrext.$ver" && acl_is_expected_elfclass < "$dir/$libname$shrext.$ver"; then
299 found_dir="$dir"
300 found_so="$dir/$libname$shrext.$ver"
301 fi
302 else
303 eval library_names=\"$acl_library_names_spec\"
304 for f in $library_names; do
305 if test -f "$dir/$f" && acl_is_expected_elfclass < "$dir/$f"; then
306 found_dir="$dir"
307 found_so="$dir/$f"
308 break
309 fi
310 done
311 fi
312 fi
292 fi 313 fi
293 else 314 dnl Then look for a static library.
294 eval library_names=\"$acl_library_names_spec\" 315 if test "X$found_dir" = "X"; then
295 for f in $library_names; do 316 if test -f "$dir/$libname.$acl_libext" && ${AR-ar} -p "$dir/$libname.$acl_libext" | acl_is_expected_elfclass; then
296 if test -f "$dir/$f"; then
297 found_dir="$dir" 317 found_dir="$dir"
298 found_so="$dir/$f" 318 found_a="$dir/$libname.$acl_libext"
299 break
300 fi 319 fi
301 done 320 fi
321 if test "X$found_dir" != "X"; then
322 if test -f "$dir/$libname.la"; then
323 found_la="$dir/$libname.la"
324 fi
325 fi
302 fi 326 fi
303 fi 327 fi
304 fi 328 done
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 329 fi
318 if test "X$found_dir" = "X"; then 330 if test "X$found_dir" = "X"; then
319 for x in $LDFLAGS $LTLIB[]NAME; do 331 for x in $LDFLAGS $LTLIB[]NAME; do
@@ -323,7 +335,7 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
323 dir=`echo "X$x" | sed -e 's/^X-L//'` 335 dir=`echo "X$x" | sed -e 's/^X-L//'`
324 dnl First look for a shared library. 336 dnl First look for a shared library.
325 if test -n "$acl_shlibext"; then 337 if test -n "$acl_shlibext"; then
326 if test -f "$dir/$libname$shrext"; then 338 if test -f "$dir/$libname$shrext" && acl_is_expected_elfclass < "$dir/$libname$shrext"; then
327 found_dir="$dir" 339 found_dir="$dir"
328 found_so="$dir/$libname$shrext" 340 found_so="$dir/$libname$shrext"
329 else 341 else
@@ -333,14 +345,14 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
333 | sed -e "s,^$libname$shrext\\\\.,," \ 345 | sed -e "s,^$libname$shrext\\\\.,," \
334 | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \ 346 | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \
335 | sed 1q ) 2>/dev/null` 347 | sed 1q ) 2>/dev/null`
336 if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then 348 if test -n "$ver" && test -f "$dir/$libname$shrext.$ver" && acl_is_expected_elfclass < "$dir/$libname$shrext.$ver"; then
337 found_dir="$dir" 349 found_dir="$dir"
338 found_so="$dir/$libname$shrext.$ver" 350 found_so="$dir/$libname$shrext.$ver"
339 fi 351 fi
340 else 352 else
341 eval library_names=\"$acl_library_names_spec\" 353 eval library_names=\"$acl_library_names_spec\"
342 for f in $library_names; do 354 for f in $library_names; do
343 if test -f "$dir/$f"; then 355 if test -f "$dir/$f" && acl_is_expected_elfclass < "$dir/$f"; then
344 found_dir="$dir" 356 found_dir="$dir"
345 found_so="$dir/$f" 357 found_so="$dir/$f"
346 break 358 break
@@ -351,7 +363,7 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
351 fi 363 fi
352 dnl Then look for a static library. 364 dnl Then look for a static library.
353 if test "X$found_dir" = "X"; then 365 if test "X$found_dir" = "X"; then
354 if test -f "$dir/$libname.$acl_libext"; then 366 if test -f "$dir/$libname.$acl_libext" && ${AR-ar} -p "$dir/$libname.$acl_libext" | acl_is_expected_elfclass; then
355 found_dir="$dir" 367 found_dir="$dir"
356 found_a="$dir/$libname.$acl_libext" 368 found_a="$dir/$libname.$acl_libext"
357 fi 369 fi
@@ -377,7 +389,8 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
377 dnl standard /usr/lib. 389 dnl standard /usr/lib.
378 if test "$enable_rpath" = no \ 390 if test "$enable_rpath" = no \
379 || test "X$found_dir" = "X/usr/$acl_libdirstem" \ 391 || test "X$found_dir" = "X/usr/$acl_libdirstem" \
380 || test "X$found_dir" = "X/usr/$acl_libdirstem2"; then 392 || test "X$found_dir" = "X/usr/$acl_libdirstem2" \
393 || test "X$found_dir" = "X/usr/$acl_libdirstem3"; then
381 dnl No hardcoding is needed. 394 dnl No hardcoding is needed.
382 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so" 395 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }$found_so"
383 else 396 else
@@ -477,6 +490,13 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
477 fi 490 fi
478 additional_includedir="$basedir/include" 491 additional_includedir="$basedir/include"
479 ;; 492 ;;
493 */$acl_libdirstem3 | */$acl_libdirstem3/)
494 basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem3/"'*$,,'`
495 if test "$name" = '$1'; then
496 LIB[]NAME[]_PREFIX="$basedir"
497 fi
498 additional_includedir="$basedir/include"
499 ;;
480 esac 500 esac
481 if test "X$additional_includedir" != "X"; then 501 if test "X$additional_includedir" != "X"; then
482 dnl Potentially add $additional_includedir to $INCNAME. 502 dnl Potentially add $additional_includedir to $INCNAME.
@@ -527,19 +547,21 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
527 for dep in $dependency_libs; do 547 for dep in $dependency_libs; do
528 case "$dep" in 548 case "$dep" in
529 -L*) 549 -L*)
530 additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'` 550 dependency_libdir=`echo "X$dep" | sed -e 's/^X-L//'`
531 dnl Potentially add $additional_libdir to $LIBNAME and $LTLIBNAME. 551 dnl Potentially add $dependency_libdir to $LIBNAME and $LTLIBNAME.
532 dnl But don't add it 552 dnl But don't add it
533 dnl 1. if it's the standard /usr/lib, 553 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, 554 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 555 dnl 3. if it's already present in $LDFLAGS or the already
536 dnl constructed $LIBNAME, 556 dnl constructed $LIBNAME,
537 dnl 4. if it doesn't exist as a directory. 557 dnl 4. if it doesn't exist as a directory.
538 if test "X$additional_libdir" != "X/usr/$acl_libdirstem" \ 558 if test "X$dependency_libdir" != "X/usr/$acl_libdirstem" \
539 && test "X$additional_libdir" != "X/usr/$acl_libdirstem2"; then 559 && test "X$dependency_libdir" != "X/usr/$acl_libdirstem2" \
560 && test "X$dependency_libdir" != "X/usr/$acl_libdirstem3"; then
540 haveit= 561 haveit=
541 if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem" \ 562 if test "X$dependency_libdir" = "X/usr/local/$acl_libdirstem" \
542 || test "X$additional_libdir" = "X/usr/local/$acl_libdirstem2"; then 563 || test "X$dependency_libdir" = "X/usr/local/$acl_libdirstem2" \
564 || test "X$dependency_libdir" = "X/usr/local/$acl_libdirstem3"; then
543 if test -n "$GCC"; then 565 if test -n "$GCC"; then
544 case $host_os in 566 case $host_os in
545 linux* | gnu* | k*bsd*-gnu) haveit=yes;; 567 linux* | gnu* | k*bsd*-gnu) haveit=yes;;
@@ -550,29 +572,29 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
550 haveit= 572 haveit=
551 for x in $LDFLAGS $LIB[]NAME; do 573 for x in $LDFLAGS $LIB[]NAME; do
552 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 574 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
553 if test "X$x" = "X-L$additional_libdir"; then 575 if test "X$x" = "X-L$dependency_libdir"; then
554 haveit=yes 576 haveit=yes
555 break 577 break
556 fi 578 fi
557 done 579 done
558 if test -z "$haveit"; then 580 if test -z "$haveit"; then
559 if test -d "$additional_libdir"; then 581 if test -d "$dependency_libdir"; then
560 dnl Really add $additional_libdir to $LIBNAME. 582 dnl Really add $dependency_libdir to $LIBNAME.
561 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$additional_libdir" 583 LIB[]NAME="${LIB[]NAME}${LIB[]NAME:+ }-L$dependency_libdir"
562 fi 584 fi
563 fi 585 fi
564 haveit= 586 haveit=
565 for x in $LDFLAGS $LTLIB[]NAME; do 587 for x in $LDFLAGS $LTLIB[]NAME; do
566 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 588 AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
567 if test "X$x" = "X-L$additional_libdir"; then 589 if test "X$x" = "X-L$dependency_libdir"; then
568 haveit=yes 590 haveit=yes
569 break 591 break
570 fi 592 fi
571 done 593 done
572 if test -z "$haveit"; then 594 if test -z "$haveit"; then
573 if test -d "$additional_libdir"; then 595 if test -d "$dependency_libdir"; then
574 dnl Really add $additional_libdir to $LTLIBNAME. 596 dnl Really add $dependency_libdir to $LTLIBNAME.
575 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$additional_libdir" 597 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-L$dependency_libdir"
576 fi 598 fi
577 fi 599 fi
578 fi 600 fi
@@ -609,7 +631,20 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
609 ;; 631 ;;
610 -l*) 632 -l*)
611 dnl Handle this in the next round. 633 dnl Handle this in the next round.
612 names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'` 634 dnl But on GNU systems, ignore -lc options, because
635 dnl - linking with libc is the default anyway,
636 dnl - linking with libc.a may produce an error
637 dnl "/usr/bin/ld: dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in `/usr/lib/libc.a(strcmp.o)' can not be used when making an executable; recompile with -fPIE and relink with -pie"
638 dnl or may produce an executable that always crashes, see
639 dnl <https://lists.gnu.org/archive/html/grep-devel/2020-09/msg00052.html>.
640 dep=`echo "X$dep" | sed -e 's/^X-l//'`
641 if test "X$dep" != Xc \
642 || case $host_os in
643 linux* | gnu* | k*bsd*-gnu) false ;;
644 *) true ;;
645 esac; then
646 names_next_round="$names_next_round $dep"
647 fi
613 ;; 648 ;;
614 *.la) 649 *.la)
615 dnl Handle this in the next round. Throw away the .la's 650 dnl Handle this in the next round. Throw away the .la's
@@ -670,7 +705,6 @@ AC_DEFUN([AC_LIB_LINKFLAGS_BODY],
670 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir" 705 LTLIB[]NAME="${LTLIB[]NAME}${LTLIB[]NAME:+ }-R$found_dir"
671 done 706 done
672 fi 707 fi
673 popdef([P_A_C_K])
674 popdef([PACKLIBS]) 708 popdef([PACKLIBS])
675 popdef([PACKUP]) 709 popdef([PACKUP])
676 popdef([PACK]) 710 popdef([PACK])
@@ -721,7 +755,8 @@ AC_DEFUN([AC_LIB_LINKFLAGS_FROM_LIBS],
721 dir="$next" 755 dir="$next"
722 dnl No need to hardcode the standard /usr/lib. 756 dnl No need to hardcode the standard /usr/lib.
723 if test "X$dir" != "X/usr/$acl_libdirstem" \ 757 if test "X$dir" != "X/usr/$acl_libdirstem" \
724 && test "X$dir" != "X/usr/$acl_libdirstem2"; then 758 && test "X$dir" != "X/usr/$acl_libdirstem2" \
759 && test "X$dir" != "X/usr/$acl_libdirstem3"; then
725 rpathdirs="$rpathdirs $dir" 760 rpathdirs="$rpathdirs $dir"
726 fi 761 fi
727 next= 762 next=
@@ -731,7 +766,8 @@ AC_DEFUN([AC_LIB_LINKFLAGS_FROM_LIBS],
731 -L*) dir=`echo "X$opt" | sed -e 's,^X-L,,'` 766 -L*) dir=`echo "X$opt" | sed -e 's,^X-L,,'`
732 dnl No need to hardcode the standard /usr/lib. 767 dnl No need to hardcode the standard /usr/lib.
733 if test "X$dir" != "X/usr/$acl_libdirstem" \ 768 if test "X$dir" != "X/usr/$acl_libdirstem" \
734 && test "X$dir" != "X/usr/$acl_libdirstem2"; then 769 && test "X$dir" != "X/usr/$acl_libdirstem2" \
770 && test "X$dir" != "X/usr/$acl_libdirstem3"; then
735 rpathdirs="$rpathdirs $dir" 771 rpathdirs="$rpathdirs $dir"
736 fi 772 fi
737 next= ;; 773 next= ;;
diff --git a/gl/m4/lib-prefix.m4 b/gl/m4/lib-prefix.m4
index 60908e8..3c94db0 100644
--- a/gl/m4/lib-prefix.m4
+++ b/gl/m4/lib-prefix.m4
@@ -1,18 +1,11 @@
1# lib-prefix.m4 serial 7 (gettext-0.18) 1# lib-prefix.m4 serial 19
2dnl Copyright (C) 2001-2005, 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2001-2005, 2008-2021 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
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 9dnl 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 10dnl to access previously installed libraries. The basic assumption is that
18dnl a user will want packages to use other packages he previously installed 11dnl a user will want packages to use other packages he previously installed
@@ -32,9 +25,9 @@ AC_DEFUN([AC_LIB_PREFIX],
32 eval additional_includedir=\"$includedir\" 25 eval additional_includedir=\"$includedir\"
33 eval additional_libdir=\"$libdir\" 26 eval additional_libdir=\"$libdir\"
34 ]) 27 ])
35 AC_LIB_ARG_WITH([lib-prefix], 28 AC_ARG_WITH([lib-prefix],
36[ --with-lib-prefix[=DIR] search for libraries in DIR/include and DIR/lib 29[[ --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], 30 --without-lib-prefix don't search for libraries in includedir and libdir]],
38[ 31[
39 if test "X$withval" = "Xno"; then 32 if test "X$withval" = "Xno"; then
40 use_additional=no 33 use_additional=no
@@ -154,71 +147,177 @@ AC_DEFUN([AC_LIB_WITH_FINAL_PREFIX],
154]) 147])
155 148
156dnl AC_LIB_PREPARE_MULTILIB creates 149dnl AC_LIB_PREPARE_MULTILIB creates
157dnl - a variable acl_libdirstem, containing the basename of the libdir, either 150dnl - a function acl_is_expected_elfclass, that tests whether standard input
158dnl "lib" or "lib64" or "lib/64", 151dn; has a 32-bit or 64-bit ELF header, depending on the host CPU ABI,
159dnl - a variable acl_libdirstem2, as a secondary possible value for 152dnl - 3 variables acl_libdirstem, acl_libdirstem2, acl_libdirstem3, containing
160dnl acl_libdirstem, either the same as acl_libdirstem or "lib/sparcv9" or 153dnl the basename of the libdir to try in turn, either "lib" or "lib64" or
161dnl "lib/amd64". 154dnl "lib/64" or "lib32" or "lib/sparcv9" or "lib/amd64" or similar.
162AC_DEFUN([AC_LIB_PREPARE_MULTILIB], 155AC_DEFUN([AC_LIB_PREPARE_MULTILIB],
163[ 156[
164 dnl There is no formal standard regarding lib and lib64. 157 dnl There is no formal standard regarding lib, lib32, and lib64.
165 dnl On glibc systems, the current practice is that on a system supporting 158 dnl On most 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 159 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 160 dnl $prefix/lib64 and 32-bit libraries go under $prefix/lib. However, on
168 dnl the compiler's default mode by looking at the compiler's library search 161 dnl Arch Linux based distributions, it's the opposite: 32-bit libraries go
169 dnl path. If at least one of its elements ends in /lib64 or points to a 162 dnl under $prefix/lib32 and 64-bit libraries go under $prefix/lib.
170 dnl directory whose absolute pathname ends in /lib64, we assume a 64-bit ABI. 163 dnl We determine the compiler's default mode by looking at the compiler's
171 dnl Otherwise we use the default, namely "lib". 164 dnl library search path. If at least one of its elements ends in /lib64 or
165 dnl points to a directory whose absolute pathname ends in /lib64, we use that
166 dnl for 64-bit ABIs. Similarly for 32-bit ABIs. Otherwise we use the default,
167 dnl namely "lib".
172 dnl On Solaris systems, the current practice is that on a system supporting 168 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 169 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 170 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. 171 dnl $prefix/lib/amd64) and 32-bit libraries go under $prefix/lib.
176 AC_REQUIRE([AC_CANONICAL_HOST]) 172 AC_REQUIRE([AC_CANONICAL_HOST])
177 acl_libdirstem=lib 173 AC_REQUIRE([gl_HOST_CPU_C_ABI_32BIT])
178 acl_libdirstem2= 174
179 case "$host_os" in 175 AC_CACHE_CHECK([for ELF binary format], [gl_cv_elf],
180 solaris*) 176 [AC_EGREP_CPP([Extensible Linking Format],
181 dnl See Solaris 10 Software Developer Collection > Solaris 64-bit Developer's Guide > The Development Environment 177 [#ifdef __ELF__
182 dnl <http://docs.sun.com/app/docs/doc/816-5138/dev-env?l=en&a=view>. 178 Extensible Linking Format
183 dnl "Portable Makefiles should refer to any library directories using the 64 symbolic link." 179 #endif
184 dnl But we want to recognize the sparcv9 or amd64 subdirectory also if the 180 ],
185 dnl symlink is missing, so we set acl_libdirstem2 too. 181 [gl_cv_elf=yes],
186 AC_CACHE_CHECK([for 64-bit host], [gl_cv_solaris_64bit], 182 [gl_cv_elf=no])
187 [AC_EGREP_CPP([sixtyfour bits], [ 183 ])
188#ifdef _LP64 184 if test $gl_cv_elf = yes; then
189sixtyfour bits 185 # Extract the ELF class of a file (5th byte) in decimal.
190#endif 186 # Cf. https://en.wikipedia.org/wiki/Executable_and_Linkable_Format#File_header
191 ], [gl_cv_solaris_64bit=yes], [gl_cv_solaris_64bit=no]) 187 if od -A x < /dev/null >/dev/null 2>/dev/null; then
192 ]) 188 # Use POSIX od.
193 if test $gl_cv_solaris_64bit = yes; then 189 func_elfclass ()
194 acl_libdirstem=lib/64 190 {
195 case "$host_cpu" in 191 od -A n -t d1 -j 4 -N 1
196 sparc*) acl_libdirstem2=lib/sparcv9 ;; 192 }
197 i*86 | x86_64) acl_libdirstem2=lib/amd64 ;; 193 else
198 esac 194 # Use BSD hexdump.
199 fi 195 func_elfclass ()
200 ;; 196 {
201 *) 197 dd bs=1 count=1 skip=4 2>/dev/null | hexdump -e '1/1 "%3d "'
202 searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'` 198 echo
203 if test -n "$searchpath"; then 199 }
204 acl_save_IFS="${IFS= }"; IFS=":" 200 fi
205 for searchdir in $searchpath; do 201 # Use 'expr', not 'test', to compare the values of func_elfclass, because on
206 if test -d "$searchdir"; then 202 # Solaris 11 OpenIndiana and Solaris 11 OmniOS, the result is 001 or 002,
207 case "$searchdir" in 203 # not 1 or 2.
208 */lib64/ | */lib64 ) acl_libdirstem=lib64 ;; 204changequote(,)dnl
209 */../ | */.. ) 205 case $HOST_CPU_C_ABI_32BIT in
210 # Better ignore directories of this form. They are misleading. 206 yes)
211 ;; 207 # 32-bit ABI.
212 *) searchdir=`cd "$searchdir" && pwd` 208 acl_is_expected_elfclass ()
213 case "$searchdir" in 209 {
214 */lib64 ) acl_libdirstem=lib64 ;; 210 expr "`func_elfclass | sed -e 's/[ ]//g'`" = 1 > /dev/null
215 esac ;; 211 }
216 esac 212 ;;
217 fi 213 no)
218 done 214 # 64-bit ABI.
219 IFS="$acl_save_IFS" 215 acl_is_expected_elfclass ()
220 fi 216 {
221 ;; 217 expr "`func_elfclass | sed -e 's/[ ]//g'`" = 2 > /dev/null
222 esac 218 }
223 test -n "$acl_libdirstem2" || acl_libdirstem2="$acl_libdirstem" 219 ;;
220 *)
221 # Unknown.
222 acl_is_expected_elfclass ()
223 {
224 :
225 }
226 ;;
227 esac
228changequote([,])dnl
229 else
230 acl_is_expected_elfclass ()
231 {
232 :
233 }
234 fi
235
236 dnl Allow the user to override the result by setting acl_cv_libdirstems.
237 AC_CACHE_CHECK([for the common suffixes of directories in the library search path],
238 [acl_cv_libdirstems],
239 [dnl Try 'lib' first, because that's the default for libdir in GNU, see
240 dnl <https://www.gnu.org/prep/standards/html_node/Directory-Variables.html>.
241 acl_libdirstem=lib
242 acl_libdirstem2=
243 acl_libdirstem3=
244 case "$host_os" in
245 solaris*)
246 dnl See Solaris 10 Software Developer Collection > Solaris 64-bit Developer's Guide > The Development Environment
247 dnl <https://docs.oracle.com/cd/E19253-01/816-5138/dev-env/index.html>.
248 dnl "Portable Makefiles should refer to any library directories using the 64 symbolic link."
249 dnl But we want to recognize the sparcv9 or amd64 subdirectory also if the
250 dnl symlink is missing, so we set acl_libdirstem2 too.
251 if test $HOST_CPU_C_ABI_32BIT = no; then
252 acl_libdirstem2=lib/64
253 case "$host_cpu" in
254 sparc*) acl_libdirstem3=lib/sparcv9 ;;
255 i*86 | x86_64) acl_libdirstem3=lib/amd64 ;;
256 esac
257 fi
258 ;;
259 *)
260 dnl If $CC generates code for a 32-bit ABI, the libraries are
261 dnl surely under $prefix/lib or $prefix/lib32, not $prefix/lib64.
262 dnl Similarly, if $CC generates code for a 64-bit ABI, the libraries
263 dnl are surely under $prefix/lib or $prefix/lib64, not $prefix/lib32.
264 dnl Find the compiler's search path. However, non-system compilers
265 dnl sometimes have odd library search paths. But we can't simply invoke
266 dnl '/usr/bin/gcc -print-search-dirs' because that would not take into
267 dnl account the -m32/-m31 or -m64 options from the $CC or $CFLAGS.
268 searchpath=`(LC_ALL=C $CC $CPPFLAGS $CFLAGS -print-search-dirs) 2>/dev/null \
269 | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'`
270 if test $HOST_CPU_C_ABI_32BIT != no; then
271 # 32-bit or unknown ABI.
272 if test -d /usr/lib32; then
273 acl_libdirstem2=lib32
274 fi
275 fi
276 if test $HOST_CPU_C_ABI_32BIT != yes; then
277 # 64-bit or unknown ABI.
278 if test -d /usr/lib64; then
279 acl_libdirstem3=lib64
280 fi
281 fi
282 if test -n "$searchpath"; then
283 acl_save_IFS="${IFS= }"; IFS=":"
284 for searchdir in $searchpath; do
285 if test -d "$searchdir"; then
286 case "$searchdir" in
287 */lib32/ | */lib32 ) acl_libdirstem2=lib32 ;;
288 */lib64/ | */lib64 ) acl_libdirstem3=lib64 ;;
289 */../ | */.. )
290 # Better ignore directories of this form. They are misleading.
291 ;;
292 *) searchdir=`cd "$searchdir" && pwd`
293 case "$searchdir" in
294 */lib32 ) acl_libdirstem2=lib32 ;;
295 */lib64 ) acl_libdirstem3=lib64 ;;
296 esac ;;
297 esac
298 fi
299 done
300 IFS="$acl_save_IFS"
301 if test $HOST_CPU_C_ABI_32BIT = yes; then
302 # 32-bit ABI.
303 acl_libdirstem3=
304 fi
305 if test $HOST_CPU_C_ABI_32BIT = no; then
306 # 64-bit ABI.
307 acl_libdirstem2=
308 fi
309 fi
310 ;;
311 esac
312 test -n "$acl_libdirstem2" || acl_libdirstem2="$acl_libdirstem"
313 test -n "$acl_libdirstem3" || acl_libdirstem3="$acl_libdirstem"
314 acl_cv_libdirstems="$acl_libdirstem,$acl_libdirstem2,$acl_libdirstem3"
315 ])
316 dnl Decompose acl_cv_libdirstems into acl_libdirstem, acl_libdirstem2, and
317 dnl acl_libdirstem3.
318changequote(,)dnl
319 acl_libdirstem=`echo "$acl_cv_libdirstems" | sed -e 's/,.*//'`
320 acl_libdirstem2=`echo "$acl_cv_libdirstems" | sed -e 's/^[^,]*,//' -e 's/,.*//'`
321 acl_libdirstem3=`echo "$acl_cv_libdirstems" | sed -e 's/^[^,]*,[^,]*,//' -e 's/,.*//'`
322changequote([,])dnl
224]) 323])
diff --git a/gl/m4/limits-h.m4 b/gl/m4/limits-h.m4
new file mode 100644
index 0000000..00c9fe9
--- /dev/null
+++ b/gl/m4/limits-h.m4
@@ -0,0 +1,44 @@
1dnl Check whether limits.h has needed features.
2
3dnl Copyright 2016-2021 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 LIMITS_H=
31 else
32 LIMITS_H=limits.h
33 fi
34 AC_SUBST([LIMITS_H])
35 AM_CONDITIONAL([GL_GENERATE_LIMITS_H], [test -n "$LIMITS_H"])
36])
37
38dnl Unconditionally enables the replacement of <limits.h>.
39AC_DEFUN([gl_REPLACE_LIMITS_H],
40[
41 AC_REQUIRE([gl_LIMITS_H])
42 LIMITS_H='limits.h'
43 AM_CONDITIONAL([GL_GENERATE_LIMITS_H], [test -n "$LIMITS_H"])
44])
diff --git a/gl/m4/localcharset.m4 b/gl/m4/localcharset.m4
index 2e93e58..04389fc 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-2021 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..b61df7e 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-2021 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..cd94288 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-2021 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..1228be8 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-2021 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..444a381 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-2021 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..e29c7c3 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-2021 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..d68c12d 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-2021 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..faab09b
--- /dev/null
+++ b/gl/m4/lseek.m4
@@ -0,0 +1,78 @@
1# lseek.m4 serial 12
2dnl Copyright (C) 2007, 2009-2021 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..972e808 100644
--- a/gl/m4/malloc.m4
+++ b/gl/m4/malloc.m4
@@ -1,98 +1,174 @@
1# malloc.m4 serial 14 1# malloc.m4 serial 27
2dnl Copyright (C) 2007, 2009-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2007, 2009-2021 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 if test $REPLACE_MALLOC = 0; then
54 [AC_DEFINE([HAVE_MALLOC_GNU], [1], 47 _AC_FUNC_MALLOC_IF([], [REPLACE_MALLOC=1])
55 [Define to 1 if your system has a GNU libc compatible 'malloc' 48 fi
56 function, and to 0 otherwise.])], 49])
57 [AC_DEFINE([HAVE_MALLOC_GNU], [0]) 50
58 REPLACE_MALLOC=1 51# gl_FUNC_MALLOC_PTRDIFF
52# ----------------------
53# Test whether malloc (N) reliably fails when N exceeds PTRDIFF_MAX,
54# and replace malloc otherwise.
55AC_DEFUN([gl_FUNC_MALLOC_PTRDIFF],
56[
57 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
58 AC_REQUIRE([gl_CHECK_MALLOC_PTRDIFF])
59 test "$gl_cv_malloc_ptrdiff" = yes || REPLACE_MALLOC=1
60])
61
62# Test whether malloc, realloc, calloc refuse to create objects
63# larger than what can be expressed in ptrdiff_t.
64# Set gl_cv_func_malloc_gnu to yes or no accordingly.
65AC_DEFUN([gl_CHECK_MALLOC_PTRDIFF],
66[
67 AC_CACHE_CHECK([whether malloc is ptrdiff_t safe],
68 [gl_cv_malloc_ptrdiff],
69 [AC_COMPILE_IFELSE(
70 [AC_LANG_PROGRAM(
71 [[#include <stdint.h>
72 ]],
73 [[/* 64-bit ptrdiff_t is so wide that no practical platform
74 can exceed it. */
75 #define WIDE_PTRDIFF (PTRDIFF_MAX >> 31 >> 31 != 0)
76
77 /* On rare machines where size_t fits in ptrdiff_t there
78 is no problem. */
79 #define NARROW_SIZE (SIZE_MAX <= PTRDIFF_MAX)
80
81 /* glibc 2.30 and later malloc refuses to exceed ptrdiff_t
82 bounds even on 32-bit platforms. We don't know which
83 non-glibc systems are safe. */
84 #define KNOWN_SAFE (2 < __GLIBC__ + (30 <= __GLIBC_MINOR__))
85
86 #if WIDE_PTRDIFF || NARROW_SIZE || KNOWN_SAFE
87 return 0;
88 #else
89 #error "malloc might not be ptrdiff_t safe"
90 syntax error
91 #endif
92 ]])],
93 [gl_cv_malloc_ptrdiff=yes],
94 [gl_cv_malloc_ptrdiff=no])
59 ]) 95 ])
60]) 96])
61 97
62# gl_FUNC_MALLOC_POSIX 98# gl_FUNC_MALLOC_POSIX
63# -------------------- 99# --------------------
64# Test whether 'malloc' is POSIX compliant (sets errno to ENOMEM when it 100# Test whether 'malloc' is POSIX compliant (sets errno to ENOMEM when it
65# fails), and replace malloc if it is not. 101# fails, and doesn't mess up with ptrdiff_t overflow), and replace
102# malloc if it is not.
66AC_DEFUN([gl_FUNC_MALLOC_POSIX], 103AC_DEFUN([gl_FUNC_MALLOC_POSIX],
67[ 104[
68 AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) 105 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
106 AC_REQUIRE([gl_FUNC_MALLOC_PTRDIFF])
69 AC_REQUIRE([gl_CHECK_MALLOC_POSIX]) 107 AC_REQUIRE([gl_CHECK_MALLOC_POSIX])
70 if test $gl_cv_func_malloc_posix = yes; then 108 if test "$gl_cv_func_malloc_posix" = yes; then
71 AC_DEFINE([HAVE_MALLOC_POSIX], [1], 109 AC_DEFINE([HAVE_MALLOC_POSIX], [1],
72 [Define if the 'malloc' function is POSIX compliant.]) 110 [Define if malloc, realloc, and calloc set errno on allocation failure.])
73 else 111 else
74 REPLACE_MALLOC=1 112 REPLACE_MALLOC=1
75 fi 113 fi
76]) 114])
77 115
78# Test whether malloc, realloc, calloc are POSIX compliant, 116# Test whether malloc, realloc, calloc set errno to ENOMEM on failure.
79# Set gl_cv_func_malloc_posix to yes or no accordingly. 117# Set gl_cv_func_malloc_posix to yes or no accordingly.
80AC_DEFUN([gl_CHECK_MALLOC_POSIX], 118AC_DEFUN([gl_CHECK_MALLOC_POSIX],
81[ 119[
82 AC_CACHE_CHECK([whether malloc, realloc, calloc are POSIX compliant], 120 AC_REQUIRE([AC_CANONICAL_HOST])
121 AC_CACHE_CHECK([whether malloc, realloc, calloc set errno on failure],
83 [gl_cv_func_malloc_posix], 122 [gl_cv_func_malloc_posix],
84 [ 123 [
85 dnl It is too dangerous to try to allocate a large amount of memory: 124 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 125 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. 126 dnl all Unix implementations of the function set errno on failure,
88 AC_COMPILE_IFELSE( 127 dnl except on those platforms where we have seen 'test-malloc-gnu',
89 [AC_LANG_PROGRAM( 128 dnl 'test-realloc-gnu', 'test-calloc-gnu' fail.
90 [[]], 129 case "$host_os" in
91 [[#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 130 mingw*)
92 choke me 131 gl_cv_func_malloc_posix=no ;;
93 #endif 132 irix* | solaris*)
94 ]])], 133 dnl On IRIX 6.5, the three functions return NULL with errno unset
95 [gl_cv_func_malloc_posix=yes], 134 dnl when the argument is larger than PTRDIFF_MAX.
96 [gl_cv_func_malloc_posix=no]) 135 dnl On Solaris 11.3, the three functions return NULL with errno set
136 dnl to EAGAIN, not ENOMEM, when the argument is larger than
137 dnl PTRDIFF_MAX.
138 dnl Here is a test program:
139m4_divert_push([KILL])
140#include <errno.h>
141#include <stdio.h>
142#include <stdlib.h>
143#define ptrdiff_t long
144#ifndef PTRDIFF_MAX
145# define PTRDIFF_MAX ((ptrdiff_t) ((1UL << (8 * sizeof (ptrdiff_t) - 1)) - 1))
146#endif
147
148int main ()
149{
150 void *p;
151
152 fprintf (stderr, "PTRDIFF_MAX = %lu\n", (unsigned long) PTRDIFF_MAX);
153
154 errno = 0;
155 p = malloc ((unsigned long) PTRDIFF_MAX + 1);
156 fprintf (stderr, "p=%p errno=%d\n", p, errno);
157
158 errno = 0;
159 p = calloc (PTRDIFF_MAX / 2 + 1, 2);
160 fprintf (stderr, "p=%p errno=%d\n", p, errno);
161
162 errno = 0;
163 p = realloc (NULL, (unsigned long) PTRDIFF_MAX + 1);
164 fprintf (stderr, "p=%p errno=%d\n", p, errno);
165
166 return 0;
167}
168m4_divert_pop([KILL])
169 gl_cv_func_malloc_posix=no ;;
170 *)
171 gl_cv_func_malloc_posix=yes ;;
172 esac
97 ]) 173 ])
98]) 174])
diff --git a/gl/m4/malloca.m4 b/gl/m4/malloca.m4
index 791ce10..06ed2c6 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-2021 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..b3a10c3 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-2021 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..1d4e73d 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-2021 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..dc6e10d 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-2021 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..e7fe358 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-2021 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..7fc74c9 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-2021 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..ca08192 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-2021 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..e21a687
--- /dev/null
+++ b/gl/m4/minmax.m4
@@ -0,0 +1,44 @@
1# minmax.m4 serial 4
2dnl Copyright (C) 2005, 2009-2021 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..721189a 100644
--- a/gl/m4/mktime.m4
+++ b/gl/m4/mktime.m4
@@ -1,5 +1,5 @@
1# serial 25 1# serial 36
2dnl Copyright (C) 2002-2003, 2005-2007, 2009-2013 Free Software Foundation, 2dnl Copyright (C) 2002-2003, 2005-2007, 2009-2021 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;
@@ -169,7 +188,6 @@ main ()
169 time_t t, delta; 188 time_t t, delta;
170 int i, j; 189 int i, j;
171 int time_t_signed_magnitude = (time_t) ~ (time_t) 0 < (time_t) -1; 190 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 191
174#if HAVE_DECL_ALARM 192#if HAVE_DECL_ALARM
175 /* This test makes some buggy mktime implementations loop. 193 /* This test makes some buggy mktime implementations loop.
@@ -179,11 +197,11 @@ main ()
179 alarm (60); 197 alarm (60);
180#endif 198#endif
181 199
182 time_t_max = (! time_t_signed 200 time_t_max = (! TIME_T_IS_SIGNED
183 ? (time_t) -1 201 ? (time_t) -1
184 : ((((time_t) 1 << (sizeof (time_t) * CHAR_BIT - 2)) - 1) 202 : ((((time_t) 1 << (sizeof (time_t) * CHAR_BIT - 2)) - 1)
185 * 2 + 1)); 203 * 2 + 1));
186 time_t_min = (! time_t_signed 204 time_t_min = (! TIME_T_IS_SIGNED
187 ? (time_t) 0 205 ? (time_t) 0
188 : time_t_signed_magnitude 206 : time_t_signed_magnitude
189 ? ~ (time_t) 0 207 ? ~ (time_t) 0
@@ -222,31 +240,58 @@ main ()
222 result |= 64; 240 result |= 64;
223 return result; 241 return result;
224}]])], 242}]])],
225 [gl_cv_func_working_mktime=yes], 243 [gl_cv_func_working_mktime=yes],
226 [gl_cv_func_working_mktime=no], 244 [gl_cv_func_working_mktime=no],
227 [gl_cv_func_working_mktime=no]) 245 [case "$host_os" in
246 # Guess no on native Windows.
247 mingw*) gl_cv_func_working_mktime="guessing no" ;;
248 *) gl_cv_func_working_mktime="$gl_cross_guess_normal" ;;
249 esac
250 ])
251 fi
228 ]) 252 ])
253])
254
255dnl Main macro of module 'mktime'.
256AC_DEFUN([gl_FUNC_MKTIME],
257[
258 AC_REQUIRE([gl_TIME_H_DEFAULTS])
259 AC_REQUIRE([AC_CANONICAL_HOST])
260 AC_REQUIRE([gl_FUNC_MKTIME_WORKS])
229 261
230 if test $gl_cv_func_working_mktime = no; then 262 REPLACE_MKTIME=0
263 if test "$gl_cv_func_working_mktime" != yes; then
231 REPLACE_MKTIME=1 264 REPLACE_MKTIME=1
232 else 265 AC_DEFINE([NEED_MKTIME_WORKING], [1],
233 REPLACE_MKTIME=0 266 [Define if the compilation of mktime.c should define 'mktime'
267 with the algorithmic workarounds.])
234 fi 268 fi
269 case "$host_os" in
270 mingw*)
271 REPLACE_MKTIME=1
272 AC_DEFINE([NEED_MKTIME_WINDOWS], [1],
273 [Define if the compilation of mktime.c should define 'mktime'
274 with the native Windows TZ workaround.])
275 ;;
276 esac
235]) 277])
236 278
279dnl Main macro of module 'mktime-internal'.
237AC_DEFUN([gl_FUNC_MKTIME_INTERNAL], [ 280AC_DEFUN([gl_FUNC_MKTIME_INTERNAL], [
238 AC_REQUIRE([gl_FUNC_MKTIME]) 281 AC_REQUIRE([gl_FUNC_MKTIME_WORKS])
239 if test $REPLACE_MKTIME = 0; then 282
240 dnl BeOS has __mktime_internal in libc, but other platforms don't. 283 WANT_MKTIME_INTERNAL=0
241 AC_CHECK_FUNC([__mktime_internal], 284 dnl BeOS has __mktime_internal in libc, but other platforms don't.
242 [AC_DEFINE([mktime_internal], [__mktime_internal], 285 AC_CHECK_FUNC([__mktime_internal],
243 [Define to the real name of the mktime_internal function.]) 286 [AC_DEFINE([mktime_internal], [__mktime_internal],
244 ], 287 [Define to the real name of the mktime_internal function.])
245 [dnl mktime works but it doesn't export __mktime_internal, 288 ],
246 dnl so we need to substitute our own mktime implementation. 289 [dnl mktime works but it doesn't export __mktime_internal,
247 REPLACE_MKTIME=1 290 dnl so we need to substitute our own mktime implementation.
248 ]) 291 WANT_MKTIME_INTERNAL=1
249 fi 292 AC_DEFINE([NEED_MKTIME_INTERNAL], [1],
293 [Define if the compilation of mktime.c should define 'mktime_internal'.])
294 ])
250]) 295])
251 296
252# Prerequisites of lib/mktime.c. 297# Prerequisites of lib/mktime.c.
diff --git a/gl/m4/mmap-anon.m4 b/gl/m4/mmap-anon.m4
index 9b60ddf..e47aa2d 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-2021 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..3bd4b89
--- /dev/null
+++ b/gl/m4/mode_t.m4
@@ -0,0 +1,26 @@
1# mode_t.m4 serial 2
2dnl Copyright (C) 2009-2021 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..49029ed 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-2021 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..3ba5b4e 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-2021 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..aae25ce 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-2021 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..f1678d9 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-2021 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..eb7c3b8 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-2021 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..c555596 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 5
2dnl Copyright (C) 2006-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2006-2021 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
diff --git a/gl/m4/nl_langinfo.m4 b/gl/m4/nl_langinfo.m4
index 25e2101..6ad32c8 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-2021 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
index 8f8a147..f4f6b80 100644
--- a/gl/m4/nls.m4
+++ b/gl/m4/nls.m4
@@ -1,17 +1,17 @@
1# nls.m4 serial 5 (gettext-0.18) 1# nls.m4 serial 6 (gettext-0.20.2)
2dnl Copyright (C) 1995-2003, 2005-2006, 2008-2013 Free Software Foundation, 2dnl Copyright (C) 1995-2003, 2005-2006, 2008-2014, 2016, 2019-2021 Free
3dnl Inc. 3dnl 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.
7dnl 7dnl
8dnl This file can can be used in projects which are not available under 8dnl This file can be used in projects which are not available under
9dnl the GNU General Public License or the GNU Library General Public 9dnl the GNU General Public License or the GNU Lesser General Public
10dnl License but which still want to provide support for the GNU gettext 10dnl License but which still want to provide support for the GNU gettext
11dnl functionality. 11dnl functionality.
12dnl Please note that the actual code of the GNU gettext library is covered 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 13dnl by the GNU Lesser General Public License, and the rest of the GNU
14dnl gettext package package is covered by the GNU General Public License. 14dnl gettext package is covered by the GNU General Public License.
15dnl They are *not* in the public domain. 15dnl They are *not* in the public domain.
16 16
17dnl Authors: 17dnl Authors:
diff --git a/gl/m4/nocrash.m4 b/gl/m4/nocrash.m4
index 105b884..27412cd 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-2021 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..bdec43c 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-2021 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..542a90f
--- /dev/null
+++ b/gl/m4/open-cloexec.m4
@@ -0,0 +1,21 @@
1# Test whether O_CLOEXEC is defined.
2
3dnl Copyright 2017-2021 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..e619039
--- /dev/null
+++ b/gl/m4/open-slash.m4
@@ -0,0 +1,60 @@
1# open-slash.m4 serial 2
2dnl Copyright (C) 2007-2021 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..c634386
--- /dev/null
+++ b/gl/m4/open.m4
@@ -0,0 +1,56 @@
1# open.m4 serial 15
2dnl Copyright (C) 2007-2021 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..e67c656
--- /dev/null
+++ b/gl/m4/pathmax.m4
@@ -0,0 +1,42 @@
1# pathmax.m4 serial 11
2dnl Copyright (C) 2002-2003, 2005-2006, 2009-2021 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..b7650a1
--- /dev/null
+++ b/gl/m4/pid_t.m4
@@ -0,0 +1,38 @@
1# pid_t.m4 serial 4
2dnl Copyright (C) 2020-2021 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
index 1c70b6c..66bea3e 100644
--- a/gl/m4/po.m4
+++ b/gl/m4/po.m4
@@ -1,16 +1,16 @@
1# po.m4 serial 21 (gettext-0.18.3) 1# po.m4 serial 31 (gettext-0.20.2)
2dnl Copyright (C) 1995-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 1995-2014, 2016, 2018-2021 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.
6dnl 6dnl
7dnl This file can can be used in projects which are not available under 7dnl This file can be used in projects which are not available under
8dnl the GNU General Public License or the GNU Library General Public 8dnl the GNU General Public License or the GNU Lesser General Public
9dnl License but which still want to provide support for the GNU gettext 9dnl License but which still want to provide support for the GNU gettext
10dnl functionality. 10dnl functionality.
11dnl Please note that the actual code of the GNU gettext library is covered 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 12dnl by the GNU Lesser General Public License, and the rest of the GNU
13dnl gettext package package is covered by the GNU General Public License. 13dnl gettext package is covered by the GNU General Public License.
14dnl They are *not* in the public domain. 14dnl They are *not* in the public domain.
15 15
16dnl Authors: 16dnl Authors:
@@ -30,7 +30,7 @@ AC_DEFUN([AM_PO_SUBDIRS],
30 30
31 dnl Release version of the gettext macros. This is used to ensure that 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. 32 dnl the gettext macros and po/Makefile.in.in are in sync.
33 AC_SUBST([GETTEXT_MACRO_VERSION], [0.18]) 33 AC_SUBST([GETTEXT_MACRO_VERSION], [0.20])
34 34
35 dnl Perform the following tests also if --disable-nls has been given, 35 dnl Perform the following tests also if --disable-nls has been given,
36 dnl because they are needed for "make dist" to work. 36 dnl because they are needed for "make dist" to work.
@@ -46,13 +46,6 @@ AC_DEFUN([AM_PO_SUBDIRS],
46 46
47 dnl Test whether it is GNU msgfmt >= 0.15. 47 dnl Test whether it is GNU msgfmt >= 0.15.
48changequote(,)dnl 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 49 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=: ;; 50 '' | 0.[0-9] | 0.[0-9].* | 0.1[0-4] | 0.1[0-4].*) GMSGFMT_015=: ;;
58 *) GMSGFMT_015=$GMSGFMT ;; 51 *) GMSGFMT_015=$GMSGFMT ;;
@@ -83,11 +76,21 @@ changequote([,])dnl
83 AM_PATH_PROG_WITH_TEST(MSGMERGE, msgmerge, 76 AM_PATH_PROG_WITH_TEST(MSGMERGE, msgmerge,
84 [$ac_dir/$ac_word --update -q /dev/null /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1], :) 77 [$ac_dir/$ac_word --update -q /dev/null /dev/null >&]AS_MESSAGE_LOG_FD[ 2>&1], :)
85 78
86 dnl Installation directories. 79 dnl Test whether it is GNU msgmerge >= 0.20.
87 dnl Autoconf >= 2.60 defines localedir. For older versions of autoconf, we 80 if LC_ALL=C $MSGMERGE --help | grep ' --for-msgfmt ' >/dev/null; then
88 dnl have to define it here, so that it can be used in po/Makefile. 81 MSGMERGE_FOR_MSGFMT_OPTION='--for-msgfmt'
89 test -n "$localedir" || localedir='${datadir}/locale' 82 else
90 AC_SUBST([localedir]) 83 dnl Test whether it is GNU msgmerge >= 0.12.
84 if LC_ALL=C $MSGMERGE --help | grep ' --no-fuzzy-matching ' >/dev/null; then
85 MSGMERGE_FOR_MSGFMT_OPTION='--no-fuzzy-matching --no-location --quiet'
86 else
87 dnl With these old versions, $(MSGMERGE) $(MSGMERGE_FOR_MSGFMT_OPTION) is
88 dnl slow. But this is not a big problem, as such old gettext versions are
89 dnl hardly in use any more.
90 MSGMERGE_FOR_MSGFMT_OPTION='--no-location --quiet'
91 fi
92 fi
93 AC_SUBST([MSGMERGE_FOR_MSGFMT_OPTION])
91 94
92 dnl Support for AM_XGETTEXT_OPTION. 95 dnl Support for AM_XGETTEXT_OPTION.
93 test -n "${XGETTEXT_EXTRA_OPTIONS+set}" || XGETTEXT_EXTRA_OPTIONS= 96 test -n "${XGETTEXT_EXTRA_OPTIONS+set}" || XGETTEXT_EXTRA_OPTIONS=
@@ -130,14 +133,11 @@ changequote([,])dnl
130 if test -n "$OBSOLETE_ALL_LINGUAS"; then 133 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" 134 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 135 fi
133 ALL_LINGUAS_=`sed -e "/^#/d" -e "s/#.*//" "$ac_given_srcdir/$ac_dir/LINGUAS"` 136 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 POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS"
137 else 138 else
138 # The set of available languages was given in configure.in. 139 # The set of available languages was given in configure.in.
139 # Hide the ALL_LINGUAS assignment from automake < 1.5. 140 ALL_LINGUAS=$OBSOLETE_ALL_LINGUAS
140 eval 'ALL_LINGUAS''=$OBSOLETE_ALL_LINGUAS'
141 fi 141 fi
142 # Compute POFILES 142 # Compute POFILES
143 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po) 143 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po)
@@ -208,9 +208,8 @@ changequote([,])dnl
208 esac 208 esac
209 done]], 209 done]],
210 [# Capture the value of obsolete ALL_LINGUAS because we need it to compute 210 [# Capture the value of obsolete ALL_LINGUAS because we need it to compute
211 # POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES, CATALOGS. But hide it 211 # POFILES, UPDATEPOFILES, DUMMYPOFILES, GMOFILES, CATALOGS.
212 # from automake < 1.5. 212 OBSOLETE_ALL_LINGUAS="$ALL_LINGUAS"
213 eval 'OBSOLETE_ALL_LINGUAS''="$ALL_LINGUAS"'
214 # Capture the value of LINGUAS because we need it to compute CATALOGS. 213 # Capture the value of LINGUAS because we need it to compute CATALOGS.
215 LINGUAS="${LINGUAS-%UNSET%}" 214 LINGUAS="${LINGUAS-%UNSET%}"
216 ]) 215 ])
@@ -311,15 +310,13 @@ changequote([,])dnl
311 fi 310 fi
312 if test -f "$ac_given_srcdir/$ac_dir/LINGUAS"; then 311 if test -f "$ac_given_srcdir/$ac_dir/LINGUAS"; then
313 # The LINGUAS file contains the set of available languages. 312 # The LINGUAS file contains the set of available languages.
314 ALL_LINGUAS_=`sed -e "/^#/d" -e "s/#.*//" "$ac_given_srcdir/$ac_dir/LINGUAS"` 313 ALL_LINGUAS=`sed -e "/^#/d" -e "s/#.*//" "$ac_given_srcdir/$ac_dir/LINGUAS"`
315 POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS" 314 POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS"
316 else 315 else
317 # Set ALL_LINGUAS to the value of the Makefile variable LINGUAS. 316 # 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'` 317 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"` 318 ALL_LINGUAS=`sed -n -e "$sed_x_LINGUAS" < "$ac_file"`
320 fi 319 fi
321 # Hide the ALL_LINGUAS assignment from automake < 1.5.
322 eval 'ALL_LINGUAS''=$ALL_LINGUAS_'
323 # Compute POFILES 320 # Compute POFILES
324 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po) 321 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po)
325 # Compute UPDATEPOFILES 322 # Compute UPDATEPOFILES
@@ -329,9 +326,9 @@ changequote([,])dnl
329 # Compute GMOFILES 326 # Compute GMOFILES
330 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).gmo) 327 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).gmo)
331 # Compute PROPERTIESFILES 328 # Compute PROPERTIESFILES
332 # as $(foreach lang, $(ALL_LINGUAS), $(top_srcdir)/$(DOMAIN)_$(lang).properties) 329 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(DOMAIN)_$(lang).properties)
333 # Compute CLASSFILES 330 # Compute CLASSFILES
334 # as $(foreach lang, $(ALL_LINGUAS), $(top_srcdir)/$(DOMAIN)_$(lang).class) 331 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(DOMAIN)_$(lang).class)
335 # Compute QMFILES 332 # Compute QMFILES
336 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).qm) 333 # as $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).qm)
337 # Compute MSGFILES 334 # Compute MSGFILES
@@ -356,8 +353,8 @@ changequote([,])dnl
356 UPDATEPOFILES="$UPDATEPOFILES $lang.po-update" 353 UPDATEPOFILES="$UPDATEPOFILES $lang.po-update"
357 DUMMYPOFILES="$DUMMYPOFILES $lang.nop" 354 DUMMYPOFILES="$DUMMYPOFILES $lang.nop"
358 GMOFILES="$GMOFILES $srcdirpre$lang.gmo" 355 GMOFILES="$GMOFILES $srcdirpre$lang.gmo"
359 PROPERTIESFILES="$PROPERTIESFILES \$(top_srcdir)/\$(DOMAIN)_$lang.properties" 356 PROPERTIESFILES="$PROPERTIESFILES \$(srcdir)/\$(DOMAIN)_$lang.properties"
360 CLASSFILES="$CLASSFILES \$(top_srcdir)/\$(DOMAIN)_$lang.class" 357 CLASSFILES="$CLASSFILES \$(srcdir)/\$(DOMAIN)_$lang.class"
361 QMFILES="$QMFILES $srcdirpre$lang.qm" 358 QMFILES="$QMFILES $srcdirpre$lang.qm"
362 frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'` 359 frobbedlang=`echo $lang | sed -e 's/\..*$//' -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
363 MSGFILES="$MSGFILES $srcdirpre$frobbedlang.msg" 360 MSGFILES="$MSGFILES $srcdirpre$frobbedlang.msg"
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..284c7c5 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-2021 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
index 7b39123..9e8823c 100644
--- a/gl/m4/progtest.m4
+++ b/gl/m4/progtest.m4
@@ -1,22 +1,22 @@
1# progtest.m4 serial 7 (gettext-0.18.2) 1# progtest.m4 serial 9 (gettext-0.21.1)
2dnl Copyright (C) 1996-2003, 2005, 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 1996-2003, 2005, 2008-2021 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.
6dnl 6dnl
7dnl This file can can be used in projects which are not available under 7dnl This file can be used in projects which are not available under
8dnl the GNU General Public License or the GNU Library General Public 8dnl the GNU General Public License or the GNU Lesser General Public
9dnl License but which still want to provide support for the GNU gettext 9dnl License but which still want to provide support for the GNU gettext
10dnl functionality. 10dnl functionality.
11dnl Please note that the actual code of the GNU gettext library is covered 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 12dnl by the GNU Lesser General Public License, and the rest of the GNU
13dnl gettext package package is covered by the GNU General Public License. 13dnl gettext package is covered by the GNU General Public License.
14dnl They are *not* in the public domain. 14dnl They are *not* in the public domain.
15 15
16dnl Authors: 16dnl Authors:
17dnl Ulrich Drepper <drepper@cygnus.com>, 1996. 17dnl Ulrich Drepper <drepper@cygnus.com>, 1996.
18 18
19AC_PREREQ([2.50]) 19AC_PREREQ([2.53])
20 20
21# Search path for a program which passes the given test. 21# Search path for a program which passes the given test.
22 22
@@ -61,7 +61,7 @@ AC_CACHE_VAL([ac_cv_path_$1],
61 ;; 61 ;;
62 *) 62 *)
63 ac_save_IFS="$IFS"; IFS=$PATH_SEPARATOR 63 ac_save_IFS="$IFS"; IFS=$PATH_SEPARATOR
64 for ac_dir in ifelse([$5], , $PATH, [$5]); do 64 for ac_dir in m4_if([$5], , $PATH, [$5]); do
65 IFS="$ac_save_IFS" 65 IFS="$ac_save_IFS"
66 test -z "$ac_dir" && ac_dir=. 66 test -z "$ac_dir" && ac_dir=.
67 for ac_exec_ext in '' $ac_executable_extensions; do 67 for ac_exec_ext in '' $ac_executable_extensions; do
@@ -77,12 +77,12 @@ AC_CACHE_VAL([ac_cv_path_$1],
77 IFS="$ac_save_IFS" 77 IFS="$ac_save_IFS"
78dnl If no 4th arg is given, leave the cache variable unset, 78dnl If no 4th arg is given, leave the cache variable unset,
79dnl so AC_PATH_PROGS will keep looking. 79dnl so AC_PATH_PROGS will keep looking.
80ifelse([$4], , , [ test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4" 80m4_if([$4], , , [ test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4"
81])dnl 81])dnl
82 ;; 82 ;;
83esac])dnl 83esac])dnl
84$1="$ac_cv_path_$1" 84$1="$ac_cv_path_$1"
85if test ifelse([$4], , [-n "[$]$1"], ["[$]$1" != "$4"]); then 85if test m4_if([$4], , [-n "[$]$1"], ["[$]$1" != "$4"]); then
86 AC_MSG_RESULT([$][$1]) 86 AC_MSG_RESULT([$][$1])
87else 87else
88 AC_MSG_RESULT([no]) 88 AC_MSG_RESULT([no])
diff --git a/gl/m4/pthread_rwlock_rdlock.m4 b/gl/m4/pthread_rwlock_rdlock.m4
new file mode 100644
index 0000000..a5fbead
--- /dev/null
+++ b/gl/m4/pthread_rwlock_rdlock.m4
@@ -0,0 +1,185 @@
1# pthread_rwlock_rdlock.m4 serial 4
2dnl Copyright (C) 2017-2021 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..0abc418
--- /dev/null
+++ b/gl/m4/realloc.m4
@@ -0,0 +1,63 @@
1# realloc.m4 serial 24
2dnl Copyright (C) 2007, 2009-2021 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 = 0; then
47 _AC_FUNC_REALLOC_IF([], [REPLACE_REALLOC=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 = 1; then
61 REPLACE_REALLOC=1
62 fi
63])
diff --git a/gl/m4/reallocarray.m4 b/gl/m4/reallocarray.m4
new file mode 100644
index 0000000..9d8a626
--- /dev/null
+++ b/gl/m4/reallocarray.m4
@@ -0,0 +1,23 @@
1# reallocarray.m4 serial 3
2dnl Copyright (C) 2017-2021 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..1c7e562 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-2021 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..9bc3bcd 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-2021 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..f79a278 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-2021 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..2c958ed
--- /dev/null
+++ b/gl/m4/setlocale_null.m4
@@ -0,0 +1,98 @@
1# setlocale_null.m4 serial 5
2dnl Copyright (C) 2019-2021 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/sha1.m4 b/gl/m4/sha1.m4
index 21c775e..fdba7a6 100644
--- a/gl/m4/sha1.m4
+++ b/gl/m4/sha1.m4
@@ -1,5 +1,5 @@
1# sha1.m4 serial 11 1# sha1.m4 serial 12
2dnl Copyright (C) 2002-2006, 2008-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2002-2006, 2008-2021 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,5 +8,7 @@ AC_DEFUN([gl_SHA1],
8[ 8[
9 dnl Prerequisites of lib/sha1.c. 9 dnl Prerequisites of lib/sha1.c.
10 AC_REQUIRE([gl_BIGENDIAN]) 10 AC_REQUIRE([gl_BIGENDIAN])
11 : 11
12 dnl Determine HAVE_OPENSSL_SHA1 and LIB_CRYPTO
13 gl_CRYPTO_CHECK([SHA1])
12]) 14])
diff --git a/gl/m4/size_max.m4 b/gl/m4/size_max.m4
index 4b247ab..1d41ce9 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-2021 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..8520994 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-2021 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..0f8a082 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-2021 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..02b43b6 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-2021 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..eca1d1b 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-2021 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..17e14c7 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-2021 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..f0ed509 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-2021 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..df1c2a7
--- /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-2021 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..9bcdb72
--- /dev/null
+++ b/gl/m4/stat.m4
@@ -0,0 +1,85 @@
1# serial 18
2
3# Copyright (C) 2009-2021 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..7b1a042
--- /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-2021 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..e22d7f7 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 stdalign.h that conforms to C11.
2 2
3dnl Copyright 2011-2013 Free Software Foundation, Inc. 3dnl Copyright 2011-2021 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.
@@ -13,12 +13,13 @@ AC_DEFUN([gl_STDALIGN_H],
13 [gl_cv_header_working_stdalign_h], 13 [gl_cv_header_working_stdalign_h],
14 [AC_COMPILE_IFELSE( 14 [AC_COMPILE_IFELSE(
15 [AC_LANG_PROGRAM( 15 [AC_LANG_PROGRAM(
16 [[#include <stdalign.h> 16 [[#include <stdint.h>
17 #include <stdalign.h>
17 #include <stddef.h> 18 #include <stddef.h>
18 19
19 /* Test that alignof yields a result consistent with offsetof. 20 /* Test that alignof yields a result consistent with offsetof.
20 This catches GCC bug 52023 21 This catches GCC bug 52023
21 <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>. */ 22 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>. */
22 #ifdef __cplusplus 23 #ifdef __cplusplus
23 template <class t> struct alignof_helper { char a; t b; }; 24 template <class t> struct alignof_helper { char a; t b; };
24 # define ao(type) offsetof (alignof_helper<type>, b) 25 # define ao(type) offsetof (alignof_helper<type>, b)
@@ -32,8 +33,13 @@ AC_DEFUN([gl_STDALIGN_H],
32 /* Test _Alignas only on platforms where gnulib can help. */ 33 /* Test _Alignas only on platforms where gnulib can help. */
33 #if \ 34 #if \
34 ((defined __cplusplus && 201103 <= __cplusplus) \ 35 ((defined __cplusplus && 201103 <= __cplusplus) \
35 || __GNUC__ || __IBMC__ || __IBMCPP__ || __ICC \ 36 || (__TINYC__ && defined __attribute__) \
36 || 0x5110 <= __SUNPRO_C || 1300 <= _MSC_VER) 37 || (defined __APPLE__ && defined __MACH__ \
38 ? 4 < __GNUC__ + (1 <= __GNUC_MINOR__) \
39 : __GNUC__) \
40 || (__ia64 && (61200 <= __HP_cc || 61200 <= __HP_aCC)) \
41 || __ICC || 0x590 <= __SUNPRO_C || 0x0600 <= __xlC__ \
42 || 1300 <= _MSC_VER)
37 struct alignas_test { char c; char alignas (8) alignas_8; }; 43 struct alignas_test { char c; char alignas (8) alignas_8; };
38 char test_alignas[offsetof (struct alignas_test, alignas_8) == 8 44 char test_alignas[offsetof (struct alignas_test, alignas_8) == 8
39 ? 1 : -1]; 45 ? 1 : -1];
diff --git a/gl/m4/stdbool.m4 b/gl/m4/stdbool.m4
index 80d5559..3169779 100644
--- a/gl/m4/stdbool.m4
+++ b/gl/m4/stdbool.m4
@@ -1,22 +1,36 @@
1# Check for stdbool.h that conforms to C99. 1# Check for stdbool.h that conforms to C99.
2 2
3dnl Copyright (C) 2002-2006, 2009-2013 Free Software Foundation, Inc. 3dnl Copyright (C) 2002-2006, 2009-2021 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
8#serial 5 8#serial 8
9 9
10# Prepare for substituting <stdbool.h> if it is not supported. 10# Prepare for substituting <stdbool.h> if it is not supported.
11 11
12AC_DEFUN([AM_STDBOOL_H], 12AC_DEFUN([AM_STDBOOL_H],
13[ 13[
14 AC_REQUIRE([AC_CHECK_HEADER_STDBOOL]) 14 AC_REQUIRE([AC_CHECK_HEADER_STDBOOL])
15 AC_REQUIRE([AC_CANONICAL_HOST])
15 16
16 # Define two additional variables used in the Makefile substitution. 17 dnl On some platforms, <stdbool.h> does not exist or does not conform to C99.
17 18 dnl On Solaris 10 with CC=cc CXX=CC, <stdbool.h> exists but is not usable
19 dnl in C++ mode (and no <cstdbool> exists). In this case, we use our
20 dnl replacement, also in C mode (for binary compatibility between C and C++).
18 if test "$ac_cv_header_stdbool_h" = yes; then 21 if test "$ac_cv_header_stdbool_h" = yes; then
19 STDBOOL_H='' 22 case "$host_os" in
23 solaris*)
24 if test -z "$GCC"; then
25 STDBOOL_H='stdbool.h'
26 else
27 STDBOOL_H=''
28 fi
29 ;;
30 *)
31 STDBOOL_H=''
32 ;;
33 esac
20 else 34 else
21 STDBOOL_H='stdbool.h' 35 STDBOOL_H='stdbool.h'
22 fi 36 fi
@@ -43,56 +57,64 @@ AC_DEFUN([AC_CHECK_HEADER_STDBOOL],
43 [AC_LANG_PROGRAM( 57 [AC_LANG_PROGRAM(
44 [[ 58 [[
45 #include <stdbool.h> 59 #include <stdbool.h>
46 #ifndef bool 60
47 "error: bool is not defined" 61 #ifdef __cplusplus
48 #endif 62 typedef bool Bool;
49 #ifndef false 63 #else
50 "error: false is not defined" 64 typedef _Bool Bool;
51 #endif 65 #ifndef bool
52 #if false 66 "error: bool is not defined"
53 "error: false is not 0" 67 #endif
54 #endif 68 #ifndef false
55 #ifndef true 69 "error: false is not defined"
56 "error: true is not defined" 70 #endif
57 #endif 71 #if false
58 #if true != 1 72 "error: false is not 0"
59 "error: true is not 1" 73 #endif
74 #ifndef true
75 "error: true is not defined"
76 #endif
77 #if true != 1
78 "error: true is not 1"
79 #endif
60 #endif 80 #endif
81
61 #ifndef __bool_true_false_are_defined 82 #ifndef __bool_true_false_are_defined
62 "error: __bool_true_false_are_defined is not defined" 83 "error: __bool_true_false_are_defined is not defined"
63 #endif 84 #endif
64 85
65 struct s { _Bool s: 1; _Bool t; } s; 86 struct s { Bool s: 1; Bool t; bool u: 1; bool v; } s;
66 87
67 char a[true == 1 ? 1 : -1]; 88 char a[true == 1 ? 1 : -1];
68 char b[false == 0 ? 1 : -1]; 89 char b[false == 0 ? 1 : -1];
69 char c[__bool_true_false_are_defined == 1 ? 1 : -1]; 90 char c[__bool_true_false_are_defined == 1 ? 1 : -1];
70 char d[(bool) 0.5 == true ? 1 : -1]; 91 char d[(bool) 0.5 == true ? 1 : -1];
71 /* See body of main program for 'e'. */ 92 /* See body of main program for 'e'. */
72 char f[(_Bool) 0.0 == false ? 1 : -1]; 93 char f[(Bool) 0.0 == false ? 1 : -1];
73 char g[true]; 94 char g[true];
74 char h[sizeof (_Bool)]; 95 char h[sizeof (Bool)];
75 char i[sizeof s.t]; 96 char i[sizeof s.t];
76 enum { j = false, k = true, l = false * true, m = true * 256 }; 97 enum { j = false, k = true, l = false * true, m = true * 256 };
77 /* The following fails for 98 /* The following fails for
78 HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */ 99 HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
79 _Bool n[m]; 100 Bool n[m];
80 char o[sizeof n == m * sizeof n[0] ? 1 : -1]; 101 char o[sizeof n == m * sizeof n[0] ? 1 : -1];
81 char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1]; 102 char p[-1 - (Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
82 /* Catch a bug in an HP-UX C compiler. See 103 /* Catch a bug in an HP-UX C compiler. See
83 http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html 104 https://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
84 http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html 105 https://lists.gnu.org/r/bug-coreutils/2005-11/msg00161.html
85 */ 106 */
86 _Bool q = true; 107 Bool q = true;
87 _Bool *pq = &q; 108 Bool *pq = &q;
109 bool *qq = &q;
88 ]], 110 ]],
89 [[ 111 [[
90 bool e = &s; 112 bool e = &s;
91 *pq |= q; 113 *pq |= q; *pq |= ! q;
92 *pq |= ! q; 114 *qq |= q; *qq |= ! q;
93 /* Refer to every declared value, to avoid compiler optimizations. */ 115 /* Refer to every declared value, to avoid compiler optimizations. */
94 return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l 116 return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
95 + !m + !n + !o + !p + !q + !pq); 117 + !m + !n + !o + !p + !q + !pq + !qq);
96 ]])], 118 ]])],
97 [ac_cv_header_stdbool_h=yes], 119 [ac_cv_header_stdbool_h=yes],
98 [ac_cv_header_stdbool_h=no])]) 120 [ac_cv_header_stdbool_h=no])])
diff --git a/gl/m4/stddef_h.m4 b/gl/m4/stddef_h.m4
index 5da8ab1..1303d2e 100644
--- a/gl/m4/stddef_h.m4
+++ b/gl/m4/stddef_h.m4
@@ -1,19 +1,54 @@
1dnl A placeholder for POSIX 2008 <stddef.h>, for platforms that have issues. 1# stddef_h.m4 serial 11
2# stddef_h.m4 serial 4 2dnl Copyright (C) 2009-2021 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])
13
14 dnl Persuade OpenBSD <stddef.h> to declare max_align_t.
15 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16
12 STDDEF_H= 17 STDDEF_H=
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 [[#include <stddef.h>
26 unsigned int s = sizeof (max_align_t);
27 #if defined __GNUC__ || defined __clang__ || defined __IBM__ALIGNOF__
28 int check1[2 * (__alignof__ (double) <= __alignof__ (max_align_t)) - 1];
29 int check2[2 * (__alignof__ (long double) <= __alignof__ (max_align_t)) - 1];
30 #endif
31 typedef struct { char a; max_align_t b; } max_helper;
32 typedef struct { char a; long b; } long_helper;
33 typedef struct { char a; double b; } double_helper;
34 typedef struct { char a; long double b; } long_double_helper;
35 int check3[2 * (offsetof (long_helper, b) <= offsetof (max_helper, b)) - 1];
36 int check4[2 * (offsetof (double_helper, b) <= offsetof (max_helper, b)) - 1];
37 int check5[2 * (offsetof (long_double_helper, b) <= offsetof (max_helper, b)) - 1];
38 ]])],
39 [gl_cv_type_max_align_t=yes],
40 [gl_cv_type_max_align_t=no])
41 ])
42 if test $gl_cv_type_max_align_t = no; then
43 HAVE_MAX_ALIGN_T=0
44 STDDEF_H=stddef.h
45 fi
46
13 if test $gt_cv_c_wchar_t = no; then 47 if test $gt_cv_c_wchar_t = no; then
14 HAVE_WCHAR_T=0 48 HAVE_WCHAR_T=0
15 STDDEF_H=stddef.h 49 STDDEF_H=stddef.h
16 fi 50 fi
51
17 AC_CACHE_CHECK([whether NULL can be used in arbitrary expressions], 52 AC_CACHE_CHECK([whether NULL can be used in arbitrary expressions],
18 [gl_cv_decl_null_works], 53 [gl_cv_decl_null_works],
19 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stddef.h> 54 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stddef.h>
@@ -25,6 +60,7 @@ AC_DEFUN([gl_STDDEF_H],
25 REPLACE_NULL=1 60 REPLACE_NULL=1
26 STDDEF_H=stddef.h 61 STDDEF_H=stddef.h
27 fi 62 fi
63
28 AC_SUBST([STDDEF_H]) 64 AC_SUBST([STDDEF_H])
29 AM_CONDITIONAL([GL_GENERATE_STDDEF_H], [test -n "$STDDEF_H"]) 65 AM_CONDITIONAL([GL_GENERATE_STDDEF_H], [test -n "$STDDEF_H"])
30 if test -n "$STDDEF_H"; then 66 if test -n "$STDDEF_H"; then
@@ -32,16 +68,32 @@ AC_DEFUN([gl_STDDEF_H],
32 fi 68 fi
33]) 69])
34 70
71# gl_STDDEF_MODULE_INDICATOR([modulename])
72# sets the shell variable that indicates the presence of the given module
73# to a C preprocessor expression that will evaluate to 1.
74# This macro invocation must not occur in macros that are AC_REQUIREd.
35AC_DEFUN([gl_STDDEF_MODULE_INDICATOR], 75AC_DEFUN([gl_STDDEF_MODULE_INDICATOR],
36[ 76[
37 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 77 dnl Ensure to expand the default settings once only.
38 AC_REQUIRE([gl_STDDEF_H_DEFAULTS]) 78 gl_STDDEF_H_REQUIRE_DEFAULTS
39 gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 79 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
40]) 80])
41 81
82# Initializes the default values for AC_SUBSTed shell variables.
83# This macro must not be AC_REQUIREd. It must only be invoked, and only
84# outside of macros or in macros that are not AC_REQUIREd.
85AC_DEFUN([gl_STDDEF_H_REQUIRE_DEFAULTS],
86[
87 m4_defun(GL_MODULE_INDICATOR_PREFIX[_STDDEF_H_MODULE_INDICATOR_DEFAULTS], [
88 ])
89 m4_require(GL_MODULE_INDICATOR_PREFIX[_STDDEF_H_MODULE_INDICATOR_DEFAULTS])
90 AC_REQUIRE([gl_STDDEF_H_DEFAULTS])
91])
92
42AC_DEFUN([gl_STDDEF_H_DEFAULTS], 93AC_DEFUN([gl_STDDEF_H_DEFAULTS],
43[ 94[
44 dnl Assume proper GNU behavior unless another module says otherwise. 95 dnl Assume proper GNU behavior unless another module says otherwise.
45 REPLACE_NULL=0; AC_SUBST([REPLACE_NULL]) 96 REPLACE_NULL=0; AC_SUBST([REPLACE_NULL])
97 HAVE_MAX_ALIGN_T=1; AC_SUBST([HAVE_MAX_ALIGN_T])
46 HAVE_WCHAR_T=1; AC_SUBST([HAVE_WCHAR_T]) 98 HAVE_WCHAR_T=1; AC_SUBST([HAVE_WCHAR_T])
47]) 99])
diff --git a/gl/m4/stdint.m4 b/gl/m4/stdint.m4
index 27cdcdb..2eb1652 100644
--- a/gl/m4/stdint.m4
+++ b/gl/m4/stdint.m4
@@ -1,5 +1,5 @@
1# stdint.m4 serial 43 1# stdint.m4 serial 60
2dnl Copyright (C) 2001-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2001-2021 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,34 +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
299 STDINT_H=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 STDINT_H=
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])
303 AC_SUBST([STDINT_H]) 367 AC_SUBST([STDINT_H])
304 AM_CONDITIONAL([GL_GENERATE_STDINT_H], [test -n "$STDINT_H"]) 368 AM_CONDITIONAL([GL_GENERATE_STDINT_H], [test -n "$STDINT_H"])
305]) 369])
@@ -429,13 +493,9 @@ AC_DEFUN([gl_INTEGER_TYPE_SUFFIX],
429dnl gl_STDINT_INCLUDES 493dnl gl_STDINT_INCLUDES
430AC_DEFUN([gl_STDINT_INCLUDES], 494AC_DEFUN([gl_STDINT_INCLUDES],
431[[ 495[[
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> 496 #include <stddef.h>
435 #include <signal.h> 497 #include <signal.h>
436 #if HAVE_WCHAR_H 498 #if HAVE_WCHAR_H
437 # include <stdio.h>
438 # include <time.h>
439 # include <wchar.h> 499 # include <wchar.h>
440 #endif 500 #endif
441]]) 501]])
@@ -467,18 +527,7 @@ AC_DEFUN([gl_STDINT_TYPE_PROPERTIES],
467 dnl requirement that wint_t is "unchanged by default argument promotions". 527 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. 528 dnl In this case gnulib's <wchar.h> and <wctype.h> override wint_t.
469 dnl Set the variable BITSIZEOF_WINT_T accordingly. 529 dnl Set the variable BITSIZEOF_WINT_T accordingly.
470 if test $BITSIZEOF_WINT_T -lt 32; then 530 if test $GNULIBHEADERS_OVERRIDE_WINT_T = 1; then
471 BITSIZEOF_WINT_T=32 531 BITSIZEOF_WINT_T=32
472 fi 532 fi
473]) 533])
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..18aa50a 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-2021 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..e704383 100644
--- a/gl/m4/stdio_h.m4
+++ b/gl/m4/stdio_h.m4
@@ -1,25 +1,45 @@
1# stdio_h.m4 serial 43 1# stdio_h.m4 serial 56
2dnl Copyright (C) 2007-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2007-2021 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
30 printf, "I64d") and fail for newer mingw (gnu printf, "lld"). */
31 #if (defined _WIN32 && ! defined __CYGWIN__) && \
32 (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
33 extern char PRIdMAX_probe[sizeof PRIdMAX == sizeof "I64d" ? 1 : -1];
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
23 dnl This ifdef is necessary to avoid an error "missing file lib/stdio-read.c" 43 dnl This ifdef is necessary to avoid an error "missing file lib/stdio-read.c"
24 dnl "expected source file, required through AC_LIBSOURCES, not found". It is 44 dnl "expected source file, required through AC_LIBSOURCES, not found". It is
25 dnl also an optimization, to avoid performing a configure check whose result 45 dnl also an optimization, to avoid performing a configure check whose result
@@ -33,18 +53,6 @@ AC_DEFUN([gl_STDIO_H],
33 fi 53 fi
34 ]) 54 ])
35 55
36 dnl No need to create extra modules for these functions. Everyone who uses
37 dnl <stdio.h> likely needs them.
38 GNULIB_FPRINTF=1
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" 56 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 57 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 58 dnl also an optimization, to avoid performing a configure check whose result
@@ -76,73 +84,103 @@ AC_DEFUN([gl_STDIO_H],
76 gl_WARN_ON_USE_PREPARE([[#include <stdio.h> 84 gl_WARN_ON_USE_PREPARE([[#include <stdio.h>
77 ]], [dprintf fpurge fseeko ftello getdelim getline gets pclose popen 85 ]], [dprintf fpurge fseeko ftello getdelim getline gets pclose popen
78 renameat snprintf tmpfile vdprintf vsnprintf]) 86 renameat snprintf tmpfile vdprintf vsnprintf])
87
88 AC_REQUIRE([AC_C_RESTRICT])
89
90 AC_CHECK_DECLS_ONCE([fcloseall])
91 if test $ac_cv_have_decl_fcloseall = no; then
92 HAVE_DECL_FCLOSEALL=0
93 fi
79]) 94])
80 95
96# gl_STDIO_MODULE_INDICATOR([modulename])
97# sets the shell variable that indicates the presence of the given module
98# to a C preprocessor expression that will evaluate to 1.
99# This macro invocation must not occur in macros that are AC_REQUIREd.
81AC_DEFUN([gl_STDIO_MODULE_INDICATOR], 100AC_DEFUN([gl_STDIO_MODULE_INDICATOR],
82[ 101[
83 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 102 dnl Ensure to expand the default settings once only.
84 AC_REQUIRE([gl_STDIO_H_DEFAULTS]) 103 gl_STDIO_H_REQUIRE_DEFAULTS
85 gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 104 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
86 dnl Define it also as a C macro, for the benefit of the unit tests. 105 dnl Define it also as a C macro, for the benefit of the unit tests.
87 gl_MODULE_INDICATOR_FOR_TESTS([$1]) 106 gl_MODULE_INDICATOR_FOR_TESTS([$1])
88]) 107])
89 108
109# Initializes the default values for AC_SUBSTed shell variables.
110# This macro must not be AC_REQUIREd. It must only be invoked, and only
111# outside of macros or in macros that are not AC_REQUIREd.
112AC_DEFUN([gl_STDIO_H_REQUIRE_DEFAULTS],
113[
114 m4_defun(GL_MODULE_INDICATOR_PREFIX[_STDIO_H_MODULE_INDICATOR_DEFAULTS], [
115 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_DPRINTF])
116 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FCLOSE])
117 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FDOPEN])
118 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FFLUSH])
119 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FGETC])
120 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FGETS])
121 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FOPEN])
122 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPRINTF])
123 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPRINTF_POSIX])
124 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPURGE])
125 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPUTC])
126 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FPUTS])
127 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FREAD])
128 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FREOPEN])
129 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FSCANF])
130 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FSEEK])
131 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FSEEKO])
132 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FTELL])
133 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FTELLO])
134 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FWRITE])
135 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETC])
136 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETCHAR])
137 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETDELIM])
138 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETLINE])
139 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_OBSTACK_PRINTF])
140 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_OBSTACK_PRINTF_POSIX])
141 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PCLOSE])
142 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PERROR])
143 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POPEN])
144 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PRINTF])
145 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PRINTF_POSIX])
146 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PUTC])
147 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PUTCHAR])
148 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PUTS])
149 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_REMOVE])
150 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RENAME])
151 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RENAMEAT])
152 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SCANF])
153 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SNPRINTF])
154 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SPRINTF_POSIX])
155 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDIO_H_NONBLOCKING])
156 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDIO_H_SIGPIPE])
157 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TMPFILE])
158 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VASPRINTF])
159 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VFSCANF])
160 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSCANF])
161 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VDPRINTF])
162 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VFPRINTF])
163 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VFPRINTF_POSIX])
164 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VPRINTF])
165 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VPRINTF_POSIX])
166 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSNPRINTF])
167 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSPRINTF_POSIX])
168 dnl Support Microsoft deprecated alias function names by default.
169 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_FCLOSEALL], [1])
170 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_FDOPEN], [1])
171 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_FILENO], [1])
172 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_GETW], [1])
173 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_PUTW], [1])
174 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_TEMPNAM], [1])
175 ])
176 m4_require(GL_MODULE_INDICATOR_PREFIX[_STDIO_H_MODULE_INDICATOR_DEFAULTS])
177 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
178])
179
90AC_DEFUN([gl_STDIO_H_DEFAULTS], 180AC_DEFUN([gl_STDIO_H_DEFAULTS],
91[ 181[
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. 182 dnl Assume proper GNU behavior unless another module says otherwise.
183 HAVE_DECL_FCLOSEALL=1; AC_SUBST([HAVE_DECL_FCLOSEALL])
146 HAVE_DECL_FPURGE=1; AC_SUBST([HAVE_DECL_FPURGE]) 184 HAVE_DECL_FPURGE=1; AC_SUBST([HAVE_DECL_FPURGE])
147 HAVE_DECL_FSEEKO=1; AC_SUBST([HAVE_DECL_FSEEKO]) 185 HAVE_DECL_FSEEKO=1; AC_SUBST([HAVE_DECL_FSEEKO])
148 HAVE_DECL_FTELLO=1; AC_SUBST([HAVE_DECL_FTELLO]) 186 HAVE_DECL_FTELLO=1; AC_SUBST([HAVE_DECL_FTELLO])
diff --git a/gl/m4/stdlib_h.m4 b/gl/m4/stdlib_h.m4
index 2027ab3..9c1d1c7 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 63
2dnl Copyright (C) 2007-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2007-2021 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,181 @@ 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_POSIX])
72 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CANONICALIZE_FILE_NAME])
73 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FREE_POSIX])
74 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETLOADAVG])
75 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETSUBOPT])
76 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GRANTPT])
77 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MALLOC_POSIX])
78 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBTOWC])
79 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKDTEMP])
80 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKOSTEMP])
81 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKOSTEMPS])
82 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKSTEMP])
83 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKSTEMPS])
84 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_MEMALIGN])
85 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POSIX_OPENPT])
86 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PTSNAME])
87 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PTSNAME_R])
88 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PUTENV])
89 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_QSORT_R])
90 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RANDOM])
91 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RANDOM_R])
92 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_REALLOCARRAY])
93 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_REALLOC_POSIX])
94 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_REALPATH])
95 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RPMATCH])
96 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SECURE_GETENV])
97 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SETENV])
98 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRTOD])
99 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRTOL])
100 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRTOLD])
101 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRTOLL])
102 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRTOUL])
103 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRTOULL])
104 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SYSTEM_POSIX])
105 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_UNLOCKPT])
106 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_UNSETENV])
107 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WCTOMB])
108 dnl Support Microsoft deprecated alias function names by default.
109 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_ECVT], [1])
110 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_FCVT], [1])
111 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_GCVT], [1])
112 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_MKTEMP], [1])
113 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_PUTENV], [1])
114 ])
115 m4_require(GL_MODULE_INDICATOR_PREFIX[_STDLIB_H_MODULE_INDICATOR_DEFAULTS])
116 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
117])
118
38AC_DEFUN([gl_STDLIB_H_DEFAULTS], 119AC_DEFUN([gl_STDLIB_H_DEFAULTS],
39[ 120[
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. 121 dnl Assume proper GNU behavior unless another module says otherwise.
73 HAVE__EXIT=1; AC_SUBST([HAVE__EXIT]) 122 HAVE__EXIT=1; AC_SUBST([HAVE__EXIT])
123 HAVE_ALIGNED_ALLOC=1; AC_SUBST([HAVE_ALIGNED_ALLOC])
74 HAVE_ATOLL=1; AC_SUBST([HAVE_ATOLL]) 124 HAVE_ATOLL=1; AC_SUBST([HAVE_ATOLL])
75 HAVE_CANONICALIZE_FILE_NAME=1; AC_SUBST([HAVE_CANONICALIZE_FILE_NAME]) 125 HAVE_CANONICALIZE_FILE_NAME=1; AC_SUBST([HAVE_CANONICALIZE_FILE_NAME])
126 HAVE_DECL_ECVT=1; AC_SUBST([HAVE_DECL_ECVT])
127 HAVE_DECL_FCVT=1; AC_SUBST([HAVE_DECL_FCVT])
128 HAVE_DECL_GCVT=1; AC_SUBST([HAVE_DECL_GCVT])
76 HAVE_DECL_GETLOADAVG=1; AC_SUBST([HAVE_DECL_GETLOADAVG]) 129 HAVE_DECL_GETLOADAVG=1; AC_SUBST([HAVE_DECL_GETLOADAVG])
77 HAVE_GETSUBOPT=1; AC_SUBST([HAVE_GETSUBOPT]) 130 HAVE_GETSUBOPT=1; AC_SUBST([HAVE_GETSUBOPT])
78 HAVE_GRANTPT=1; AC_SUBST([HAVE_GRANTPT]) 131 HAVE_GRANTPT=1; AC_SUBST([HAVE_GRANTPT])
132 HAVE_INITSTATE=1; AC_SUBST([HAVE_INITSTATE])
133 HAVE_DECL_INITSTATE=1; AC_SUBST([HAVE_DECL_INITSTATE])
134 HAVE_MBTOWC=1; AC_SUBST([HAVE_MBTOWC])
79 HAVE_MKDTEMP=1; AC_SUBST([HAVE_MKDTEMP]) 135 HAVE_MKDTEMP=1; AC_SUBST([HAVE_MKDTEMP])
80 HAVE_MKOSTEMP=1; AC_SUBST([HAVE_MKOSTEMP]) 136 HAVE_MKOSTEMP=1; AC_SUBST([HAVE_MKOSTEMP])
81 HAVE_MKOSTEMPS=1; AC_SUBST([HAVE_MKOSTEMPS]) 137 HAVE_MKOSTEMPS=1; AC_SUBST([HAVE_MKOSTEMPS])
82 HAVE_MKSTEMP=1; AC_SUBST([HAVE_MKSTEMP]) 138 HAVE_MKSTEMP=1; AC_SUBST([HAVE_MKSTEMP])
83 HAVE_MKSTEMPS=1; AC_SUBST([HAVE_MKSTEMPS]) 139 HAVE_MKSTEMPS=1; AC_SUBST([HAVE_MKSTEMPS])
140 HAVE_POSIX_MEMALIGN=1; AC_SUBST([HAVE_POSIX_MEMALIGN])
84 HAVE_POSIX_OPENPT=1; AC_SUBST([HAVE_POSIX_OPENPT]) 141 HAVE_POSIX_OPENPT=1; AC_SUBST([HAVE_POSIX_OPENPT])
85 HAVE_PTSNAME=1; AC_SUBST([HAVE_PTSNAME]) 142 HAVE_PTSNAME=1; AC_SUBST([HAVE_PTSNAME])
86 HAVE_PTSNAME_R=1; AC_SUBST([HAVE_PTSNAME_R]) 143 HAVE_PTSNAME_R=1; AC_SUBST([HAVE_PTSNAME_R])
144 HAVE_QSORT_R=1; AC_SUBST([HAVE_QSORT_R])
87 HAVE_RANDOM=1; AC_SUBST([HAVE_RANDOM]) 145 HAVE_RANDOM=1; AC_SUBST([HAVE_RANDOM])
88 HAVE_RANDOM_H=1; AC_SUBST([HAVE_RANDOM_H]) 146 HAVE_RANDOM_H=1; AC_SUBST([HAVE_RANDOM_H])
89 HAVE_RANDOM_R=1; AC_SUBST([HAVE_RANDOM_R]) 147 HAVE_RANDOM_R=1; AC_SUBST([HAVE_RANDOM_R])
148 HAVE_REALLOCARRAY=1; AC_SUBST([HAVE_REALLOCARRAY])
90 HAVE_REALPATH=1; AC_SUBST([HAVE_REALPATH]) 149 HAVE_REALPATH=1; AC_SUBST([HAVE_REALPATH])
91 HAVE_RPMATCH=1; AC_SUBST([HAVE_RPMATCH]) 150 HAVE_RPMATCH=1; AC_SUBST([HAVE_RPMATCH])
92 HAVE_SECURE_GETENV=1; AC_SUBST([HAVE_SECURE_GETENV]) 151 HAVE_SECURE_GETENV=1; AC_SUBST([HAVE_SECURE_GETENV])
93 HAVE_SETENV=1; AC_SUBST([HAVE_SETENV]) 152 HAVE_SETENV=1; AC_SUBST([HAVE_SETENV])
94 HAVE_DECL_SETENV=1; AC_SUBST([HAVE_DECL_SETENV]) 153 HAVE_DECL_SETENV=1; AC_SUBST([HAVE_DECL_SETENV])
154 HAVE_SETSTATE=1; AC_SUBST([HAVE_SETSTATE])
155 HAVE_DECL_SETSTATE=1; AC_SUBST([HAVE_DECL_SETSTATE])
95 HAVE_STRTOD=1; AC_SUBST([HAVE_STRTOD]) 156 HAVE_STRTOD=1; AC_SUBST([HAVE_STRTOD])
157 HAVE_STRTOL=1; AC_SUBST([HAVE_STRTOL])
158 HAVE_STRTOLD=1; AC_SUBST([HAVE_STRTOLD])
96 HAVE_STRTOLL=1; AC_SUBST([HAVE_STRTOLL]) 159 HAVE_STRTOLL=1; AC_SUBST([HAVE_STRTOLL])
160 HAVE_STRTOUL=1; AC_SUBST([HAVE_STRTOUL])
97 HAVE_STRTOULL=1; AC_SUBST([HAVE_STRTOULL]) 161 HAVE_STRTOULL=1; AC_SUBST([HAVE_STRTOULL])
98 HAVE_STRUCT_RANDOM_DATA=1; AC_SUBST([HAVE_STRUCT_RANDOM_DATA]) 162 HAVE_STRUCT_RANDOM_DATA=1; AC_SUBST([HAVE_STRUCT_RANDOM_DATA])
99 HAVE_SYS_LOADAVG_H=0; AC_SUBST([HAVE_SYS_LOADAVG_H]) 163 HAVE_SYS_LOADAVG_H=0; AC_SUBST([HAVE_SYS_LOADAVG_H])
100 HAVE_UNLOCKPT=1; AC_SUBST([HAVE_UNLOCKPT]) 164 HAVE_UNLOCKPT=1; AC_SUBST([HAVE_UNLOCKPT])
101 HAVE_DECL_UNSETENV=1; AC_SUBST([HAVE_DECL_UNSETENV]) 165 HAVE_DECL_UNSETENV=1; AC_SUBST([HAVE_DECL_UNSETENV])
166 REPLACE_ALIGNED_ALLOC=0; AC_SUBST([REPLACE_ALIGNED_ALLOC])
102 REPLACE_CALLOC=0; AC_SUBST([REPLACE_CALLOC]) 167 REPLACE_CALLOC=0; AC_SUBST([REPLACE_CALLOC])
103 REPLACE_CANONICALIZE_FILE_NAME=0; AC_SUBST([REPLACE_CANONICALIZE_FILE_NAME]) 168 REPLACE_CANONICALIZE_FILE_NAME=0; AC_SUBST([REPLACE_CANONICALIZE_FILE_NAME])
169 REPLACE_FREE=0; AC_SUBST([REPLACE_FREE])
170 REPLACE_INITSTATE=0; AC_SUBST([REPLACE_INITSTATE])
104 REPLACE_MALLOC=0; AC_SUBST([REPLACE_MALLOC]) 171 REPLACE_MALLOC=0; AC_SUBST([REPLACE_MALLOC])
105 REPLACE_MBTOWC=0; AC_SUBST([REPLACE_MBTOWC]) 172 REPLACE_MBTOWC=0; AC_SUBST([REPLACE_MBTOWC])
106 REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP]) 173 REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP])
174 REPLACE_POSIX_MEMALIGN=0; AC_SUBST([REPLACE_POSIX_MEMALIGN])
107 REPLACE_PTSNAME=0; AC_SUBST([REPLACE_PTSNAME]) 175 REPLACE_PTSNAME=0; AC_SUBST([REPLACE_PTSNAME])
108 REPLACE_PTSNAME_R=0; AC_SUBST([REPLACE_PTSNAME_R]) 176 REPLACE_PTSNAME_R=0; AC_SUBST([REPLACE_PTSNAME_R])
109 REPLACE_PUTENV=0; AC_SUBST([REPLACE_PUTENV]) 177 REPLACE_PUTENV=0; AC_SUBST([REPLACE_PUTENV])
178 REPLACE_QSORT_R=0; AC_SUBST([REPLACE_QSORT_R])
179 REPLACE_RANDOM=0; AC_SUBST([REPLACE_RANDOM])
110 REPLACE_RANDOM_R=0; AC_SUBST([REPLACE_RANDOM_R]) 180 REPLACE_RANDOM_R=0; AC_SUBST([REPLACE_RANDOM_R])
111 REPLACE_REALLOC=0; AC_SUBST([REPLACE_REALLOC]) 181 REPLACE_REALLOC=0; AC_SUBST([REPLACE_REALLOC])
182 REPLACE_REALLOCARRAY=0; AC_SUBST([REPLACE_REALLOCARRAY])
112 REPLACE_REALPATH=0; AC_SUBST([REPLACE_REALPATH]) 183 REPLACE_REALPATH=0; AC_SUBST([REPLACE_REALPATH])
113 REPLACE_SETENV=0; AC_SUBST([REPLACE_SETENV]) 184 REPLACE_SETENV=0; AC_SUBST([REPLACE_SETENV])
185 REPLACE_SETSTATE=0; AC_SUBST([REPLACE_SETSTATE])
114 REPLACE_STRTOD=0; AC_SUBST([REPLACE_STRTOD]) 186 REPLACE_STRTOD=0; AC_SUBST([REPLACE_STRTOD])
187 REPLACE_STRTOL=0; AC_SUBST([REPLACE_STRTOL])
188 REPLACE_STRTOLD=0; AC_SUBST([REPLACE_STRTOLD])
189 REPLACE_STRTOLL=0; AC_SUBST([REPLACE_STRTOLL])
190 REPLACE_STRTOUL=0; AC_SUBST([REPLACE_STRTOUL])
191 REPLACE_STRTOULL=0; AC_SUBST([REPLACE_STRTOULL])
115 REPLACE_UNSETENV=0; AC_SUBST([REPLACE_UNSETENV]) 192 REPLACE_UNSETENV=0; AC_SUBST([REPLACE_UNSETENV])
116 REPLACE_WCTOMB=0; AC_SUBST([REPLACE_WCTOMB]) 193 REPLACE_WCTOMB=0; AC_SUBST([REPLACE_WCTOMB])
117]) 194])
diff --git a/gl/m4/strcase.m4 b/gl/m4/strcase.m4
index 22bf57c..ea88283 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-2021 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..6939144 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-2021 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..438ba92 100644
--- a/gl/m4/strerror.m4
+++ b/gl/m4/strerror.m4
@@ -1,12 +1,12 @@
1# strerror.m4 serial 17 1# strerror.m4 serial 22
2dnl Copyright (C) 2002, 2007-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2002, 2007-2021 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
@@ -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..e88ac9c 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-2021 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 34
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
@@ -29,62 +23,88 @@ AC_DEFUN([gl_HEADER_STRING_H_BODY],
29 ]], 23 ]],
30 [ffsl ffsll memmem mempcpy memrchr rawmemchr stpcpy stpncpy strchrnul 24 [ffsl ffsll memmem mempcpy memrchr rawmemchr stpcpy stpncpy strchrnul
31 strdup strncat strndup strnlen strpbrk strsep strcasestr strtok_r 25 strdup strncat strndup strnlen strpbrk strsep strcasestr strtok_r
32 strerror_r strsignal strverscmp]) 26 strerror_r strerrorname_np sigabbrev_np sigdescr_np strsignal strverscmp])
27
28 AC_REQUIRE([AC_C_RESTRICT])
33]) 29])
34 30
31# gl_STRING_MODULE_INDICATOR([modulename])
32# sets the shell variable that indicates the presence of the given module
33# to a C preprocessor expression that will evaluate to 1.
34# This macro invocation must not occur in macros that are AC_REQUIREd.
35AC_DEFUN([gl_STRING_MODULE_INDICATOR], 35AC_DEFUN([gl_STRING_MODULE_INDICATOR],
36[ 36[
37 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 37 dnl Ensure to expand the default settings once only.
38 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) 38 gl_STRING_H_REQUIRE_DEFAULTS
39 gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 39 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
40 dnl Define it also as a C macro, for the benefit of the unit tests. 40 dnl Define it also as a C macro, for the benefit of the unit tests.
41 gl_MODULE_INDICATOR_FOR_TESTS([$1]) 41 gl_MODULE_INDICATOR_FOR_TESTS([$1])
42]) 42])
43 43
44AC_DEFUN([gl_HEADER_STRING_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_STRING_H_REQUIRE_DEFAULTS],
45[ 48[
46 GNULIB_FFSL=0; AC_SUBST([GNULIB_FFSL]) 49 m4_defun(GL_MODULE_INDICATOR_PREFIX[_STRING_H_MODULE_INDICATOR_DEFAULTS], [
47 GNULIB_FFSLL=0; AC_SUBST([GNULIB_FFSLL]) 50 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_EXPLICIT_BZERO])
48 GNULIB_MEMCHR=0; AC_SUBST([GNULIB_MEMCHR]) 51 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FFSL])
49 GNULIB_MEMMEM=0; AC_SUBST([GNULIB_MEMMEM]) 52 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FFSLL])
50 GNULIB_MEMPCPY=0; AC_SUBST([GNULIB_MEMPCPY]) 53 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MEMCHR])
51 GNULIB_MEMRCHR=0; AC_SUBST([GNULIB_MEMRCHR]) 54 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MEMMEM])
52 GNULIB_RAWMEMCHR=0; AC_SUBST([GNULIB_RAWMEMCHR]) 55 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MEMPCPY])
53 GNULIB_STPCPY=0; AC_SUBST([GNULIB_STPCPY]) 56 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MEMRCHR])
54 GNULIB_STPNCPY=0; AC_SUBST([GNULIB_STPNCPY]) 57 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RAWMEMCHR])
55 GNULIB_STRCHRNUL=0; AC_SUBST([GNULIB_STRCHRNUL]) 58 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STPCPY])
56 GNULIB_STRDUP=0; AC_SUBST([GNULIB_STRDUP]) 59 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STPNCPY])
57 GNULIB_STRNCAT=0; AC_SUBST([GNULIB_STRNCAT]) 60 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRCHRNUL])
58 GNULIB_STRNDUP=0; AC_SUBST([GNULIB_STRNDUP]) 61 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRDUP])
59 GNULIB_STRNLEN=0; AC_SUBST([GNULIB_STRNLEN]) 62 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRNCAT])
60 GNULIB_STRPBRK=0; AC_SUBST([GNULIB_STRPBRK]) 63 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRNDUP])
61 GNULIB_STRSEP=0; AC_SUBST([GNULIB_STRSEP]) 64 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRNLEN])
62 GNULIB_STRSTR=0; AC_SUBST([GNULIB_STRSTR]) 65 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRPBRK])
63 GNULIB_STRCASESTR=0; AC_SUBST([GNULIB_STRCASESTR]) 66 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRSEP])
64 GNULIB_STRTOK_R=0; AC_SUBST([GNULIB_STRTOK_R]) 67 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRSTR])
65 GNULIB_MBSLEN=0; AC_SUBST([GNULIB_MBSLEN]) 68 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRCASESTR])
66 GNULIB_MBSNLEN=0; AC_SUBST([GNULIB_MBSNLEN]) 69 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRTOK_R])
67 GNULIB_MBSCHR=0; AC_SUBST([GNULIB_MBSCHR]) 70 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSLEN])
68 GNULIB_MBSRCHR=0; AC_SUBST([GNULIB_MBSRCHR]) 71 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSNLEN])
69 GNULIB_MBSSTR=0; AC_SUBST([GNULIB_MBSSTR]) 72 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSCHR])
70 GNULIB_MBSCASECMP=0; AC_SUBST([GNULIB_MBSCASECMP]) 73 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSRCHR])
71 GNULIB_MBSNCASECMP=0; AC_SUBST([GNULIB_MBSNCASECMP]) 74 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSSTR])
72 GNULIB_MBSPCASECMP=0; AC_SUBST([GNULIB_MBSPCASECMP]) 75 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSCASECMP])
73 GNULIB_MBSCASESTR=0; AC_SUBST([GNULIB_MBSCASESTR]) 76 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSNCASECMP])
74 GNULIB_MBSCSPN=0; AC_SUBST([GNULIB_MBSCSPN]) 77 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSPCASECMP])
75 GNULIB_MBSPBRK=0; AC_SUBST([GNULIB_MBSPBRK]) 78 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSCASESTR])
76 GNULIB_MBSSPN=0; AC_SUBST([GNULIB_MBSSPN]) 79 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSCSPN])
77 GNULIB_MBSSEP=0; AC_SUBST([GNULIB_MBSSEP]) 80 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSPBRK])
78 GNULIB_MBSTOK_R=0; AC_SUBST([GNULIB_MBSTOK_R]) 81 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSSPN])
79 GNULIB_STRERROR=0; AC_SUBST([GNULIB_STRERROR]) 82 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSSEP])
80 GNULIB_STRERROR_R=0; AC_SUBST([GNULIB_STRERROR_R]) 83 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSTOK_R])
81 GNULIB_STRSIGNAL=0; AC_SUBST([GNULIB_STRSIGNAL]) 84 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRERROR])
82 GNULIB_STRVERSCMP=0; AC_SUBST([GNULIB_STRVERSCMP]) 85 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRERROR_R])
83 HAVE_MBSLEN=0; AC_SUBST([HAVE_MBSLEN]) 86 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRERRORNAME_NP])
87 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SIGABBREV_NP])
88 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SIGDESCR_NP])
89 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRSIGNAL])
90 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRVERSCMP])
91 dnl Support Microsoft deprecated alias function names by default.
92 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_MEMCCPY], [1])
93 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_STRDUP], [1])
94 ])
95 m4_require(GL_MODULE_INDICATOR_PREFIX[_STRING_H_MODULE_INDICATOR_DEFAULTS])
96 dnl Make sure the shell variable for GNULIB_FREE_POSIX is initialized.
97 gl_STDLIB_H_REQUIRE_DEFAULTS
98 AC_REQUIRE([gl_STRING_H_DEFAULTS])
99])
100
101AC_DEFUN([gl_STRING_H_DEFAULTS],
102[
103 HAVE_MBSLEN=0; AC_SUBST([HAVE_MBSLEN])
84 dnl Assume proper GNU behavior unless another module says otherwise. 104 dnl Assume proper GNU behavior unless another module says otherwise.
105 HAVE_EXPLICIT_BZERO=1; AC_SUBST([HAVE_EXPLICIT_BZERO])
85 HAVE_FFSL=1; AC_SUBST([HAVE_FFSL]) 106 HAVE_FFSL=1; AC_SUBST([HAVE_FFSL])
86 HAVE_FFSLL=1; AC_SUBST([HAVE_FFSLL]) 107 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]) 108 HAVE_DECL_MEMMEM=1; AC_SUBST([HAVE_DECL_MEMMEM])
89 HAVE_MEMPCPY=1; AC_SUBST([HAVE_MEMPCPY]) 109 HAVE_MEMPCPY=1; AC_SUBST([HAVE_MEMPCPY])
90 HAVE_DECL_MEMRCHR=1; AC_SUBST([HAVE_DECL_MEMRCHR]) 110 HAVE_DECL_MEMRCHR=1; AC_SUBST([HAVE_DECL_MEMRCHR])
@@ -100,21 +120,26 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS],
100 HAVE_STRCASESTR=1; AC_SUBST([HAVE_STRCASESTR]) 120 HAVE_STRCASESTR=1; AC_SUBST([HAVE_STRCASESTR])
101 HAVE_DECL_STRTOK_R=1; AC_SUBST([HAVE_DECL_STRTOK_R]) 121 HAVE_DECL_STRTOK_R=1; AC_SUBST([HAVE_DECL_STRTOK_R])
102 HAVE_DECL_STRERROR_R=1; AC_SUBST([HAVE_DECL_STRERROR_R]) 122 HAVE_DECL_STRERROR_R=1; AC_SUBST([HAVE_DECL_STRERROR_R])
123 HAVE_STRERRORNAME_NP=1; AC_SUBST([HAVE_STRERRORNAME_NP])
124 HAVE_SIGABBREV_NP=1; AC_SUBST([HAVE_SIGABBREV_NP])
125 HAVE_SIGDESCR_NP=1; AC_SUBST([HAVE_SIGDESCR_NP])
103 HAVE_DECL_STRSIGNAL=1; AC_SUBST([HAVE_DECL_STRSIGNAL]) 126 HAVE_DECL_STRSIGNAL=1; AC_SUBST([HAVE_DECL_STRSIGNAL])
104 HAVE_STRVERSCMP=1; AC_SUBST([HAVE_STRVERSCMP]) 127 HAVE_STRVERSCMP=1; AC_SUBST([HAVE_STRVERSCMP])
128 REPLACE_FFSLL=0; AC_SUBST([REPLACE_FFSLL])
105 REPLACE_MEMCHR=0; AC_SUBST([REPLACE_MEMCHR]) 129 REPLACE_MEMCHR=0; AC_SUBST([REPLACE_MEMCHR])
106 REPLACE_MEMMEM=0; AC_SUBST([REPLACE_MEMMEM]) 130 REPLACE_MEMMEM=0; AC_SUBST([REPLACE_MEMMEM])
107 REPLACE_STPNCPY=0; AC_SUBST([REPLACE_STPNCPY]) 131 REPLACE_STPNCPY=0; AC_SUBST([REPLACE_STPNCPY])
132 REPLACE_STRCHRNUL=0; AC_SUBST([REPLACE_STRCHRNUL])
108 REPLACE_STRDUP=0; AC_SUBST([REPLACE_STRDUP]) 133 REPLACE_STRDUP=0; AC_SUBST([REPLACE_STRDUP])
134 REPLACE_STRNCAT=0; AC_SUBST([REPLACE_STRNCAT])
135 REPLACE_STRNDUP=0; AC_SUBST([REPLACE_STRNDUP])
136 REPLACE_STRNLEN=0; AC_SUBST([REPLACE_STRNLEN])
109 REPLACE_STRSTR=0; AC_SUBST([REPLACE_STRSTR]) 137 REPLACE_STRSTR=0; AC_SUBST([REPLACE_STRSTR])
110 REPLACE_STRCASESTR=0; AC_SUBST([REPLACE_STRCASESTR]) 138 REPLACE_STRCASESTR=0; AC_SUBST([REPLACE_STRCASESTR])
111 REPLACE_STRCHRNUL=0; AC_SUBST([REPLACE_STRCHRNUL]) 139 REPLACE_STRTOK_R=0; AC_SUBST([REPLACE_STRTOK_R])
112 REPLACE_STRERROR=0; AC_SUBST([REPLACE_STRERROR]) 140 REPLACE_STRERROR=0; AC_SUBST([REPLACE_STRERROR])
113 REPLACE_STRERROR_R=0; AC_SUBST([REPLACE_STRERROR_R]) 141 REPLACE_STRERROR_R=0; AC_SUBST([REPLACE_STRERROR_R])
114 REPLACE_STRNCAT=0; AC_SUBST([REPLACE_STRNCAT]) 142 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]) 143 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]) 144 UNDEFINE_STRTOK_R=0; AC_SUBST([UNDEFINE_STRTOK_R])
120]) 145])
diff --git a/gl/m4/strings_h.m4 b/gl/m4/strings_h.m4
index 76ef242..69de32a 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-2021 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..8743f05 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-2021 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..a32e9c1 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-2021 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..5676a0d 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 28
2dnl Copyright (C) 2005-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2005-2021 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])
@@ -95,6 +95,8 @@ AC_DEFUN([gl_HEADER_SYS_SOCKET],
95#include <sys/socket.h> 95#include <sys/socket.h>
96 ]], [socket connect accept bind getpeername getsockname getsockopt 96 ]], [socket connect accept bind getpeername getsockname getsockopt
97 listen recv send recvfrom sendto setsockopt shutdown accept4]) 97 listen recv send recvfrom sendto setsockopt shutdown accept4])
98
99 AC_REQUIRE([AC_C_RESTRICT])
98]) 100])
99 101
100AC_DEFUN([gl_PREREQ_SYS_H_SOCKET], 102AC_DEFUN([gl_PREREQ_SYS_H_SOCKET],
@@ -104,17 +106,11 @@ AC_DEFUN([gl_PREREQ_SYS_H_SOCKET],
104 gl_CHECK_NEXT_HEADERS([sys/socket.h]) 106 gl_CHECK_NEXT_HEADERS([sys/socket.h])
105 if test $ac_cv_header_sys_socket_h = yes; then 107 if test $ac_cv_header_sys_socket_h = yes; then
106 HAVE_SYS_SOCKET_H=1 108 HAVE_SYS_SOCKET_H=1
107 HAVE_WS2TCPIP_H=0
108 else 109 else
109 HAVE_SYS_SOCKET_H=0 110 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 111 fi
116 AC_SUBST([HAVE_SYS_SOCKET_H]) 112 AC_SUBST([HAVE_SYS_SOCKET_H])
117 AC_SUBST([HAVE_WS2TCPIP_H]) 113 gl_PREREQ_SYS_H_WS2TCPIP
118]) 114])
119 115
120# Common prerequisites of the <sys/socket.h> replacement and of the 116# Common prerequisites of the <sys/socket.h> replacement and of the
@@ -142,32 +138,65 @@ AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2],
142 AC_SUBST([HAVE_WINSOCK2_H]) 138 AC_SUBST([HAVE_WINSOCK2_H])
143]) 139])
144 140
141# Common prerequisites of the <sys/socket.h> replacement and of the
142# <arpa/inet.h> replacement.
143# Sets and substitutes HAVE_WS2TCPIP_H.
144AC_DEFUN([gl_PREREQ_SYS_H_WS2TCPIP],
145[
146 AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])
147 if test $ac_cv_header_sys_socket_h = yes; then
148 HAVE_WS2TCPIP_H=0
149 else
150 if test $ac_cv_header_ws2tcpip_h = yes; then
151 HAVE_WS2TCPIP_H=1
152 else
153 HAVE_WS2TCPIP_H=0
154 fi
155 fi
156 AC_SUBST([HAVE_WS2TCPIP_H])
157])
158
159# gl_SYS_SOCKET_MODULE_INDICATOR([modulename])
160# sets the shell variable that indicates the presence of the given module
161# to a C preprocessor expression that will evaluate to 1.
162# This macro invocation must not occur in macros that are AC_REQUIREd.
145AC_DEFUN([gl_SYS_SOCKET_MODULE_INDICATOR], 163AC_DEFUN([gl_SYS_SOCKET_MODULE_INDICATOR],
146[ 164[
147 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 165 dnl Ensure to expand the default settings once only.
148 AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS]) 166 gl_SYS_SOCKET_H_REQUIRE_DEFAULTS
149 gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 167 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
150 dnl Define it also as a C macro, for the benefit of the unit tests. 168 dnl Define it also as a C macro, for the benefit of the unit tests.
151 gl_MODULE_INDICATOR_FOR_TESTS([$1]) 169 gl_MODULE_INDICATOR_FOR_TESTS([$1])
152]) 170])
153 171
172# Initializes the default values for AC_SUBSTed shell variables.
173# This macro must not be AC_REQUIREd. It must only be invoked, and only
174# outside of macros or in macros that are not AC_REQUIREd.
175AC_DEFUN([gl_SYS_SOCKET_H_REQUIRE_DEFAULTS],
176[
177 m4_defun(GL_MODULE_INDICATOR_PREFIX[_SYS_SOCKET_H_MODULE_INDICATOR_DEFAULTS], [
178 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SOCKET])
179 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CONNECT])
180 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ACCEPT])
181 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_BIND])
182 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETPEERNAME])
183 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETSOCKNAME])
184 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETSOCKOPT])
185 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LISTEN])
186 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RECV])
187 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SEND])
188 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RECVFROM])
189 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SENDTO])
190 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SETSOCKOPT])
191 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SHUTDOWN])
192 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ACCEPT4])
193 ])
194 m4_require(GL_MODULE_INDICATOR_PREFIX[_SYS_SOCKET_H_MODULE_INDICATOR_DEFAULTS])
195 AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
196])
197
154AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS], 198AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
155[ 199[
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]) 200 HAVE_STRUCT_SOCKADDR_STORAGE=1; AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE])
172 HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=1; 201 HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=1;
173 AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY]) 202 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..ac91d42
--- /dev/null
+++ b/gl/m4/sys_stat_h.m4
@@ -0,0 +1,127 @@
1# sys_stat_h.m4 serial 41 -*- Autoconf -*-
2dnl Copyright (C) 2006-2021 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 ]], [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_FCHMODAT])
76 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FSTAT])
77 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FSTATAT])
78 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FUTIMENS])
79 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETUMASK])
80 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LCHMOD])
81 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LSTAT])
82 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKDIR])
83 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKDIRAT])
84 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKFIFO])
85 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKFIFOAT])
86 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKNOD])
87 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKNODAT])
88 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STAT])
89 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_UTIMENSAT])
90 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_OVERRIDES_STRUCT_STAT])
91 dnl Support Microsoft deprecated alias function names by default.
92 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_CHMOD], [1])
93 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_MKDIR], [1])
94 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_UMASK], [1])
95 ])
96 m4_require(GL_MODULE_INDICATOR_PREFIX[_SYS_STAT_H_MODULE_INDICATOR_DEFAULTS])
97 AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
98])
99
100AC_DEFUN([gl_SYS_STAT_H_DEFAULTS],
101[
102 dnl Assume proper GNU behavior unless another module says otherwise.
103 HAVE_FCHMODAT=1; AC_SUBST([HAVE_FCHMODAT])
104 HAVE_FSTATAT=1; AC_SUBST([HAVE_FSTATAT])
105 HAVE_FUTIMENS=1; AC_SUBST([HAVE_FUTIMENS])
106 HAVE_GETUMASK=1; AC_SUBST([HAVE_GETUMASK])
107 HAVE_LCHMOD=1; AC_SUBST([HAVE_LCHMOD])
108 HAVE_LSTAT=1; AC_SUBST([HAVE_LSTAT])
109 HAVE_MKDIRAT=1; AC_SUBST([HAVE_MKDIRAT])
110 HAVE_MKFIFO=1; AC_SUBST([HAVE_MKFIFO])
111 HAVE_MKFIFOAT=1; AC_SUBST([HAVE_MKFIFOAT])
112 HAVE_MKNOD=1; AC_SUBST([HAVE_MKNOD])
113 HAVE_MKNODAT=1; AC_SUBST([HAVE_MKNODAT])
114 HAVE_UTIMENSAT=1; AC_SUBST([HAVE_UTIMENSAT])
115 REPLACE_FCHMODAT=0; AC_SUBST([REPLACE_FCHMODAT])
116 REPLACE_FSTAT=0; AC_SUBST([REPLACE_FSTAT])
117 REPLACE_FSTATAT=0; AC_SUBST([REPLACE_FSTATAT])
118 REPLACE_FUTIMENS=0; AC_SUBST([REPLACE_FUTIMENS])
119 REPLACE_LSTAT=0; AC_SUBST([REPLACE_LSTAT])
120 REPLACE_MKDIR=0; AC_SUBST([REPLACE_MKDIR])
121 REPLACE_MKFIFO=0; AC_SUBST([REPLACE_MKFIFO])
122 REPLACE_MKFIFOAT=0; AC_SUBST([REPLACE_MKFIFOAT])
123 REPLACE_MKNOD=0; AC_SUBST([REPLACE_MKNOD])
124 REPLACE_MKNODAT=0; AC_SUBST([REPLACE_MKNODAT])
125 REPLACE_STAT=0; AC_SUBST([REPLACE_STAT])
126 REPLACE_UTIMENSAT=0; AC_SUBST([REPLACE_UTIMENSAT])
127])
diff --git a/gl/m4/sys_types_h.m4 b/gl/m4/sys_types_h.m4
index d15c1b3..6dd6fee 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-2021 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..fa176e0 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-2021 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..6b43bbd 100644
--- a/gl/m4/threadlib.m4
+++ b/gl/m4/threadlib.m4
@@ -1,11 +1,388 @@
1# threadlib.m4 serial 10 (gettext-0.18.2) 1# threadlib.m4 serial 32
2dnl Copyright (C) 2005-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2005-2021 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
264 solaris | solaris2.[1-9] | solaris2.[1-9].* | hpux*)
265 AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], [1],
266 [Define if the pthread_in_use() detection is hard.])
267 esac
268 fi
269 ])
270 elif test $gl_pthread_api != yes; then
271 # Some library is needed. Try libpthread and libc_r.
272 AC_CHECK_LIB([pthread], [pthread_kill],
273 [gl_pthread_api=yes
274 LIBPTHREAD=-lpthread
275 LIBPMULTITHREAD=-lpthread])
276 if test $gl_pthread_api != yes; then
277 # For FreeBSD 4.
278 AC_CHECK_LIB([c_r], [pthread_kill],
279 [gl_pthread_api=yes
280 LIBPTHREAD=-lc_r
281 LIBPMULTITHREAD=-lc_r])
282 fi
283 fi
284 echo "$as_me:__oline__: LIBPMULTITHREAD=$LIBPMULTITHREAD" >&AS_MESSAGE_LOG_FD
285 fi
286 AC_MSG_CHECKING([whether POSIX threads API is available])
287 AC_MSG_RESULT([$gl_pthread_api])
288 AC_SUBST([LIBPTHREAD])
289 AC_SUBST([LIBPMULTITHREAD])
290 if test $gl_pthread_api = yes; then
291 AC_DEFINE([HAVE_PTHREAD_API], [1],
292 [Define if you have the <pthread.h> header and the POSIX threads API.])
293 fi
294
295 dnl On some systems, sched_yield is in librt, rather than in libpthread.
296 AC_LINK_IFELSE(
297 [AC_LANG_PROGRAM(
298 [[#include <sched.h>]],
299 [[sched_yield ();]])],
300 [LIB_SCHED_YIELD=
301 ],
302 [dnl Solaris 7...10 has sched_yield in librt, not in libpthread or libc.
303 AC_CHECK_LIB([rt], [sched_yield], [LIB_SCHED_YIELD=-lrt],
304 [dnl Solaris 2.5.1, 2.6 has sched_yield in libposix4, not librt.
305 AC_CHECK_LIB([posix4], [sched_yield], [LIB_SCHED_YIELD=-lposix4])])
306 ])
307 AC_SUBST([LIB_SCHED_YIELD])
308
309 gl_pthreadlib_body_done=done
310 fi
311])
312
313AC_DEFUN([gl_PTHREADLIB],
314[
315 AC_REQUIRE([gl_ANYTHREADLIB_EARLY])
316 gl_PTHREADLIB_BODY
317])
318
319dnl ============================================================================
320dnl Macros for the ISO C API
321
322dnl gl_STDTHREADLIB
323dnl ---------------
324dnl Tests for the libraries needs for using the ISO C threads API.
325dnl Sets the variable LIBSTDTHREAD to the linker options for use in a Makefile.
326dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for
327dnl multithread-safe programs.
328dnl Defines the C macro HAVE_THREADS_H if (at least parts of) the ISO C threads
329dnl API is available.
330
331dnl The guts of gl_STDTHREADLIB. Needs to be expanded only once.
332
333AC_DEFUN([gl_STDTHREADLIB_BODY],
334[
335 AC_REQUIRE([gl_ANYTHREADLIB_EARLY])
336 AC_REQUIRE([AC_CANONICAL_HOST])
337 if test -z "$gl_stdthreadlib_body_done"; then
338 AC_CHECK_HEADERS_ONCE([threads.h])
339
340 case "$host_os" in
341 mingw*)
342 LIBSTDTHREAD=
343 ;;
344 *)
345 gl_PTHREADLIB_BODY
346 if test $ac_cv_header_threads_h = yes; then
347 dnl glibc >= 2.29 has thrd_create in libpthread.
348 dnl FreeBSD >= 10 has thrd_create in libstdthreads; this library depends
349 dnl on libpthread (for the symbol 'pthread_mutexattr_gettype').
350 dnl glibc >= 2.34, AIX >= 7.1, and Solaris >= 11.4 have thrd_create in
351 dnl libc.
352 AC_CHECK_FUNCS([thrd_create])
353 if test $ac_cv_func_thrd_create = yes; then
354 LIBSTDTHREAD=
355 else
356 AC_CHECK_LIB([stdthreads], [thrd_create], [
357 LIBSTDTHREAD='-lstdthreads -lpthread'
358 ], [
359 dnl Guess that thrd_create is in libpthread.
360 LIBSTDTHREAD="$LIBPMULTITHREAD"
361 ])
362 fi
363 else
364 dnl Libraries needed by thrd.c, mtx.c, cnd.c, tss.c.
365 LIBSTDTHREAD="$LIBPMULTITHREAD $LIB_SCHED_YIELD"
366 fi
367 ;;
368 esac
369 AC_SUBST([LIBSTDTHREAD])
370
371 AC_MSG_CHECKING([whether ISO C threads API is available])
372 AC_MSG_RESULT([$ac_cv_header_threads_h])
373 gl_stdthreadlib_body_done=done
374 fi
375])
376
377AC_DEFUN([gl_STDTHREADLIB],
378[
379 AC_REQUIRE([gl_ANYTHREADLIB_EARLY])
380 gl_STDTHREADLIB_BODY
381])
382
383dnl ============================================================================
384dnl Macros for the Gnulib API
385
9dnl gl_THREADLIB 386dnl gl_THREADLIB
10dnl ------------ 387dnl ------------
11dnl Tests for a multithreading library to be used. 388dnl Tests for a multithreading library to be used.
@@ -14,17 +391,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 391dnl 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 392dnl can change the choice through the options --enable-threads=choice or
16dnl --disable-threads. 393dnl --disable-threads.
17dnl Defines at most one of the macros USE_POSIX_THREADS, USE_SOLARIS_THREADS, 394dnl Defines at most one of the macros USE_ISOC_THREADS, USE_POSIX_THREADS,
18dnl USE_PTH_THREADS, USE_WINDOWS_THREADS 395dnl USE_ISOC_AND_POSIX_THREADS, USE_WINDOWS_THREADS.
396dnl The choice --enable-threads=isoc+posix is available only on platforms that
397dnl have both the ISO C and the POSIX threads APIs. It has the effect of using
398dnl the ISO C API for most things and the POSIX API only for creating and
399dnl controlling threads (because there is no equivalent to pthread_atfork in
400dnl the ISO C API).
19dnl Sets the variables LIBTHREAD and LTLIBTHREAD to the linker options for use 401dnl 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 402dnl in a Makefile (LIBTHREAD for use without libtool, LTLIBTHREAD for use with
21dnl libtool). 403dnl libtool).
22dnl Sets the variables LIBMULTITHREAD and LTLIBMULTITHREAD similarly, for 404dnl Sets the variables LIBMULTITHREAD and LTLIBMULTITHREAD similarly, for
23dnl programs that really need multithread functionality. The difference 405dnl programs that really need multithread functionality. The difference
24dnl between LIBTHREAD and LIBMULTITHREAD is that on platforms supporting weak 406dnl between LIBTHREAD and LIBMULTITHREAD is that on platforms supporting weak
25dnl symbols, typically LIBTHREAD="" whereas LIBMULTITHREAD="-lpthread". 407dnl symbols, typically LIBTHREAD is empty whereas LIBMULTITHREAD is not.
26dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for 408dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for
27dnl multithread-safe programs. 409dnl multithread-safe programs.
410dnl Since support for GNU pth was removed, $LTLIBTHREAD and $LIBTHREAD have the
411dnl same value, and similarly $LTLIBMULTITHREAD and $LIBMULTITHREAD have the
412dnl same value. Only system libraries are needed.
28 413
29AC_DEFUN([gl_THREADLIB_EARLY], 414AC_DEFUN([gl_THREADLIB_EARLY],
30[ 415[
@@ -43,18 +428,15 @@ AC_DEFUN([gl_THREADLIB_EARLY_BODY],
43 428
44 AC_REQUIRE([AC_CANONICAL_HOST]) 429 AC_REQUIRE([AC_CANONICAL_HOST])
45 dnl _GNU_SOURCE is needed for pthread_rwlock_t on glibc systems. 430 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 431 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. 432 dnl Check for multithreading.
52 m4_ifdef([gl_THREADLIB_DEFAULT_NO], 433 m4_ifdef([gl_THREADLIB_DEFAULT_NO],
53 [m4_divert_text([DEFAULTS], [gl_use_threads_default=no])], 434 [m4_divert_text([DEFAULTS], [gl_use_threads_default=no])],
54 [m4_divert_text([DEFAULTS], [gl_use_threads_default=])]) 435 [m4_divert_text([DEFAULTS], [gl_use_threads_default=])])
436 m4_divert_text([DEFAULTS], [gl_use_winpthreads_default=])
55 AC_ARG_ENABLE([threads], 437 AC_ARG_ENABLE([threads],
56AC_HELP_STRING([--enable-threads={posix|solaris|pth|windows}], [specify multithreading API])m4_ifdef([gl_THREADLIB_DEFAULT_NO], [], [ 438AS_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])]), 439AS_HELP_STRING([--disable-threads], [build without multithread safety])]),
58 [gl_use_threads=$enableval], 440 [gl_use_threads=$enableval],
59 [if test -n "$gl_use_threads_default"; then 441 [if test -n "$gl_use_threads_default"; then
60 gl_use_threads="$gl_use_threads_default" 442 gl_use_threads="$gl_use_threads_default"
@@ -64,41 +446,35 @@ changequote(,)dnl
64 dnl Disable multithreading by default on OSF/1, because it interferes 446 dnl Disable multithreading by default on OSF/1, because it interferes
65 dnl with fork()/exec(): When msgexec is linked with -lpthread, its 447 dnl with fork()/exec(): When msgexec is linked with -lpthread, its
66 dnl child process gets an endless segmentation fault inside execvp(). 448 dnl child process gets an endless segmentation fault inside execvp().
449 osf*) gl_use_threads=no ;;
67 dnl Disable multithreading by default on Cygwin 1.5.x, because it has 450 dnl Disable multithreading by default on Cygwin 1.5.x, because it has
68 dnl bugs that lead to endless loops or crashes. See 451 dnl bugs that lead to endless loops or crashes. See
69 dnl <http://cygwin.com/ml/cygwin/2009-08/msg00283.html>. 452 dnl <https://cygwin.com/ml/cygwin/2009-08/msg00283.html>.
70 osf*) gl_use_threads=no ;;
71 cygwin*) 453 cygwin*)
72 case `uname -r` in 454 case `uname -r` in
73 1.[0-5].*) gl_use_threads=no ;; 455 1.[0-5].*) gl_use_threads=no ;;
74 *) gl_use_threads=yes ;; 456 *) gl_use_threads=yes ;;
75 esac 457 esac
76 ;; 458 ;;
459 dnl Obey gl_AVOID_WINPTHREAD on mingw.
460 mingw*)
461 case "$gl_use_winpthreads_default" in
462 yes) gl_use_threads=posix ;;
463 no) gl_use_threads=windows ;;
464 *) gl_use_threads=yes ;;
465 esac
466 ;;
77 *) gl_use_threads=yes ;; 467 *) gl_use_threads=yes ;;
78 esac 468 esac
79changequote([,])dnl 469changequote([,])dnl
80 fi 470 fi
81 ]) 471 ])
82 if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then 472 if test "$gl_use_threads" = yes \
83 # For using <pthread.h>: 473 || test "$gl_use_threads" = isoc \
84 case "$host_os" in 474 || test "$gl_use_threads" = posix \
85 osf*) 475 || test "$gl_use_threads" = isoc+posix; then
86 # On OSF/1, the compiler needs the flag -D_REENTRANT so that it 476 # For using <threads.h> or <pthread.h>:
87 # groks <pthread.h>. cc also understands the flag -pthread, but 477 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 478 fi
103]) 479])
104 480
@@ -114,168 +490,69 @@ AC_DEFUN([gl_THREADLIB_BODY],
114 LTLIBMULTITHREAD= 490 LTLIBMULTITHREAD=
115 if test "$gl_use_threads" != no; then 491 if test "$gl_use_threads" != no; then
116 dnl Check whether the compiler and linker support weak declarations. 492 dnl Check whether the compiler and linker support weak declarations.
117 AC_CACHE_CHECK([whether imported symbols can be declared weak], 493 gl_WEAK_SYMBOLS
118 [gl_cv_have_weak], 494 if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then
119 [gl_cv_have_weak=no 495 dnl If we use weak symbols to implement pthread_in_use / pth_in_use /
120 dnl First, test whether the compiler accepts it syntactically. 496 dnl thread_in_use, we also need to test whether the ISO C 11 thrd_create
121 AC_LINK_IFELSE( 497 dnl facility is in use.
122 [AC_LANG_PROGRAM( 498 AC_CHECK_HEADERS_ONCE([threads.h])
123 [[extern void xyzzy (); 499 :
124#pragma weak xyzzy]], 500 fi
125 [[xyzzy();]])], 501 if test "$gl_use_threads" = isoc || test "$gl_use_threads" = isoc+posix; then
126 [gl_cv_have_weak=maybe]) 502 AC_CHECK_HEADERS_ONCE([threads.h])
127 if test $gl_cv_have_weak = maybe; then 503 gl_have_isoc_threads="$ac_cv_header_threads_h"
128 dnl Second, test whether it actually works. On Cygwin 1.7.2, with 504 fi
129 dnl gcc 4.3, symbols declared weak always evaluate to the address 0. 505 if test "$gl_use_threads" = yes \
130 AC_RUN_IFELSE( 506 || test "$gl_use_threads" = posix \
131 [AC_LANG_SOURCE([[ 507 || test "$gl_use_threads" = isoc+posix; then
132#include <stdio.h> 508 gl_PTHREADLIB_BODY
133#pragma weak fputs 509 LIBTHREAD=$LIBPTHREAD LTLIBTHREAD=$LIBPTHREAD
134int main () 510 LIBMULTITHREAD=$LIBPMULTITHREAD LTLIBMULTITHREAD=$LIBPMULTITHREAD
135{ 511 if test $gl_pthread_api = yes; then
136 return (fputs == NULL); 512 if test "$gl_use_threads" = isoc+posix && test "$gl_have_isoc_threads" = yes; then
137}]])], 513 gl_threads_api='isoc+posix'
138 [gl_cv_have_weak=yes], 514 AC_DEFINE([USE_ISOC_AND_POSIX_THREADS], [1],
139 [gl_cv_have_weak=no], 515 [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 516 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 517 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 518 gl_threads_api=posix
204 AC_DEFINE([USE_POSIX_THREADS], [1], 519 AC_DEFINE([USE_POSIX_THREADS], [1],
205 [Define if the POSIX multithreading library can be used.]) 520 [Define if the POSIX multithreading library can be used.])
206 if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then 521 if test -z "$LIBMULTITHREAD" && test -z "$LTLIBMULTITHREAD"; then
522 AC_DEFINE([USE_POSIX_THREADS_FROM_LIBC], [1],
523 [Define if references to the POSIX multithreading library are satisfied by libc.])
524 else
207 if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then 525 if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then
208 AC_DEFINE([USE_POSIX_THREADS_WEAK], [1], 526 AC_DEFINE([USE_POSIX_THREADS_WEAK], [1],
209 [Define if references to the POSIX multithreading library should be made weak.]) 527 [Define if references to the POSIX multithreading library should be made weak.])
210 LIBTHREAD= 528 LIBTHREAD= LTLIBTHREAD=
211 LTLIBTHREAD= 529 else
530 case "$host_os" in
531 freebsd* | dragonfly* | midnightbsd*)
532 if test "x$LIBTHREAD" != "x$LIBMULTITHREAD"; then
533 dnl If weak symbols can't tell whether pthread_create(), pthread_key_create()
534 dnl etc. will succeed, we need a runtime test.
535 AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], [1],
536 [Define if the pthread_in_use() detection is hard.])
537 fi
538 ;;
539 esac
212 fi 540 fi
213 fi 541 fi
214 fi 542 fi
215 fi 543 fi
216 fi 544 fi
217 if test -z "$gl_have_pthread"; then 545 if test $gl_threads_api = none; then
218 if test "$gl_use_threads" = yes || test "$gl_use_threads" = solaris; then 546 if test "$gl_use_threads" = isoc && test "$gl_have_isoc_threads" = yes; then
219 gl_have_solaristhread= 547 gl_STDTHREADLIB_BODY
220 gl_save_LIBS="$LIBS" 548 LIBTHREAD=$LIBSTDTHREAD LTLIBTHREAD=$LIBSTDTHREAD
221 LIBS="$LIBS -lthread" 549 LIBMULTITHREAD=$LIBSTDTHREAD LTLIBMULTITHREAD=$LIBSTDTHREAD
222 AC_LINK_IFELSE( 550 gl_threads_api=isoc
223 [AC_LANG_PROGRAM( 551 AC_DEFINE([USE_ISOC_THREADS], [1],
224 [[ 552 [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 553 fi
247 fi 554 fi
248 if test "$gl_use_threads" = pth; then 555 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 556 case "$gl_use_threads" in
280 yes | windows | win32) # The 'win32' is for backward compatibility. 557 yes | windows | win32) # The 'win32' is for backward compatibility.
281 if { case "$host_os" in 558 if { case "$host_os" in
@@ -317,6 +594,21 @@ AC_DEFUN([gl_DISABLE_THREADS], [
317]) 594])
318 595
319 596
597dnl gl_AVOID_WINPTHREAD
598dnl -------------------
599dnl Sets the gl_THREADLIB default so that on mingw, a dependency to the
600dnl libwinpthread DLL (mingw-w64 winpthreads library) is avoided.
601dnl The user can still override it at installation time, by using the
602dnl configure option '--enable-threads'.
603
604AC_DEFUN([gl_AVOID_WINPTHREAD], [
605 m4_divert_text([INIT_PREPARE], [gl_use_winpthreads_default=no])
606])
607
608
609dnl ============================================================================
610
611
320dnl Survey of platforms: 612dnl Survey of platforms:
321dnl 613dnl
322dnl Platform Available Compiler Supports test-lock 614dnl Platform Available Compiler Supports test-lock
@@ -324,7 +616,11 @@ dnl flavours option weak result
324dnl --------------- --------- --------- -------- --------- 616dnl --------------- --------- --------- -------- ---------
325dnl Linux 2.4/glibc posix -lpthread Y OK 617dnl Linux 2.4/glibc posix -lpthread Y OK
326dnl 618dnl
327dnl GNU Hurd/glibc posix 619dnl Linux/glibc 2.34 posix Y OK
620dnl
621dnl GNU Hurd/glibc posix -lpthread Y OK
622dnl
623dnl Ubuntu 14.04 posix -pthread Y OK
328dnl 624dnl
329dnl FreeBSD 5.3 posix -lc_r Y 625dnl FreeBSD 5.3 posix -lc_r Y
330dnl posix -lkse ? Y 626dnl posix -lkse ? Y
@@ -344,7 +640,6 @@ dnl
344dnl Mac OS X 10.[123] posix -lpthread Y OK 640dnl Mac OS X 10.[123] posix -lpthread Y OK
345dnl 641dnl
346dnl Solaris 7,8,9 posix -lpthread Y Sol 7,8: 0.0; Sol 9: OK 642dnl 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 643dnl
349dnl HP-UX 11 posix -lpthread N (cc) OK 644dnl HP-UX 11 posix -lpthread N (cc) OK
350dnl Y (gcc) 645dnl Y (gcc)
@@ -358,8 +653,6 @@ dnl -lpthread (gcc) Y
358dnl 653dnl
359dnl Cygwin posix -lpthread Y OK 654dnl Cygwin posix -lpthread Y OK
360dnl 655dnl
361dnl Any of the above pth -lpth 0.0
362dnl
363dnl Mingw windows N OK 656dnl Mingw windows N OK
364dnl 657dnl
365dnl BeOS 5 -- 658dnl BeOS 5 --
diff --git a/gl/m4/time_h.m4 b/gl/m4/time_h.m4
index 3b83900..b57474b 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-2021 Free Software Foundation, Inc.
4 4
5# serial 7 5# serial 18
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,36 @@
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 AC_REQUIRE([AC_C_RESTRICT])
23
24 AC_CACHE_CHECK([for TIME_UTC in <time.h>],
25 [gl_cv_time_h_has_TIME_UTC],
26 [AC_COMPILE_IFELSE(
27 [AC_LANG_PROGRAM(
28 [[#include <time.h>
29 ]],
30 [[static int x = TIME_UTC; x++;]])],
31 [gl_cv_time_h_has_TIME_UTC=yes],
32 [gl_cv_time_h_has_TIME_UTC=no])])
33 if test $gl_cv_time_h_has_TIME_UTC = yes; then
34 TIME_H_DEFINES_TIME_UTC=1
35 else
36 TIME_H_DEFINES_TIME_UTC=0
37 fi
38 AC_SUBST([TIME_H_DEFINES_TIME_UTC])
26]) 39])
27 40
28dnl Check whether 'struct timespec' is declared 41dnl Check whether 'struct timespec' is declared
29dnl in time.h, sys/time.h, or pthread.h. 42dnl in time.h, sys/time.h, pthread.h, or unistd.h.
30 43
31AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC], 44AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
32[ 45[
@@ -44,6 +57,7 @@ AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
44 TIME_H_DEFINES_STRUCT_TIMESPEC=0 57 TIME_H_DEFINES_STRUCT_TIMESPEC=0
45 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0 58 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0
46 PTHREAD_H_DEFINES_STRUCT_TIMESPEC=0 59 PTHREAD_H_DEFINES_STRUCT_TIMESPEC=0
60 UNISTD_H_DEFINES_STRUCT_TIMESPEC=0
47 if test $gl_cv_sys_struct_timespec_in_time_h = yes; then 61 if test $gl_cv_sys_struct_timespec_in_time_h = yes; then
48 TIME_H_DEFINES_STRUCT_TIMESPEC=1 62 TIME_H_DEFINES_STRUCT_TIMESPEC=1
49 else 63 else
@@ -70,40 +84,92 @@ AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
70 [gl_cv_sys_struct_timespec_in_pthread_h=no])]) 84 [gl_cv_sys_struct_timespec_in_pthread_h=no])])
71 if test $gl_cv_sys_struct_timespec_in_pthread_h = yes; then 85 if test $gl_cv_sys_struct_timespec_in_pthread_h = yes; then
72 PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1 86 PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1
87 else
88 AC_CACHE_CHECK([for struct timespec in <unistd.h>],
89 [gl_cv_sys_struct_timespec_in_unistd_h],
90 [AC_COMPILE_IFELSE(
91 [AC_LANG_PROGRAM(
92 [[#include <unistd.h>
93 ]],
94 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
95 [gl_cv_sys_struct_timespec_in_unistd_h=yes],
96 [gl_cv_sys_struct_timespec_in_unistd_h=no])])
97 if test $gl_cv_sys_struct_timespec_in_unistd_h = yes; then
98 UNISTD_H_DEFINES_STRUCT_TIMESPEC=1
99 fi
73 fi 100 fi
74 fi 101 fi
75 fi 102 fi
76 AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC]) 103 AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC])
77 AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC]) 104 AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC])
78 AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC]) 105 AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC])
106 AC_SUBST([UNISTD_H_DEFINES_STRUCT_TIMESPEC])
79]) 107])
80 108
109# gl_TIME_MODULE_INDICATOR([modulename])
110# sets the shell variable that indicates the presence of the given module
111# to a C preprocessor expression that will evaluate to 1.
112# This macro invocation must not occur in macros that are AC_REQUIREd.
81AC_DEFUN([gl_TIME_MODULE_INDICATOR], 113AC_DEFUN([gl_TIME_MODULE_INDICATOR],
82[ 114[
83 dnl Use AC_REQUIRE here, so that the default settings are expanded once only. 115 dnl Ensure to expand the default settings once only.
84 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) 116 gl_TIME_H_REQUIRE_DEFAULTS
85 gl_MODULE_INDICATOR_SET_VARIABLE([$1]) 117 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
86 dnl Define it also as a C macro, for the benefit of the unit tests. 118 dnl Define it also as a C macro, for the benefit of the unit tests.
87 gl_MODULE_INDICATOR_FOR_TESTS([$1]) 119 gl_MODULE_INDICATOR_FOR_TESTS([$1])
88]) 120])
89 121
90AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS], 122# Initializes the default values for AC_SUBSTed shell variables.
123# This macro must not be AC_REQUIREd. It must only be invoked, and only
124# outside of macros or in macros that are not AC_REQUIREd.
125AC_DEFUN([gl_TIME_H_REQUIRE_DEFAULTS],
126[
127 m4_defun(GL_MODULE_INDICATOR_PREFIX[_TIME_H_MODULE_INDICATOR_DEFAULTS], [
128 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_CTIME])
129 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKTIME])
130 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LOCALTIME])
131 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_NANOSLEEP])
132 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRFTIME])
133 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRPTIME])
134 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIMEGM])
135 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIMESPEC_GET])
136 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIME_R])
137 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIME_RZ])
138 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TZSET])
139 dnl Support Microsoft deprecated alias function names by default.
140 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_TZSET], [1])
141 ])
142 m4_require(GL_MODULE_INDICATOR_PREFIX[_TIME_H_MODULE_INDICATOR_DEFAULTS])
143 AC_REQUIRE([gl_TIME_H_DEFAULTS])
144])
145
146AC_DEFUN([gl_TIME_H_DEFAULTS],
91[ 147[
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. 148 dnl Assume proper GNU behavior unless another module says otherwise.
98 HAVE_DECL_LOCALTIME_R=1; AC_SUBST([HAVE_DECL_LOCALTIME_R]) 149 HAVE_DECL_LOCALTIME_R=1; AC_SUBST([HAVE_DECL_LOCALTIME_R])
99 HAVE_NANOSLEEP=1; AC_SUBST([HAVE_NANOSLEEP]) 150 HAVE_NANOSLEEP=1; AC_SUBST([HAVE_NANOSLEEP])
100 HAVE_STRPTIME=1; AC_SUBST([HAVE_STRPTIME]) 151 HAVE_STRPTIME=1; AC_SUBST([HAVE_STRPTIME])
101 HAVE_TIMEGM=1; AC_SUBST([HAVE_TIMEGM]) 152 HAVE_TIMEGM=1; AC_SUBST([HAVE_TIMEGM])
153 HAVE_TIMESPEC_GET=1; AC_SUBST([HAVE_TIMESPEC_GET])
154 dnl Even GNU libc does not have timezone_t yet.
155 HAVE_TIMEZONE_T=0; AC_SUBST([HAVE_TIMEZONE_T])
102 dnl If another module says to replace or to not replace, do that. 156 dnl If another module says to replace or to not replace, do that.
103 dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK; 157 dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK;
104 dnl this lets maintainers check for portability. 158 dnl this lets maintainers check for portability.
159 REPLACE_CTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_CTIME])
105 REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R]) 160 REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R])
106 REPLACE_MKTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_MKTIME]) 161 REPLACE_MKTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_MKTIME])
107 REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP]) 162 REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP])
163 REPLACE_STRFTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_STRFTIME])
108 REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM]) 164 REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM])
165 REPLACE_TZSET=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TZSET])
166
167 dnl Hack so that the time module doesn't depend on the sys_time module.
168 dnl First, default GNULIB_GETTIMEOFDAY to 0 if sys_time is absent.
169 : ${GNULIB_GETTIMEOFDAY=0}; AC_SUBST([GNULIB_GETTIMEOFDAY])
170 dnl Second, it's OK to not use GNULIB_PORTCHECK for REPLACE_GMTIME
171 dnl and REPLACE_LOCALTIME, as portability to Solaris 2.6 and earlier
172 dnl is no longer a big deal.
173 REPLACE_GMTIME=0; AC_SUBST([REPLACE_GMTIME])
174 REPLACE_LOCALTIME=0; AC_SUBST([REPLACE_LOCALTIME])
109]) 175])
diff --git a/gl/m4/time_r.m4 b/gl/m4/time_r.m4
index c388a83..2d49b64 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-2021 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..58123be 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-2021 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..dd5d1dd
--- /dev/null
+++ b/gl/m4/ungetc.m4
@@ -0,0 +1,73 @@
1# ungetc.m4 serial 10
2dnl Copyright (C) 2009-2021 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..0ce4ea4 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 89
2dnl Copyright (C) 2006-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2006-2021 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,83 +37,144 @@ 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_GETUSERSHELL])
116 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GROUP_MEMBER])
117 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISATTY])
118 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LCHOWN])
119 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LINK])
120 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LINKAT])
121 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LSEEK])
122 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PIPE])
123 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PIPE2])
124 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PREAD])
125 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PWRITE])
126 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_READ])
127 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_READLINK])
128 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_READLINKAT])
129 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RMDIR])
130 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SETHOSTNAME])
131 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SLEEP])
132 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SYMLINK])
133 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SYMLINKAT])
134 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TRUNCATE])
135 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TTYNAME_R])
136 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_UNISTD_H_GETOPT])
137 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_UNISTD_H_NONBLOCKING])
138 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_UNISTD_H_SIGPIPE])
139 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_UNLINK])
140 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_UNLINKAT])
141 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_USLEEP])
142 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_WRITE])
143 dnl Support Microsoft deprecated alias function names by default.
144 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_ACCESS], [1])
145 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_CHDIR], [1])
146 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_CLOSE], [1])
147 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_DUP], [1])
148 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_DUP2], [1])
149 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_EXECL], [1])
150 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_EXECLE], [1])
151 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_EXECLP], [1])
152 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_EXECV], [1])
153 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_EXECVE], [1])
154 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_EXECVP], [1])
155 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_EXECVPE], [1])
156 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_GETCWD], [1])
157 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_GETPID], [1])
158 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_ISATTY], [1])
159 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_LSEEK], [1])
160 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_READ], [1])
161 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_RMDIR], [1])
162 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_SWAB], [1])
163 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_UNLINK], [1])
164 gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_WRITE], [1])
165 ])
166 m4_require(GL_MODULE_INDICATOR_PREFIX[_UNISTD_H_MODULE_INDICATOR_DEFAULTS])
167 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
168])
169
62AC_DEFUN([gl_UNISTD_H_DEFAULTS], 170AC_DEFUN([gl_UNISTD_H_DEFAULTS],
63[ 171[
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. 172 dnl Assume proper GNU behavior unless another module says otherwise.
113 HAVE_CHOWN=1; AC_SUBST([HAVE_CHOWN]) 173 HAVE_CHOWN=1; AC_SUBST([HAVE_CHOWN])
114 HAVE_DUP2=1; AC_SUBST([HAVE_DUP2]) 174 HAVE_COPY_FILE_RANGE=1; AC_SUBST([HAVE_COPY_FILE_RANGE])
115 HAVE_DUP3=1; AC_SUBST([HAVE_DUP3]) 175 HAVE_DUP3=1; AC_SUBST([HAVE_DUP3])
116 HAVE_EUIDACCESS=1; AC_SUBST([HAVE_EUIDACCESS]) 176 HAVE_EUIDACCESS=1; AC_SUBST([HAVE_EUIDACCESS])
177 HAVE_EXECVPE=1; AC_SUBST([HAVE_EXECVPE])
117 HAVE_FACCESSAT=1; AC_SUBST([HAVE_FACCESSAT]) 178 HAVE_FACCESSAT=1; AC_SUBST([HAVE_FACCESSAT])
118 HAVE_FCHDIR=1; AC_SUBST([HAVE_FCHDIR]) 179 HAVE_FCHDIR=1; AC_SUBST([HAVE_FCHDIR])
119 HAVE_FCHOWNAT=1; AC_SUBST([HAVE_FCHOWNAT]) 180 HAVE_FCHOWNAT=1; AC_SUBST([HAVE_FCHOWNAT])
@@ -121,10 +182,12 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
121 HAVE_FSYNC=1; AC_SUBST([HAVE_FSYNC]) 182 HAVE_FSYNC=1; AC_SUBST([HAVE_FSYNC])
122 HAVE_FTRUNCATE=1; AC_SUBST([HAVE_FTRUNCATE]) 183 HAVE_FTRUNCATE=1; AC_SUBST([HAVE_FTRUNCATE])
123 HAVE_GETDTABLESIZE=1; AC_SUBST([HAVE_GETDTABLESIZE]) 184 HAVE_GETDTABLESIZE=1; AC_SUBST([HAVE_GETDTABLESIZE])
185 HAVE_GETENTROPY=1; AC_SUBST([HAVE_GETENTROPY])
124 HAVE_GETGROUPS=1; AC_SUBST([HAVE_GETGROUPS]) 186 HAVE_GETGROUPS=1; AC_SUBST([HAVE_GETGROUPS])
125 HAVE_GETHOSTNAME=1; AC_SUBST([HAVE_GETHOSTNAME]) 187 HAVE_GETHOSTNAME=1; AC_SUBST([HAVE_GETHOSTNAME])
126 HAVE_GETLOGIN=1; AC_SUBST([HAVE_GETLOGIN]) 188 HAVE_GETLOGIN=1; AC_SUBST([HAVE_GETLOGIN])
127 HAVE_GETPAGESIZE=1; AC_SUBST([HAVE_GETPAGESIZE]) 189 HAVE_GETPAGESIZE=1; AC_SUBST([HAVE_GETPAGESIZE])
190 HAVE_GETPASS=1; AC_SUBST([HAVE_GETPASS])
128 HAVE_GROUP_MEMBER=1; AC_SUBST([HAVE_GROUP_MEMBER]) 191 HAVE_GROUP_MEMBER=1; AC_SUBST([HAVE_GROUP_MEMBER])
129 HAVE_LCHOWN=1; AC_SUBST([HAVE_LCHOWN]) 192 HAVE_LCHOWN=1; AC_SUBST([HAVE_LCHOWN])
130 HAVE_LINK=1; AC_SUBST([HAVE_LINK]) 193 HAVE_LINK=1; AC_SUBST([HAVE_LINK])
@@ -142,27 +205,41 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
142 HAVE_UNLINKAT=1; AC_SUBST([HAVE_UNLINKAT]) 205 HAVE_UNLINKAT=1; AC_SUBST([HAVE_UNLINKAT])
143 HAVE_USLEEP=1; AC_SUBST([HAVE_USLEEP]) 206 HAVE_USLEEP=1; AC_SUBST([HAVE_USLEEP])
144 HAVE_DECL_ENVIRON=1; AC_SUBST([HAVE_DECL_ENVIRON]) 207 HAVE_DECL_ENVIRON=1; AC_SUBST([HAVE_DECL_ENVIRON])
208 HAVE_DECL_EXECVPE=1; AC_SUBST([HAVE_DECL_EXECVPE])
145 HAVE_DECL_FCHDIR=1; AC_SUBST([HAVE_DECL_FCHDIR]) 209 HAVE_DECL_FCHDIR=1; AC_SUBST([HAVE_DECL_FCHDIR])
146 HAVE_DECL_FDATASYNC=1; AC_SUBST([HAVE_DECL_FDATASYNC]) 210 HAVE_DECL_FDATASYNC=1; AC_SUBST([HAVE_DECL_FDATASYNC])
147 HAVE_DECL_GETDOMAINNAME=1; AC_SUBST([HAVE_DECL_GETDOMAINNAME]) 211 HAVE_DECL_GETDOMAINNAME=1; AC_SUBST([HAVE_DECL_GETDOMAINNAME])
212 HAVE_DECL_GETLOGIN=1; AC_SUBST([HAVE_DECL_GETLOGIN])
148 HAVE_DECL_GETLOGIN_R=1; AC_SUBST([HAVE_DECL_GETLOGIN_R]) 213 HAVE_DECL_GETLOGIN_R=1; AC_SUBST([HAVE_DECL_GETLOGIN_R])
149 HAVE_DECL_GETPAGESIZE=1; AC_SUBST([HAVE_DECL_GETPAGESIZE]) 214 HAVE_DECL_GETPAGESIZE=1; AC_SUBST([HAVE_DECL_GETPAGESIZE])
150 HAVE_DECL_GETUSERSHELL=1; AC_SUBST([HAVE_DECL_GETUSERSHELL]) 215 HAVE_DECL_GETUSERSHELL=1; AC_SUBST([HAVE_DECL_GETUSERSHELL])
151 HAVE_DECL_SETHOSTNAME=1; AC_SUBST([HAVE_DECL_SETHOSTNAME]) 216 HAVE_DECL_SETHOSTNAME=1; AC_SUBST([HAVE_DECL_SETHOSTNAME])
217 HAVE_DECL_TRUNCATE=1; AC_SUBST([HAVE_DECL_TRUNCATE])
152 HAVE_DECL_TTYNAME_R=1; AC_SUBST([HAVE_DECL_TTYNAME_R]) 218 HAVE_DECL_TTYNAME_R=1; AC_SUBST([HAVE_DECL_TTYNAME_R])
153 HAVE_OS_H=0; AC_SUBST([HAVE_OS_H]) 219 HAVE_OS_H=0; AC_SUBST([HAVE_OS_H])
154 HAVE_SYS_PARAM_H=0; AC_SUBST([HAVE_SYS_PARAM_H]) 220 HAVE_SYS_PARAM_H=0; AC_SUBST([HAVE_SYS_PARAM_H])
221 REPLACE_ACCESS=0; AC_SUBST([REPLACE_ACCESS])
155 REPLACE_CHOWN=0; AC_SUBST([REPLACE_CHOWN]) 222 REPLACE_CHOWN=0; AC_SUBST([REPLACE_CHOWN])
156 REPLACE_CLOSE=0; AC_SUBST([REPLACE_CLOSE]) 223 REPLACE_CLOSE=0; AC_SUBST([REPLACE_CLOSE])
157 REPLACE_DUP=0; AC_SUBST([REPLACE_DUP]) 224 REPLACE_DUP=0; AC_SUBST([REPLACE_DUP])
158 REPLACE_DUP2=0; AC_SUBST([REPLACE_DUP2]) 225 REPLACE_DUP2=0; AC_SUBST([REPLACE_DUP2])
226 REPLACE_EXECL=0; AC_SUBST([REPLACE_EXECL])
227 REPLACE_EXECLE=0; AC_SUBST([REPLACE_EXECLE])
228 REPLACE_EXECLP=0; AC_SUBST([REPLACE_EXECLP])
229 REPLACE_EXECV=0; AC_SUBST([REPLACE_EXECV])
230 REPLACE_EXECVE=0; AC_SUBST([REPLACE_EXECVE])
231 REPLACE_EXECVP=0; AC_SUBST([REPLACE_EXECVP])
232 REPLACE_EXECVPE=0; AC_SUBST([REPLACE_EXECVPE])
233 REPLACE_FACCESSAT=0; AC_SUBST([REPLACE_FACCESSAT])
159 REPLACE_FCHOWNAT=0; AC_SUBST([REPLACE_FCHOWNAT]) 234 REPLACE_FCHOWNAT=0; AC_SUBST([REPLACE_FCHOWNAT])
160 REPLACE_FTRUNCATE=0; AC_SUBST([REPLACE_FTRUNCATE]) 235 REPLACE_FTRUNCATE=0; AC_SUBST([REPLACE_FTRUNCATE])
161 REPLACE_GETCWD=0; AC_SUBST([REPLACE_GETCWD]) 236 REPLACE_GETCWD=0; AC_SUBST([REPLACE_GETCWD])
162 REPLACE_GETDOMAINNAME=0; AC_SUBST([REPLACE_GETDOMAINNAME]) 237 REPLACE_GETDOMAINNAME=0; AC_SUBST([REPLACE_GETDOMAINNAME])
238 REPLACE_GETDTABLESIZE=0; AC_SUBST([REPLACE_GETDTABLESIZE])
163 REPLACE_GETLOGIN_R=0; AC_SUBST([REPLACE_GETLOGIN_R]) 239 REPLACE_GETLOGIN_R=0; AC_SUBST([REPLACE_GETLOGIN_R])
164 REPLACE_GETGROUPS=0; AC_SUBST([REPLACE_GETGROUPS]) 240 REPLACE_GETGROUPS=0; AC_SUBST([REPLACE_GETGROUPS])
165 REPLACE_GETPAGESIZE=0; AC_SUBST([REPLACE_GETPAGESIZE]) 241 REPLACE_GETPAGESIZE=0; AC_SUBST([REPLACE_GETPAGESIZE])
242 REPLACE_GETPASS=0; AC_SUBST([REPLACE_GETPASS])
166 REPLACE_ISATTY=0; AC_SUBST([REPLACE_ISATTY]) 243 REPLACE_ISATTY=0; AC_SUBST([REPLACE_ISATTY])
167 REPLACE_LCHOWN=0; AC_SUBST([REPLACE_LCHOWN]) 244 REPLACE_LCHOWN=0; AC_SUBST([REPLACE_LCHOWN])
168 REPLACE_LINK=0; AC_SUBST([REPLACE_LINK]) 245 REPLACE_LINK=0; AC_SUBST([REPLACE_LINK])
@@ -172,14 +249,18 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
172 REPLACE_PWRITE=0; AC_SUBST([REPLACE_PWRITE]) 249 REPLACE_PWRITE=0; AC_SUBST([REPLACE_PWRITE])
173 REPLACE_READ=0; AC_SUBST([REPLACE_READ]) 250 REPLACE_READ=0; AC_SUBST([REPLACE_READ])
174 REPLACE_READLINK=0; AC_SUBST([REPLACE_READLINK]) 251 REPLACE_READLINK=0; AC_SUBST([REPLACE_READLINK])
252 REPLACE_READLINKAT=0; AC_SUBST([REPLACE_READLINKAT])
175 REPLACE_RMDIR=0; AC_SUBST([REPLACE_RMDIR]) 253 REPLACE_RMDIR=0; AC_SUBST([REPLACE_RMDIR])
176 REPLACE_SLEEP=0; AC_SUBST([REPLACE_SLEEP]) 254 REPLACE_SLEEP=0; AC_SUBST([REPLACE_SLEEP])
177 REPLACE_SYMLINK=0; AC_SUBST([REPLACE_SYMLINK]) 255 REPLACE_SYMLINK=0; AC_SUBST([REPLACE_SYMLINK])
256 REPLACE_SYMLINKAT=0; AC_SUBST([REPLACE_SYMLINKAT])
257 REPLACE_TRUNCATE=0; AC_SUBST([REPLACE_TRUNCATE])
178 REPLACE_TTYNAME_R=0; AC_SUBST([REPLACE_TTYNAME_R]) 258 REPLACE_TTYNAME_R=0; AC_SUBST([REPLACE_TTYNAME_R])
179 REPLACE_UNLINK=0; AC_SUBST([REPLACE_UNLINK]) 259 REPLACE_UNLINK=0; AC_SUBST([REPLACE_UNLINK])
180 REPLACE_UNLINKAT=0; AC_SUBST([REPLACE_UNLINKAT]) 260 REPLACE_UNLINKAT=0; AC_SUBST([REPLACE_UNLINKAT])
181 REPLACE_USLEEP=0; AC_SUBST([REPLACE_USLEEP]) 261 REPLACE_USLEEP=0; AC_SUBST([REPLACE_USLEEP])
182 REPLACE_WRITE=0; AC_SUBST([REPLACE_WRITE]) 262 REPLACE_WRITE=0; AC_SUBST([REPLACE_WRITE])
263 UNISTD_H_HAVE_SYS_RANDOM_H=0; AC_SUBST([UNISTD_H_HAVE_SYS_RANDOM_H])
183 UNISTD_H_HAVE_WINSOCK2_H=0; AC_SUBST([UNISTD_H_HAVE_WINSOCK2_H]) 264 UNISTD_H_HAVE_WINSOCK2_H=0; AC_SUBST([UNISTD_H_HAVE_WINSOCK2_H])
184 UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=0; 265 UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=0;
185 AC_SUBST([UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS]) 266 AC_SUBST([UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS])
diff --git a/gl/m4/unlocked-io.m4 b/gl/m4/unlocked-io.m4
new file mode 100644
index 0000000..b689020
--- /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-2021 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/vasnprintf.m4 b/gl/m4/vasnprintf.m4
index d730e43..483bba9 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-2021 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..a26de84 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-2021 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..d161bd7 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-2021 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..5f5375e 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-2021 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..04edfe8 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 9
2dnl Copyright (C) 2010-2013 Free Software Foundation, Inc. 2dnl Copyright (C) 2010-2021 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,25 @@ 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 AC_CACHE_CHECK([whether $gl_func is declared without a macro],
34 AC_CACHE_CHECK([whether $gl_func is declared without a macro], 36 [gl_Symbol],
35 gl_Symbol, 37 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$1],
36 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$1], 38[[#undef $gl_func
37[@%:@undef $gl_func 39 (void) $gl_func;]])],
38 (void) $gl_func;])], 40 [AS_VAR_SET([gl_Symbol], [yes])], [AS_VAR_SET([gl_Symbol], [no])])])
39 [AS_VAR_SET(gl_Symbol, [yes])], [AS_VAR_SET(gl_Symbol, [no])])]) 41 AS_VAR_IF([gl_Symbol], [yes],
40 AS_VAR_IF(gl_Symbol, [yes], 42 [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_RAW_DECL_$gl_func]), [1])
41 [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_RAW_DECL_$gl_func]), [1]) 43 dnl shortcut - if the raw declaration exists, then set a cache
42 dnl shortcut - if the raw declaration exists, then set a cache 44 dnl variable to allow skipping any later AC_CHECK_DECL efforts
43 dnl variable to allow skipping any later AC_CHECK_DECL efforts 45 eval ac_cv_have_decl_$gl_func=yes])
44 eval ac_cv_have_decl_$gl_func=yes]) 46 AS_VAR_POPDEF([gl_Symbol])dnl
45 AS_VAR_POPDEF([gl_Symbol])dnl 47 done
46 done 48 ])
47]) 49])
diff --git a/gl/m4/wchar_h.m4 b/gl/m4/wchar_h.m4
index bedb15a..9529cdd 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-2021 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..34db10e 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-2021 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..cd96f11 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-2021 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..7d74212 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-2021 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..a49c508 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-2021 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..8fabf1c 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-2021 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..64e8a4f 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-2021 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/year2038.m4 b/gl/m4/year2038.m4
new file mode 100644
index 0000000..da0f8d7
--- /dev/null
+++ b/gl/m4/year2038.m4
@@ -0,0 +1,124 @@
1# year2038.m4 serial 7
2dnl Copyright (C) 2017-2021 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 Attempt to ensure that 'time_t' can go past the year 2038 and that
8dnl the functions 'time', 'stat', etc. work with post-2038 timestamps.
9
10AC_DEFUN([gl_YEAR2038_EARLY],
11[
12 AC_REQUIRE([AC_CANONICAL_HOST])
13 case "$host_os" in
14 mingw*)
15 AC_DEFINE([__MINGW_USE_VC2005_COMPAT], [1],
16 [For 64-bit time_t on 32-bit mingw.])
17 ;;
18 esac
19])
20
21# gl_YEAR2038_TEST_INCLUDES
22# -------------------------
23AC_DEFUN([gl_YEAR2038_TEST_INCLUDES],
24[[
25 #include <time.h>
26 /* Check that time_t can represent 2**32 - 1 correctly. */
27 #define LARGE_TIME_T \\
28 ((time_t) (((time_t) 1 << 30) - 1 + 3 * ((time_t) 1 << 30)))
29 int verify_time_t_range[(LARGE_TIME_T / 65537 == 65535
30 && LARGE_TIME_T % 65537 == 0)
31 ? 1 : -1];
32]])
33
34# gl_YEAR2038_BODY(REQUIRE-YEAR2038-SAFE)
35-----------------------------------------
36AC_DEFUN([gl_YEAR2038_BODY],
37[
38 AC_ARG_ENABLE([year2038],
39 [ --disable-year2038 omit support for timestamps past the year 2038])
40 AS_IF([test "$enable_year2038" != no],
41 [
42 dnl On many systems, time_t is already a 64-bit type.
43 dnl On those systems where time_t is still 32-bit, it requires kernel
44 dnl and libc support to make it 64-bit. For glibc 2.34 and later on Linux,
45 dnl defining _TIME_BITS=64 and _FILE_OFFSET_BITS=64 is needed on x86 and ARM.
46 dnl
47 dnl On native Windows, the system include files define types __time32_t
48 dnl and __time64_t. By default, time_t is an alias of
49 dnl - __time32_t on 32-bit mingw,
50 dnl - __time64_t on 64-bit mingw and on MSVC (since MSVC 8).
51 dnl But when compiling with -D__MINGW_USE_VC2005_COMPAT, time_t is an
52 dnl alias of __time64_t.
53 dnl And when compiling with -D_USE_32BIT_TIME_T, time_t is an alias of
54 dnl __time32_t.
55 AC_CACHE_CHECK([for time_t past the year 2038], [gl_cv_type_time_t_y2038],
56 [AC_COMPILE_IFELSE(
57 [AC_LANG_SOURCE([gl_YEAR2038_TEST_INCLUDES])],
58 [gl_cv_type_time_t_y2038=yes], [gl_cv_type_time_t_y2038=no])
59 ])
60 if test "$gl_cv_type_time_t_y2038" = no; then
61 AC_CACHE_CHECK([for 64-bit time_t with _TIME_BITS=64],
62 [gl_cv_type_time_t_bits_macro],
63 [AC_COMPILE_IFELSE(
64 [AC_LANG_SOURCE([[#define _TIME_BITS 64
65 #define _FILE_OFFSET_BITS 64
66 ]gl_YEAR2038_TEST_INCLUDES])],
67 [gl_cv_type_time_t_bits_macro=yes],
68 [gl_cv_type_time_t_bits_macro=no])
69 ])
70 if test "$gl_cv_type_time_t_bits_macro" = yes; then
71 AC_DEFINE([_TIME_BITS], [64],
72 [Number of bits in a timestamp, on hosts where this is settable.])
73 dnl AC_SYS_LARGFILE also defines this; it's OK if we do too.
74 AC_DEFINE([_FILE_OFFSET_BITS], [64],
75 [Number of bits in a file offset, on hosts where this is settable.])
76 gl_cv_type_time_t_y2038=yes
77 fi
78 fi
79 if test $gl_cv_type_time_t_y2038 = no; then
80 AC_COMPILE_IFELSE(
81 [AC_LANG_SOURCE(
82 [[#ifdef _USE_32BIT_TIME_T
83 int ok;
84 #else
85 error fail
86 #endif
87 ]])],
88 [AC_MSG_FAILURE(
89 [The 'time_t' type stops working after January 2038.
90 Remove _USE_32BIT_TIME_T from the compiler flags.])],
91 [# If not cross-compiling and $1 says we should check,
92 # and 'touch' works with a large timestamp, then evidently wider time_t
93 # is desired and supported, so fail and ask the builder to fix the
94 # problem. Otherwise, just warn the builder.
95 m4_ifval([$1],
96 [if test $cross_compiling = no \
97 && TZ=UTC0 touch -t 210602070628.15 conftest.time 2>/dev/null; then
98 case `TZ=UTC0 LC_ALL=C ls -l conftest.time 2>/dev/null` in
99 *'Feb 7 2106'* | *'Feb 7 17:10'*)
100 AC_MSG_FAILURE(
101 [The 'time_t' type stops working after January 2038,
102 and your system appears to support a wider 'time_t'.
103 Try configuring with 'CC="${CC} -m64"'.
104 To build with a 32-bit time_t anyway (not recommended),
105 configure with '--disable-year2038'.]);;
106 esac
107 rm -f conftest.time
108 fi])
109 if test "$gl_warned_about_y2038" != yes; then
110 AC_MSG_WARN(
111 [The 'time_t' type stops working after January 2038,
112 and this package needs a wider 'time_t' type
113 if there is any way to access timestamps after that.
114 Configure with 'CC="${CC} -m64"' perhaps?])
115 gl_warned_about_y2038=yes
116 fi
117 ])
118 fi])
119])
120
121AC_DEFUN([gl_YEAR2038],
122[
123 gl_YEAR2038_BODY([require-year2038-safe])
124])
diff --git a/gl/m4/zzgnulib.m4 b/gl/m4/zzgnulib.m4
new file mode 100644
index 0000000..b953384
--- /dev/null
+++ b/gl/m4/zzgnulib.m4
@@ -0,0 +1,23 @@
1# zzgnulib.m4 serial 1
2dnl Copyright (C) 2020-2021 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..0d8b359 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-2021 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..48210e3
--- /dev/null
+++ b/gl/malloc/dynarray-skeleton.c
@@ -0,0 +1,528 @@
1/* Type-safe arrays which grow dynamically.
2 Copyright (C) 2017-2021 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..638c33f
--- /dev/null
+++ b/gl/malloc/dynarray.h
@@ -0,0 +1,178 @@
1/* Type-safe arrays which grow dynamically. Shared definitions.
2 Copyright (C) 2017-2021 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 <stdbool.h>
98#include <stddef.h>
99#include <string.h>
100
101struct dynarray_header
102{
103 size_t used;
104 size_t allocated;
105 void *array;
106};
107
108/* Marker used in the allocated member to indicate that an error was
109 encountered. */
110static inline size_t
111__dynarray_error_marker (void)
112{
113 return -1;
114}
115
116/* Internal function. See the has_failed function in
117 dynarray-skeleton.c. */
118static inline bool
119__dynarray_error (struct dynarray_header *list)
120{
121 return list->allocated == __dynarray_error_marker ();
122}
123
124/* Internal function. Enlarge the dynamically allocated area of the
125 array to make room for one more element. SCRATCH is a pointer to
126 the scratch area (which is not heap-allocated and must not be
127 freed). ELEMENT_SIZE is the size, in bytes, of one element.
128 Return false on failure, true on success. */
129bool __libc_dynarray_emplace_enlarge (struct dynarray_header *,
130 void *scratch, size_t element_size);
131
132/* Internal function. Enlarge the dynamically allocated area of the
133 array to make room for at least SIZE elements (which must be larger
134 than the existing used part of the dynamic array). SCRATCH is a
135 pointer to the scratch area (which is not heap-allocated and must
136 not be freed). ELEMENT_SIZE is the size, in bytes, of one element.
137 Return false on failure, true on success. */
138bool __libc_dynarray_resize (struct dynarray_header *, size_t size,
139 void *scratch, size_t element_size);
140
141/* Internal function. Like __libc_dynarray_resize, but clear the new
142 part of the dynamic array. */
143bool __libc_dynarray_resize_clear (struct dynarray_header *, size_t size,
144 void *scratch, size_t element_size);
145
146/* Internal type. */
147struct dynarray_finalize_result
148{
149 void *array;
150 size_t length;
151};
152
153/* Internal function. Copy the dynamically-allocated area to an
154 explicitly-sized heap allocation. SCRATCH is a pointer to the
155 embedded scratch space. ELEMENT_SIZE is the size, in bytes, of the
156 element type. On success, true is returned, and pointer and length
157 are written to *RESULT. On failure, false is returned. The caller
158 has to take care of some of the memory management; this function is
159 expected to be called from dynarray-skeleton.c. */
160bool __libc_dynarray_finalize (struct dynarray_header *list, void *scratch,
161 size_t element_size,
162 struct dynarray_finalize_result *result);
163
164
165/* Internal function. Terminate the process after an index error.
166 SIZE is the number of elements of the dynamic array. INDEX is the
167 lookup index which triggered the failure. */
168_Noreturn void __libc_dynarray_at_failure (size_t size, size_t index);
169
170#ifndef _ISOMAC
171libc_hidden_proto (__libc_dynarray_emplace_enlarge)
172libc_hidden_proto (__libc_dynarray_resize)
173libc_hidden_proto (__libc_dynarray_resize_clear)
174libc_hidden_proto (__libc_dynarray_finalize)
175libc_hidden_proto (__libc_dynarray_at_failure)
176#endif
177
178#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..8dd6850
--- /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-2021 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..0f8baf9
--- /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-2021 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..c33da41
--- /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-2021 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..5a57166
--- /dev/null
+++ b/gl/malloc/dynarray_resize.c
@@ -0,0 +1,68 @@
1/* Increase the size of a dynamic array.
2 Copyright (C) 2017-2021 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..9c43b00
--- /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-2021 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..b488423 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-2021 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,57 @@
21/* Specification. */ 21/* Specification. */
22#include "malloca.h" 22#include "malloca.h"
23 23
24#include <stdint.h> 24#include "idx.h"
25 25#include "intprops.h"
26#include "verify.h" 26#include "verify.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 42verify (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 (!INT_ADD_WRAPV (n, plus, &nplus) && !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 INT_ADD_WRAPV avoids signed integer overflow on
89 61 theoretical platforms where UINTPTR_MAX <= INT_MAX. */
90 p = h + 1; 62 INT_ADD_WRAPV (umem, sizeof (small_t) + sa_alignment_max - 1,
91 63 &umemplus);
92 /* Put a magic number into the indicator word. */ 64 idx_t offset = ((umemplus & ~alignment2_mask)
93 h->magic.word = MAGIC_NUMBER; 65 + sa_alignment_max - umem);
94 66 void *vp = mem + offset;
95 /* Enter p into the hash table. */ 67 small_t *p = vp;
96 slot = (uintptr_t) p % HASH_TABLE_SIZE; 68 /* Here p >= mem + sizeof (small_t),
97 h->next = mmalloca_results[slot]; 69 and p <= mem + sizeof (small_t) + 2 * sa_alignment_max - 1
98 mmalloca_results[slot] = p; 70 hence p + n <= mem + nplus.
99 71 So, the memory range [p, p+n) lies in the allocated memory range
72 [mem, mem + nplus). */
73 p[-1] = offset;
74 /* p ≡ sa_alignment_max mod 2*sa_alignment_max. */
100 return p; 75 return p;
101 } 76 }
102 } 77 }
@@ -115,35 +90,24 @@ mmalloca (size_t n)
115void 90void
116freea (void *p) 91freea (void *p)
117{ 92{
118 /* mmalloca() may have returned NULL. */ 93 /* Check argument. */
119 if (p != NULL) 94 if ((uintptr_t) p & (sa_alignment_max - 1))
120 { 95 {
121 /* Attempt to quickly distinguish the mmalloca() result - which has 96 /* p was not the result of a malloca() call. Invalid argument. */
122 a magic indicator word - and the alloca() result - which has an 97 abort ();
123 uninitialized indicator word. It is for this test that sa_increment 98 }
124 additional bytes are allocated in the alloca() case. */ 99 /* Determine whether p was a non-NULL pointer returned by mmalloca(). */
125 if (((int *) p)[-1] == MAGIC_NUMBER) 100 if ((uintptr_t) p & sa_alignment_max)
126 { 101 {
127 /* Looks like a mmalloca() result. To see whether it really is one, 102 void *mem = (char *) p - ((small_t *) p)[-1];
128 perform a lookup in the hash table. */ 103 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 } 104 }
148} 105}
149#endif 106#endif
107
108/*
109 * Hey Emacs!
110 * Local Variables:
111 * coding: utf-8
112 * End:
113 */
diff --git a/gl/malloca.h b/gl/malloca.h
index 6fbe45e..7eb63d2 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-2021 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..3ffd1d7 100644
--- a/gl/math.c
+++ b/gl/math.c
@@ -1,3 +1,22 @@
1/* Inline functions for <math.h>.
2
3 Copyright (C) 2012-2021 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..c87cc12 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-2021 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
@@ -403,6 +491,7 @@ _GL_WARN_ON_USE (ceilf, "ceilf is unportable - "
403#if @GNULIB_CEIL@ 491#if @GNULIB_CEIL@
404# if @REPLACE_CEIL@ 492# if @REPLACE_CEIL@
405# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 493# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
494# undef ceil
406# define ceil rpl_ceil 495# define ceil rpl_ceil
407# endif 496# endif
408_GL_FUNCDECL_RPL (ceil, double, (double x)); 497_GL_FUNCDECL_RPL (ceil, double, (double x));
@@ -410,7 +499,9 @@ _GL_CXXALIAS_RPL (ceil, double, (double x));
410# else 499# else
411_GL_CXXALIAS_SYS (ceil, double, (double x)); 500_GL_CXXALIAS_SYS (ceil, double, (double x));
412# endif 501# endif
413_GL_CXXALIASWARN (ceil); 502# if __GLIBC__ >= 2
503_GL_CXXALIASWARN1 (ceil, double, (double x));
504# endif
414#endif 505#endif
415 506
416#if @GNULIB_CEILL@ 507#if @GNULIB_CEILL@
@@ -428,7 +519,9 @@ _GL_FUNCDECL_SYS (ceill, long double, (long double x));
428# endif 519# endif
429_GL_CXXALIAS_SYS (ceill, long double, (long double x)); 520_GL_CXXALIAS_SYS (ceill, long double, (long double x));
430# endif 521# endif
522# if __GLIBC__ >= 2
431_GL_CXXALIASWARN (ceill); 523_GL_CXXALIASWARN (ceill);
524# endif
432#elif defined GNULIB_POSIXCHECK 525#elif defined GNULIB_POSIXCHECK
433# undef ceill 526# undef ceill
434# if HAVE_RAW_DECL_CEILL 527# if HAVE_RAW_DECL_CEILL
@@ -440,6 +533,7 @@ _GL_WARN_ON_USE (ceill, "ceill is unportable - "
440 533
441#if @GNULIB_COPYSIGNF@ 534#if @GNULIB_COPYSIGNF@
442# if !@HAVE_DECL_COPYSIGNF@ 535# if !@HAVE_DECL_COPYSIGNF@
536# undef copysignf
443_GL_FUNCDECL_SYS (copysignf, float, (float x, float y)); 537_GL_FUNCDECL_SYS (copysignf, float, (float x, float y));
444# endif 538# endif
445_GL_CXXALIAS_SYS (copysignf, float, (float x, float y)); 539_GL_CXXALIAS_SYS (copysignf, float, (float x, float y));
@@ -457,7 +551,9 @@ _GL_WARN_ON_USE (copysignf, "copysignf is unportable - "
457_GL_FUNCDECL_SYS (copysign, double, (double x, double y)); 551_GL_FUNCDECL_SYS (copysign, double, (double x, double y));
458# endif 552# endif
459_GL_CXXALIAS_SYS (copysign, double, (double x, double y)); 553_GL_CXXALIAS_SYS (copysign, double, (double x, double y));
460_GL_CXXALIASWARN (copysign); 554# if __GLIBC__ >= 2
555_GL_CXXALIASWARN1 (copysign, double, (double x, double y));
556# endif
461#elif defined GNULIB_POSIXCHECK 557#elif defined GNULIB_POSIXCHECK
462# undef copysign 558# undef copysign
463# if HAVE_RAW_DECL_COPYSIGN 559# if HAVE_RAW_DECL_COPYSIGN
@@ -482,11 +578,20 @@ _GL_WARN_ON_USE (copysign, "copysignl is unportable - "
482 578
483 579
484#if @GNULIB_COSF@ 580#if @GNULIB_COSF@
485# if !@HAVE_COSF@ 581# if @REPLACE_COSF@
486# undef cosf 582# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
583# undef cosf
584# define cosf rpl_cosf
585# endif
586_GL_FUNCDECL_RPL (cosf, float, (float x));
587_GL_CXXALIAS_RPL (cosf, float, (float x));
588# else
589# if !@HAVE_COSF@
590# undef cosf
487_GL_FUNCDECL_SYS (cosf, float, (float x)); 591_GL_FUNCDECL_SYS (cosf, float, (float x));
488# endif 592# endif
489_GL_CXXALIAS_SYS (cosf, float, (float x)); 593_GL_CXXALIAS_SYS (cosf, float, (float x));
594# endif
490_GL_CXXALIASWARN (cosf); 595_GL_CXXALIASWARN (cosf);
491#elif defined GNULIB_POSIXCHECK 596#elif defined GNULIB_POSIXCHECK
492# undef cosf 597# undef cosf
@@ -502,7 +607,9 @@ _GL_WARN_ON_USE (cosf, "cosf is unportable - "
502_GL_FUNCDECL_SYS (cosl, long double, (long double x)); 607_GL_FUNCDECL_SYS (cosl, long double, (long double x));
503# endif 608# endif
504_GL_CXXALIAS_SYS (cosl, long double, (long double x)); 609_GL_CXXALIAS_SYS (cosl, long double, (long double x));
610# if __GLIBC__ >= 2
505_GL_CXXALIASWARN (cosl); 611_GL_CXXALIASWARN (cosl);
612# endif
506#elif defined GNULIB_POSIXCHECK 613#elif defined GNULIB_POSIXCHECK
507# undef cosl 614# undef cosl
508# if HAVE_RAW_DECL_COSL 615# if HAVE_RAW_DECL_COSL
@@ -513,11 +620,20 @@ _GL_WARN_ON_USE (cosl, "cosl is unportable - "
513 620
514 621
515#if @GNULIB_COSHF@ 622#if @GNULIB_COSHF@
516# if !@HAVE_COSHF@ 623# if @REPLACE_COSHF@
517# undef coshf 624# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
625# undef coshf
626# define coshf rpl_coshf
627# endif
628_GL_FUNCDECL_RPL (coshf, float, (float x));
629_GL_CXXALIAS_RPL (coshf, float, (float x));
630# else
631# if !@HAVE_COSHF@
632# undef coshf
518_GL_FUNCDECL_SYS (coshf, float, (float x)); 633_GL_FUNCDECL_SYS (coshf, float, (float x));
519# endif 634# endif
520_GL_CXXALIAS_SYS (coshf, float, (float x)); 635_GL_CXXALIAS_SYS (coshf, float, (float x));
636# endif
521_GL_CXXALIASWARN (coshf); 637_GL_CXXALIASWARN (coshf);
522#elif defined GNULIB_POSIXCHECK 638#elif defined GNULIB_POSIXCHECK
523# undef coshf 639# undef coshf
@@ -529,11 +645,20 @@ _GL_WARN_ON_USE (coshf, "coshf is unportable - "
529 645
530 646
531#if @GNULIB_EXPF@ 647#if @GNULIB_EXPF@
532# if !@HAVE_EXPF@ 648# if @REPLACE_EXPF@
533# undef expf 649# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
650# undef expf
651# define expf rpl_expf
652# endif
653_GL_FUNCDECL_RPL (expf, float, (float x));
654_GL_CXXALIAS_RPL (expf, float, (float x));
655# else
656# if !@HAVE_EXPF@
657# undef expf
534_GL_FUNCDECL_SYS (expf, float, (float x)); 658_GL_FUNCDECL_SYS (expf, float, (float x));
535# endif 659# endif
536_GL_CXXALIAS_SYS (expf, float, (float x)); 660_GL_CXXALIAS_SYS (expf, float, (float x));
661# endif
537_GL_CXXALIASWARN (expf); 662_GL_CXXALIASWARN (expf);
538#elif defined GNULIB_POSIXCHECK 663#elif defined GNULIB_POSIXCHECK
539# undef expf 664# undef expf
@@ -544,12 +669,23 @@ _GL_WARN_ON_USE (expf, "expf is unportable - "
544#endif 669#endif
545 670
546#if @GNULIB_EXPL@ 671#if @GNULIB_EXPL@
547# if !@HAVE_EXPL@ || !@HAVE_DECL_EXPL@ 672# if @REPLACE_EXPL@
548# undef expl 673# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
674# undef expl
675# define expl rpl_expl
676# endif
677_GL_FUNCDECL_RPL (expl, long double, (long double x));
678_GL_CXXALIAS_RPL (expl, long double, (long double x));
679# else
680# if !@HAVE_EXPL@ || !@HAVE_DECL_EXPL@
681# undef expl
549_GL_FUNCDECL_SYS (expl, long double, (long double x)); 682_GL_FUNCDECL_SYS (expl, long double, (long double x));
550# endif 683# endif
551_GL_CXXALIAS_SYS (expl, long double, (long double x)); 684_GL_CXXALIAS_SYS (expl, long double, (long double x));
685# endif
686# if __GLIBC__ >= 2
552_GL_CXXALIASWARN (expl); 687_GL_CXXALIASWARN (expl);
688# endif
553#elif defined GNULIB_POSIXCHECK 689#elif defined GNULIB_POSIXCHECK
554# undef expl 690# undef expl
555# if HAVE_RAW_DECL_EXPL 691# if HAVE_RAW_DECL_EXPL
@@ -587,7 +723,9 @@ _GL_FUNCDECL_SYS (exp2, double, (double x));
587# endif 723# endif
588_GL_CXXALIAS_SYS (exp2, double, (double x)); 724_GL_CXXALIAS_SYS (exp2, double, (double x));
589# endif 725# endif
590_GL_CXXALIASWARN (exp2); 726# if __GLIBC__ >= 2
727_GL_CXXALIASWARN1 (exp2, double, (double x));
728# endif
591#elif defined GNULIB_POSIXCHECK 729#elif defined GNULIB_POSIXCHECK
592# undef exp2 730# undef exp2
593# if HAVE_RAW_DECL_EXP2 731# if HAVE_RAW_DECL_EXP2
@@ -658,7 +796,9 @@ _GL_FUNCDECL_SYS (expm1, double, (double x));
658# endif 796# endif
659_GL_CXXALIAS_SYS (expm1, double, (double x)); 797_GL_CXXALIAS_SYS (expm1, double, (double x));
660# endif 798# endif
661_GL_CXXALIASWARN (expm1); 799# if __GLIBC__ >= 2
800_GL_CXXALIASWARN1 (expm1, double, (double x));
801# endif
662#elif defined GNULIB_POSIXCHECK 802#elif defined GNULIB_POSIXCHECK
663# undef expm1 803# undef expm1
664# if HAVE_RAW_DECL_EXPM1 804# if HAVE_RAW_DECL_EXPM1
@@ -668,11 +808,22 @@ _GL_WARN_ON_USE (expm1, "expm1 is unportable - "
668#endif 808#endif
669 809
670#if @GNULIB_EXPM1L@ 810#if @GNULIB_EXPM1L@
671# if !@HAVE_DECL_EXPM1L@ 811# if @REPLACE_EXPM1L@
672# undef expm1l 812# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
813# undef expm1l
814# define expm1l rpl_expm1l
815# endif
816_GL_FUNCDECL_RPL (expm1l, long double, (long double x));
817_GL_CXXALIAS_RPL (expm1l, long double, (long double x));
818# else
819# if !@HAVE_DECL_EXPM1L@
820# undef expm1l
821# if !(defined __cplusplus && defined _AIX)
673_GL_FUNCDECL_SYS (expm1l, long double, (long double x)); 822_GL_FUNCDECL_SYS (expm1l, long double, (long double x));
674# endif 823# endif
824# endif
675_GL_CXXALIAS_SYS (expm1l, long double, (long double x)); 825_GL_CXXALIAS_SYS (expm1l, long double, (long double x));
826# endif
676_GL_CXXALIASWARN (expm1l); 827_GL_CXXALIASWARN (expm1l);
677#elif defined GNULIB_POSIXCHECK 828#elif defined GNULIB_POSIXCHECK
678# undef expm1l 829# undef expm1l
@@ -689,7 +840,9 @@ _GL_WARN_ON_USE (expm1l, "expm1l is unportable - "
689_GL_FUNCDECL_SYS (fabsf, float, (float x)); 840_GL_FUNCDECL_SYS (fabsf, float, (float x));
690# endif 841# endif
691_GL_CXXALIAS_SYS (fabsf, float, (float x)); 842_GL_CXXALIAS_SYS (fabsf, float, (float x));
843# if __GLIBC__ >= 2
692_GL_CXXALIASWARN (fabsf); 844_GL_CXXALIASWARN (fabsf);
845# endif
693#elif defined GNULIB_POSIXCHECK 846#elif defined GNULIB_POSIXCHECK
694# undef fabsf 847# undef fabsf
695# if HAVE_RAW_DECL_FABSF 848# if HAVE_RAW_DECL_FABSF
@@ -713,7 +866,9 @@ _GL_FUNCDECL_SYS (fabsl, long double, (long double x));
713# endif 866# endif
714_GL_CXXALIAS_SYS (fabsl, long double, (long double x)); 867_GL_CXXALIAS_SYS (fabsl, long double, (long double x));
715# endif 868# endif
869# if __GLIBC__ >= 2
716_GL_CXXALIASWARN (fabsl); 870_GL_CXXALIASWARN (fabsl);
871# endif
717#elif defined GNULIB_POSIXCHECK 872#elif defined GNULIB_POSIXCHECK
718# undef fabsl 873# undef fabsl
719# if HAVE_RAW_DECL_FABSL 874# if HAVE_RAW_DECL_FABSL
@@ -750,6 +905,7 @@ _GL_WARN_ON_USE (floorf, "floorf is unportable - "
750#if @GNULIB_FLOOR@ 905#if @GNULIB_FLOOR@
751# if @REPLACE_FLOOR@ 906# if @REPLACE_FLOOR@
752# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 907# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
908# undef floor
753# define floor rpl_floor 909# define floor rpl_floor
754# endif 910# endif
755_GL_FUNCDECL_RPL (floor, double, (double x)); 911_GL_FUNCDECL_RPL (floor, double, (double x));
@@ -757,7 +913,9 @@ _GL_CXXALIAS_RPL (floor, double, (double x));
757# else 913# else
758_GL_CXXALIAS_SYS (floor, double, (double x)); 914_GL_CXXALIAS_SYS (floor, double, (double x));
759# endif 915# endif
760_GL_CXXALIASWARN (floor); 916# if __GLIBC__ >= 2
917_GL_CXXALIASWARN1 (floor, double, (double x));
918# endif
761#endif 919#endif
762 920
763#if @GNULIB_FLOORL@ 921#if @GNULIB_FLOORL@
@@ -775,7 +933,9 @@ _GL_FUNCDECL_SYS (floorl, long double, (long double x));
775# endif 933# endif
776_GL_CXXALIAS_SYS (floorl, long double, (long double x)); 934_GL_CXXALIAS_SYS (floorl, long double, (long double x));
777# endif 935# endif
936# if __GLIBC__ >= 2
778_GL_CXXALIASWARN (floorl); 937_GL_CXXALIASWARN (floorl);
938# endif
779#elif defined GNULIB_POSIXCHECK 939#elif defined GNULIB_POSIXCHECK
780# undef floorl 940# undef floorl
781# if HAVE_RAW_DECL_FLOORL 941# if HAVE_RAW_DECL_FLOORL
@@ -795,6 +955,7 @@ _GL_FUNCDECL_RPL (fmaf, float, (float x, float y, float z));
795_GL_CXXALIAS_RPL (fmaf, float, (float x, float y, float z)); 955_GL_CXXALIAS_RPL (fmaf, float, (float x, float y, float z));
796# else 956# else
797# if !@HAVE_FMAF@ 957# if !@HAVE_FMAF@
958# undef fmaf
798_GL_FUNCDECL_SYS (fmaf, float, (float x, float y, float z)); 959_GL_FUNCDECL_SYS (fmaf, float, (float x, float y, float z));
799# endif 960# endif
800_GL_CXXALIAS_SYS (fmaf, float, (float x, float y, float z)); 961_GL_CXXALIAS_SYS (fmaf, float, (float x, float y, float z));
@@ -818,11 +979,14 @@ _GL_FUNCDECL_RPL (fma, double, (double x, double y, double z));
818_GL_CXXALIAS_RPL (fma, double, (double x, double y, double z)); 979_GL_CXXALIAS_RPL (fma, double, (double x, double y, double z));
819# else 980# else
820# if !@HAVE_FMA@ 981# if !@HAVE_FMA@
982# undef fma
821_GL_FUNCDECL_SYS (fma, double, (double x, double y, double z)); 983_GL_FUNCDECL_SYS (fma, double, (double x, double y, double z));
822# endif 984# endif
823_GL_CXXALIAS_SYS (fma, double, (double x, double y, double z)); 985_GL_CXXALIAS_SYS (fma, double, (double x, double y, double z));
824# endif 986# endif
825_GL_CXXALIASWARN (fma); 987# if __GLIBC__ >= 2
988_GL_CXXALIASWARN1 (fma, double, (double x, double y, double z));
989# endif
826#elif defined GNULIB_POSIXCHECK 990#elif defined GNULIB_POSIXCHECK
827# undef fma 991# undef fma
828# if HAVE_RAW_DECL_FMA 992# if HAVE_RAW_DECL_FMA
@@ -844,8 +1008,10 @@ _GL_CXXALIAS_RPL (fmal, long double,
844# else 1008# else
845# if !@HAVE_FMAL@ 1009# if !@HAVE_FMAL@
846# undef fmal 1010# undef fmal
1011# if !(defined __cplusplus && defined _AIX)
847_GL_FUNCDECL_SYS (fmal, long double, 1012_GL_FUNCDECL_SYS (fmal, long double,
848 (long double x, long double y, long double z)); 1013 (long double x, long double y, long double z));
1014# endif
849# endif 1015# endif
850_GL_CXXALIAS_SYS (fmal, long double, 1016_GL_CXXALIAS_SYS (fmal, long double,
851 (long double x, long double y, long double z)); 1017 (long double x, long double y, long double z));
@@ -895,7 +1061,9 @@ _GL_CXXALIAS_RPL (fmod, double, (double x, double y));
895# else 1061# else
896_GL_CXXALIAS_SYS (fmod, double, (double x, double y)); 1062_GL_CXXALIAS_SYS (fmod, double, (double x, double y));
897# endif 1063# endif
898_GL_CXXALIASWARN (fmod); 1064# if __GLIBC__ >= 2
1065_GL_CXXALIASWARN1 (fmod, double, (double x, double y));
1066# endif
899#elif defined GNULIB_POSIXCHECK 1067#elif defined GNULIB_POSIXCHECK
900# undef fmod 1068# undef fmod
901# if HAVE_RAW_DECL_FMOD 1069# if HAVE_RAW_DECL_FMOD
@@ -919,7 +1087,9 @@ _GL_FUNCDECL_SYS (fmodl, long double, (long double x, long double y));
919# endif 1087# endif
920_GL_CXXALIAS_SYS (fmodl, long double, (long double x, long double y)); 1088_GL_CXXALIAS_SYS (fmodl, long double, (long double x, long double y));
921# endif 1089# endif
1090# if __GLIBC__ >= 2
922_GL_CXXALIASWARN (fmodl); 1091_GL_CXXALIASWARN (fmodl);
1092# endif
923#elif defined GNULIB_POSIXCHECK 1093#elif defined GNULIB_POSIXCHECK
924# undef fmodl 1094# undef fmodl
925# if HAVE_RAW_DECL_FMODL 1095# if HAVE_RAW_DECL_FMODL
@@ -951,7 +1121,9 @@ _GL_FUNCDECL_SYS (frexpf, float, (float x, int *expptr) _GL_ARG_NONNULL ((2)));
951# endif 1121# endif
952_GL_CXXALIAS_SYS (frexpf, float, (float x, int *expptr)); 1122_GL_CXXALIAS_SYS (frexpf, float, (float x, int *expptr));
953# endif 1123# endif
1124# if __GLIBC__ >= 2
954_GL_CXXALIASWARN (frexpf); 1125_GL_CXXALIASWARN (frexpf);
1126# endif
955#elif defined GNULIB_POSIXCHECK 1127#elif defined GNULIB_POSIXCHECK
956# undef frexpf 1128# undef frexpf
957# if HAVE_RAW_DECL_FREXPF 1129# if HAVE_RAW_DECL_FREXPF
@@ -970,6 +1142,7 @@ _GL_WARN_ON_USE (frexpf, "frexpf is unportable - "
970#if @GNULIB_FREXP@ 1142#if @GNULIB_FREXP@
971# if @REPLACE_FREXP@ 1143# if @REPLACE_FREXP@
972# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1144# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1145# undef frexp
973# define frexp rpl_frexp 1146# define frexp rpl_frexp
974# endif 1147# endif
975_GL_FUNCDECL_RPL (frexp, double, (double x, int *expptr) _GL_ARG_NONNULL ((2))); 1148_GL_FUNCDECL_RPL (frexp, double, (double x, int *expptr) _GL_ARG_NONNULL ((2)));
@@ -977,7 +1150,9 @@ _GL_CXXALIAS_RPL (frexp, double, (double x, int *expptr));
977# else 1150# else
978_GL_CXXALIAS_SYS (frexp, double, (double x, int *expptr)); 1151_GL_CXXALIAS_SYS (frexp, double, (double x, int *expptr));
979# endif 1152# endif
980_GL_CXXALIASWARN (frexp); 1153# if __GLIBC__ >= 2
1154_GL_CXXALIASWARN1 (frexp, double, (double x, int *expptr));
1155# endif
981#elif defined GNULIB_POSIXCHECK 1156#elif defined GNULIB_POSIXCHECK
982# undef frexp 1157# undef frexp
983/* Assume frexp is always declared. */ 1158/* Assume frexp is always declared. */
@@ -1010,7 +1185,9 @@ _GL_CXXALIAS_SYS (frexpl, long double, (long double x, int *expptr));
1010# endif 1185# endif
1011#endif 1186#endif
1012#if @GNULIB_FREXPL@ && !(@REPLACE_FREXPL@ && !@HAVE_DECL_FREXPL@) 1187#if @GNULIB_FREXPL@ && !(@REPLACE_FREXPL@ && !@HAVE_DECL_FREXPL@)
1188# if __GLIBC__ >= 2
1013_GL_CXXALIASWARN (frexpl); 1189_GL_CXXALIASWARN (frexpl);
1190# endif
1014#endif 1191#endif
1015#if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK 1192#if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK
1016# undef frexpl 1193# undef frexpl
@@ -1036,7 +1213,9 @@ _GL_FUNCDECL_SYS (hypotf, float, (float x, float y));
1036# endif 1213# endif
1037_GL_CXXALIAS_SYS (hypotf, float, (float x, float y)); 1214_GL_CXXALIAS_SYS (hypotf, float, (float x, float y));
1038# endif 1215# endif
1216# if __GLIBC__ >= 2
1039_GL_CXXALIASWARN (hypotf); 1217_GL_CXXALIASWARN (hypotf);
1218# endif
1040#elif defined GNULIB_POSIXCHECK 1219#elif defined GNULIB_POSIXCHECK
1041# undef hypotf 1220# undef hypotf
1042# if HAVE_RAW_DECL_HYPOTF 1221# if HAVE_RAW_DECL_HYPOTF
@@ -1057,7 +1236,9 @@ _GL_CXXALIAS_RPL (hypot, double, (double x, double y));
1057# else 1236# else
1058_GL_CXXALIAS_SYS (hypot, double, (double x, double y)); 1237_GL_CXXALIAS_SYS (hypot, double, (double x, double y));
1059# endif 1238# endif
1060_GL_CXXALIASWARN (hypot); 1239# if __GLIBC__ >= 2
1240_GL_CXXALIASWARN1 (hypot, double, (double x, double y));
1241# endif
1061#elif defined GNULIB_POSIXCHECK 1242#elif defined GNULIB_POSIXCHECK
1062# undef hypot 1243# undef hypot
1063# if HAVE_RAW_DECL_HYPOT 1244# if HAVE_RAW_DECL_HYPOT
@@ -1081,7 +1262,9 @@ _GL_FUNCDECL_SYS (hypotl, long double, (long double x, long double y));
1081# endif 1262# endif
1082_GL_CXXALIAS_SYS (hypotl, long double, (long double x, long double y)); 1263_GL_CXXALIAS_SYS (hypotl, long double, (long double x, long double y));
1083# endif 1264# endif
1265# if __GLIBC__ >= 2
1084_GL_CXXALIASWARN (hypotl); 1266_GL_CXXALIASWARN (hypotl);
1267# endif
1085#elif defined GNULIB_POSIXCHECK 1268#elif defined GNULIB_POSIXCHECK
1086# undef hypotl 1269# undef hypotl
1087# if HAVE_RAW_DECL_HYPOTL 1270# if HAVE_RAW_DECL_HYPOTL
@@ -1128,7 +1311,9 @@ _GL_FUNCDECL_SYS (ilogb, int, (double x));
1128# endif 1311# endif
1129_GL_CXXALIAS_SYS (ilogb, int, (double x)); 1312_GL_CXXALIAS_SYS (ilogb, int, (double x));
1130# endif 1313# endif
1131_GL_CXXALIASWARN (ilogb); 1314# if __GLIBC__ >= 2
1315_GL_CXXALIASWARN1 (ilogb, int, (double x));
1316# endif
1132#elif defined GNULIB_POSIXCHECK 1317#elif defined GNULIB_POSIXCHECK
1133# undef ilogb 1318# undef ilogb
1134# if HAVE_RAW_DECL_ILOGB 1319# if HAVE_RAW_DECL_ILOGB
@@ -1138,10 +1323,20 @@ _GL_WARN_ON_USE (ilogb, "ilogb is unportable - "
1138#endif 1323#endif
1139 1324
1140#if @GNULIB_ILOGBL@ 1325#if @GNULIB_ILOGBL@
1141# if !@HAVE_ILOGBL@ 1326# if @REPLACE_ILOGBL@
1327# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1328# undef ilogbl
1329# define ilogbl rpl_ilogbl
1330# endif
1331_GL_FUNCDECL_RPL (ilogbl, int, (long double x));
1332_GL_CXXALIAS_RPL (ilogbl, int, (long double x));
1333# else
1334# if !@HAVE_ILOGBL@
1335# undef ilogbl
1142_GL_FUNCDECL_SYS (ilogbl, int, (long double x)); 1336_GL_FUNCDECL_SYS (ilogbl, int, (long double x));
1143# endif 1337# endif
1144_GL_CXXALIAS_SYS (ilogbl, int, (long double x)); 1338_GL_CXXALIAS_SYS (ilogbl, int, (long double x));
1339# endif
1145_GL_CXXALIASWARN (ilogbl); 1340_GL_CXXALIASWARN (ilogbl);
1146#elif defined GNULIB_POSIXCHECK 1341#elif defined GNULIB_POSIXCHECK
1147# undef ilogbl 1342# undef ilogbl
@@ -1152,6 +1347,55 @@ _GL_WARN_ON_USE (ilogbl, "ilogbl is unportable - "
1152#endif 1347#endif
1153 1348
1154 1349
1350#if @GNULIB_MDA_J0@
1351/* On native Windows, map 'j0' to '_j0', so that -loldnames is not
1352 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1353 platforms by defining GNULIB_NAMESPACE::j0 always. */
1354# if defined _WIN32 && !defined __CYGWIN__
1355# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1356# undef j0
1357# define j0 _j0
1358# endif
1359_GL_CXXALIAS_MDA (j0, double, (double x));
1360# else
1361_GL_CXXALIAS_SYS (j0, double, (double x));
1362# endif
1363_GL_CXXALIASWARN (j0);
1364#endif
1365
1366#if @GNULIB_MDA_J1@
1367/* On native Windows, map 'j1' to '_j1', so that -loldnames is not
1368 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1369 platforms by defining GNULIB_NAMESPACE::j1 always. */
1370# if defined _WIN32 && !defined __CYGWIN__
1371# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1372# undef j1
1373# define j1 _j1
1374# endif
1375_GL_CXXALIAS_MDA (j1, double, (double x));
1376# else
1377_GL_CXXALIAS_SYS (j1, double, (double x));
1378# endif
1379_GL_CXXALIASWARN (j1);
1380#endif
1381
1382#if @GNULIB_MDA_JN@
1383/* On native Windows, map 'jn' to '_jn', so that -loldnames is not
1384 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1385 platforms by defining GNULIB_NAMESPACE::jn always. */
1386# if defined _WIN32 && !defined __CYGWIN__
1387# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1388# undef jn
1389# define jn _jn
1390# endif
1391_GL_CXXALIAS_MDA (jn, double, (int n, double x));
1392# else
1393_GL_CXXALIAS_SYS (jn, double, (int n, double x));
1394# endif
1395_GL_CXXALIASWARN (jn);
1396#endif
1397
1398
1155/* Return x * 2^exp. */ 1399/* Return x * 2^exp. */
1156#if @GNULIB_LDEXPF@ 1400#if @GNULIB_LDEXPF@
1157# if !@HAVE_LDEXPF@ 1401# if !@HAVE_LDEXPF@
@@ -1159,7 +1403,9 @@ _GL_WARN_ON_USE (ilogbl, "ilogbl is unportable - "
1159_GL_FUNCDECL_SYS (ldexpf, float, (float x, int exp)); 1403_GL_FUNCDECL_SYS (ldexpf, float, (float x, int exp));
1160# endif 1404# endif
1161_GL_CXXALIAS_SYS (ldexpf, float, (float x, int exp)); 1405_GL_CXXALIAS_SYS (ldexpf, float, (float x, int exp));
1406# if __GLIBC__ >= 2
1162_GL_CXXALIASWARN (ldexpf); 1407_GL_CXXALIASWARN (ldexpf);
1408# endif
1163#elif defined GNULIB_POSIXCHECK 1409#elif defined GNULIB_POSIXCHECK
1164# undef ldexpf 1410# undef ldexpf
1165# if HAVE_RAW_DECL_LDEXPF 1411# if HAVE_RAW_DECL_LDEXPF
@@ -1185,7 +1431,9 @@ _GL_CXXALIAS_SYS (ldexpl, long double, (long double x, int exp));
1185# endif 1431# endif
1186#endif 1432#endif
1187#if @GNULIB_LDEXPL@ 1433#if @GNULIB_LDEXPL@
1434# if __GLIBC__ >= 2
1188_GL_CXXALIASWARN (ldexpl); 1435_GL_CXXALIASWARN (ldexpl);
1436# endif
1189#endif 1437#endif
1190#if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK 1438#if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK
1191# undef ldexpl 1439# undef ldexpl
@@ -1231,7 +1479,9 @@ _GL_CXXALIAS_RPL (log, double, (double x));
1231# else 1479# else
1232_GL_CXXALIAS_SYS (log, double, (double x)); 1480_GL_CXXALIAS_SYS (log, double, (double x));
1233# endif 1481# endif
1234_GL_CXXALIASWARN (log); 1482# if __GLIBC__ >= 2
1483_GL_CXXALIASWARN1 (log, double, (double x));
1484# endif
1235#elif defined GNULIB_POSIXCHECK 1485#elif defined GNULIB_POSIXCHECK
1236# undef log 1486# undef log
1237# if HAVE_RAW_DECL_LOG 1487# if HAVE_RAW_DECL_LOG
@@ -1255,7 +1505,9 @@ _GL_FUNCDECL_SYS (logl, long double, (long double x));
1255# endif 1505# endif
1256_GL_CXXALIAS_SYS (logl, long double, (long double x)); 1506_GL_CXXALIAS_SYS (logl, long double, (long double x));
1257# endif 1507# endif
1508# if __GLIBC__ >= 2
1258_GL_CXXALIASWARN (logl); 1509_GL_CXXALIASWARN (logl);
1510# endif
1259#elif defined GNULIB_POSIXCHECK 1511#elif defined GNULIB_POSIXCHECK
1260# undef logl 1512# undef logl
1261# if HAVE_RAW_DECL_LOGL 1513# if HAVE_RAW_DECL_LOGL
@@ -1300,7 +1552,9 @@ _GL_CXXALIAS_RPL (log10, double, (double x));
1300# else 1552# else
1301_GL_CXXALIAS_SYS (log10, double, (double x)); 1553_GL_CXXALIAS_SYS (log10, double, (double x));
1302# endif 1554# endif
1303_GL_CXXALIASWARN (log10); 1555# if __GLIBC__ >= 2
1556_GL_CXXALIASWARN1 (log10, double, (double x));
1557# endif
1304#elif defined GNULIB_POSIXCHECK 1558#elif defined GNULIB_POSIXCHECK
1305# undef log10 1559# undef log10
1306# if HAVE_RAW_DECL_LOG10 1560# if HAVE_RAW_DECL_LOG10
@@ -1324,7 +1578,9 @@ _GL_FUNCDECL_SYS (log10l, long double, (long double x));
1324# endif 1578# endif
1325_GL_CXXALIAS_SYS (log10l, long double, (long double x)); 1579_GL_CXXALIAS_SYS (log10l, long double, (long double x));
1326# endif 1580# endif
1581# if __GLIBC__ >= 2
1327_GL_CXXALIASWARN (log10l); 1582_GL_CXXALIASWARN (log10l);
1583# endif
1328#elif defined GNULIB_POSIXCHECK 1584#elif defined GNULIB_POSIXCHECK
1329# undef log10l 1585# undef log10l
1330# if HAVE_RAW_DECL_LOG10L 1586# if HAVE_RAW_DECL_LOG10L
@@ -1371,7 +1627,9 @@ _GL_FUNCDECL_SYS (log1p, double, (double x));
1371# endif 1627# endif
1372_GL_CXXALIAS_SYS (log1p, double, (double x)); 1628_GL_CXXALIAS_SYS (log1p, double, (double x));
1373# endif 1629# endif
1374_GL_CXXALIASWARN (log1p); 1630# if __GLIBC__ >= 2
1631_GL_CXXALIASWARN1 (log1p, double, (double x));
1632# endif
1375#elif defined GNULIB_POSIXCHECK 1633#elif defined GNULIB_POSIXCHECK
1376# undef log1p 1634# undef log1p
1377# if HAVE_RAW_DECL_LOG1P 1635# if HAVE_RAW_DECL_LOG1P
@@ -1443,7 +1701,9 @@ _GL_FUNCDECL_SYS (log2, double, (double x));
1443# endif 1701# endif
1444_GL_CXXALIAS_SYS (log2, double, (double x)); 1702_GL_CXXALIAS_SYS (log2, double, (double x));
1445# endif 1703# endif
1446_GL_CXXALIASWARN (log2); 1704# if __GLIBC__ >= 2
1705_GL_CXXALIASWARN1 (log2, double, (double x));
1706# endif
1447#elif defined GNULIB_POSIXCHECK 1707#elif defined GNULIB_POSIXCHECK
1448# undef log2 1708# undef log2
1449# if HAVE_RAW_DECL_LOG2 1709# if HAVE_RAW_DECL_LOG2
@@ -1513,7 +1773,9 @@ _GL_FUNCDECL_SYS (logb, double, (double x));
1513# endif 1773# endif
1514_GL_CXXALIAS_SYS (logb, double, (double x)); 1774_GL_CXXALIAS_SYS (logb, double, (double x));
1515# endif 1775# endif
1516_GL_CXXALIASWARN (logb); 1776# if __GLIBC__ >= 2
1777_GL_CXXALIASWARN1 (logb, double, (double x));
1778# endif
1517#elif defined GNULIB_POSIXCHECK 1779#elif defined GNULIB_POSIXCHECK
1518# undef logb 1780# undef logb
1519# if HAVE_RAW_DECL_LOGB 1781# if HAVE_RAW_DECL_LOGB
@@ -1581,7 +1843,9 @@ _GL_CXXALIAS_RPL (modf, double, (double x, double *iptr));
1581# else 1843# else
1582_GL_CXXALIAS_SYS (modf, double, (double x, double *iptr)); 1844_GL_CXXALIAS_SYS (modf, double, (double x, double *iptr));
1583# endif 1845# endif
1584_GL_CXXALIASWARN (modf); 1846# if __GLIBC__ >= 2
1847_GL_CXXALIASWARN1 (modf, double, (double x, double *iptr));
1848# endif
1585#elif defined GNULIB_POSIXCHECK 1849#elif defined GNULIB_POSIXCHECK
1586# undef modf 1850# undef modf
1587# if HAVE_RAW_DECL_MODF 1851# if HAVE_RAW_DECL_MODF
@@ -1607,7 +1871,9 @@ _GL_FUNCDECL_SYS (modfl, long double, (long double x, long double *iptr)
1607# endif 1871# endif
1608_GL_CXXALIAS_SYS (modfl, long double, (long double x, long double *iptr)); 1872_GL_CXXALIAS_SYS (modfl, long double, (long double x, long double *iptr));
1609# endif 1873# endif
1874# if __GLIBC__ >= 2
1610_GL_CXXALIASWARN (modfl); 1875_GL_CXXALIASWARN (modfl);
1876# endif
1611#elif defined GNULIB_POSIXCHECK 1877#elif defined GNULIB_POSIXCHECK
1612# undef modfl 1878# undef modfl
1613# if HAVE_RAW_DECL_MODFL 1879# if HAVE_RAW_DECL_MODFL
@@ -1670,7 +1936,9 @@ _GL_FUNCDECL_SYS (remainder, double, (double x, double y));
1670# endif 1936# endif
1671_GL_CXXALIAS_SYS (remainder, double, (double x, double y)); 1937_GL_CXXALIAS_SYS (remainder, double, (double x, double y));
1672# endif 1938# endif
1673_GL_CXXALIASWARN (remainder); 1939# if __GLIBC__ >= 2
1940_GL_CXXALIASWARN1 (remainder, double, (double x, double y));
1941# endif
1674#elif defined GNULIB_POSIXCHECK 1942#elif defined GNULIB_POSIXCHECK
1675# undef remainder 1943# undef remainder
1676# if HAVE_RAW_DECL_REMAINDER 1944# if HAVE_RAW_DECL_REMAINDER
@@ -1690,7 +1958,9 @@ _GL_CXXALIAS_RPL (remainderl, long double, (long double x, long double y));
1690# else 1958# else
1691# if !@HAVE_DECL_REMAINDERL@ 1959# if !@HAVE_DECL_REMAINDERL@
1692# undef remainderl 1960# undef remainderl
1961# if !(defined __cplusplus && defined _AIX)
1693_GL_FUNCDECL_SYS (remainderl, long double, (long double x, long double y)); 1962_GL_FUNCDECL_SYS (remainderl, long double, (long double x, long double y));
1963# endif
1694# endif 1964# endif
1695_GL_CXXALIAS_SYS (remainderl, long double, (long double x, long double y)); 1965_GL_CXXALIAS_SYS (remainderl, long double, (long double x, long double y));
1696# endif 1966# endif
@@ -1723,7 +1993,9 @@ _GL_WARN_ON_USE (rintf, "rintf is unportable - "
1723_GL_FUNCDECL_SYS (rint, double, (double x)); 1993_GL_FUNCDECL_SYS (rint, double, (double x));
1724# endif 1994# endif
1725_GL_CXXALIAS_SYS (rint, double, (double x)); 1995_GL_CXXALIAS_SYS (rint, double, (double x));
1726_GL_CXXALIASWARN (rint); 1996# if __GLIBC__ >= 2
1997_GL_CXXALIASWARN1 (rint, double, (double x));
1998# endif
1727#elif defined GNULIB_POSIXCHECK 1999#elif defined GNULIB_POSIXCHECK
1728# undef rint 2000# undef rint
1729# if HAVE_RAW_DECL_RINT 2001# if HAVE_RAW_DECL_RINT
@@ -1733,10 +2005,19 @@ _GL_WARN_ON_USE (rint, "rint is unportable - "
1733#endif 2005#endif
1734 2006
1735#if @GNULIB_RINTL@ 2007#if @GNULIB_RINTL@
1736# if !@HAVE_RINTL@ 2008# if @REPLACE_RINTL@
2009# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2010# undef rintl
2011# define rintl rpl_rintl
2012# endif
2013_GL_FUNCDECL_RPL (rintl, long double, (long double x));
2014_GL_CXXALIAS_RPL (rintl, long double, (long double x));
2015# else
2016# if !@HAVE_RINTL@
1737_GL_FUNCDECL_SYS (rintl, long double, (long double x)); 2017_GL_FUNCDECL_SYS (rintl, long double, (long double x));
1738# endif 2018# endif
1739_GL_CXXALIAS_SYS (rintl, long double, (long double x)); 2019_GL_CXXALIAS_SYS (rintl, long double, (long double x));
2020# endif
1740_GL_CXXALIASWARN (rintl); 2021_GL_CXXALIASWARN (rintl);
1741#elif defined GNULIB_POSIXCHECK 2022#elif defined GNULIB_POSIXCHECK
1742# undef rintl 2023# undef rintl
@@ -1784,7 +2065,9 @@ _GL_FUNCDECL_SYS (round, double, (double x));
1784# endif 2065# endif
1785_GL_CXXALIAS_SYS (round, double, (double x)); 2066_GL_CXXALIAS_SYS (round, double, (double x));
1786# endif 2067# endif
1787_GL_CXXALIASWARN (round); 2068# if __GLIBC__ >= 2
2069_GL_CXXALIASWARN1 (round, double, (double x));
2070# endif
1788#elif defined GNULIB_POSIXCHECK 2071#elif defined GNULIB_POSIXCHECK
1789# undef round 2072# undef round
1790# if HAVE_RAW_DECL_ROUND 2073# if HAVE_RAW_DECL_ROUND
@@ -1804,7 +2087,9 @@ _GL_CXXALIAS_RPL (roundl, long double, (long double x));
1804# else 2087# else
1805# if !@HAVE_DECL_ROUNDL@ 2088# if !@HAVE_DECL_ROUNDL@
1806# undef roundl 2089# undef roundl
2090# if !(defined __cplusplus && defined _AIX)
1807_GL_FUNCDECL_SYS (roundl, long double, (long double x)); 2091_GL_FUNCDECL_SYS (roundl, long double, (long double x));
2092# endif
1808# endif 2093# endif
1809_GL_CXXALIAS_SYS (roundl, long double, (long double x)); 2094_GL_CXXALIAS_SYS (roundl, long double, (long double x));
1810# endif 2095# endif
@@ -1819,11 +2104,20 @@ _GL_WARN_ON_USE (roundl, "roundl is unportable - "
1819 2104
1820 2105
1821#if @GNULIB_SINF@ 2106#if @GNULIB_SINF@
1822# if !@HAVE_SINF@ 2107# if @REPLACE_SINF@
1823# undef sinf 2108# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2109# undef sinf
2110# define sinf rpl_sinf
2111# endif
2112_GL_FUNCDECL_RPL (sinf, float, (float x));
2113_GL_CXXALIAS_RPL (sinf, float, (float x));
2114# else
2115# if !@HAVE_SINF@
2116# undef sinf
1824_GL_FUNCDECL_SYS (sinf, float, (float x)); 2117_GL_FUNCDECL_SYS (sinf, float, (float x));
1825# endif 2118# endif
1826_GL_CXXALIAS_SYS (sinf, float, (float x)); 2119_GL_CXXALIAS_SYS (sinf, float, (float x));
2120# endif
1827_GL_CXXALIASWARN (sinf); 2121_GL_CXXALIASWARN (sinf);
1828#elif defined GNULIB_POSIXCHECK 2122#elif defined GNULIB_POSIXCHECK
1829# undef sinf 2123# undef sinf
@@ -1839,7 +2133,9 @@ _GL_WARN_ON_USE (sinf, "sinf is unportable - "
1839_GL_FUNCDECL_SYS (sinl, long double, (long double x)); 2133_GL_FUNCDECL_SYS (sinl, long double, (long double x));
1840# endif 2134# endif
1841_GL_CXXALIAS_SYS (sinl, long double, (long double x)); 2135_GL_CXXALIAS_SYS (sinl, long double, (long double x));
2136# if __GLIBC__ >= 2
1842_GL_CXXALIASWARN (sinl); 2137_GL_CXXALIASWARN (sinl);
2138# endif
1843#elif defined GNULIB_POSIXCHECK 2139#elif defined GNULIB_POSIXCHECK
1844# undef sinl 2140# undef sinl
1845# if HAVE_RAW_DECL_SINL 2141# if HAVE_RAW_DECL_SINL
@@ -1850,11 +2146,20 @@ _GL_WARN_ON_USE (sinl, "sinl is unportable - "
1850 2146
1851 2147
1852#if @GNULIB_SINHF@ 2148#if @GNULIB_SINHF@
1853# if !@HAVE_SINHF@ 2149# if @REPLACE_SINHF@
1854# undef sinhf 2150# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2151# undef sinhf
2152# define sinhf rpl_sinhf
2153# endif
2154_GL_FUNCDECL_RPL (sinhf, float, (float x));
2155_GL_CXXALIAS_RPL (sinhf, float, (float x));
2156# else
2157# if !@HAVE_SINHF@
2158# undef sinhf
1855_GL_FUNCDECL_SYS (sinhf, float, (float x)); 2159_GL_FUNCDECL_SYS (sinhf, float, (float x));
1856# endif 2160# endif
1857_GL_CXXALIAS_SYS (sinhf, float, (float x)); 2161_GL_CXXALIAS_SYS (sinhf, float, (float x));
2162# endif
1858_GL_CXXALIASWARN (sinhf); 2163_GL_CXXALIASWARN (sinhf);
1859#elif defined GNULIB_POSIXCHECK 2164#elif defined GNULIB_POSIXCHECK
1860# undef sinhf 2165# undef sinhf
@@ -1866,11 +2171,20 @@ _GL_WARN_ON_USE (sinhf, "sinhf is unportable - "
1866 2171
1867 2172
1868#if @GNULIB_SQRTF@ 2173#if @GNULIB_SQRTF@
1869# if !@HAVE_SQRTF@ 2174# if @REPLACE_SQRTF@
1870# undef sqrtf 2175# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2176# undef sqrtf
2177# define sqrtf rpl_sqrtf
2178# endif
2179_GL_FUNCDECL_RPL (sqrtf, float, (float x));
2180_GL_CXXALIAS_RPL (sqrtf, float, (float x));
2181# else
2182# if !@HAVE_SQRTF@
2183# undef sqrtf
1871_GL_FUNCDECL_SYS (sqrtf, float, (float x)); 2184_GL_FUNCDECL_SYS (sqrtf, float, (float x));
1872# endif 2185# endif
1873_GL_CXXALIAS_SYS (sqrtf, float, (float x)); 2186_GL_CXXALIAS_SYS (sqrtf, float, (float x));
2187# endif
1874_GL_CXXALIASWARN (sqrtf); 2188_GL_CXXALIASWARN (sqrtf);
1875#elif defined GNULIB_POSIXCHECK 2189#elif defined GNULIB_POSIXCHECK
1876# undef sqrtf 2190# undef sqrtf
@@ -1895,7 +2209,9 @@ _GL_FUNCDECL_SYS (sqrtl, long double, (long double x));
1895# endif 2209# endif
1896_GL_CXXALIAS_SYS (sqrtl, long double, (long double x)); 2210_GL_CXXALIAS_SYS (sqrtl, long double, (long double x));
1897# endif 2211# endif
2212# if __GLIBC__ >= 2
1898_GL_CXXALIASWARN (sqrtl); 2213_GL_CXXALIASWARN (sqrtl);
2214# endif
1899#elif defined GNULIB_POSIXCHECK 2215#elif defined GNULIB_POSIXCHECK
1900# undef sqrtl 2216# undef sqrtl
1901# if HAVE_RAW_DECL_SQRTL 2217# if HAVE_RAW_DECL_SQRTL
@@ -1906,11 +2222,20 @@ _GL_WARN_ON_USE (sqrtl, "sqrtl is unportable - "
1906 2222
1907 2223
1908#if @GNULIB_TANF@ 2224#if @GNULIB_TANF@
1909# if !@HAVE_TANF@ 2225# if @REPLACE_TANF@
1910# undef tanf 2226# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2227# undef tanf
2228# define tanf rpl_tanf
2229# endif
2230_GL_FUNCDECL_RPL (tanf, float, (float x));
2231_GL_CXXALIAS_RPL (tanf, float, (float x));
2232# else
2233# if !@HAVE_TANF@
2234# undef tanf
1911_GL_FUNCDECL_SYS (tanf, float, (float x)); 2235_GL_FUNCDECL_SYS (tanf, float, (float x));
1912# endif 2236# endif
1913_GL_CXXALIAS_SYS (tanf, float, (float x)); 2237_GL_CXXALIAS_SYS (tanf, float, (float x));
2238# endif
1914_GL_CXXALIASWARN (tanf); 2239_GL_CXXALIASWARN (tanf);
1915#elif defined GNULIB_POSIXCHECK 2240#elif defined GNULIB_POSIXCHECK
1916# undef tanf 2241# undef tanf
@@ -1926,7 +2251,9 @@ _GL_WARN_ON_USE (tanf, "tanf is unportable - "
1926_GL_FUNCDECL_SYS (tanl, long double, (long double x)); 2251_GL_FUNCDECL_SYS (tanl, long double, (long double x));
1927# endif 2252# endif
1928_GL_CXXALIAS_SYS (tanl, long double, (long double x)); 2253_GL_CXXALIAS_SYS (tanl, long double, (long double x));
2254# if __GLIBC__ >= 2
1929_GL_CXXALIASWARN (tanl); 2255_GL_CXXALIASWARN (tanl);
2256# endif
1930#elif defined GNULIB_POSIXCHECK 2257#elif defined GNULIB_POSIXCHECK
1931# undef tanl 2258# undef tanl
1932# if HAVE_RAW_DECL_TANL 2259# if HAVE_RAW_DECL_TANL
@@ -1937,11 +2264,20 @@ _GL_WARN_ON_USE (tanl, "tanl is unportable - "
1937 2264
1938 2265
1939#if @GNULIB_TANHF@ 2266#if @GNULIB_TANHF@
1940# if !@HAVE_TANHF@ 2267# if @REPLACE_TANHF@
1941# undef tanhf 2268# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2269# undef tanhf
2270# define tanhf rpl_tanhf
2271# endif
2272_GL_FUNCDECL_RPL (tanhf, float, (float x));
2273_GL_CXXALIAS_RPL (tanhf, float, (float x));
2274# else
2275# if !@HAVE_TANHF@
2276# undef tanhf
1942_GL_FUNCDECL_SYS (tanhf, float, (float x)); 2277_GL_FUNCDECL_SYS (tanhf, float, (float x));
1943# endif 2278# endif
1944_GL_CXXALIAS_SYS (tanhf, float, (float x)); 2279_GL_CXXALIAS_SYS (tanhf, float, (float x));
2280# endif
1945_GL_CXXALIASWARN (tanhf); 2281_GL_CXXALIASWARN (tanhf);
1946#elif defined GNULIB_POSIXCHECK 2282#elif defined GNULIB_POSIXCHECK
1947# undef tanhf 2283# undef tanhf
@@ -1955,6 +2291,7 @@ _GL_WARN_ON_USE (tanhf, "tanhf is unportable - "
1955#if @GNULIB_TRUNCF@ 2291#if @GNULIB_TRUNCF@
1956# if @REPLACE_TRUNCF@ 2292# if @REPLACE_TRUNCF@
1957# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 2293# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2294# undef truncf
1958# define truncf rpl_truncf 2295# define truncf rpl_truncf
1959# endif 2296# endif
1960_GL_FUNCDECL_RPL (truncf, float, (float x)); 2297_GL_FUNCDECL_RPL (truncf, float, (float x));
@@ -1977,6 +2314,7 @@ _GL_WARN_ON_USE (truncf, "truncf is unportable - "
1977#if @GNULIB_TRUNC@ 2314#if @GNULIB_TRUNC@
1978# if @REPLACE_TRUNC@ 2315# if @REPLACE_TRUNC@
1979# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 2316# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2317# undef trunc
1980# define trunc rpl_trunc 2318# define trunc rpl_trunc
1981# endif 2319# endif
1982_GL_FUNCDECL_RPL (trunc, double, (double x)); 2320_GL_FUNCDECL_RPL (trunc, double, (double x));
@@ -1987,7 +2325,9 @@ _GL_FUNCDECL_SYS (trunc, double, (double x));
1987# endif 2325# endif
1988_GL_CXXALIAS_SYS (trunc, double, (double x)); 2326_GL_CXXALIAS_SYS (trunc, double, (double x));
1989# endif 2327# endif
1990_GL_CXXALIASWARN (trunc); 2328# if __GLIBC__ >= 2
2329_GL_CXXALIASWARN1 (trunc, double, (double x));
2330# endif
1991#elif defined GNULIB_POSIXCHECK 2331#elif defined GNULIB_POSIXCHECK
1992# undef trunc 2332# undef trunc
1993# if HAVE_RAW_DECL_TRUNC 2333# if HAVE_RAW_DECL_TRUNC
@@ -2020,6 +2360,55 @@ _GL_WARN_ON_USE (truncl, "truncl is unportable - "
2020#endif 2360#endif
2021 2361
2022 2362
2363#if @GNULIB_MDA_Y0@
2364/* On native Windows, map 'y0' to '_y0', so that -loldnames is not
2365 required. In C++ with GNULIB_NAMESPACE, avoid differences between
2366 platforms by defining GNULIB_NAMESPACE::y0 always. */
2367# if defined _WIN32 && !defined __CYGWIN__
2368# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2369# undef y0
2370# define y0 _y0
2371# endif
2372_GL_CXXALIAS_MDA (y0, double, (double x));
2373# else
2374_GL_CXXALIAS_SYS (y0, double, (double x));
2375# endif
2376_GL_CXXALIASWARN (y0);
2377#endif
2378
2379#if @GNULIB_MDA_Y1@
2380/* On native Windows, map 'y1' to '_y1', so that -loldnames is not
2381 required. In C++ with GNULIB_NAMESPACE, avoid differences between
2382 platforms by defining GNULIB_NAMESPACE::y1 always. */
2383# if defined _WIN32 && !defined __CYGWIN__
2384# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2385# undef y1
2386# define y1 _y1
2387# endif
2388_GL_CXXALIAS_MDA (y1, double, (double x));
2389# else
2390_GL_CXXALIAS_SYS (y1, double, (double x));
2391# endif
2392_GL_CXXALIASWARN (y1);
2393#endif
2394
2395#if @GNULIB_MDA_YN@
2396/* On native Windows, map 'yn' to '_yn', so that -loldnames is not
2397 required. In C++ with GNULIB_NAMESPACE, avoid differences between
2398 platforms by defining GNULIB_NAMESPACE::yn always. */
2399# if defined _WIN32 && !defined __CYGWIN__
2400# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2401# undef yn
2402# define yn _yn
2403# endif
2404_GL_CXXALIAS_MDA (yn, double, (int n, double x));
2405# else
2406_GL_CXXALIAS_SYS (yn, double, (int n, double x));
2407# endif
2408_GL_CXXALIASWARN (yn);
2409#endif
2410
2411
2023/* Definitions of function-like macros come here, after the function 2412/* Definitions of function-like macros come here, after the function
2024 declarations. */ 2413 declarations. */
2025 2414
@@ -2036,10 +2425,17 @@ _GL_EXTERN_C int gl_isfinitel (long double x);
2036 gl_isfinitef (x)) 2425 gl_isfinitef (x))
2037# endif 2426# endif
2038# ifdef __cplusplus 2427# ifdef __cplusplus
2039# ifdef isfinite 2428# if defined isfinite || defined GNULIB_NAMESPACE
2040_GL_MATH_CXX_REAL_FLOATING_DECL_1 (isfinite) 2429_GL_MATH_CXX_REAL_FLOATING_DECL_1 (isfinite)
2041# undef isfinite 2430# undef isfinite
2042_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isfinite) 2431# if __GNUC__ >= 6 || (defined __clang__ && !((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __OpenBSD__ || defined _AIX || (defined _WIN32 && !defined __CYGWIN__)))
2432 /* This platform's <cmath> possibly defines isfinite through a set of inline
2433 functions. */
2434_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isfinite, rpl_isfinite, bool)
2435# define isfinite rpl_isfinite
2436# else
2437_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isfinite, isfinite, bool)
2438# endif
2043# endif 2439# endif
2044# endif 2440# endif
2045#elif defined GNULIB_POSIXCHECK 2441#elif defined GNULIB_POSIXCHECK
@@ -2063,10 +2459,17 @@ _GL_EXTERN_C int gl_isinfl (long double x);
2063 gl_isinff (x)) 2459 gl_isinff (x))
2064# endif 2460# endif
2065# ifdef __cplusplus 2461# ifdef __cplusplus
2066# ifdef isinf 2462# if defined isinf || defined GNULIB_NAMESPACE
2067_GL_MATH_CXX_REAL_FLOATING_DECL_1 (isinf) 2463_GL_MATH_CXX_REAL_FLOATING_DECL_1 (isinf)
2068# undef isinf 2464# undef isinf
2069_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isinf) 2465# if __GNUC__ >= 6 || (defined __clang__ && !((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __OpenBSD__ || (defined _WIN32 && !defined __CYGWIN__)))
2466 /* This platform's <cmath> possibly defines isinf through a set of inline
2467 functions. */
2468_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isinf, rpl_isinf, bool)
2469# define isinf rpl_isinf
2470# else
2471_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isinf, isinf, bool)
2472# endif
2070# endif 2473# endif
2071# endif 2474# endif
2072#elif defined GNULIB_POSIXCHECK 2475#elif defined GNULIB_POSIXCHECK
@@ -2083,10 +2486,11 @@ _GL_WARN_REAL_FLOATING_DECL (isinf);
2083# if @HAVE_ISNANF@ 2486# if @HAVE_ISNANF@
2084/* The original <math.h> included above provides a declaration of isnan macro 2487/* The original <math.h> included above provides a declaration of isnan macro
2085 or (older) isnanf function. */ 2488 or (older) isnanf function. */
2086# if __GNUC__ >= 4 2489# if (__GNUC__ >= 4) || (__clang_major__ >= 4)
2087 /* GCC 4.0 and newer provides three built-ins for isnan. */ 2490 /* GCC >= 4.0 and clang provide a type-generic built-in for isnan.
2491 GCC >= 4.0 also provides __builtin_isnanf, but clang doesn't. */
2088# undef isnanf 2492# undef isnanf
2089# define isnanf(x) __builtin_isnanf ((float)(x)) 2493# define isnanf(x) __builtin_isnan ((float)(x))
2090# elif defined isnan 2494# elif defined isnan
2091# undef isnanf 2495# undef isnanf
2092# define isnanf(x) isnan ((float)(x)) 2496# define isnanf(x) isnan ((float)(x))
@@ -2106,8 +2510,8 @@ _GL_EXTERN_C int isnanf (float x);
2106# if @HAVE_ISNAND@ 2510# if @HAVE_ISNAND@
2107/* The original <math.h> included above provides a declaration of isnan 2511/* The original <math.h> included above provides a declaration of isnan
2108 macro. */ 2512 macro. */
2109# if __GNUC__ >= 4 2513# if (__GNUC__ >= 4) || (__clang_major__ >= 4)
2110 /* GCC 4.0 and newer provides three built-ins for isnan. */ 2514 /* GCC >= 4.0 and clang provide a type-generic built-in for isnan. */
2111# undef isnand 2515# undef isnand
2112# define isnand(x) __builtin_isnan ((double)(x)) 2516# define isnand(x) __builtin_isnan ((double)(x))
2113# else 2517# else
@@ -2127,10 +2531,11 @@ _GL_EXTERN_C int isnand (double x);
2127# if @HAVE_ISNANL@ 2531# if @HAVE_ISNANL@
2128/* The original <math.h> included above provides a declaration of isnan 2532/* The original <math.h> included above provides a declaration of isnan
2129 macro or (older) isnanl function. */ 2533 macro or (older) isnanl function. */
2130# if __GNUC__ >= 4 2534# if (__GNUC__ >= 4) || (__clang_major__ >= 4)
2131 /* GCC 4.0 and newer provides three built-ins for isnan. */ 2535 /* GCC >= 4.0 and clang provide a type-generic built-in for isnan.
2536 GCC >= 4.0 also provides __builtin_isnanl, but clang doesn't. */
2132# undef isnanl 2537# undef isnanl
2133# define isnanl(x) __builtin_isnanl ((long double)(x)) 2538# define isnanl(x) __builtin_isnan ((long double)(x))
2134# elif defined isnan 2539# elif defined isnan
2135# undef isnanl 2540# undef isnanl
2136# define isnanl(x) isnan ((long double)(x)) 2541# define isnanl(x) isnan ((long double)(x))
@@ -2150,20 +2555,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 2555 isnanf.h (e.g.) here, because those may end up being macros
2151 that recursively expand back to isnan. So use the gnulib 2556 that recursively expand back to isnan. So use the gnulib
2152 replacements for them directly. */ 2557 replacements for them directly. */
2153# if @HAVE_ISNANF@ && __GNUC__ >= 4 2558# if @HAVE_ISNANF@ && (__GNUC__ >= 4) || (__clang_major__ >= 4)
2154# define gl_isnan_f(x) __builtin_isnanf ((float)(x)) 2559# define gl_isnan_f(x) __builtin_isnan ((float)(x))
2155# else 2560# else
2156_GL_EXTERN_C int rpl_isnanf (float x); 2561_GL_EXTERN_C int rpl_isnanf (float x);
2157# define gl_isnan_f(x) rpl_isnanf (x) 2562# define gl_isnan_f(x) rpl_isnanf (x)
2158# endif 2563# endif
2159# if @HAVE_ISNAND@ && __GNUC__ >= 4 2564# if @HAVE_ISNAND@ && (__GNUC__ >= 4) || (__clang_major__ >= 4)
2160# define gl_isnan_d(x) __builtin_isnan ((double)(x)) 2565# define gl_isnan_d(x) __builtin_isnan ((double)(x))
2161# else 2566# else
2162_GL_EXTERN_C int rpl_isnand (double x); 2567_GL_EXTERN_C int rpl_isnand (double x);
2163# define gl_isnan_d(x) rpl_isnand (x) 2568# define gl_isnan_d(x) rpl_isnand (x)
2164# endif 2569# endif
2165# if @HAVE_ISNANL@ && __GNUC__ >= 4 2570# if @HAVE_ISNANL@ && (__GNUC__ >= 4) || (__clang_major__ >= 4)
2166# define gl_isnan_l(x) __builtin_isnanl ((long double)(x)) 2571# define gl_isnan_l(x) __builtin_isnan ((long double)(x))
2167# else 2572# else
2168_GL_EXTERN_C int rpl_isnanl (long double x) _GL_ATTRIBUTE_CONST; 2573_GL_EXTERN_C int rpl_isnanl (long double x) _GL_ATTRIBUTE_CONST;
2169# define gl_isnan_l(x) rpl_isnanl (x) 2574# define gl_isnan_l(x) rpl_isnanl (x)
@@ -2173,18 +2578,25 @@ _GL_EXTERN_C int rpl_isnanl (long double x) _GL_ATTRIBUTE_CONST;
2173 (sizeof (x) == sizeof (long double) ? gl_isnan_l (x) : \ 2578 (sizeof (x) == sizeof (long double) ? gl_isnan_l (x) : \
2174 sizeof (x) == sizeof (double) ? gl_isnan_d (x) : \ 2579 sizeof (x) == sizeof (double) ? gl_isnan_d (x) : \
2175 gl_isnan_f (x)) 2580 gl_isnan_f (x))
2176# elif __GNUC__ >= 4 2581# elif (__GNUC__ >= 4) || (__clang_major__ >= 4)
2177# undef isnan 2582# undef isnan
2178# define isnan(x) \ 2583# define isnan(x) \
2179 (sizeof (x) == sizeof (long double) ? __builtin_isnanl ((long double)(x)) : \ 2584 (sizeof (x) == sizeof (long double) ? __builtin_isnan ((long double)(x)) : \
2180 sizeof (x) == sizeof (double) ? __builtin_isnan ((double)(x)) : \ 2585 sizeof (x) == sizeof (double) ? __builtin_isnan ((double)(x)) : \
2181 __builtin_isnanf ((float)(x))) 2586 __builtin_isnan ((float)(x)))
2182# endif 2587# endif
2183# ifdef __cplusplus 2588# ifdef __cplusplus
2184# ifdef isnan 2589# if defined isnan || defined GNULIB_NAMESPACE
2185_GL_MATH_CXX_REAL_FLOATING_DECL_1 (isnan) 2590_GL_MATH_CXX_REAL_FLOATING_DECL_1 (isnan)
2186# undef isnan 2591# undef isnan
2187_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isnan) 2592# if __GNUC__ >= 6 || (defined __clang__ && !((defined __APPLE__ && defined __MACH__ && __clang_major__ < 12) || (defined __FreeBSD__ && __clang_major__ < 7) || defined __OpenBSD__ || (defined _WIN32 && !defined __CYGWIN__)))
2593 /* This platform's <cmath> possibly defines isnan through a set of inline
2594 functions. */
2595_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isnan, rpl_isnan, bool)
2596# define isnan rpl_isnan
2597# else
2598_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isnan, isnan, bool)
2599# endif
2188# endif 2600# endif
2189# else 2601# else
2190/* Ensure isnan is a macro. */ 2602/* Ensure isnan is a macro. */
@@ -2202,20 +2614,21 @@ _GL_WARN_REAL_FLOATING_DECL (isnan);
2202 2614
2203 2615
2204#if @GNULIB_SIGNBIT@ 2616#if @GNULIB_SIGNBIT@
2205# if @REPLACE_SIGNBIT_USING_GCC@ 2617# if (@REPLACE_SIGNBIT_USING_BUILTINS@ \
2618 && (!defined __cplusplus || __cplusplus < 201103))
2206# undef signbit 2619# undef signbit
2207 /* GCC 4.0 and newer provides three built-ins for signbit. */ 2620 /* GCC >= 4.0 and clang provide three built-ins for signbit. */
2208# define signbit(x) \ 2621# define signbit(x) \
2209 (sizeof (x) == sizeof (long double) ? __builtin_signbitl (x) : \ 2622 (sizeof (x) == sizeof (long double) ? __builtin_signbitl (x) : \
2210 sizeof (x) == sizeof (double) ? __builtin_signbit (x) : \ 2623 sizeof (x) == sizeof (double) ? __builtin_signbit (x) : \
2211 __builtin_signbitf (x)) 2624 __builtin_signbitf (x))
2212# endif 2625# endif
2213# if @REPLACE_SIGNBIT@ 2626# if @REPLACE_SIGNBIT@ && !GNULIB_defined_signbit
2214# undef signbit 2627# undef signbit
2215_GL_EXTERN_C int gl_signbitf (float arg); 2628_GL_EXTERN_C int gl_signbitf (float arg);
2216_GL_EXTERN_C int gl_signbitd (double arg); 2629_GL_EXTERN_C int gl_signbitd (double arg);
2217_GL_EXTERN_C int gl_signbitl (long double arg); 2630_GL_EXTERN_C int gl_signbitl (long double arg);
2218# if __GNUC__ >= 2 && !defined __STRICT_ANSI__ 2631# if (__GNUC__ >= 2 || defined __clang__) && !defined __STRICT_ANSI__
2219# define _GL_NUM_UINT_WORDS(type) \ 2632# define _GL_NUM_UINT_WORDS(type) \
2220 ((sizeof (type) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) 2633 ((sizeof (type) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
2221# if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT && !defined gl_signbitf 2634# if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT && !defined gl_signbitf
@@ -2253,12 +2666,20 @@ _GL_EXTERN_C int gl_signbitl (long double arg);
2253 (sizeof (x) == sizeof (long double) ? gl_signbitl (x) : \ 2666 (sizeof (x) == sizeof (long double) ? gl_signbitl (x) : \
2254 sizeof (x) == sizeof (double) ? gl_signbitd (x) : \ 2667 sizeof (x) == sizeof (double) ? gl_signbitd (x) : \
2255 gl_signbitf (x)) 2668 gl_signbitf (x))
2669# define GNULIB_defined_signbit 1
2256# endif 2670# endif
2257# ifdef __cplusplus 2671# ifdef __cplusplus
2258# ifdef signbit 2672# if defined signbit || defined GNULIB_NAMESPACE
2259_GL_MATH_CXX_REAL_FLOATING_DECL_1 (signbit) 2673_GL_MATH_CXX_REAL_FLOATING_DECL_1 (signbit)
2260# undef signbit 2674# undef signbit
2261_GL_MATH_CXX_REAL_FLOATING_DECL_2 (signbit) 2675# if __GNUC__ >= 6 || (defined __clang__ && !((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __OpenBSD__ || defined _AIX || (defined _WIN32 && !defined __CYGWIN__)))
2676 /* This platform's <cmath> possibly defines signbit through a set of inline
2677 functions. */
2678_GL_MATH_CXX_REAL_FLOATING_DECL_2 (signbit, rpl_signbit, bool)
2679# define signbit rpl_signbit
2680# else
2681_GL_MATH_CXX_REAL_FLOATING_DECL_2 (signbit, signbit, bool)
2682# endif
2262# endif 2683# endif
2263# endif 2684# endif
2264#elif defined GNULIB_POSIXCHECK 2685#elif defined GNULIB_POSIXCHECK
@@ -2272,4 +2693,5 @@ _GL_WARN_REAL_FLOATING_DECL (signbit);
2272_GL_INLINE_HEADER_END 2693_GL_INLINE_HEADER_END
2273 2694
2274#endif /* _@GUARD_PREFIX@_MATH_H */ 2695#endif /* _@GUARD_PREFIX@_MATH_H */
2696#endif /* _GL_INCLUDING_MATH_H */
2275#endif /* _@GUARD_PREFIX@_MATH_H */ 2697#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..330fb10
--- /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-2021 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..bc3e688
--- /dev/null
+++ b/gl/mbrtowc-impl.h
@@ -0,0 +1,262 @@
1/* Convert multibyte character to wide character.
2 Copyright (C) 1999-2002, 2005-2021 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..8832f6e 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-2021 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,67 @@
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
33
34verify (sizeof (mbstate_t) >= 4);
35
36static char internal_state[4];
37
38size_t
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 32
50 if (n == 0) 33# define WIN32_LEAN_AND_MEAN /* avoid including junk */
51 return (size_t)(-2); 34# include <windows.h>
52 35
53 /* Here n > 0. */ 36# elif HAVE_PTHREAD_API
54 37
55 if (pstate == NULL) 38# include <pthread.h>
56 pstate = internal_state; 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
57 46
58 { 47# elif HAVE_THREADS_H
59 size_t nstate = pstate[0];
60 char buf[4];
61 const char *p;
62 size_t m;
63 48
64 switch (nstate) 49# include <threads.h>
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 50
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
254 if ((c >= 0x90 && c <= 0xe3) || (c >= 0xf8 && c <= 0xfe))
255 goto incomplete;
256 }
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
287 if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea)
288 || (c >= 0xf0 && c <= 0xf9))
289 goto incomplete;
290 }
291 goto invalid;
292 }
293 52
294 /* An unknown multibyte encoding. */ 53# include "attribute.h"
295 goto incomplete; 54# include "verify.h"
296 } 55# include "lc-charset-dispatch.h"
56# include "mbtowc-lock.h"
297 57
298 incomplete: 58verify (sizeof (mbstate_t) >= 4);
299 { 59static char internal_state[4];
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 60
315 invalid: 61size_t
316 errno = EILSEQ; 62mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
317 /* The conversion state is undefined, says POSIX. */ 63{
318 return (size_t)(-1); 64# define FITS_IN_CHAR_TYPE(wc) ((wc) <= WCHAR_MAX)
319 } 65# include "mbrtowc-impl.h"
320 }
321} 66}
322 67
323#else 68#else
324/* Override the system's mbrtowc() function. */ 69/* Override the system's mbrtowc() function. */
325 70
71# if MBRTOWC_IN_C_LOCALE_MAYBE_EILSEQ
72# include "hard-locale.h"
73# include <locale.h>
74# endif
75
326# undef mbrtowc 76# undef mbrtowc
327 77
328size_t 78size_t
329rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) 79rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
330{ 80{
331# if MBRTOWC_NULL_ARG2_BUG || MBRTOWC_RETVAL_BUG 81 size_t ret;
82 wchar_t wc;
83
84# if MBRTOWC_NULL_ARG2_BUG || MBRTOWC_RETVAL_BUG || MBRTOWC_EMPTY_INPUT_BUG
332 if (s == NULL) 85 if (s == NULL)
333 { 86 {
334 pwc = NULL; 87 pwc = NULL;
@@ -337,6 +90,14 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
337 } 90 }
338# endif 91# endif
339 92
93# if MBRTOWC_EMPTY_INPUT_BUG
94 if (n == 0)
95 return (size_t) -2;
96# endif
97
98 if (! pwc)
99 pwc = &wc;
100
340# if MBRTOWC_RETVAL_BUG 101# if MBRTOWC_RETVAL_BUG
341 { 102 {
342 static mbstate_t internal_state; 103 static mbstate_t internal_state;
@@ -352,8 +113,7 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
352 size_t count = 0; 113 size_t count = 0;
353 for (; n > 0; s++, n--) 114 for (; n > 0; s++, n--)
354 { 115 {
355 wchar_t wc; 116 ret = mbrtowc (&wc, s, 1, ps);
356 size_t ret = mbrtowc (&wc, s, 1, ps);
357 117
358 if (ret == (size_t)(-1)) 118 if (ret == (size_t)(-1))
359 return (size_t)(-1); 119 return (size_t)(-1);
@@ -361,8 +121,7 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
361 if (ret != (size_t)(-2)) 121 if (ret != (size_t)(-2))
362 { 122 {
363 /* The multibyte character has been completed. */ 123 /* The multibyte character has been completed. */
364 if (pwc != NULL) 124 *pwc = wc;
365 *pwc = wc;
366 return (wc == 0 ? 0 : count); 125 return (wc == 0 ? 0 : count);
367 } 126 }
368 } 127 }
@@ -371,32 +130,29 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
371 } 130 }
372# endif 131# endif
373 132
374# if MBRTOWC_NUL_RETVAL_BUG 133# if MBRTOWC_STORES_INCOMPLETE_BUG
375 { 134 ret = mbrtowc (&wc, s, n, ps);
376 wchar_t wc; 135 if (ret < (size_t) -2 && pwc != NULL)
377 size_t ret = mbrtowc (&wc, s, n, ps); 136 *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 137# else
389 { 138 ret = mbrtowc (pwc, s, n, ps);
390# if MBRTOWC_NULL_ARG1_BUG 139# endif
391 wchar_t dummy;
392 140
393 if (pwc == NULL) 141# if MBRTOWC_NUL_RETVAL_BUG
394 pwc = &dummy; 142 if (ret < (size_t) -2 && !*pwc)
395# endif 143 return 0;
144# endif
396 145
397 return mbrtowc (pwc, s, n, ps); 146# if MBRTOWC_IN_C_LOCALE_MAYBE_EILSEQ
398 } 147 if ((size_t) -2 <= ret && n != 0 && ! hard_locale (LC_CTYPE))
148 {
149 unsigned char uc = *s;
150 *pwc = uc;
151 return 1;
152 }
399# endif 153# endif
154
155 return ret;
400} 156}
401 157
402#endif 158#endif
diff --git a/gl/mbsinit.c b/gl/mbsinit.c
index 26fbb7f..f440155 100644
--- a/gl/mbsinit.c
+++ b/gl/mbsinit.c
@@ -1,19 +1,19 @@
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-2021 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
@@ -22,17 +22,7 @@
22 22
23#include "verify.h" 23#include "verify.h"
24 24
25#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__ 25#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 26
37/* Platforms that lack mbsinit() also lack mbrlen(), mbrtowc(), mbsrtowcs() 27/* Platforms that lack mbsinit() also lack mbrlen(), mbrtowc(), mbsrtowcs()
38 and wcrtomb(), wcsrtombs(). 28 and wcrtomb(), wcsrtombs().
@@ -45,6 +35,7 @@ mbsinit (const mbstate_t *ps)
45 We define the meaning of mbstate_t as follows: 35 We define the meaning of mbstate_t as follows:
46 - In mb -> wc direction, mbstate_t's first byte contains the number of 36 - 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. 37 buffered bytes (in the range 0..3), followed by up to 3 buffered bytes.
38 See mbrtowc.c.
48 - In wc -> mb direction, mbstate_t contains no information. In other 39 - In wc -> mb direction, mbstate_t contains no information. In other
49 words, it is always in the initial state. */ 40 words, it is always in the initial state. */
50 41
@@ -58,4 +49,22 @@ mbsinit (const mbstate_t *ps)
58 return pstate == NULL || pstate[0] == 0; 49 return pstate == NULL || pstate[0] == 0;
59} 50}
60 51
52#else
53
54int
55mbsinit (const mbstate_t *ps)
56{
57# if defined _WIN32 && !defined __CYGWIN__
58 /* Native Windows. */
59 /* MSVC defines 'mbstate_t' as an 8-byte struct; the first 4 bytes matter.
60 On mingw, 'mbstate_t' is sometimes defined as 'int', sometimes defined as
61 an 8-byte struct, of which the first 4 bytes matter. */
62 return ps == NULL || *(const unsigned int *)ps == 0;
63# else
64 /* Minix, HP-UX 11.00, Solaris 2.6, Interix, ... */
65 /* Maybe this definition works, maybe not... */
66 return ps == NULL || *(const char *)ps == 0;
67# endif
68}
69
61#endif 70#endif
diff --git a/gl/mbtowc-impl.h b/gl/mbtowc-impl.h
index 767ab39..30d715d 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-2021 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..0f7ae6c
--- /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-2021 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..d31b0b6
--- /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-2021 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..47b431a 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-2021 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..56fd59d 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-2021
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..4f16481 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-2021 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..a03361b
--- /dev/null
+++ b/gl/minmax.h
@@ -0,0 +1,60 @@
1/* MIN, MAX macros.
2 Copyright (C) 1995, 1998, 2001, 2003, 2005, 2009-2021 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..7386625 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-2021 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..ae721c7 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-2021 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. */
@@ -531,211 +456,111 @@ __mktime_internal (struct tm *tp,
531 456
532 for (delta = stride; delta < delta_bound; delta += stride) 457 for (delta = stride; delta < delta_bound; delta += stride)
533 for (direction = -1; direction <= 1; direction += 2) 458 for (direction = -1; direction <= 1; direction += 2)
534 if (time_t_int_add_ok (t, delta * direction)) 459 {
535 { 460 long_int ot;
536 time_t ot = t + delta * direction; 461 if (! INT_ADD_WRAPV (t, delta * direction, &ot))
537 struct tm otm; 462 {
538 ranged_convert (convert, &ot, &otm); 463 struct tm otm;
539 if (! isdst_differ (isdst, otm.tm_isdst)) 464 if (! ranged_convert (convert, &ot, &otm))
540 { 465 return -1;
541 /* We found the desired tm_isdst. 466 if (! isdst_differ (isdst, otm.tm_isdst))
542 Extrapolate back to the desired time. */ 467 {
543 t = guess_time_tm (year, yday, hour, min, sec, &ot, &otm); 468 /* We found the desired tm_isdst.
544 ranged_convert (convert, &t, &tm); 469 Extrapolate back to the desired time. */
545 goto offset_found; 470 long_int gt = ot + tm_diff (year, yday, hour, min, sec,
546 } 471 &otm);
547 } 472 if (mktime_min <= gt && gt <= mktime_max)
473 {
474 if (convert_time (convert, gt, &tm))
475 {
476 t = gt;
477 goto offset_found;
478 }
479 if (errno != EOVERFLOW)
480 return -1;
481 }
482 }
483 }
484 }
485
486 __set_errno (EOVERFLOW);
487 return -1;
548 } 488 }
549 489
550 offset_found: 490 offset_found:
551 *offset = guessed_offset + t - t0; 491 /* Set *OFFSET to the low-order bits of T - T0 - NEGATIVE_OFFSET_GUESS.
492 This is just a heuristic to speed up the next mktime call, and
493 correctness is unaffected if integer overflow occurs here. */
494 INT_SUBTRACT_WRAPV (t, t0, offset);
495 INT_SUBTRACT_WRAPV (*offset, negative_offset_guess, offset);
552 496
553 if (LEAP_SECONDS_POSSIBLE && sec_requested != tm.tm_sec) 497 if (LEAP_SECONDS_POSSIBLE && sec_requested != tm.tm_sec)
554 { 498 {
555 /* Adjust time to reflect the tm_sec requested, not the normalized value. 499 /* 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. */ 500 Also, repair any damage from a false match due to a leap second. */
557 int sec_adjustment = (sec == 0 && tm.tm_sec == 60) - sec; 501 long_int sec_adjustment = sec == 0 && tm.tm_sec == 60;
558 if (! time_t_int_add_ok (t, sec_requested)) 502 sec_adjustment -= sec;
559 return -1; 503 sec_adjustment += sec_requested;
560 t1 = t + sec_requested; 504 if (INT_ADD_WRAPV (t, sec_adjustment, &t)
561 if (! time_t_int_add_ok (t1, sec_adjustment)) 505 || ! (mktime_min <= t && t <= mktime_max))
562 return -1; 506 {
563 t2 = t1 + sec_adjustment; 507 __set_errno (EOVERFLOW);
564 if (! convert (&t2, &tm)) 508 return -1;
509 }
510 if (! convert_time (convert, t, &tm))
565 return -1; 511 return -1;
566 t = t2;
567 } 512 }
568 513
569 *tp = tm; 514 *tp = tm;
570 return t; 515 return t;
571} 516}
572 517
518#endif /* _LIBC || NEED_MKTIME_WORKING || NEED_MKTIME_INTERNAL */
573 519
574/* FIXME: This should use a signed type wide enough to hold any UTC 520#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 521
580/* Convert *TP to a time_t value. */ 522/* Convert *TP to a __time64_t value. */
581time_t 523__time64_t
582mktime (struct tm *tp) 524__mktime64 (struct tm *tp)
583{ 525{
584#ifdef _LIBC
585 /* POSIX.1 8.1.1 requires that whenever mktime() is called, the 526 /* POSIX.1 8.1.1 requires that whenever mktime() is called, the
586 time zone names contained in the external variable 'tzname' shall 527 time zone names contained in the external variable 'tzname' shall
587 be set as if the tzset() function had been called. */ 528 be set as if the tzset() function had been called. */
588 __tzset (); 529 __tzset ();
589#endif
590
591 return __mktime_internal (tp, __localtime_r, &localtime_offset);
592}
593
594#ifdef weak_alias
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 530
605static int 531# if defined _LIBC || NEED_MKTIME_WORKING
606not_equal_tm (const struct tm *a, const struct tm *b) 532 static mktime_offset_t localtime_offset;
607{ 533 return __mktime_internal (tp, __localtime64_r, &localtime_offset);
608 return ((a->tm_sec ^ b->tm_sec) 534# else
609 | (a->tm_min ^ b->tm_min) 535# undef mktime
610 | (a->tm_hour ^ b->tm_hour) 536 return mktime (tp);
611 | (a->tm_mday ^ b->tm_mday) 537# endif
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
618static void
619print_tm (const 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} 538}
539#endif /* _LIBC || NEED_MKTIME_WORKING || NEED_MKTIME_WINDOWS */
629 540
630static int 541#if defined _LIBC && __TIMESIZE != 64
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 542
643 return 0; 543libc_hidden_def (__mktime64)
644}
645 544
646int 545time_t
647main (int argc, char **argv) 546mktime (struct tm *tp)
648{ 547{
649 int status = 0; 548 struct tm tm = *tp;
650 struct tm tm, tmk, tml; 549 __time64_t t = __mktime64 (&tm);
651 struct tm *lt; 550 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 { 551 {
663 tm.tm_year -= TM_YEAR_BASE; 552 *tp = tm;
664 tm.tm_mon--; 553 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 } 554 }
679 else if (argc == 4 || (argc == 5 && strcmp (argv[4], "-") == 0)) 555 else
680 { 556 {
681 time_t from = atol (argv[1]); 557 __set_errno (EOVERFLOW);
682 time_t by = atol (argv[2]); 558 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 } 559 }
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} 560}
734 561
735#endif /* DEBUG */ 562#endif
736 563
737/* 564weak_alias (mktime, timelocal)
738Local Variables: 565libc_hidden_def (mktime)
739compile-command: "gcc -DDEBUG -I. -Wall -W -O2 -g mktime.c -o mktime" 566libc_hidden_weak (timelocal)
740End:
741*/
diff --git a/gl/mountlist.c b/gl/mountlist.c
index 30f4286..352b35f 100644
--- a/gl/mountlist.c
+++ b/gl/mountlist.c
@@ -1,6 +1,6 @@
1/* mountlist.c -- return a list of mounted file systems 1/* mountlist.c -- return a list of mounted file systems
2 2
3 Copyright (C) 1991-1992, 1997-2013 Free Software Foundation, Inc. 3 Copyright (C) 1991-1992, 1997-2021 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
@@ -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..fbad124 100644
--- a/gl/mountlist.h
+++ b/gl/mountlist.h
@@ -1,6 +1,6 @@
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-2021 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
@@ -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#ifndef MOUNTLIST_H_ 19#ifndef MOUNTLIST_H_
20# define MOUNTLIST_H_ 20# define MOUNTLIST_H_
@@ -27,15 +27,18 @@ struct mount_entry
27{ 27{
28 char *me_devname; /* Device node name, including "/dev/". */ 28 char *me_devname; /* Device node name, including "/dev/". */
29 char *me_mountdir; /* Mount point directory name. */ 29 char *me_mountdir; /* Mount point directory name. */
30 char *me_mntroot; /* Directory on filesystem of device used */
31 /* as root for the (bind) mount. */
30 char *me_type; /* "nfs", "4.2", etc. */ 32 char *me_type; /* "nfs", "4.2", etc. */
31 dev_t me_dev; /* Device number of me_mountdir. */ 33 dev_t me_dev; /* Device number of me_mountdir. */
32 unsigned int me_dummy : 1; /* Nonzero for dummy file systems. */ 34 unsigned int me_dummy : 1; /* Nonzero for dummy file systems. */
33 unsigned int me_remote : 1; /* Nonzero for remote fileystems. */ 35 unsigned int me_remote : 1; /* Nonzero for remote file systems. */
34 unsigned int me_type_malloced : 1; /* Nonzero if me_type was malloced. */ 36 unsigned int me_type_malloced : 1; /* Nonzero if me_type was malloced. */
35 struct mount_entry *me_next; 37 struct mount_entry *me_next;
36}; 38};
37 39
38struct mount_entry *read_file_system_list (bool need_fs_type); 40struct mount_entry *read_file_system_list (bool need_fs_type)
41 _GL_ATTRIBUTE_MALLOC;
39void free_mount_entry (struct mount_entry *entry); 42void free_mount_entry (struct mount_entry *entry);
40 43
41#endif 44#endif
diff --git a/gl/msvc-inval.c b/gl/msvc-inval.c
index 396031e..a23dac9 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-2021 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..e115a35 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-2021 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..d3c1f54 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-2021 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..057b5dd 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-2021 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..eb5c960 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-2021 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..21f3a64 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-2021 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..fcdf56d
--- /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-2021 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..b481f20 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-2021 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..372cda8
--- /dev/null
+++ b/gl/open.c
@@ -0,0 +1,209 @@
1/* Open a descriptor to a file.
2 Copyright (C) 2007-2021 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..716f4a9
--- /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-2021 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..b822682 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-2021 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..c8d9174 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-2021 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..f21cc17 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-2021 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..77b7409 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-2021 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..af03f0c
--- /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-2021 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..1fb2f3c
--- /dev/null
+++ b/gl/reallocarray.c
@@ -0,0 +1,39 @@
1/* reallocarray function that is glibc compatible.
2
3 Copyright (C) 2017-2021 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 <stdlib.h>
23#include <errno.h>
24
25#include "intprops.h"
26
27void *
28reallocarray (void *ptr, size_t nmemb, size_t size)
29{
30 size_t nbytes;
31 if (INT_MULTIPLY_WRAPV (nmemb, size, &nbytes))
32 {
33 errno = ENOMEM;
34 return NULL;
35 }
36
37 /* Rely on the semantics of GNU realloc. */
38 return realloc (ptr, nbytes);
39}
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..887e5b5 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-2021 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);
@@ -55,7 +59,7 @@ static reg_errcode_t calc_inveclosure (re_dfa_t *dfa);
55static Idx fetch_number (re_string_t *input, re_token_t *token, 59static Idx fetch_number (re_string_t *input, re_token_t *token,
56 reg_syntax_t syntax); 60 reg_syntax_t syntax);
57static int peek_token (re_token_t *token, re_string_t *input, 61static int peek_token (re_token_t *token, re_string_t *input,
58 reg_syntax_t syntax) internal_function; 62 reg_syntax_t syntax);
59static bin_tree_t *parse (re_string_t *regexp, regex_t *preg, 63static bin_tree_t *parse (re_string_t *regexp, regex_t *preg,
60 reg_syntax_t syntax, reg_errcode_t *err); 64 reg_syntax_t syntax, reg_errcode_t *err);
61static bin_tree_t *parse_reg_exp (re_string_t *regexp, regex_t *preg, 65static bin_tree_t *parse_reg_exp (re_string_t *regexp, regex_t *preg,
@@ -149,9 +153,9 @@ static const char __re_error_msgid[] =
149 gettext_noop ("Invalid back reference") /* REG_ESUBREG */ 153 gettext_noop ("Invalid back reference") /* REG_ESUBREG */
150 "\0" 154 "\0"
151#define REG_EBRACK_IDX (REG_ESUBREG_IDX + sizeof "Invalid back reference") 155#define REG_EBRACK_IDX (REG_ESUBREG_IDX + sizeof "Invalid back reference")
152 gettext_noop ("Unmatched [ or [^") /* REG_EBRACK */ 156 gettext_noop ("Unmatched [, [^, [:, [., or [=") /* REG_EBRACK */
153 "\0" 157 "\0"
154#define REG_EPAREN_IDX (REG_EBRACK_IDX + sizeof "Unmatched [ or [^") 158#define REG_EPAREN_IDX (REG_EBRACK_IDX + sizeof "Unmatched [, [^, [:, [., or [=")
155 gettext_noop ("Unmatched ( or \\(") /* REG_EPAREN */ 159 gettext_noop ("Unmatched ( or \\(") /* REG_EPAREN */
156 "\0" 160 "\0"
157#define REG_EBRACE_IDX (REG_EPAREN_IDX + sizeof "Unmatched ( or \\(") 161#define REG_EBRACE_IDX (REG_EPAREN_IDX + sizeof "Unmatched ( or \\(")
@@ -209,17 +213,9 @@ static const size_t __re_error_msgid_idx[] =
209 Assumes the 'allocated' (and perhaps 'buffer') and 'translate' fields 213 Assumes the 'allocated' (and perhaps 'buffer') and 'translate' fields
210 are set in BUFP on entry. */ 214 are set in BUFP on entry. */
211 215
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 * 216const char *
220re_compile_pattern (const char *pattern, size_t length, 217re_compile_pattern (const char *pattern, size_t length,
221 struct re_pattern_buffer *bufp) 218 struct re_pattern_buffer *bufp)
222#endif
223{ 219{
224 reg_errcode_t ret; 220 reg_errcode_t ret;
225 221
@@ -237,9 +233,7 @@ re_compile_pattern (const char *pattern, size_t length,
237 return NULL; 233 return NULL;
238 return gettext (__re_error_msgid + __re_error_msgid_idx[(int) ret]); 234 return gettext (__re_error_msgid + __re_error_msgid_idx[(int) ret]);
239} 235}
240#ifdef _LIBC
241weak_alias (__re_compile_pattern, re_compile_pattern) 236weak_alias (__re_compile_pattern, re_compile_pattern)
242#endif
243 237
244/* Set by 're_set_syntax' to the current regexp syntax to recognize. Can 238/* 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 239 also be assigned to arbitrarily: each pattern buffer stores its own
@@ -257,21 +251,17 @@ reg_syntax_t re_syntax_options;
257 defined in regex.h. We return the old syntax. */ 251 defined in regex.h. We return the old syntax. */
258 252
259reg_syntax_t 253reg_syntax_t
260re_set_syntax (syntax) 254re_set_syntax (reg_syntax_t syntax)
261 reg_syntax_t syntax;
262{ 255{
263 reg_syntax_t ret = re_syntax_options; 256 reg_syntax_t ret = re_syntax_options;
264 257
265 re_syntax_options = syntax; 258 re_syntax_options = syntax;
266 return ret; 259 return ret;
267} 260}
268#ifdef _LIBC
269weak_alias (__re_set_syntax, re_set_syntax) 261weak_alias (__re_set_syntax, re_set_syntax)
270#endif
271 262
272int 263int
273re_compile_fastmap (bufp) 264re_compile_fastmap (struct re_pattern_buffer *bufp)
274 struct re_pattern_buffer *bufp;
275{ 265{
276 re_dfa_t *dfa = bufp->buffer; 266 re_dfa_t *dfa = bufp->buffer;
277 char *fastmap = bufp->fastmap; 267 char *fastmap = bufp->fastmap;
@@ -287,9 +277,7 @@ re_compile_fastmap (bufp)
287 bufp->fastmap_accurate = 1; 277 bufp->fastmap_accurate = 1;
288 return 0; 278 return 0;
289} 279}
290#ifdef _LIBC
291weak_alias (__re_compile_fastmap, re_compile_fastmap) 280weak_alias (__re_compile_fastmap, re_compile_fastmap)
292#endif
293 281
294static inline void 282static inline void
295__attribute__ ((always_inline)) 283__attribute__ ((always_inline))
@@ -335,7 +323,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
335 memset (&state, '\0', sizeof (state)); 323 memset (&state, '\0', sizeof (state));
336 if (__mbrtowc (&wc, (const char *) buf, p - buf, 324 if (__mbrtowc (&wc, (const char *) buf, p - buf,
337 &state) == p - buf 325 &state) == p - buf
338 && (__wcrtomb ((char *) buf, towlower (wc), &state) 326 && (__wcrtomb ((char *) buf, __towlower (wc), &state)
339 != (size_t) -1)) 327 != (size_t) -1))
340 re_set_fastmap (fastmap, false, buf[0]); 328 re_set_fastmap (fastmap, false, buf[0]);
341 } 329 }
@@ -411,7 +399,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
411 re_set_fastmap (fastmap, icase, *(unsigned char *) buf); 399 re_set_fastmap (fastmap, icase, *(unsigned char *) buf);
412 if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1) 400 if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1)
413 { 401 {
414 if (__wcrtomb (buf, towlower (cset->mbchars[i]), &state) 402 if (__wcrtomb (buf, __towlower (cset->mbchars[i]), &state)
415 != (size_t) -1) 403 != (size_t) -1)
416 re_set_fastmap (fastmap, false, *(unsigned char *) buf); 404 re_set_fastmap (fastmap, false, *(unsigned char *) buf);
417 } 405 }
@@ -470,10 +458,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
470 the return codes and their meanings.) */ 458 the return codes and their meanings.) */
471 459
472int 460int
473regcomp (preg, pattern, cflags) 461regcomp (regex_t *__restrict preg, const char *__restrict pattern, int cflags)
474 regex_t *_Restrict_ preg;
475 const char *_Restrict_ pattern;
476 int cflags;
477{ 462{
478 reg_errcode_t ret; 463 reg_errcode_t ret;
479 reg_syntax_t syntax = ((cflags & REG_EXTENDED) ? RE_SYNTAX_POSIX_EXTENDED 464 reg_syntax_t syntax = ((cflags & REG_EXTENDED) ? RE_SYNTAX_POSIX_EXTENDED
@@ -485,7 +470,7 @@ regcomp (preg, pattern, cflags)
485 470
486 /* Try to allocate space for the fastmap. */ 471 /* Try to allocate space for the fastmap. */
487 preg->fastmap = re_malloc (char, SBC_MAX); 472 preg->fastmap = re_malloc (char, SBC_MAX);
488 if (BE (preg->fastmap == NULL, 0)) 473 if (__glibc_unlikely (preg->fastmap == NULL))
489 return REG_ESPACE; 474 return REG_ESPACE;
490 475
491 syntax |= (cflags & REG_ICASE) ? RE_ICASE : 0; 476 syntax |= (cflags & REG_ICASE) ? RE_ICASE : 0;
@@ -511,7 +496,7 @@ regcomp (preg, pattern, cflags)
511 ret = REG_EPAREN; 496 ret = REG_EPAREN;
512 497
513 /* We have already checked preg->fastmap != NULL. */ 498 /* We have already checked preg->fastmap != NULL. */
514 if (BE (ret == REG_NOERROR, 1)) 499 if (__glibc_likely (ret == REG_NOERROR))
515 /* Compute the fastmap now, since regexec cannot modify the pattern 500 /* Compute the fastmap now, since regexec cannot modify the pattern
516 buffer. This function never fails in this implementation. */ 501 buffer. This function never fails in this implementation. */
517 (void) re_compile_fastmap (preg); 502 (void) re_compile_fastmap (preg);
@@ -524,32 +509,21 @@ regcomp (preg, pattern, cflags)
524 509
525 return (int) ret; 510 return (int) ret;
526} 511}
527#ifdef _LIBC 512libc_hidden_def (__regcomp)
528weak_alias (__regcomp, regcomp) 513weak_alias (__regcomp, regcomp)
529#endif
530 514
531/* Returns a message corresponding to an error code, ERRCODE, returned 515/* Returns a message corresponding to an error code, ERRCODE, returned
532 from either regcomp or regexec. We don't use PREG here. */ 516 from either regcomp or regexec. We don't use PREG here. */
533 517
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 518size_t
543regerror (int errcode, const regex_t *_Restrict_ preg, 519regerror (int errcode, const regex_t *__restrict preg, char *__restrict errbuf,
544 char *_Restrict_ errbuf, size_t errbuf_size) 520 size_t errbuf_size)
545#endif
546{ 521{
547 const char *msg; 522 const char *msg;
548 size_t msg_size; 523 size_t msg_size;
524 int nerrcodes = sizeof __re_error_msgid_idx / sizeof __re_error_msgid_idx[0];
549 525
550 if (BE (errcode < 0 526 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 527 /* 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 528 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. 529 code generates an invalid error code, then the program has a bug.
@@ -560,10 +534,10 @@ regerror (int errcode, const regex_t *_Restrict_ preg,
560 534
561 msg_size = strlen (msg) + 1; /* Includes the null. */ 535 msg_size = strlen (msg) + 1; /* Includes the null. */
562 536
563 if (BE (errbuf_size != 0, 1)) 537 if (__glibc_likely (errbuf_size != 0))
564 { 538 {
565 size_t cpy_size = msg_size; 539 size_t cpy_size = msg_size;
566 if (BE (msg_size > errbuf_size, 0)) 540 if (__glibc_unlikely (msg_size > errbuf_size))
567 { 541 {
568 cpy_size = errbuf_size - 1; 542 cpy_size = errbuf_size - 1;
569 errbuf[cpy_size] = '\0'; 543 errbuf[cpy_size] = '\0';
@@ -573,9 +547,7 @@ regerror (int errcode, const regex_t *_Restrict_ preg,
573 547
574 return msg_size; 548 return msg_size;
575} 549}
576#ifdef _LIBC
577weak_alias (__regerror, regerror) 550weak_alias (__regerror, regerror)
578#endif
579 551
580 552
581#ifdef RE_ENABLE_I18N 553#ifdef RE_ENABLE_I18N
@@ -586,7 +558,7 @@ weak_alias (__regerror, regerror)
586static const bitset_t utf8_sb_map = 558static const bitset_t utf8_sb_map =
587{ 559{
588 /* Set the first 128 bits. */ 560 /* Set the first 128 bits. */
589# if defined __GNUC__ && !defined __STRICT_ANSI__ 561# if (defined __GNUC__ || __clang_major__ >= 4) && !defined __STRICT_ANSI__
590 [0 ... 0x80 / BITSET_WORD_BITS - 1] = BITSET_WORD_MAX 562 [0 ... 0x80 / BITSET_WORD_BITS - 1] = BITSET_WORD_MAX
591# else 563# else
592# if 4 * BITSET_WORD_BITS < ASCII_CHARS 564# if 4 * BITSET_WORD_BITS < ASCII_CHARS
@@ -658,11 +630,10 @@ free_dfa_content (re_dfa_t *dfa)
658/* Free dynamically allocated space used by PREG. */ 630/* Free dynamically allocated space used by PREG. */
659 631
660void 632void
661regfree (preg) 633regfree (regex_t *preg)
662 regex_t *preg;
663{ 634{
664 re_dfa_t *dfa = preg->buffer; 635 re_dfa_t *dfa = preg->buffer;
665 if (BE (dfa != NULL, 1)) 636 if (__glibc_likely (dfa != NULL))
666 { 637 {
667 lock_fini (dfa->lock); 638 lock_fini (dfa->lock);
668 free_dfa_content (dfa); 639 free_dfa_content (dfa);
@@ -676,9 +647,8 @@ regfree (preg)
676 re_free (preg->translate); 647 re_free (preg->translate);
677 preg->translate = NULL; 648 preg->translate = NULL;
678} 649}
679#ifdef _LIBC 650libc_hidden_def (__regfree)
680weak_alias (__regfree, regfree) 651weak_alias (__regfree, regfree)
681#endif
682 652
683/* Entry points compatible with 4.2 BSD regex library. We don't define 653/* Entry points compatible with 4.2 BSD regex library. We don't define
684 them unless specifically requested. */ 654 them unless specifically requested. */
@@ -695,8 +665,7 @@ char *
695 regcomp/regexec above without link errors. */ 665 regcomp/regexec above without link errors. */
696weak_function 666weak_function
697# endif 667# endif
698re_comp (s) 668re_comp (const char *s)
699 const char *s;
700{ 669{
701 reg_errcode_t ret; 670 reg_errcode_t ret;
702 char *fastmap; 671 char *fastmap;
@@ -719,7 +688,7 @@ re_comp (s)
719 688
720 if (re_comp_buf.fastmap == NULL) 689 if (re_comp_buf.fastmap == NULL)
721 { 690 {
722 re_comp_buf.fastmap = (char *) malloc (SBC_MAX); 691 re_comp_buf.fastmap = re_malloc (char, SBC_MAX);
723 if (re_comp_buf.fastmap == NULL) 692 if (re_comp_buf.fastmap == NULL)
724 return (char *) gettext (__re_error_msgid 693 return (char *) gettext (__re_error_msgid
725 + __re_error_msgid_idx[(int) REG_ESPACE]); 694 + __re_error_msgid_idx[(int) REG_ESPACE]);
@@ -772,7 +741,7 @@ re_compile_internal (regex_t *preg, const char * pattern, size_t length,
772 741
773 /* Initialize the dfa. */ 742 /* Initialize the dfa. */
774 dfa = preg->buffer; 743 dfa = preg->buffer;
775 if (BE (preg->allocated < sizeof (re_dfa_t), 0)) 744 if (__glibc_unlikely (preg->allocated < sizeof (re_dfa_t)))
776 { 745 {
777 /* If zero allocated, but buffer is non-null, try to realloc 746 /* If zero allocated, but buffer is non-null, try to realloc
778 enough space. This loses if buffer's address is bogus, but 747 enough space. This loses if buffer's address is bogus, but
@@ -787,9 +756,9 @@ re_compile_internal (regex_t *preg, const char * pattern, size_t length,
787 preg->used = sizeof (re_dfa_t); 756 preg->used = sizeof (re_dfa_t);
788 757
789 err = init_dfa (dfa, length); 758 err = init_dfa (dfa, length);
790 if (BE (err == REG_NOERROR && lock_init (dfa->lock) != 0, 0)) 759 if (__glibc_unlikely (err == REG_NOERROR && lock_init (dfa->lock) != 0))
791 err = REG_ESPACE; 760 err = REG_ESPACE;
792 if (BE (err != REG_NOERROR, 0)) 761 if (__glibc_unlikely (err != REG_NOERROR))
793 { 762 {
794 free_dfa_content (dfa); 763 free_dfa_content (dfa);
795 preg->buffer = NULL; 764 preg->buffer = NULL;
@@ -804,7 +773,7 @@ re_compile_internal (regex_t *preg, const char * pattern, size_t length,
804 773
805 err = re_string_construct (&regexp, pattern, length, preg->translate, 774 err = re_string_construct (&regexp, pattern, length, preg->translate,
806 (syntax & RE_ICASE) != 0, dfa); 775 (syntax & RE_ICASE) != 0, dfa);
807 if (BE (err != REG_NOERROR, 0)) 776 if (__glibc_unlikely (err != REG_NOERROR))
808 { 777 {
809 re_compile_internal_free_return: 778 re_compile_internal_free_return:
810 free_workarea_compile (preg); 779 free_workarea_compile (preg);
@@ -819,12 +788,12 @@ re_compile_internal (regex_t *preg, const char * pattern, size_t length,
819 /* Parse the regular expression, and build a structure tree. */ 788 /* Parse the regular expression, and build a structure tree. */
820 preg->re_nsub = 0; 789 preg->re_nsub = 0;
821 dfa->str_tree = parse (&regexp, preg, syntax, &err); 790 dfa->str_tree = parse (&regexp, preg, syntax, &err);
822 if (BE (dfa->str_tree == NULL, 0)) 791 if (__glibc_unlikely (dfa->str_tree == NULL))
823 goto re_compile_internal_free_return; 792 goto re_compile_internal_free_return;
824 793
825 /* Analyze the tree and create the nfa. */ 794 /* Analyze the tree and create the nfa. */
826 err = analyze (preg); 795 err = analyze (preg);
827 if (BE (err != REG_NOERROR, 0)) 796 if (__glibc_unlikely (err != REG_NOERROR))
828 goto re_compile_internal_free_return; 797 goto re_compile_internal_free_return;
829 798
830#ifdef RE_ENABLE_I18N 799#ifdef RE_ENABLE_I18N
@@ -840,7 +809,7 @@ re_compile_internal (regex_t *preg, const char * pattern, size_t length,
840 free_workarea_compile (preg); 809 free_workarea_compile (preg);
841 re_string_destruct (&regexp); 810 re_string_destruct (&regexp);
842 811
843 if (BE (err != REG_NOERROR, 0)) 812 if (__glibc_unlikely (err != REG_NOERROR))
844 { 813 {
845 lock_fini (dfa->lock); 814 lock_fini (dfa->lock);
846 free_dfa_content (dfa); 815 free_dfa_content (dfa);
@@ -882,7 +851,8 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)
882 calculation below, and for similar doubling calculations 851 calculation below, and for similar doubling calculations
883 elsewhere. And it's <= rather than <, because some of the 852 elsewhere. And it's <= rather than <, because some of the
884 doubling calculations add 1 afterwards. */ 853 doubling calculations add 1 afterwards. */
885 if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) / 2 <= pat_len, 0)) 854 if (__glibc_unlikely (MIN (IDX_MAX, SIZE_MAX / max_object_size) / 2
855 <= pat_len))
886 return REG_ESPACE; 856 return REG_ESPACE;
887 857
888 dfa->nodes_alloc = pat_len + 1; 858 dfa->nodes_alloc = pat_len + 1;
@@ -926,7 +896,7 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)
926 int i, j, ch; 896 int i, j, ch;
927 897
928 dfa->sb_char = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1); 898 dfa->sb_char = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
929 if (BE (dfa->sb_char == NULL, 0)) 899 if (__glibc_unlikely (dfa->sb_char == NULL))
930 return REG_ESPACE; 900 return REG_ESPACE;
931 901
932 /* Set the bits corresponding to single byte chars. */ 902 /* Set the bits corresponding to single byte chars. */
@@ -945,7 +915,7 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)
945 } 915 }
946#endif 916#endif
947 917
948 if (BE (dfa->nodes == NULL || dfa->state_table == NULL, 0)) 918 if (__glibc_unlikely (dfa->nodes == NULL || dfa->state_table == NULL))
949 return REG_ESPACE; 919 return REG_ESPACE;
950 return REG_NOERROR; 920 return REG_NOERROR;
951} 921}
@@ -955,21 +925,23 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)
955 character used by some operators like "\<", "\>", etc. */ 925 character used by some operators like "\<", "\>", etc. */
956 926
957static void 927static void
958internal_function
959init_word_char (re_dfa_t *dfa) 928init_word_char (re_dfa_t *dfa)
960{ 929{
961 int i = 0; 930 int i = 0;
962 int j; 931 int j;
963 int ch = 0; 932 int ch = 0;
964 dfa->word_ops_used = 1; 933 dfa->word_ops_used = 1;
965 if (BE (dfa->map_notascii == 0, 1)) 934 if (__glibc_likely (dfa->map_notascii == 0))
966 { 935 {
936 /* Avoid uint32_t and uint64_t as some non-GCC platforms lack
937 them, an issue when this code is used in Gnulib. */
967 bitset_word_t bits0 = 0x00000000; 938 bitset_word_t bits0 = 0x00000000;
968 bitset_word_t bits1 = 0x03ff0000; 939 bitset_word_t bits1 = 0x03ff0000;
969 bitset_word_t bits2 = 0x87fffffe; 940 bitset_word_t bits2 = 0x87fffffe;
970 bitset_word_t bits3 = 0x07fffffe; 941 bitset_word_t bits3 = 0x07fffffe;
971 if (BITSET_WORD_BITS == 64) 942 if (BITSET_WORD_BITS == 64)
972 { 943 {
944 /* Pacify gcc -Woverflow on 32-bit platformns. */
973 dfa->word_char[0] = bits1 << 31 << 1 | bits0; 945 dfa->word_char[0] = bits1 << 31 << 1 | bits0;
974 dfa->word_char[1] = bits3 << 31 << 1 | bits2; 946 dfa->word_char[1] = bits3 << 31 << 1 | bits2;
975 i = 2; 947 i = 2;
@@ -986,7 +958,7 @@ init_word_char (re_dfa_t *dfa)
986 goto general_case; 958 goto general_case;
987 ch = 128; 959 ch = 128;
988 960
989 if (BE (dfa->is_utf8, 1)) 961 if (__glibc_likely (dfa->is_utf8))
990 { 962 {
991 memset (&dfa->word_char[i], '\0', (SBC_MAX - ch) / 8); 963 memset (&dfa->word_char[i], '\0', (SBC_MAX - ch) / 8);
992 return; 964 return;
@@ -1033,7 +1005,7 @@ create_initial_state (re_dfa_t *dfa)
1033 first = dfa->str_tree->first->node_idx; 1005 first = dfa->str_tree->first->node_idx;
1034 dfa->init_node = first; 1006 dfa->init_node = first;
1035 err = re_node_set_init_copy (&init_nodes, dfa->eclosures + first); 1007 err = re_node_set_init_copy (&init_nodes, dfa->eclosures + first);
1036 if (BE (err != REG_NOERROR, 0)) 1008 if (__glibc_unlikely (err != REG_NOERROR))
1037 return err; 1009 return err;
1038 1010
1039 /* The back-references which are in initial states can epsilon transit, 1011 /* The back-references which are in initial states can epsilon transit,
@@ -1077,7 +1049,7 @@ create_initial_state (re_dfa_t *dfa)
1077 /* It must be the first time to invoke acquire_state. */ 1049 /* It must be the first time to invoke acquire_state. */
1078 dfa->init_state = re_acquire_state_context (&err, dfa, &init_nodes, 0); 1050 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. */ 1051 /* We don't check ERR here, since the initial state must not be NULL. */
1080 if (BE (dfa->init_state == NULL, 0)) 1052 if (__glibc_unlikely (dfa->init_state == NULL))
1081 return err; 1053 return err;
1082 if (dfa->init_state->has_constraint) 1054 if (dfa->init_state->has_constraint)
1083 { 1055 {
@@ -1089,8 +1061,9 @@ create_initial_state (re_dfa_t *dfa)
1089 &init_nodes, 1061 &init_nodes,
1090 CONTEXT_NEWLINE 1062 CONTEXT_NEWLINE
1091 | CONTEXT_BEGBUF); 1063 | CONTEXT_BEGBUF);
1092 if (BE (dfa->init_state_word == NULL || dfa->init_state_nl == NULL 1064 if (__glibc_unlikely (dfa->init_state_word == NULL
1093 || dfa->init_state_begbuf == NULL, 0)) 1065 || dfa->init_state_nl == NULL
1066 || dfa->init_state_begbuf == NULL))
1094 return err; 1067 return err;
1095 } 1068 }
1096 else 1069 else
@@ -1197,8 +1170,8 @@ analyze (regex_t *preg)
1197 dfa->org_indices = re_malloc (Idx, dfa->nodes_alloc); 1170 dfa->org_indices = re_malloc (Idx, dfa->nodes_alloc);
1198 dfa->edests = re_malloc (re_node_set, dfa->nodes_alloc); 1171 dfa->edests = re_malloc (re_node_set, dfa->nodes_alloc);
1199 dfa->eclosures = re_malloc (re_node_set, dfa->nodes_alloc); 1172 dfa->eclosures = re_malloc (re_node_set, dfa->nodes_alloc);
1200 if (BE (dfa->nexts == NULL || dfa->org_indices == NULL || dfa->edests == NULL 1173 if (__glibc_unlikely (dfa->nexts == NULL || dfa->org_indices == NULL
1201 || dfa->eclosures == NULL, 0)) 1174 || dfa->edests == NULL || dfa->eclosures == NULL))
1202 return REG_ESPACE; 1175 return REG_ESPACE;
1203 1176
1204 dfa->subexp_map = re_malloc (Idx, preg->re_nsub); 1177 dfa->subexp_map = re_malloc (Idx, preg->re_nsub);
@@ -1213,23 +1186,23 @@ analyze (regex_t *preg)
1213 break; 1186 break;
1214 if (i == preg->re_nsub) 1187 if (i == preg->re_nsub)
1215 { 1188 {
1216 free (dfa->subexp_map); 1189 re_free (dfa->subexp_map);
1217 dfa->subexp_map = NULL; 1190 dfa->subexp_map = NULL;
1218 } 1191 }
1219 } 1192 }
1220 1193
1221 ret = postorder (dfa->str_tree, lower_subexps, preg); 1194 ret = postorder (dfa->str_tree, lower_subexps, preg);
1222 if (BE (ret != REG_NOERROR, 0)) 1195 if (__glibc_unlikely (ret != REG_NOERROR))
1223 return ret; 1196 return ret;
1224 ret = postorder (dfa->str_tree, calc_first, dfa); 1197 ret = postorder (dfa->str_tree, calc_first, dfa);
1225 if (BE (ret != REG_NOERROR, 0)) 1198 if (__glibc_unlikely (ret != REG_NOERROR))
1226 return ret; 1199 return ret;
1227 preorder (dfa->str_tree, calc_next, dfa); 1200 preorder (dfa->str_tree, calc_next, dfa);
1228 ret = preorder (dfa->str_tree, link_nfa_nodes, dfa); 1201 ret = preorder (dfa->str_tree, link_nfa_nodes, dfa);
1229 if (BE (ret != REG_NOERROR, 0)) 1202 if (__glibc_unlikely (ret != REG_NOERROR))
1230 return ret; 1203 return ret;
1231 ret = calc_eclosure (dfa); 1204 ret = calc_eclosure (dfa);
1232 if (BE (ret != REG_NOERROR, 0)) 1205 if (__glibc_unlikely (ret != REG_NOERROR))
1233 return ret; 1206 return ret;
1234 1207
1235 /* We only need this during the prune_impossible_nodes pass in regexec.c; 1208 /* We only need this during the prune_impossible_nodes pass in regexec.c;
@@ -1238,7 +1211,7 @@ analyze (regex_t *preg)
1238 || dfa->nbackref) 1211 || dfa->nbackref)
1239 { 1212 {
1240 dfa->inveclosures = re_malloc (re_node_set, dfa->nodes_len); 1213 dfa->inveclosures = re_malloc (re_node_set, dfa->nodes_len);
1241 if (BE (dfa->inveclosures == NULL, 0)) 1214 if (__glibc_unlikely (dfa->inveclosures == NULL))
1242 return REG_ESPACE; 1215 return REG_ESPACE;
1243 ret = calc_inveclosure (dfa); 1216 ret = calc_inveclosure (dfa);
1244 } 1217 }
@@ -1268,7 +1241,7 @@ postorder (bin_tree_t *root, reg_errcode_t (fn (void *, bin_tree_t *)),
1268 do 1241 do
1269 { 1242 {
1270 reg_errcode_t err = fn (extra, node); 1243 reg_errcode_t err = fn (extra, node);
1271 if (BE (err != REG_NOERROR, 0)) 1244 if (__glibc_unlikely (err != REG_NOERROR))
1272 return err; 1245 return err;
1273 if (node->parent == NULL) 1246 if (node->parent == NULL)
1274 return REG_NOERROR; 1247 return REG_NOERROR;
@@ -1290,7 +1263,7 @@ preorder (bin_tree_t *root, reg_errcode_t (fn (void *, bin_tree_t *)),
1290 for (node = root; ; ) 1263 for (node = root; ; )
1291 { 1264 {
1292 reg_errcode_t err = fn (extra, node); 1265 reg_errcode_t err = fn (extra, node);
1293 if (BE (err != REG_NOERROR, 0)) 1266 if (__glibc_unlikely (err != REG_NOERROR))
1294 return err; 1267 return err;
1295 1268
1296 /* Go to the left node, or up and to the right. */ 1269 /* Go to the left node, or up and to the right. */
@@ -1391,7 +1364,8 @@ lower_subexp (reg_errcode_t *err, regex_t *preg, bin_tree_t *node)
1391 cls = create_tree (dfa, NULL, NULL, OP_CLOSE_SUBEXP); 1364 cls = create_tree (dfa, NULL, NULL, OP_CLOSE_SUBEXP);
1392 tree1 = body ? create_tree (dfa, body, cls, CONCAT) : cls; 1365 tree1 = body ? create_tree (dfa, body, cls, CONCAT) : cls;
1393 tree = create_tree (dfa, op, tree1, CONCAT); 1366 tree = create_tree (dfa, op, tree1, CONCAT);
1394 if (BE (tree == NULL || tree1 == NULL || op == NULL || cls == NULL, 0)) 1367 if (__glibc_unlikely (tree == NULL || tree1 == NULL
1368 || op == NULL || cls == NULL))
1395 { 1369 {
1396 *err = REG_ESPACE; 1370 *err = REG_ESPACE;
1397 return NULL; 1371 return NULL;
@@ -1417,7 +1391,7 @@ calc_first (void *extra, bin_tree_t *node)
1417 { 1391 {
1418 node->first = node; 1392 node->first = node;
1419 node->node_idx = re_dfa_add_node (dfa, node->token); 1393 node->node_idx = re_dfa_add_node (dfa, node->token);
1420 if (BE (node->node_idx == REG_MISSING, 0)) 1394 if (__glibc_unlikely (node->node_idx == -1))
1421 return REG_ESPACE; 1395 return REG_ESPACE;
1422 if (node->token.type == ANCHOR) 1396 if (node->token.type == ANCHOR)
1423 dfa->nodes[node->node_idx].constraint = node->token.opr.ctx_type; 1397 dfa->nodes[node->node_idx].constraint = node->token.opr.ctx_type;
@@ -1462,7 +1436,7 @@ link_nfa_nodes (void *extra, bin_tree_t *node)
1462 break; 1436 break;
1463 1437
1464 case END_OF_RE: 1438 case END_OF_RE:
1465 assert (node->next == NULL); 1439 DEBUG_ASSERT (node->next == NULL);
1466 break; 1440 break;
1467 1441
1468 case OP_DUP_ASTERISK: 1442 case OP_DUP_ASTERISK:
@@ -1478,8 +1452,8 @@ link_nfa_nodes (void *extra, bin_tree_t *node)
1478 right = node->right->first->node_idx; 1452 right = node->right->first->node_idx;
1479 else 1453 else
1480 right = node->next->node_idx; 1454 right = node->next->node_idx;
1481 assert (REG_VALID_INDEX (left)); 1455 DEBUG_ASSERT (left > -1);
1482 assert (REG_VALID_INDEX (right)); 1456 DEBUG_ASSERT (right > -1);
1483 err = re_node_set_init_2 (dfa->edests + idx, left, right); 1457 err = re_node_set_init_2 (dfa->edests + idx, left, right);
1484 } 1458 }
1485 break; 1459 break;
@@ -1497,7 +1471,7 @@ link_nfa_nodes (void *extra, bin_tree_t *node)
1497 break; 1471 break;
1498 1472
1499 default: 1473 default:
1500 assert (!IS_EPSILON_NODE (node->token.type)); 1474 DEBUG_ASSERT (!IS_EPSILON_NODE (node->token.type));
1501 dfa->nexts[idx] = node->next->node_idx; 1475 dfa->nexts[idx] = node->next->node_idx;
1502 break; 1476 break;
1503 } 1477 }
@@ -1510,7 +1484,6 @@ link_nfa_nodes (void *extra, bin_tree_t *node)
1510 to their own constraint. */ 1484 to their own constraint. */
1511 1485
1512static reg_errcode_t 1486static reg_errcode_t
1513internal_function
1514duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, Idx top_clone_node, 1487duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, Idx top_clone_node,
1515 Idx root_node, unsigned int init_constraint) 1488 Idx root_node, unsigned int init_constraint)
1516{ 1489{
@@ -1529,11 +1502,11 @@ duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, Idx top_clone_node,
1529 org_dest = dfa->nexts[org_node]; 1502 org_dest = dfa->nexts[org_node];
1530 re_node_set_empty (dfa->edests + clone_node); 1503 re_node_set_empty (dfa->edests + clone_node);
1531 clone_dest = duplicate_node (dfa, org_dest, constraint); 1504 clone_dest = duplicate_node (dfa, org_dest, constraint);
1532 if (BE (clone_dest == REG_MISSING, 0)) 1505 if (__glibc_unlikely (clone_dest == -1))
1533 return REG_ESPACE; 1506 return REG_ESPACE;
1534 dfa->nexts[clone_node] = dfa->nexts[org_node]; 1507 dfa->nexts[clone_node] = dfa->nexts[org_node];
1535 ok = re_node_set_insert (dfa->edests + clone_node, clone_dest); 1508 ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
1536 if (BE (! ok, 0)) 1509 if (__glibc_unlikely (! ok))
1537 return REG_ESPACE; 1510 return REG_ESPACE;
1538 } 1511 }
1539 else if (dfa->edests[org_node].nelem == 0) 1512 else if (dfa->edests[org_node].nelem == 0)
@@ -1555,17 +1528,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) 1528 if (org_node == root_node && clone_node != org_node)
1556 { 1529 {
1557 ok = re_node_set_insert (dfa->edests + clone_node, org_dest); 1530 ok = re_node_set_insert (dfa->edests + clone_node, org_dest);
1558 if (BE (! ok, 0)) 1531 if (__glibc_unlikely (! ok))
1559 return REG_ESPACE; 1532 return REG_ESPACE;
1560 break; 1533 break;
1561 } 1534 }
1562 /* In case the node has another constraint, append it. */ 1535 /* In case the node has another constraint, append it. */
1563 constraint |= dfa->nodes[org_node].constraint; 1536 constraint |= dfa->nodes[org_node].constraint;
1564 clone_dest = duplicate_node (dfa, org_dest, constraint); 1537 clone_dest = duplicate_node (dfa, org_dest, constraint);
1565 if (BE (clone_dest == REG_MISSING, 0)) 1538 if (__glibc_unlikely (clone_dest == -1))
1566 return REG_ESPACE; 1539 return REG_ESPACE;
1567 ok = re_node_set_insert (dfa->edests + clone_node, clone_dest); 1540 ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
1568 if (BE (! ok, 0)) 1541 if (__glibc_unlikely (! ok))
1569 return REG_ESPACE; 1542 return REG_ESPACE;
1570 } 1543 }
1571 else /* dfa->edests[org_node].nelem == 2 */ 1544 else /* dfa->edests[org_node].nelem == 2 */
@@ -1576,19 +1549,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); 1549 re_node_set_empty (dfa->edests + clone_node);
1577 /* Search for a duplicated node which satisfies the constraint. */ 1550 /* Search for a duplicated node which satisfies the constraint. */
1578 clone_dest = search_duplicated_node (dfa, org_dest, constraint); 1551 clone_dest = search_duplicated_node (dfa, org_dest, constraint);
1579 if (clone_dest == REG_MISSING) 1552 if (clone_dest == -1)
1580 { 1553 {
1581 /* There is no such duplicated node, create a new one. */ 1554 /* There is no such duplicated node, create a new one. */
1582 reg_errcode_t err; 1555 reg_errcode_t err;
1583 clone_dest = duplicate_node (dfa, org_dest, constraint); 1556 clone_dest = duplicate_node (dfa, org_dest, constraint);
1584 if (BE (clone_dest == REG_MISSING, 0)) 1557 if (__glibc_unlikely (clone_dest == -1))
1585 return REG_ESPACE; 1558 return REG_ESPACE;
1586 ok = re_node_set_insert (dfa->edests + clone_node, clone_dest); 1559 ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
1587 if (BE (! ok, 0)) 1560 if (__glibc_unlikely (! ok))
1588 return REG_ESPACE; 1561 return REG_ESPACE;
1589 err = duplicate_node_closure (dfa, org_dest, clone_dest, 1562 err = duplicate_node_closure (dfa, org_dest, clone_dest,
1590 root_node, constraint); 1563 root_node, constraint);
1591 if (BE (err != REG_NOERROR, 0)) 1564 if (__glibc_unlikely (err != REG_NOERROR))
1592 return err; 1565 return err;
1593 } 1566 }
1594 else 1567 else
@@ -1596,16 +1569,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, 1569 /* There is a duplicated node which satisfies the constraint,
1597 use it to avoid infinite loop. */ 1570 use it to avoid infinite loop. */
1598 ok = re_node_set_insert (dfa->edests + clone_node, clone_dest); 1571 ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
1599 if (BE (! ok, 0)) 1572 if (__glibc_unlikely (! ok))
1600 return REG_ESPACE; 1573 return REG_ESPACE;
1601 } 1574 }
1602 1575
1603 org_dest = dfa->edests[org_node].elems[1]; 1576 org_dest = dfa->edests[org_node].elems[1];
1604 clone_dest = duplicate_node (dfa, org_dest, constraint); 1577 clone_dest = duplicate_node (dfa, org_dest, constraint);
1605 if (BE (clone_dest == REG_MISSING, 0)) 1578 if (__glibc_unlikely (clone_dest == -1))
1606 return REG_ESPACE; 1579 return REG_ESPACE;
1607 ok = re_node_set_insert (dfa->edests + clone_node, clone_dest); 1580 ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
1608 if (BE (! ok, 0)) 1581 if (__glibc_unlikely (! ok))
1609 return REG_ESPACE; 1582 return REG_ESPACE;
1610 } 1583 }
1611 org_node = org_dest; 1584 org_node = org_dest;
@@ -1628,18 +1601,18 @@ search_duplicated_node (const re_dfa_t *dfa, Idx org_node,
1628 && constraint == dfa->nodes[idx].constraint) 1601 && constraint == dfa->nodes[idx].constraint)
1629 return idx; /* Found. */ 1602 return idx; /* Found. */
1630 } 1603 }
1631 return REG_MISSING; /* Not found. */ 1604 return -1; /* Not found. */
1632} 1605}
1633 1606
1634/* Duplicate the node whose index is ORG_IDX and set the constraint CONSTRAINT. 1607/* 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 1608 Return the index of the new node, or -1 if insufficient storage is
1636 available. */ 1609 available. */
1637 1610
1638static Idx 1611static Idx
1639duplicate_node (re_dfa_t *dfa, Idx org_idx, unsigned int constraint) 1612duplicate_node (re_dfa_t *dfa, Idx org_idx, unsigned int constraint)
1640{ 1613{
1641 Idx dup_idx = re_dfa_add_node (dfa, dfa->nodes[org_idx]); 1614 Idx dup_idx = re_dfa_add_node (dfa, dfa->nodes[org_idx]);
1642 if (BE (dup_idx != REG_MISSING, 1)) 1615 if (__glibc_likely (dup_idx != -1))
1643 { 1616 {
1644 dfa->nodes[dup_idx].constraint = constraint; 1617 dfa->nodes[dup_idx].constraint = constraint;
1645 dfa->nodes[dup_idx].constraint |= dfa->nodes[org_idx].constraint; 1618 dfa->nodes[dup_idx].constraint |= dfa->nodes[org_idx].constraint;
@@ -1665,7 +1638,7 @@ calc_inveclosure (re_dfa_t *dfa)
1665 for (idx = 0; idx < dfa->eclosures[src].nelem; ++idx) 1638 for (idx = 0; idx < dfa->eclosures[src].nelem; ++idx)
1666 { 1639 {
1667 ok = re_node_set_insert_last (dfa->inveclosures + elems[idx], src); 1640 ok = re_node_set_insert_last (dfa->inveclosures + elems[idx], src);
1668 if (BE (! ok, 0)) 1641 if (__glibc_unlikely (! ok))
1669 return REG_ESPACE; 1642 return REG_ESPACE;
1670 } 1643 }
1671 } 1644 }
@@ -1680,9 +1653,7 @@ calc_eclosure (re_dfa_t *dfa)
1680{ 1653{
1681 Idx node_idx; 1654 Idx node_idx;
1682 bool incomplete; 1655 bool incomplete;
1683#ifdef DEBUG 1656 DEBUG_ASSERT (dfa->nodes_len > 0);
1684 assert (dfa->nodes_len > 0);
1685#endif
1686 incomplete = false; 1657 incomplete = false;
1687 /* For each nodes, calculate epsilon closure. */ 1658 /* For each nodes, calculate epsilon closure. */
1688 for (node_idx = 0; ; ++node_idx) 1659 for (node_idx = 0; ; ++node_idx)
@@ -1697,16 +1668,14 @@ calc_eclosure (re_dfa_t *dfa)
1697 node_idx = 0; 1668 node_idx = 0;
1698 } 1669 }
1699 1670
1700#ifdef DEBUG 1671 DEBUG_ASSERT (dfa->eclosures[node_idx].nelem != -1);
1701 assert (dfa->eclosures[node_idx].nelem != REG_MISSING);
1702#endif
1703 1672
1704 /* If we have already calculated, skip it. */ 1673 /* If we have already calculated, skip it. */
1705 if (dfa->eclosures[node_idx].nelem != 0) 1674 if (dfa->eclosures[node_idx].nelem != 0)
1706 continue; 1675 continue;
1707 /* Calculate epsilon closure of 'node_idx'. */ 1676 /* Calculate epsilon closure of 'node_idx'. */
1708 err = calc_eclosure_iter (&eclosure_elem, dfa, node_idx, true); 1677 err = calc_eclosure_iter (&eclosure_elem, dfa, node_idx, true);
1709 if (BE (err != REG_NOERROR, 0)) 1678 if (__glibc_unlikely (err != REG_NOERROR))
1710 return err; 1679 return err;
1711 1680
1712 if (dfa->eclosures[node_idx].nelem == 0) 1681 if (dfa->eclosures[node_idx].nelem == 0)
@@ -1726,15 +1695,17 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root)
1726 reg_errcode_t err; 1695 reg_errcode_t err;
1727 Idx i; 1696 Idx i;
1728 re_node_set eclosure; 1697 re_node_set eclosure;
1729 bool ok;
1730 bool incomplete = false; 1698 bool incomplete = false;
1731 err = re_node_set_alloc (&eclosure, dfa->edests[node].nelem + 1); 1699 err = re_node_set_alloc (&eclosure, dfa->edests[node].nelem + 1);
1732 if (BE (err != REG_NOERROR, 0)) 1700 if (__glibc_unlikely (err != REG_NOERROR))
1733 return err; 1701 return err;
1734 1702
1703 /* An epsilon closure includes itself. */
1704 eclosure.elems[eclosure.nelem++] = node;
1705
1735 /* This indicates that we are calculating this node now. 1706 /* This indicates that we are calculating this node now.
1736 We reference this value to avoid infinite loop. */ 1707 We reference this value to avoid infinite loop. */
1737 dfa->eclosures[node].nelem = REG_MISSING; 1708 dfa->eclosures[node].nelem = -1;
1738 1709
1739 /* If the current node has constraints, duplicate all nodes 1710 /* If the current node has constraints, duplicate all nodes
1740 since they must inherit the constraints. */ 1711 since they must inherit the constraints. */
@@ -1744,7 +1715,7 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root)
1744 { 1715 {
1745 err = duplicate_node_closure (dfa, node, node, node, 1716 err = duplicate_node_closure (dfa, node, node, node,
1746 dfa->nodes[node].constraint); 1717 dfa->nodes[node].constraint);
1747 if (BE (err != REG_NOERROR, 0)) 1718 if (__glibc_unlikely (err != REG_NOERROR))
1748 return err; 1719 return err;
1749 } 1720 }
1750 1721
@@ -1756,7 +1727,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]; 1727 Idx edest = dfa->edests[node].elems[i];
1757 /* If calculating the epsilon closure of 'edest' is in progress, 1728 /* If calculating the epsilon closure of 'edest' is in progress,
1758 return intermediate result. */ 1729 return intermediate result. */
1759 if (dfa->eclosures[edest].nelem == REG_MISSING) 1730 if (dfa->eclosures[edest].nelem == -1)
1760 { 1731 {
1761 incomplete = true; 1732 incomplete = true;
1762 continue; 1733 continue;
@@ -1766,14 +1737,14 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root)
1766 if (dfa->eclosures[edest].nelem == 0) 1737 if (dfa->eclosures[edest].nelem == 0)
1767 { 1738 {
1768 err = calc_eclosure_iter (&eclosure_elem, dfa, edest, false); 1739 err = calc_eclosure_iter (&eclosure_elem, dfa, edest, false);
1769 if (BE (err != REG_NOERROR, 0)) 1740 if (__glibc_unlikely (err != REG_NOERROR))
1770 return err; 1741 return err;
1771 } 1742 }
1772 else 1743 else
1773 eclosure_elem = dfa->eclosures[edest]; 1744 eclosure_elem = dfa->eclosures[edest];
1774 /* Merge the epsilon closure of 'edest'. */ 1745 /* Merge the epsilon closure of 'edest'. */
1775 err = re_node_set_merge (&eclosure, &eclosure_elem); 1746 err = re_node_set_merge (&eclosure, &eclosure_elem);
1776 if (BE (err != REG_NOERROR, 0)) 1747 if (__glibc_unlikely (err != REG_NOERROR))
1777 return err; 1748 return err;
1778 /* If the epsilon closure of 'edest' is incomplete, 1749 /* If the epsilon closure of 'edest' is incomplete,
1779 the epsilon closure of this node is also incomplete. */ 1750 the epsilon closure of this node is also incomplete. */
@@ -1784,10 +1755,6 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root)
1784 } 1755 }
1785 } 1756 }
1786 1757
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) 1758 if (incomplete && !root)
1792 dfa->eclosures[node].nelem = 0; 1759 dfa->eclosures[node].nelem = 0;
1793 else 1760 else
@@ -1802,7 +1769,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. */ 1769 We must not use this function inside bracket expressions. */
1803 1770
1804static void 1771static void
1805internal_function
1806fetch_token (re_token_t *result, re_string_t *input, reg_syntax_t syntax) 1772fetch_token (re_token_t *result, re_string_t *input, reg_syntax_t syntax)
1807{ 1773{
1808 re_string_skip_bytes (input, peek_token (result, input, syntax)); 1774 re_string_skip_bytes (input, peek_token (result, input, syntax));
@@ -1812,7 +1778,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. */ 1778 We must not use this function inside bracket expressions. */
1813 1779
1814static int 1780static int
1815internal_function
1816peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax) 1781peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
1817{ 1782{
1818 unsigned char c; 1783 unsigned char c;
@@ -1829,8 +1794,8 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
1829 token->word_char = 0; 1794 token->word_char = 0;
1830#ifdef RE_ENABLE_I18N 1795#ifdef RE_ENABLE_I18N
1831 token->mb_partial = 0; 1796 token->mb_partial = 0;
1832 if (input->mb_cur_max > 1 && 1797 if (input->mb_cur_max > 1
1833 !re_string_first_byte (input, re_string_cur_idx (input))) 1798 && !re_string_first_byte (input, re_string_cur_idx (input)))
1834 { 1799 {
1835 token->type = CHARACTER; 1800 token->type = CHARACTER;
1836 token->mb_partial = 1; 1801 token->mb_partial = 1;
@@ -2017,8 +1982,8 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
2017 token->type = OP_PERIOD; 1982 token->type = OP_PERIOD;
2018 break; 1983 break;
2019 case '^': 1984 case '^':
2020 if (!(syntax & (RE_CONTEXT_INDEP_ANCHORS | RE_CARET_ANCHORS_HERE)) && 1985 if (!(syntax & (RE_CONTEXT_INDEP_ANCHORS | RE_CARET_ANCHORS_HERE))
2021 re_string_cur_idx (input) != 0) 1986 && re_string_cur_idx (input) != 0)
2022 { 1987 {
2023 char prev = re_string_peek_byte (input, -1); 1988 char prev = re_string_peek_byte (input, -1);
2024 if (!(syntax & RE_NEWLINE_ALT) || prev != '\n') 1989 if (!(syntax & RE_NEWLINE_ALT) || prev != '\n')
@@ -2028,8 +1993,8 @@ peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
2028 token->opr.ctx_type = LINE_FIRST; 1993 token->opr.ctx_type = LINE_FIRST;
2029 break; 1994 break;
2030 case '$': 1995 case '$':
2031 if (!(syntax & RE_CONTEXT_INDEP_ANCHORS) && 1996 if (!(syntax & RE_CONTEXT_INDEP_ANCHORS)
2032 re_string_cur_idx (input) + 1 != re_string_length (input)) 1997 && re_string_cur_idx (input) + 1 != re_string_length (input))
2033 { 1998 {
2034 re_token_t next; 1999 re_token_t next;
2035 re_string_skip_bytes (input, 1); 2000 re_string_skip_bytes (input, 1);
@@ -2051,7 +2016,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. */ 2016 We must not use this function out of bracket expressions. */
2052 2017
2053static int 2018static int
2054internal_function
2055peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax) 2019peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
2056{ 2020{
2057 unsigned char c; 2021 unsigned char c;
@@ -2064,8 +2028,8 @@ peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
2064 token->opr.c = c; 2028 token->opr.c = c;
2065 2029
2066#ifdef RE_ENABLE_I18N 2030#ifdef RE_ENABLE_I18N
2067 if (input->mb_cur_max > 1 && 2031 if (input->mb_cur_max > 1
2068 !re_string_first_byte (input, re_string_cur_idx (input))) 2032 && !re_string_first_byte (input, re_string_cur_idx (input)))
2069 { 2033 {
2070 token->type = CHARACTER; 2034 token->type = CHARACTER;
2071 return 1; 2035 return 1;
@@ -2098,16 +2062,18 @@ peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
2098 case '.': 2062 case '.':
2099 token->type = OP_OPEN_COLL_ELEM; 2063 token->type = OP_OPEN_COLL_ELEM;
2100 break; 2064 break;
2065
2101 case '=': 2066 case '=':
2102 token->type = OP_OPEN_EQUIV_CLASS; 2067 token->type = OP_OPEN_EQUIV_CLASS;
2103 break; 2068 break;
2069
2104 case ':': 2070 case ':':
2105 if (syntax & RE_CHAR_CLASSES) 2071 if (syntax & RE_CHAR_CLASSES)
2106 { 2072 {
2107 token->type = OP_OPEN_CHAR_CLASS; 2073 token->type = OP_OPEN_CHAR_CLASS;
2108 break; 2074 break;
2109 } 2075 }
2110 /* else fall through. */ 2076 FALLTHROUGH;
2111 default: 2077 default:
2112 token->type = CHARACTER; 2078 token->type = CHARACTER;
2113 token->opr.c = c; 2079 token->opr.c = c;
@@ -2157,14 +2123,14 @@ parse (re_string_t *regexp, regex_t *preg, reg_syntax_t syntax,
2157 dfa->syntax = syntax; 2123 dfa->syntax = syntax;
2158 fetch_token (&current_token, regexp, syntax | RE_CARET_ANCHORS_HERE); 2124 fetch_token (&current_token, regexp, syntax | RE_CARET_ANCHORS_HERE);
2159 tree = parse_reg_exp (regexp, preg, &current_token, syntax, 0, err); 2125 tree = parse_reg_exp (regexp, preg, &current_token, syntax, 0, err);
2160 if (BE (*err != REG_NOERROR && tree == NULL, 0)) 2126 if (__glibc_unlikely (*err != REG_NOERROR && tree == NULL))
2161 return NULL; 2127 return NULL;
2162 eor = create_tree (dfa, NULL, NULL, END_OF_RE); 2128 eor = create_tree (dfa, NULL, NULL, END_OF_RE);
2163 if (tree != NULL) 2129 if (tree != NULL)
2164 root = create_tree (dfa, tree, eor, CONCAT); 2130 root = create_tree (dfa, tree, eor, CONCAT);
2165 else 2131 else
2166 root = eor; 2132 root = eor;
2167 if (BE (eor == NULL || root == NULL, 0)) 2133 if (__glibc_unlikely (eor == NULL || root == NULL))
2168 { 2134 {
2169 *err = REG_ESPACE; 2135 *err = REG_ESPACE;
2170 return NULL; 2136 return NULL;
@@ -2187,8 +2153,9 @@ parse_reg_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
2187{ 2153{
2188 re_dfa_t *dfa = preg->buffer; 2154 re_dfa_t *dfa = preg->buffer;
2189 bin_tree_t *tree, *branch = NULL; 2155 bin_tree_t *tree, *branch = NULL;
2156 bitset_word_t initial_bkref_map = dfa->completed_bkref_map;
2190 tree = parse_branch (regexp, preg, token, syntax, nest, err); 2157 tree = parse_branch (regexp, preg, token, syntax, nest, err);
2191 if (BE (*err != REG_NOERROR && tree == NULL, 0)) 2158 if (__glibc_unlikely (*err != REG_NOERROR && tree == NULL))
2192 return NULL; 2159 return NULL;
2193 2160
2194 while (token->type == OP_ALT) 2161 while (token->type == OP_ALT)
@@ -2197,14 +2164,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 2164 if (token->type != OP_ALT && token->type != END_OF_RE
2198 && (nest == 0 || token->type != OP_CLOSE_SUBEXP)) 2165 && (nest == 0 || token->type != OP_CLOSE_SUBEXP))
2199 { 2166 {
2167 bitset_word_t accumulated_bkref_map = dfa->completed_bkref_map;
2168 dfa->completed_bkref_map = initial_bkref_map;
2200 branch = parse_branch (regexp, preg, token, syntax, nest, err); 2169 branch = parse_branch (regexp, preg, token, syntax, nest, err);
2201 if (BE (*err != REG_NOERROR && branch == NULL, 0)) 2170 if (__glibc_unlikely (*err != REG_NOERROR && branch == NULL))
2202 return NULL; 2171 {
2172 if (tree != NULL)
2173 postorder (tree, free_tree, NULL);
2174 return NULL;
2175 }
2176 dfa->completed_bkref_map |= accumulated_bkref_map;
2203 } 2177 }
2204 else 2178 else
2205 branch = NULL; 2179 branch = NULL;
2206 tree = create_tree (dfa, tree, branch, OP_ALT); 2180 tree = create_tree (dfa, tree, branch, OP_ALT);
2207 if (BE (tree == NULL, 0)) 2181 if (__glibc_unlikely (tree == NULL))
2208 { 2182 {
2209 *err = REG_ESPACE; 2183 *err = REG_ESPACE;
2210 return NULL; 2184 return NULL;
@@ -2229,14 +2203,14 @@ parse_branch (re_string_t *regexp, regex_t *preg, re_token_t *token,
2229 bin_tree_t *tree, *expr; 2203 bin_tree_t *tree, *expr;
2230 re_dfa_t *dfa = preg->buffer; 2204 re_dfa_t *dfa = preg->buffer;
2231 tree = parse_expression (regexp, preg, token, syntax, nest, err); 2205 tree = parse_expression (regexp, preg, token, syntax, nest, err);
2232 if (BE (*err != REG_NOERROR && tree == NULL, 0)) 2206 if (__glibc_unlikely (*err != REG_NOERROR && tree == NULL))
2233 return NULL; 2207 return NULL;
2234 2208
2235 while (token->type != OP_ALT && token->type != END_OF_RE 2209 while (token->type != OP_ALT && token->type != END_OF_RE
2236 && (nest == 0 || token->type != OP_CLOSE_SUBEXP)) 2210 && (nest == 0 || token->type != OP_CLOSE_SUBEXP))
2237 { 2211 {
2238 expr = parse_expression (regexp, preg, token, syntax, nest, err); 2212 expr = parse_expression (regexp, preg, token, syntax, nest, err);
2239 if (BE (*err != REG_NOERROR && expr == NULL, 0)) 2213 if (__glibc_unlikely (*err != REG_NOERROR && expr == NULL))
2240 { 2214 {
2241 if (tree != NULL) 2215 if (tree != NULL)
2242 postorder (tree, free_tree, NULL); 2216 postorder (tree, free_tree, NULL);
@@ -2277,7 +2251,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
2277 { 2251 {
2278 case CHARACTER: 2252 case CHARACTER:
2279 tree = create_token_tree (dfa, NULL, NULL, token); 2253 tree = create_token_tree (dfa, NULL, NULL, token);
2280 if (BE (tree == NULL, 0)) 2254 if (__glibc_unlikely (tree == NULL))
2281 { 2255 {
2282 *err = REG_ESPACE; 2256 *err = REG_ESPACE;
2283 return NULL; 2257 return NULL;
@@ -2292,7 +2266,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
2292 fetch_token (token, regexp, syntax); 2266 fetch_token (token, regexp, syntax);
2293 mbc_remain = create_token_tree (dfa, NULL, NULL, token); 2267 mbc_remain = create_token_tree (dfa, NULL, NULL, token);
2294 tree = create_tree (dfa, tree, mbc_remain, CONCAT); 2268 tree = create_tree (dfa, tree, mbc_remain, CONCAT);
2295 if (BE (mbc_remain == NULL || tree == NULL, 0)) 2269 if (__glibc_unlikely (mbc_remain == NULL || tree == NULL))
2296 { 2270 {
2297 *err = REG_ESPACE; 2271 *err = REG_ESPACE;
2298 return NULL; 2272 return NULL;
@@ -2301,25 +2275,28 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
2301 } 2275 }
2302#endif 2276#endif
2303 break; 2277 break;
2278
2304 case OP_OPEN_SUBEXP: 2279 case OP_OPEN_SUBEXP:
2305 tree = parse_sub_exp (regexp, preg, token, syntax, nest + 1, err); 2280 tree = parse_sub_exp (regexp, preg, token, syntax, nest + 1, err);
2306 if (BE (*err != REG_NOERROR && tree == NULL, 0)) 2281 if (__glibc_unlikely (*err != REG_NOERROR && tree == NULL))
2307 return NULL; 2282 return NULL;
2308 break; 2283 break;
2284
2309 case OP_OPEN_BRACKET: 2285 case OP_OPEN_BRACKET:
2310 tree = parse_bracket_exp (regexp, dfa, token, syntax, err); 2286 tree = parse_bracket_exp (regexp, dfa, token, syntax, err);
2311 if (BE (*err != REG_NOERROR && tree == NULL, 0)) 2287 if (__glibc_unlikely (*err != REG_NOERROR && tree == NULL))
2312 return NULL; 2288 return NULL;
2313 break; 2289 break;
2290
2314 case OP_BACK_REF: 2291 case OP_BACK_REF:
2315 if (!BE (dfa->completed_bkref_map & (1 << token->opr.idx), 1)) 2292 if (!__glibc_likely (dfa->completed_bkref_map & (1 << token->opr.idx)))
2316 { 2293 {
2317 *err = REG_ESUBREG; 2294 *err = REG_ESUBREG;
2318 return NULL; 2295 return NULL;
2319 } 2296 }
2320 dfa->used_bkref_map |= 1 << token->opr.idx; 2297 dfa->used_bkref_map |= 1 << token->opr.idx;
2321 tree = create_token_tree (dfa, NULL, NULL, token); 2298 tree = create_token_tree (dfa, NULL, NULL, token);
2322 if (BE (tree == NULL, 0)) 2299 if (__glibc_unlikely (tree == NULL))
2323 { 2300 {
2324 *err = REG_ESPACE; 2301 *err = REG_ESPACE;
2325 return NULL; 2302 return NULL;
@@ -2327,13 +2304,14 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
2327 ++dfa->nbackref; 2304 ++dfa->nbackref;
2328 dfa->has_mb_node = 1; 2305 dfa->has_mb_node = 1;
2329 break; 2306 break;
2307
2330 case OP_OPEN_DUP_NUM: 2308 case OP_OPEN_DUP_NUM:
2331 if (syntax & RE_CONTEXT_INVALID_DUP) 2309 if (syntax & RE_CONTEXT_INVALID_DUP)
2332 { 2310 {
2333 *err = REG_BADRPT; 2311 *err = REG_BADRPT;
2334 return NULL; 2312 return NULL;
2335 } 2313 }
2336 /* FALLTHROUGH */ 2314 FALLTHROUGH;
2337 case OP_DUP_ASTERISK: 2315 case OP_DUP_ASTERISK:
2338 case OP_DUP_PLUS: 2316 case OP_DUP_PLUS:
2339 case OP_DUP_QUESTION: 2317 case OP_DUP_QUESTION:
@@ -2347,15 +2325,15 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
2347 fetch_token (token, regexp, syntax); 2325 fetch_token (token, regexp, syntax);
2348 return parse_expression (regexp, preg, token, syntax, nest, err); 2326 return parse_expression (regexp, preg, token, syntax, nest, err);
2349 } 2327 }
2350 /* else fall through */ 2328 FALLTHROUGH;
2351 case OP_CLOSE_SUBEXP: 2329 case OP_CLOSE_SUBEXP:
2352 if ((token->type == OP_CLOSE_SUBEXP) && 2330 if ((token->type == OP_CLOSE_SUBEXP)
2353 !(syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)) 2331 && !(syntax & RE_UNMATCHED_RIGHT_PAREN_ORD))
2354 { 2332 {
2355 *err = REG_ERPAREN; 2333 *err = REG_ERPAREN;
2356 return NULL; 2334 return NULL;
2357 } 2335 }
2358 /* else fall through */ 2336 FALLTHROUGH;
2359 case OP_CLOSE_DUP_NUM: 2337 case OP_CLOSE_DUP_NUM:
2360 /* We treat it as a normal character. */ 2338 /* We treat it as a normal character. */
2361 2339
@@ -2364,12 +2342,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 2342 /* mb_partial and word_char bits should be initialized already
2365 by peek_token. */ 2343 by peek_token. */
2366 tree = create_token_tree (dfa, NULL, NULL, token); 2344 tree = create_token_tree (dfa, NULL, NULL, token);
2367 if (BE (tree == NULL, 0)) 2345 if (__glibc_unlikely (tree == NULL))
2368 { 2346 {
2369 *err = REG_ESPACE; 2347 *err = REG_ESPACE;
2370 return NULL; 2348 return NULL;
2371 } 2349 }
2372 break; 2350 break;
2351
2373 case ANCHOR: 2352 case ANCHOR:
2374 if ((token->opr.ctx_type 2353 if ((token->opr.ctx_type
2375 & (WORD_DELIM | NOT_WORD_DELIM | WORD_FIRST | WORD_LAST)) 2354 & (WORD_DELIM | NOT_WORD_DELIM | WORD_FIRST | WORD_LAST))
@@ -2393,7 +2372,8 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
2393 } 2372 }
2394 tree_last = create_token_tree (dfa, NULL, NULL, token); 2373 tree_last = create_token_tree (dfa, NULL, NULL, token);
2395 tree = create_tree (dfa, tree_first, tree_last, OP_ALT); 2374 tree = create_tree (dfa, tree_first, tree_last, OP_ALT);
2396 if (BE (tree_first == NULL || tree_last == NULL || tree == NULL, 0)) 2375 if (__glibc_unlikely (tree_first == NULL || tree_last == NULL
2376 || tree == NULL))
2397 { 2377 {
2398 *err = REG_ESPACE; 2378 *err = REG_ESPACE;
2399 return NULL; 2379 return NULL;
@@ -2402,7 +2382,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
2402 else 2382 else
2403 { 2383 {
2404 tree = create_token_tree (dfa, NULL, NULL, token); 2384 tree = create_token_tree (dfa, NULL, NULL, token);
2405 if (BE (tree == NULL, 0)) 2385 if (__glibc_unlikely (tree == NULL))
2406 { 2386 {
2407 *err = REG_ESPACE; 2387 *err = REG_ESPACE;
2408 return NULL; 2388 return NULL;
@@ -2414,9 +2394,10 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
2414 it must not be "<ANCHOR(^)><REPEAT(*)>". */ 2394 it must not be "<ANCHOR(^)><REPEAT(*)>". */
2415 fetch_token (token, regexp, syntax); 2395 fetch_token (token, regexp, syntax);
2416 return tree; 2396 return tree;
2397
2417 case OP_PERIOD: 2398 case OP_PERIOD:
2418 tree = create_token_tree (dfa, NULL, NULL, token); 2399 tree = create_token_tree (dfa, NULL, NULL, token);
2419 if (BE (tree == NULL, 0)) 2400 if (__glibc_unlikely (tree == NULL))
2420 { 2401 {
2421 *err = REG_ESPACE; 2402 *err = REG_ESPACE;
2422 return NULL; 2403 return NULL;
@@ -2424,35 +2405,38 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
2424 if (dfa->mb_cur_max > 1) 2405 if (dfa->mb_cur_max > 1)
2425 dfa->has_mb_node = 1; 2406 dfa->has_mb_node = 1;
2426 break; 2407 break;
2408
2427 case OP_WORD: 2409 case OP_WORD:
2428 case OP_NOTWORD: 2410 case OP_NOTWORD:
2429 tree = build_charclass_op (dfa, regexp->trans, 2411 tree = build_charclass_op (dfa, regexp->trans,
2430 "alnum", 2412 "alnum",
2431 "_", 2413 "_",
2432 token->type == OP_NOTWORD, err); 2414 token->type == OP_NOTWORD, err);
2433 if (BE (*err != REG_NOERROR && tree == NULL, 0)) 2415 if (__glibc_unlikely (*err != REG_NOERROR && tree == NULL))
2434 return NULL; 2416 return NULL;
2435 break; 2417 break;
2418
2436 case OP_SPACE: 2419 case OP_SPACE:
2437 case OP_NOTSPACE: 2420 case OP_NOTSPACE:
2438 tree = build_charclass_op (dfa, regexp->trans, 2421 tree = build_charclass_op (dfa, regexp->trans,
2439 "space", 2422 "space",
2440 "", 2423 "",
2441 token->type == OP_NOTSPACE, err); 2424 token->type == OP_NOTSPACE, err);
2442 if (BE (*err != REG_NOERROR && tree == NULL, 0)) 2425 if (__glibc_unlikely (*err != REG_NOERROR && tree == NULL))
2443 return NULL; 2426 return NULL;
2444 break; 2427 break;
2428
2445 case OP_ALT: 2429 case OP_ALT:
2446 case END_OF_RE: 2430 case END_OF_RE:
2447 return NULL; 2431 return NULL;
2432
2448 case BACK_SLASH: 2433 case BACK_SLASH:
2449 *err = REG_EESCAPE; 2434 *err = REG_EESCAPE;
2450 return NULL; 2435 return NULL;
2436
2451 default: 2437 default:
2452 /* Must not happen? */ 2438 /* Must not happen? */
2453#ifdef DEBUG 2439 DEBUG_ASSERT (false);
2454 assert (0);
2455#endif
2456 return NULL; 2440 return NULL;
2457 } 2441 }
2458 fetch_token (token, regexp, syntax); 2442 fetch_token (token, regexp, syntax);
@@ -2460,14 +2444,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 2444 while (token->type == OP_DUP_ASTERISK || token->type == OP_DUP_PLUS
2461 || token->type == OP_DUP_QUESTION || token->type == OP_OPEN_DUP_NUM) 2445 || token->type == OP_DUP_QUESTION || token->type == OP_OPEN_DUP_NUM)
2462 { 2446 {
2463 tree = parse_dup_op (tree, regexp, dfa, token, syntax, err); 2447 bin_tree_t *dup_tree = parse_dup_op (tree, regexp, dfa, token,
2464 if (BE (*err != REG_NOERROR && tree == NULL, 0)) 2448 syntax, err);
2465 return NULL; 2449 if (__glibc_unlikely (*err != REG_NOERROR && dup_tree == NULL))
2450 {
2451 if (tree != NULL)
2452 postorder (tree, free_tree, NULL);
2453 return NULL;
2454 }
2455 tree = dup_tree;
2466 /* In BRE consecutive duplications are not allowed. */ 2456 /* In BRE consecutive duplications are not allowed. */
2467 if ((syntax & RE_CONTEXT_INVALID_DUP) 2457 if ((syntax & RE_CONTEXT_INVALID_DUP)
2468 && (token->type == OP_DUP_ASTERISK 2458 && (token->type == OP_DUP_ASTERISK
2469 || token->type == OP_OPEN_DUP_NUM)) 2459 || token->type == OP_OPEN_DUP_NUM))
2470 { 2460 {
2461 if (tree != NULL)
2462 postorder (tree, free_tree, NULL);
2471 *err = REG_BADRPT; 2463 *err = REG_BADRPT;
2472 return NULL; 2464 return NULL;
2473 } 2465 }
@@ -2500,13 +2492,14 @@ parse_sub_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
2500 else 2492 else
2501 { 2493 {
2502 tree = parse_reg_exp (regexp, preg, token, syntax, nest, err); 2494 tree = parse_reg_exp (regexp, preg, token, syntax, nest, err);
2503 if (BE (*err == REG_NOERROR && token->type != OP_CLOSE_SUBEXP, 0)) 2495 if (__glibc_unlikely (*err == REG_NOERROR
2496 && token->type != OP_CLOSE_SUBEXP))
2504 { 2497 {
2505 if (tree != NULL) 2498 if (tree != NULL)
2506 postorder (tree, free_tree, NULL); 2499 postorder (tree, free_tree, NULL);
2507 *err = REG_EPAREN; 2500 *err = REG_EPAREN;
2508 } 2501 }
2509 if (BE (*err != REG_NOERROR, 0)) 2502 if (__glibc_unlikely (*err != REG_NOERROR))
2510 return NULL; 2503 return NULL;
2511 } 2504 }
2512 2505
@@ -2514,7 +2507,7 @@ parse_sub_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
2514 dfa->completed_bkref_map |= 1 << cur_nsub; 2507 dfa->completed_bkref_map |= 1 << cur_nsub;
2515 2508
2516 tree = create_tree (dfa, tree, NULL, SUBEXP); 2509 tree = create_tree (dfa, tree, NULL, SUBEXP);
2517 if (BE (tree == NULL, 0)) 2510 if (__glibc_unlikely (tree == NULL))
2518 { 2511 {
2519 *err = REG_ESPACE; 2512 *err = REG_ESPACE;
2520 return NULL; 2513 return NULL;
@@ -2537,7 +2530,7 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
2537 { 2530 {
2538 end = 0; 2531 end = 0;
2539 start = fetch_number (regexp, token, syntax); 2532 start = fetch_number (regexp, token, syntax);
2540 if (start == REG_MISSING) 2533 if (start == -1)
2541 { 2534 {
2542 if (token->type == CHARACTER && token->opr.c == ',') 2535 if (token->type == CHARACTER && token->opr.c == ',')
2543 start = 0; /* We treat "{,m}" as "{0,m}". */ 2536 start = 0; /* We treat "{,m}" as "{0,m}". */
@@ -2547,17 +2540,17 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
2547 return NULL; 2540 return NULL;
2548 } 2541 }
2549 } 2542 }
2550 if (BE (start != REG_ERROR, 1)) 2543 if (__glibc_likely (start != -2))
2551 { 2544 {
2552 /* We treat "{n}" as "{n,n}". */ 2545 /* We treat "{n}" as "{n,n}". */
2553 end = ((token->type == OP_CLOSE_DUP_NUM) ? start 2546 end = ((token->type == OP_CLOSE_DUP_NUM) ? start
2554 : ((token->type == CHARACTER && token->opr.c == ',') 2547 : ((token->type == CHARACTER && token->opr.c == ',')
2555 ? fetch_number (regexp, token, syntax) : REG_ERROR)); 2548 ? fetch_number (regexp, token, syntax) : -2));
2556 } 2549 }
2557 if (BE (start == REG_ERROR || end == REG_ERROR, 0)) 2550 if (__glibc_unlikely (start == -2 || end == -2))
2558 { 2551 {
2559 /* Invalid sequence. */ 2552 /* Invalid sequence. */
2560 if (BE (!(syntax & RE_INVALID_INTERVAL_ORD), 0)) 2553 if (__glibc_unlikely (!(syntax & RE_INVALID_INTERVAL_ORD)))
2561 { 2554 {
2562 if (token->type == END_OF_RE) 2555 if (token->type == END_OF_RE)
2563 *err = REG_EBRACE; 2556 *err = REG_EBRACE;
@@ -2576,15 +2569,15 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
2576 return elem; 2569 return elem;
2577 } 2570 }
2578 2571
2579 if (BE ((end != REG_MISSING && start > end) 2572 if (__glibc_unlikely ((end != -1 && start > end)
2580 || token->type != OP_CLOSE_DUP_NUM, 0)) 2573 || token->type != OP_CLOSE_DUP_NUM))
2581 { 2574 {
2582 /* First number greater than second. */ 2575 /* First number greater than second. */
2583 *err = REG_BADBR; 2576 *err = REG_BADBR;
2584 return NULL; 2577 return NULL;
2585 } 2578 }
2586 2579
2587 if (BE (RE_DUP_MAX < (end == REG_MISSING ? start : end), 0)) 2580 if (__glibc_unlikely (RE_DUP_MAX < (end == -1 ? start : end)))
2588 { 2581 {
2589 *err = REG_ESIZE; 2582 *err = REG_ESIZE;
2590 return NULL; 2583 return NULL;
@@ -2593,28 +2586,28 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
2593 else 2586 else
2594 { 2587 {
2595 start = (token->type == OP_DUP_PLUS) ? 1 : 0; 2588 start = (token->type == OP_DUP_PLUS) ? 1 : 0;
2596 end = (token->type == OP_DUP_QUESTION) ? 1 : REG_MISSING; 2589 end = (token->type == OP_DUP_QUESTION) ? 1 : -1;
2597 } 2590 }
2598 2591
2599 fetch_token (token, regexp, syntax); 2592 fetch_token (token, regexp, syntax);
2600 2593
2601 if (BE (elem == NULL, 0)) 2594 if (__glibc_unlikely (elem == NULL))
2602 return NULL; 2595 return NULL;
2603 if (BE (start == 0 && end == 0, 0)) 2596 if (__glibc_unlikely (start == 0 && end == 0))
2604 { 2597 {
2605 postorder (elem, free_tree, NULL); 2598 postorder (elem, free_tree, NULL);
2606 return NULL; 2599 return NULL;
2607 } 2600 }
2608 2601
2609 /* Extract "<re>{n,m}" to "<re><re>...<re><re>{0,<m-n>}". */ 2602 /* Extract "<re>{n,m}" to "<re><re>...<re><re>{0,<m-n>}". */
2610 if (BE (start > 0, 0)) 2603 if (__glibc_unlikely (start > 0))
2611 { 2604 {
2612 tree = elem; 2605 tree = elem;
2613 for (i = 2; i <= start; ++i) 2606 for (i = 2; i <= start; ++i)
2614 { 2607 {
2615 elem = duplicate_tree (elem, dfa); 2608 elem = duplicate_tree (elem, dfa);
2616 tree = create_tree (dfa, tree, elem, CONCAT); 2609 tree = create_tree (dfa, tree, elem, CONCAT);
2617 if (BE (elem == NULL || tree == NULL, 0)) 2610 if (__glibc_unlikely (elem == NULL || tree == NULL))
2618 goto parse_dup_op_espace; 2611 goto parse_dup_op_espace;
2619 } 2612 }
2620 2613
@@ -2623,6 +2616,8 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
2623 2616
2624 /* Duplicate ELEM before it is marked optional. */ 2617 /* Duplicate ELEM before it is marked optional. */
2625 elem = duplicate_tree (elem, dfa); 2618 elem = duplicate_tree (elem, dfa);
2619 if (__glibc_unlikely (elem == NULL))
2620 goto parse_dup_op_espace;
2626 old_tree = tree; 2621 old_tree = tree;
2627 } 2622 }
2628 else 2623 else
@@ -2635,27 +2630,23 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
2635 } 2630 }
2636 2631
2637 tree = create_tree (dfa, elem, NULL, 2632 tree = create_tree (dfa, elem, NULL,
2638 (end == REG_MISSING ? OP_DUP_ASTERISK : OP_ALT)); 2633 (end == -1 ? OP_DUP_ASTERISK : OP_ALT));
2639 if (BE (tree == NULL, 0)) 2634 if (__glibc_unlikely (tree == NULL))
2640 goto parse_dup_op_espace; 2635 goto parse_dup_op_espace;
2641 2636
2642/* From gnulib's "intprops.h": 2637 /* 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 2638 to rewrite <re>{0,n} as (<re>(<re>...<re>?)?)?... We have
2648 already created the start+1-th copy. */ 2639 already created the start+1-th copy. */
2649 if (TYPE_SIGNED (Idx) || end != REG_MISSING) 2640 if (TYPE_SIGNED (Idx) || end != -1)
2650 for (i = start + 2; i <= end; ++i) 2641 for (i = start + 2; i <= end; ++i)
2651 { 2642 {
2652 elem = duplicate_tree (elem, dfa); 2643 elem = duplicate_tree (elem, dfa);
2653 tree = create_tree (dfa, tree, elem, CONCAT); 2644 tree = create_tree (dfa, tree, elem, CONCAT);
2654 if (BE (elem == NULL || tree == NULL, 0)) 2645 if (__glibc_unlikely (elem == NULL || tree == NULL))
2655 goto parse_dup_op_espace; 2646 goto parse_dup_op_espace;
2656 2647
2657 tree = create_tree (dfa, tree, NULL, OP_ALT); 2648 tree = create_tree (dfa, tree, NULL, OP_ALT);
2658 if (BE (tree == NULL, 0)) 2649 if (__glibc_unlikely (tree == NULL))
2659 goto parse_dup_op_espace; 2650 goto parse_dup_op_espace;
2660 } 2651 }
2661 2652
@@ -2674,6 +2665,18 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
2674#define BRACKET_NAME_BUF_SIZE 32 2665#define BRACKET_NAME_BUF_SIZE 32
2675 2666
2676#ifndef _LIBC 2667#ifndef _LIBC
2668
2669# ifdef RE_ENABLE_I18N
2670/* Convert the byte B to the corresponding wide character. In a
2671 unibyte locale, treat B as itself. In a multibyte locale, return
2672 WEOF if B is an encoding error. */
2673static wint_t
2674parse_byte (unsigned char b, re_charset_t *mbcset)
2675{
2676 return mbcset == NULL ? b : __btowc (b);
2677}
2678# endif
2679
2677 /* Local function for parse_bracket_exp only used in case of NOT _LIBC. 2680 /* Local function for parse_bracket_exp only used in case of NOT _LIBC.
2678 Build the range expression which starts from START_ELEM, and ends 2681 Build the range expression which starts from START_ELEM, and ends
2679 at END_ELEM. The result are written to MBCSET and SBCSET. 2682 at END_ELEM. The result are written to MBCSET and SBCSET.
@@ -2682,7 +2685,6 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
2682 update it. */ 2685 update it. */
2683 2686
2684static reg_errcode_t 2687static reg_errcode_t
2685internal_function
2686# ifdef RE_ENABLE_I18N 2688# ifdef RE_ENABLE_I18N
2687build_range_exp (const reg_syntax_t syntax, 2689build_range_exp (const reg_syntax_t syntax,
2688 bitset_t sbcset, 2690 bitset_t sbcset,
@@ -2699,17 +2701,18 @@ build_range_exp (const reg_syntax_t syntax,
2699{ 2701{
2700 unsigned int start_ch, end_ch; 2702 unsigned int start_ch, end_ch;
2701 /* Equivalence Classes and Character Classes can't be a range start/end. */ 2703 /* 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 2704 if (__glibc_unlikely (start_elem->type == EQUIV_CLASS
2703 || end_elem->type == EQUIV_CLASS || end_elem->type == CHAR_CLASS, 2705 || start_elem->type == CHAR_CLASS
2704 0)) 2706 || end_elem->type == EQUIV_CLASS
2707 || end_elem->type == CHAR_CLASS))
2705 return REG_ERANGE; 2708 return REG_ERANGE;
2706 2709
2707 /* We can handle no multi character collating elements without libc 2710 /* We can handle no multi character collating elements without libc
2708 support. */ 2711 support. */
2709 if (BE ((start_elem->type == COLL_SYM 2712 if (__glibc_unlikely ((start_elem->type == COLL_SYM
2710 && strlen ((char *) start_elem->opr.name) > 1) 2713 && strlen ((char *) start_elem->opr.name) > 1)
2711 || (end_elem->type == COLL_SYM 2714 || (end_elem->type == COLL_SYM
2712 && strlen ((char *) end_elem->opr.name) > 1), 0)) 2715 && strlen ((char *) end_elem->opr.name) > 1)))
2713 return REG_ECOLLATE; 2716 return REG_ECOLLATE;
2714 2717
2715# ifdef RE_ENABLE_I18N 2718# ifdef RE_ENABLE_I18N
@@ -2725,12 +2728,13 @@ build_range_exp (const reg_syntax_t syntax,
2725 : ((end_elem->type == COLL_SYM) ? end_elem->opr.name[0] 2728 : ((end_elem->type == COLL_SYM) ? end_elem->opr.name[0]
2726 : 0)); 2729 : 0));
2727 start_wc = ((start_elem->type == SB_CHAR || start_elem->type == COLL_SYM) 2730 start_wc = ((start_elem->type == SB_CHAR || start_elem->type == COLL_SYM)
2728 ? __btowc (start_ch) : start_elem->opr.wch); 2731 ? parse_byte (start_ch, mbcset) : start_elem->opr.wch);
2729 end_wc = ((end_elem->type == SB_CHAR || end_elem->type == COLL_SYM) 2732 end_wc = ((end_elem->type == SB_CHAR || end_elem->type == COLL_SYM)
2730 ? __btowc (end_ch) : end_elem->opr.wch); 2733 ? parse_byte (end_ch, mbcset) : end_elem->opr.wch);
2731 if (start_wc == WEOF || end_wc == WEOF) 2734 if (start_wc == WEOF || end_wc == WEOF)
2732 return REG_ECOLLATE; 2735 return REG_ECOLLATE;
2733 else if (BE ((syntax & RE_NO_EMPTY_RANGES) && start_wc > end_wc, 0)) 2736 else if (__glibc_unlikely ((syntax & RE_NO_EMPTY_RANGES)
2737 && start_wc > end_wc))
2734 return REG_ERANGE; 2738 return REG_ERANGE;
2735 2739
2736 /* Got valid collation sequence values, add them as a new entry. 2740 /* Got valid collation sequence values, add them as a new entry.
@@ -2741,7 +2745,7 @@ build_range_exp (const reg_syntax_t syntax,
2741 if (mbcset) 2745 if (mbcset)
2742 { 2746 {
2743 /* Check the space of the arrays. */ 2747 /* Check the space of the arrays. */
2744 if (BE (*range_alloc == mbcset->nranges, 0)) 2748 if (__glibc_unlikely (*range_alloc == mbcset->nranges))
2745 { 2749 {
2746 /* There is not enough space, need realloc. */ 2750 /* There is not enough space, need realloc. */
2747 wchar_t *new_array_start, *new_array_end; 2751 wchar_t *new_array_start, *new_array_end;
@@ -2756,8 +2760,13 @@ build_range_exp (const reg_syntax_t syntax,
2756 new_array_end = re_realloc (mbcset->range_ends, wchar_t, 2760 new_array_end = re_realloc (mbcset->range_ends, wchar_t,
2757 new_nranges); 2761 new_nranges);
2758 2762
2759 if (BE (new_array_start == NULL || new_array_end == NULL, 0)) 2763 if (__glibc_unlikely (new_array_start == NULL
2760 return REG_ESPACE; 2764 || new_array_end == NULL))
2765 {
2766 re_free (new_array_start);
2767 re_free (new_array_end);
2768 return REG_ESPACE;
2769 }
2761 2770
2762 mbcset->range_starts = new_array_start; 2771 mbcset->range_starts = new_array_start;
2763 mbcset->range_ends = new_array_end; 2772 mbcset->range_ends = new_array_end;
@@ -2804,7 +2813,6 @@ build_range_exp (const reg_syntax_t syntax,
2804 pointer argument since we may update it. */ 2813 pointer argument since we may update it. */
2805 2814
2806static reg_errcode_t 2815static reg_errcode_t
2807internal_function
2808# ifdef RE_ENABLE_I18N 2816# ifdef RE_ENABLE_I18N
2809build_collating_symbol (bitset_t sbcset, re_charset_t *mbcset, 2817build_collating_symbol (bitset_t sbcset, re_charset_t *mbcset,
2810 Idx *coll_sym_alloc, const unsigned char *name) 2818 Idx *coll_sym_alloc, const unsigned char *name)
@@ -2813,7 +2821,7 @@ build_collating_symbol (bitset_t sbcset, const unsigned char *name)
2813# endif /* not RE_ENABLE_I18N */ 2821# endif /* not RE_ENABLE_I18N */
2814{ 2822{
2815 size_t name_len = strlen ((const char *) name); 2823 size_t name_len = strlen ((const char *) name);
2816 if (BE (name_len != 1, 0)) 2824 if (__glibc_unlikely (name_len != 1))
2817 return REG_ECOLLATE; 2825 return REG_ECOLLATE;
2818 else 2826 else
2819 { 2827 {
@@ -2948,18 +2956,21 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
2948 2956
2949 /* Equivalence Classes and Character Classes can't be a range 2957 /* Equivalence Classes and Character Classes can't be a range
2950 start/end. */ 2958 start/end. */
2951 if (BE (start_elem->type == EQUIV_CLASS || start_elem->type == CHAR_CLASS 2959 if (__glibc_unlikely (start_elem->type == EQUIV_CLASS
2952 || end_elem->type == EQUIV_CLASS || end_elem->type == CHAR_CLASS, 2960 || start_elem->type == CHAR_CLASS
2953 0)) 2961 || end_elem->type == EQUIV_CLASS
2962 || end_elem->type == CHAR_CLASS))
2954 return REG_ERANGE; 2963 return REG_ERANGE;
2955 2964
2956 /* FIXME: Implement rational ranges here, too. */ 2965 /* FIXME: Implement rational ranges here, too. */
2957 start_collseq = lookup_collation_sequence_value (start_elem); 2966 start_collseq = lookup_collation_sequence_value (start_elem);
2958 end_collseq = lookup_collation_sequence_value (end_elem); 2967 end_collseq = lookup_collation_sequence_value (end_elem);
2959 /* Check start/end collation sequence values. */ 2968 /* Check start/end collation sequence values. */
2960 if (BE (start_collseq == UINT_MAX || end_collseq == UINT_MAX, 0)) 2969 if (__glibc_unlikely (start_collseq == UINT_MAX
2970 || end_collseq == UINT_MAX))
2961 return REG_ECOLLATE; 2971 return REG_ECOLLATE;
2962 if (BE ((syntax & RE_NO_EMPTY_RANGES) && start_collseq > end_collseq, 0)) 2972 if (__glibc_unlikely ((syntax & RE_NO_EMPTY_RANGES)
2973 && start_collseq > end_collseq))
2963 return REG_ERANGE; 2974 return REG_ERANGE;
2964 2975
2965 /* Got valid collation sequence values, add them as a new entry. 2976 /* Got valid collation sequence values, add them as a new entry.
@@ -2969,7 +2980,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
2969 if (nrules > 0 || dfa->mb_cur_max > 1) 2980 if (nrules > 0 || dfa->mb_cur_max > 1)
2970 { 2981 {
2971 /* Check the space of the arrays. */ 2982 /* Check the space of the arrays. */
2972 if (BE (*range_alloc == mbcset->nranges, 0)) 2983 if (__glibc_unlikely (*range_alloc == mbcset->nranges))
2973 { 2984 {
2974 /* There is not enough space, need realloc. */ 2985 /* There is not enough space, need realloc. */
2975 uint32_t *new_array_start; 2986 uint32_t *new_array_start;
@@ -2983,7 +2994,8 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
2983 new_array_end = re_realloc (mbcset->range_ends, uint32_t, 2994 new_array_end = re_realloc (mbcset->range_ends, uint32_t,
2984 new_nranges); 2995 new_nranges);
2985 2996
2986 if (BE (new_array_start == NULL || new_array_end == NULL, 0)) 2997 if (__glibc_unlikely (new_array_start == NULL
2998 || new_array_end == NULL))
2987 return REG_ESPACE; 2999 return REG_ESPACE;
2988 3000
2989 mbcset->range_starts = new_array_start; 3001 mbcset->range_starts = new_array_start;
@@ -3047,7 +3059,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3047 3059
3048 /* Got valid collation sequence, add it as a new entry. */ 3060 /* Got valid collation sequence, add it as a new entry. */
3049 /* Check the space of the arrays. */ 3061 /* Check the space of the arrays. */
3050 if (BE (*coll_sym_alloc == mbcset->ncoll_syms, 0)) 3062 if (__glibc_unlikely (*coll_sym_alloc == mbcset->ncoll_syms))
3051 { 3063 {
3052 /* Not enough, realloc it. */ 3064 /* Not enough, realloc it. */
3053 /* +1 in case of mbcset->ncoll_syms is 0. */ 3065 /* +1 in case of mbcset->ncoll_syms is 0. */
@@ -3056,7 +3068,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3056 if *alloc == 0. */ 3068 if *alloc == 0. */
3057 int32_t *new_coll_syms = re_realloc (mbcset->coll_syms, int32_t, 3069 int32_t *new_coll_syms = re_realloc (mbcset->coll_syms, int32_t,
3058 new_coll_sym_alloc); 3070 new_coll_sym_alloc);
3059 if (BE (new_coll_syms == NULL, 0)) 3071 if (__glibc_unlikely (new_coll_syms == NULL))
3060 return REG_ESPACE; 3072 return REG_ESPACE;
3061 mbcset->coll_syms = new_coll_syms; 3073 mbcset->coll_syms = new_coll_syms;
3062 *coll_sym_alloc = new_coll_sym_alloc; 3074 *coll_sym_alloc = new_coll_sym_alloc;
@@ -3066,7 +3078,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3066 } 3078 }
3067 else 3079 else
3068 { 3080 {
3069 if (BE (name_len != 1, 0)) 3081 if (__glibc_unlikely (name_len != 1))
3070 return REG_ECOLLATE; 3082 return REG_ECOLLATE;
3071 else 3083 else
3072 { 3084 {
@@ -3110,9 +3122,9 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3110 mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1); 3122 mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);
3111#endif /* RE_ENABLE_I18N */ 3123#endif /* RE_ENABLE_I18N */
3112#ifdef RE_ENABLE_I18N 3124#ifdef RE_ENABLE_I18N
3113 if (BE (sbcset == NULL || mbcset == NULL, 0)) 3125 if (__glibc_unlikely (sbcset == NULL || mbcset == NULL))
3114#else 3126#else
3115 if (BE (sbcset == NULL, 0)) 3127 if (__glibc_unlikely (sbcset == NULL))
3116#endif /* RE_ENABLE_I18N */ 3128#endif /* RE_ENABLE_I18N */
3117 { 3129 {
3118 re_free (sbcset); 3130 re_free (sbcset);
@@ -3124,7 +3136,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3124 } 3136 }
3125 3137
3126 token_len = peek_token_bracket (token, regexp, syntax); 3138 token_len = peek_token_bracket (token, regexp, syntax);
3127 if (BE (token->type == END_OF_RE, 0)) 3139 if (__glibc_unlikely (token->type == END_OF_RE))
3128 { 3140 {
3129 *err = REG_BADPAT; 3141 *err = REG_BADPAT;
3130 goto parse_bracket_exp_free_return; 3142 goto parse_bracket_exp_free_return;
@@ -3139,7 +3151,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3139 bitset_set (sbcset, '\n'); 3151 bitset_set (sbcset, '\n');
3140 re_string_skip_bytes (regexp, token_len); /* Skip a token. */ 3152 re_string_skip_bytes (regexp, token_len); /* Skip a token. */
3141 token_len = peek_token_bracket (token, regexp, syntax); 3153 token_len = peek_token_bracket (token, regexp, syntax);
3142 if (BE (token->type == END_OF_RE, 0)) 3154 if (__glibc_unlikely (token->type == END_OF_RE))
3143 { 3155 {
3144 *err = REG_BADPAT; 3156 *err = REG_BADPAT;
3145 goto parse_bracket_exp_free_return; 3157 goto parse_bracket_exp_free_return;
@@ -3161,9 +3173,10 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3161 re_token_t token2; 3173 re_token_t token2;
3162 3174
3163 start_elem.opr.name = start_name_buf; 3175 start_elem.opr.name = start_name_buf;
3176 start_elem.type = COLL_SYM;
3164 ret = parse_bracket_element (&start_elem, regexp, token, token_len, dfa, 3177 ret = parse_bracket_element (&start_elem, regexp, token, token_len, dfa,
3165 syntax, first_round); 3178 syntax, first_round);
3166 if (BE (ret != REG_NOERROR, 0)) 3179 if (__glibc_unlikely (ret != REG_NOERROR))
3167 { 3180 {
3168 *err = ret; 3181 *err = ret;
3169 goto parse_bracket_exp_free_return; 3182 goto parse_bracket_exp_free_return;
@@ -3176,7 +3189,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. */ 3189 /* Do not check for ranges if we know they are not allowed. */
3177 if (start_elem.type != CHAR_CLASS && start_elem.type != EQUIV_CLASS) 3190 if (start_elem.type != CHAR_CLASS && start_elem.type != EQUIV_CLASS)
3178 { 3191 {
3179 if (BE (token->type == END_OF_RE, 0)) 3192 if (__glibc_unlikely (token->type == END_OF_RE))
3180 { 3193 {
3181 *err = REG_EBRACK; 3194 *err = REG_EBRACK;
3182 goto parse_bracket_exp_free_return; 3195 goto parse_bracket_exp_free_return;
@@ -3185,7 +3198,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3185 { 3198 {
3186 re_string_skip_bytes (regexp, token_len); /* Skip '-'. */ 3199 re_string_skip_bytes (regexp, token_len); /* Skip '-'. */
3187 token_len2 = peek_token_bracket (&token2, regexp, syntax); 3200 token_len2 = peek_token_bracket (&token2, regexp, syntax);
3188 if (BE (token2.type == END_OF_RE, 0)) 3201 if (__glibc_unlikely (token2.type == END_OF_RE))
3189 { 3202 {
3190 *err = REG_EBRACK; 3203 *err = REG_EBRACK;
3191 goto parse_bracket_exp_free_return; 3204 goto parse_bracket_exp_free_return;
@@ -3204,9 +3217,10 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3204 if (is_range_exp == true) 3217 if (is_range_exp == true)
3205 { 3218 {
3206 end_elem.opr.name = end_name_buf; 3219 end_elem.opr.name = end_name_buf;
3220 end_elem.type = COLL_SYM;
3207 ret = parse_bracket_element (&end_elem, regexp, &token2, token_len2, 3221 ret = parse_bracket_element (&end_elem, regexp, &token2, token_len2,
3208 dfa, syntax, true); 3222 dfa, syntax, true);
3209 if (BE (ret != REG_NOERROR, 0)) 3223 if (__glibc_unlikely (ret != REG_NOERROR))
3210 { 3224 {
3211 *err = ret; 3225 *err = ret;
3212 goto parse_bracket_exp_free_return; 3226 goto parse_bracket_exp_free_return;
@@ -3226,7 +3240,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3226 *err = build_range_exp (syntax, sbcset, &start_elem, &end_elem); 3240 *err = build_range_exp (syntax, sbcset, &start_elem, &end_elem);
3227# endif 3241# endif
3228#endif /* RE_ENABLE_I18N */ 3242#endif /* RE_ENABLE_I18N */
3229 if (BE (*err != REG_NOERROR, 0)) 3243 if (__glibc_unlikely (*err != REG_NOERROR))
3230 goto parse_bracket_exp_free_return; 3244 goto parse_bracket_exp_free_return;
3231 } 3245 }
3232 else 3246 else
@@ -3239,7 +3253,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3239#ifdef RE_ENABLE_I18N 3253#ifdef RE_ENABLE_I18N
3240 case MB_CHAR: 3254 case MB_CHAR:
3241 /* Check whether the array has enough space. */ 3255 /* Check whether the array has enough space. */
3242 if (BE (mbchar_alloc == mbcset->nmbchars, 0)) 3256 if (__glibc_unlikely (mbchar_alloc == mbcset->nmbchars))
3243 { 3257 {
3244 wchar_t *new_mbchars; 3258 wchar_t *new_mbchars;
3245 /* Not enough, realloc it. */ 3259 /* Not enough, realloc it. */
@@ -3248,7 +3262,7 @@ 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. */ 3262 /* Use realloc since array is NULL if *alloc == 0. */
3249 new_mbchars = re_realloc (mbcset->mbchars, wchar_t, 3263 new_mbchars = re_realloc (mbcset->mbchars, wchar_t,
3250 mbchar_alloc); 3264 mbchar_alloc);
3251 if (BE (new_mbchars == NULL, 0)) 3265 if (__glibc_unlikely (new_mbchars == NULL))
3252 goto parse_bracket_exp_espace; 3266 goto parse_bracket_exp_espace;
3253 mbcset->mbchars = new_mbchars; 3267 mbcset->mbchars = new_mbchars;
3254 } 3268 }
@@ -3261,7 +3275,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3261 mbcset, &equiv_class_alloc, 3275 mbcset, &equiv_class_alloc,
3262#endif /* RE_ENABLE_I18N */ 3276#endif /* RE_ENABLE_I18N */
3263 start_elem.opr.name); 3277 start_elem.opr.name);
3264 if (BE (*err != REG_NOERROR, 0)) 3278 if (__glibc_unlikely (*err != REG_NOERROR))
3265 goto parse_bracket_exp_free_return; 3279 goto parse_bracket_exp_free_return;
3266 break; 3280 break;
3267 case COLL_SYM: 3281 case COLL_SYM:
@@ -3270,7 +3284,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3270 mbcset, &coll_sym_alloc, 3284 mbcset, &coll_sym_alloc,
3271#endif /* RE_ENABLE_I18N */ 3285#endif /* RE_ENABLE_I18N */
3272 start_elem.opr.name); 3286 start_elem.opr.name);
3273 if (BE (*err != REG_NOERROR, 0)) 3287 if (__glibc_unlikely (*err != REG_NOERROR))
3274 goto parse_bracket_exp_free_return; 3288 goto parse_bracket_exp_free_return;
3275 break; 3289 break;
3276 case CHAR_CLASS: 3290 case CHAR_CLASS:
@@ -3280,15 +3294,15 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3280#endif /* RE_ENABLE_I18N */ 3294#endif /* RE_ENABLE_I18N */
3281 (const char *) start_elem.opr.name, 3295 (const char *) start_elem.opr.name,
3282 syntax); 3296 syntax);
3283 if (BE (*err != REG_NOERROR, 0)) 3297 if (__glibc_unlikely (*err != REG_NOERROR))
3284 goto parse_bracket_exp_free_return; 3298 goto parse_bracket_exp_free_return;
3285 break; 3299 break;
3286 default: 3300 default:
3287 assert (0); 3301 DEBUG_ASSERT (false);
3288 break; 3302 break;
3289 } 3303 }
3290 } 3304 }
3291 if (BE (token->type == END_OF_RE, 0)) 3305 if (__glibc_unlikely (token->type == END_OF_RE))
3292 { 3306 {
3293 *err = REG_EBRACK; 3307 *err = REG_EBRACK;
3294 goto parse_bracket_exp_free_return; 3308 goto parse_bracket_exp_free_return;
@@ -3319,7 +3333,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3319 br_token.type = COMPLEX_BRACKET; 3333 br_token.type = COMPLEX_BRACKET;
3320 br_token.opr.mbcset = mbcset; 3334 br_token.opr.mbcset = mbcset;
3321 mbc_tree = create_token_tree (dfa, NULL, NULL, &br_token); 3335 mbc_tree = create_token_tree (dfa, NULL, NULL, &br_token);
3322 if (BE (mbc_tree == NULL, 0)) 3336 if (__glibc_unlikely (mbc_tree == NULL))
3323 goto parse_bracket_exp_espace; 3337 goto parse_bracket_exp_espace;
3324 for (sbc_idx = 0; sbc_idx < BITSET_WORDS; ++sbc_idx) 3338 for (sbc_idx = 0; sbc_idx < BITSET_WORDS; ++sbc_idx)
3325 if (sbcset[sbc_idx]) 3339 if (sbcset[sbc_idx])
@@ -3332,12 +3346,12 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3332 br_token.type = SIMPLE_BRACKET; 3346 br_token.type = SIMPLE_BRACKET;
3333 br_token.opr.sbcset = sbcset; 3347 br_token.opr.sbcset = sbcset;
3334 work_tree = create_token_tree (dfa, NULL, NULL, &br_token); 3348 work_tree = create_token_tree (dfa, NULL, NULL, &br_token);
3335 if (BE (work_tree == NULL, 0)) 3349 if (__glibc_unlikely (work_tree == NULL))
3336 goto parse_bracket_exp_espace; 3350 goto parse_bracket_exp_espace;
3337 3351
3338 /* Then join them by ALT node. */ 3352 /* Then join them by ALT node. */
3339 work_tree = create_tree (dfa, work_tree, mbc_tree, OP_ALT); 3353 work_tree = create_tree (dfa, work_tree, mbc_tree, OP_ALT);
3340 if (BE (work_tree == NULL, 0)) 3354 if (__glibc_unlikely (work_tree == NULL))
3341 goto parse_bracket_exp_espace; 3355 goto parse_bracket_exp_espace;
3342 } 3356 }
3343 else 3357 else
@@ -3356,7 +3370,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3356 br_token.type = SIMPLE_BRACKET; 3370 br_token.type = SIMPLE_BRACKET;
3357 br_token.opr.sbcset = sbcset; 3371 br_token.opr.sbcset = sbcset;
3358 work_tree = create_token_tree (dfa, NULL, NULL, &br_token); 3372 work_tree = create_token_tree (dfa, NULL, NULL, &br_token);
3359 if (BE (work_tree == NULL, 0)) 3373 if (__glibc_unlikely (work_tree == NULL))
3360 goto parse_bracket_exp_espace; 3374 goto parse_bracket_exp_espace;
3361 } 3375 }
3362 return work_tree; 3376 return work_tree;
@@ -3393,7 +3407,7 @@ parse_bracket_element (bracket_elem_t *elem, re_string_t *regexp,
3393 if (token->type == OP_OPEN_COLL_ELEM || token->type == OP_OPEN_CHAR_CLASS 3407 if (token->type == OP_OPEN_COLL_ELEM || token->type == OP_OPEN_CHAR_CLASS
3394 || token->type == OP_OPEN_EQUIV_CLASS) 3408 || token->type == OP_OPEN_EQUIV_CLASS)
3395 return parse_bracket_symbol (elem, regexp, token); 3409 return parse_bracket_symbol (elem, regexp, token);
3396 if (BE (token->type == OP_CHARSET_RANGE, 0) && !accept_hyphen) 3410 if (__glibc_unlikely (token->type == OP_CHARSET_RANGE) && !accept_hyphen)
3397 { 3411 {
3398 /* A '-' must only appear as anything but a range indicator before 3412 /* A '-' must only appear as anything but a range indicator before
3399 the closing bracket. Everything else is an error. */ 3413 the closing bracket. Everything else is an error. */
@@ -3478,8 +3492,6 @@ build_equiv_class (bitset_t sbcset, const unsigned char *name)
3478 int32_t idx1, idx2; 3492 int32_t idx1, idx2;
3479 unsigned int ch; 3493 unsigned int ch;
3480 size_t len; 3494 size_t len;
3481 /* This #include defines a local function! */
3482# include <locale/weight.h>
3483 /* Calculate the index for equivalence class. */ 3495 /* Calculate the index for equivalence class. */
3484 cp = name; 3496 cp = name;
3485 table = (const int32_t *) _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB); 3497 table = (const int32_t *) _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
@@ -3489,8 +3501,8 @@ build_equiv_class (bitset_t sbcset, const unsigned char *name)
3489 _NL_COLLATE_EXTRAMB); 3501 _NL_COLLATE_EXTRAMB);
3490 indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE, 3502 indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE,
3491 _NL_COLLATE_INDIRECTMB); 3503 _NL_COLLATE_INDIRECTMB);
3492 idx1 = findidx (&cp, -1); 3504 idx1 = findidx (table, indirect, extra, &cp, -1);
3493 if (BE (idx1 == 0 || *cp != '\0', 0)) 3505 if (__glibc_unlikely (idx1 == 0 || *cp != '\0'))
3494 /* This isn't a valid character. */ 3506 /* This isn't a valid character. */
3495 return REG_ECOLLATE; 3507 return REG_ECOLLATE;
3496 3508
@@ -3500,7 +3512,7 @@ build_equiv_class (bitset_t sbcset, const unsigned char *name)
3500 { 3512 {
3501 char_buf[0] = ch; 3513 char_buf[0] = ch;
3502 cp = char_buf; 3514 cp = char_buf;
3503 idx2 = findidx (&cp, 1); 3515 idx2 = findidx (table, indirect, extra, &cp, 1);
3504/* 3516/*
3505 idx2 = table[ch]; 3517 idx2 = table[ch];
3506*/ 3518*/
@@ -3509,21 +3521,13 @@ build_equiv_class (bitset_t sbcset, const unsigned char *name)
3509 continue; 3521 continue;
3510 /* Compare only if the length matches and the collation rule 3522 /* Compare only if the length matches and the collation rule
3511 index is the same. */ 3523 index is the same. */
3512 if (len == weights[idx2 & 0xffffff] && (idx1 >> 24) == (idx2 >> 24)) 3524 if (len == weights[idx2 & 0xffffff] && (idx1 >> 24) == (idx2 >> 24)
3513 { 3525 && memcmp (weights + (idx1 & 0xffffff) + 1,
3514 int cnt = 0; 3526 weights + (idx2 & 0xffffff) + 1, len) == 0)
3515 3527 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 } 3528 }
3525 /* Check whether the array has enough space. */ 3529 /* Check whether the array has enough space. */
3526 if (BE (*equiv_class_alloc == mbcset->nequiv_classes, 0)) 3530 if (__glibc_unlikely (*equiv_class_alloc == mbcset->nequiv_classes))
3527 { 3531 {
3528 /* Not enough, realloc it. */ 3532 /* Not enough, realloc it. */
3529 /* +1 in case of mbcset->nequiv_classes is 0. */ 3533 /* +1 in case of mbcset->nequiv_classes is 0. */
@@ -3532,7 +3536,7 @@ build_equiv_class (bitset_t sbcset, const unsigned char *name)
3532 int32_t *new_equiv_classes = re_realloc (mbcset->equiv_classes, 3536 int32_t *new_equiv_classes = re_realloc (mbcset->equiv_classes,
3533 int32_t, 3537 int32_t,
3534 new_equiv_class_alloc); 3538 new_equiv_class_alloc);
3535 if (BE (new_equiv_classes == NULL, 0)) 3539 if (__glibc_unlikely (new_equiv_classes == NULL))
3536 return REG_ESPACE; 3540 return REG_ESPACE;
3537 mbcset->equiv_classes = new_equiv_classes; 3541 mbcset->equiv_classes = new_equiv_classes;
3538 *equiv_class_alloc = new_equiv_class_alloc; 3542 *equiv_class_alloc = new_equiv_class_alloc;
@@ -3542,7 +3546,7 @@ build_equiv_class (bitset_t sbcset, const unsigned char *name)
3542 else 3546 else
3543#endif /* _LIBC */ 3547#endif /* _LIBC */
3544 { 3548 {
3545 if (BE (strlen ((const char *) name) != 1, 0)) 3549 if (__glibc_unlikely (strlen ((const char *) name) != 1))
3546 return REG_ECOLLATE; 3550 return REG_ECOLLATE;
3547 bitset_set (sbcset, *name); 3551 bitset_set (sbcset, *name);
3548 } 3552 }
@@ -3576,7 +3580,7 @@ build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset,
3576 3580
3577#ifdef RE_ENABLE_I18N 3581#ifdef RE_ENABLE_I18N
3578 /* Check the space of the arrays. */ 3582 /* Check the space of the arrays. */
3579 if (BE (*char_class_alloc == mbcset->nchar_classes, 0)) 3583 if (__glibc_unlikely (*char_class_alloc == mbcset->nchar_classes))
3580 { 3584 {
3581 /* Not enough, realloc it. */ 3585 /* Not enough, realloc it. */
3582 /* +1 in case of mbcset->nchar_classes is 0. */ 3586 /* +1 in case of mbcset->nchar_classes is 0. */
@@ -3584,7 +3588,7 @@ build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset,
3584 /* Use realloc since array is NULL if *alloc == 0. */ 3588 /* Use realloc since array is NULL if *alloc == 0. */
3585 wctype_t *new_char_classes = re_realloc (mbcset->char_classes, wctype_t, 3589 wctype_t *new_char_classes = re_realloc (mbcset->char_classes, wctype_t,
3586 new_char_class_alloc); 3590 new_char_class_alloc);
3587 if (BE (new_char_classes == NULL, 0)) 3591 if (__glibc_unlikely (new_char_classes == NULL))
3588 return REG_ESPACE; 3592 return REG_ESPACE;
3589 mbcset->char_classes = new_char_classes; 3593 mbcset->char_classes = new_char_classes;
3590 *char_class_alloc = new_char_class_alloc; 3594 *char_class_alloc = new_char_class_alloc;
@@ -3594,7 +3598,7 @@ build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset,
3594 3598
3595#define BUILD_CHARCLASS_LOOP(ctype_func) \ 3599#define BUILD_CHARCLASS_LOOP(ctype_func) \
3596 do { \ 3600 do { \
3597 if (BE (trans != NULL, 0)) \ 3601 if (__glibc_unlikely (trans != NULL)) \
3598 { \ 3602 { \
3599 for (i = 0; i < SBC_MAX; ++i) \ 3603 for (i = 0; i < SBC_MAX; ++i) \
3600 if (ctype_func (i)) \ 3604 if (ctype_func (i)) \
@@ -3650,30 +3654,24 @@ build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans,
3650 Idx alloc = 0; 3654 Idx alloc = 0;
3651#endif /* not RE_ENABLE_I18N */ 3655#endif /* not RE_ENABLE_I18N */
3652 reg_errcode_t ret; 3656 reg_errcode_t ret;
3653 re_token_t br_token;
3654 bin_tree_t *tree; 3657 bin_tree_t *tree;
3655 3658
3656 sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1); 3659 sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
3657#ifdef RE_ENABLE_I18N 3660 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 { 3661 {
3667 *err = REG_ESPACE; 3662 *err = REG_ESPACE;
3668 return NULL; 3663 return NULL;
3669 } 3664 }
3670
3671 if (non_match)
3672 {
3673#ifdef RE_ENABLE_I18N 3665#ifdef RE_ENABLE_I18N
3674 mbcset->non_match = 1; 3666 mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);
3675#endif /* not RE_ENABLE_I18N */ 3667 if (__glibc_unlikely (mbcset == NULL))
3668 {
3669 re_free (sbcset);
3670 *err = REG_ESPACE;
3671 return NULL;
3676 } 3672 }
3673 mbcset->non_match = non_match;
3674#endif /* RE_ENABLE_I18N */
3677 3675
3678 /* We don't care the syntax in this case. */ 3676 /* We don't care the syntax in this case. */
3679 ret = build_charclass (trans, sbcset, 3677 ret = build_charclass (trans, sbcset,
@@ -3682,7 +3680,7 @@ build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans,
3682#endif /* RE_ENABLE_I18N */ 3680#endif /* RE_ENABLE_I18N */
3683 class_name, 0); 3681 class_name, 0);
3684 3682
3685 if (BE (ret != REG_NOERROR, 0)) 3683 if (__glibc_unlikely (ret != REG_NOERROR))
3686 { 3684 {
3687 re_free (sbcset); 3685 re_free (sbcset);
3688#ifdef RE_ENABLE_I18N 3686#ifdef RE_ENABLE_I18N
@@ -3706,10 +3704,9 @@ build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans,
3706#endif 3704#endif
3707 3705
3708 /* Build a tree for simple bracket. */ 3706 /* Build a tree for simple bracket. */
3709 br_token.type = SIMPLE_BRACKET; 3707 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); 3708 tree = create_token_tree (dfa, NULL, NULL, &br_token);
3712 if (BE (tree == NULL, 0)) 3709 if (__glibc_unlikely (tree == NULL))
3713 goto build_word_op_espace; 3710 goto build_word_op_espace;
3714 3711
3715#ifdef RE_ENABLE_I18N 3712#ifdef RE_ENABLE_I18N
@@ -3721,11 +3718,11 @@ build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans,
3721 br_token.opr.mbcset = mbcset; 3718 br_token.opr.mbcset = mbcset;
3722 dfa->has_mb_node = 1; 3719 dfa->has_mb_node = 1;
3723 mbc_tree = create_token_tree (dfa, NULL, NULL, &br_token); 3720 mbc_tree = create_token_tree (dfa, NULL, NULL, &br_token);
3724 if (BE (mbc_tree == NULL, 0)) 3721 if (__glibc_unlikely (mbc_tree == NULL))
3725 goto build_word_op_espace; 3722 goto build_word_op_espace;
3726 /* Then join them by ALT node. */ 3723 /* Then join them by ALT node. */
3727 tree = create_tree (dfa, tree, mbc_tree, OP_ALT); 3724 tree = create_tree (dfa, tree, mbc_tree, OP_ALT);
3728 if (BE (mbc_tree != NULL, 1)) 3725 if (__glibc_likely (mbc_tree != NULL))
3729 return tree; 3726 return tree;
3730 } 3727 }
3731 else 3728 else
@@ -3748,27 +3745,26 @@ build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans,
3748 3745
3749/* This is intended for the expressions like "a{1,3}". 3746/* This is intended for the expressions like "a{1,3}".
3750 Fetch a number from 'input', and return the number. 3747 Fetch a number from 'input', and return the number.
3751 Return REG_MISSING if the number field is empty like "{,1}". 3748 Return -1 if the number field is empty like "{,1}".
3752 Return RE_DUP_MAX + 1 if the number field is too large. 3749 Return RE_DUP_MAX + 1 if the number field is too large.
3753 Return REG_ERROR if an error occurred. */ 3750 Return -2 if an error occurred. */
3754 3751
3755static Idx 3752static Idx
3756fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax) 3753fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax)
3757{ 3754{
3758 Idx num = REG_MISSING; 3755 Idx num = -1;
3759 unsigned char c; 3756 unsigned char c;
3760 while (1) 3757 while (1)
3761 { 3758 {
3762 fetch_token (token, input, syntax); 3759 fetch_token (token, input, syntax);
3763 c = token->opr.c; 3760 c = token->opr.c;
3764 if (BE (token->type == END_OF_RE, 0)) 3761 if (__glibc_unlikely (token->type == END_OF_RE))
3765 return REG_ERROR; 3762 return -2;
3766 if (token->type == OP_CLOSE_DUP_NUM || c == ',') 3763 if (token->type == OP_CLOSE_DUP_NUM || c == ',')
3767 break; 3764 break;
3768 num = ((token->type != CHARACTER || c < '0' || '9' < c 3765 num = ((token->type != CHARACTER || c < '0' || '9' < c || num == -2)
3769 || num == REG_ERROR) 3766 ? -2
3770 ? REG_ERROR 3767 : num == -1
3771 : num == REG_MISSING
3772 ? c - '0' 3768 ? c - '0'
3773 : MIN (RE_DUP_MAX + 1, num * 10 + c - '0')); 3769 : MIN (RE_DUP_MAX + 1, num * 10 + c - '0'));
3774 } 3770 }
@@ -3783,9 +3779,9 @@ free_charset (re_charset_t *cset)
3783# ifdef _LIBC 3779# ifdef _LIBC
3784 re_free (cset->coll_syms); 3780 re_free (cset->coll_syms);
3785 re_free (cset->equiv_classes); 3781 re_free (cset->equiv_classes);
3782# endif
3786 re_free (cset->range_starts); 3783 re_free (cset->range_starts);
3787 re_free (cset->range_ends); 3784 re_free (cset->range_ends);
3788# endif
3789 re_free (cset->char_classes); 3785 re_free (cset->char_classes);
3790 re_free (cset); 3786 re_free (cset);
3791} 3787}
@@ -3799,8 +3795,7 @@ static bin_tree_t *
3799create_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right, 3795create_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right,
3800 re_token_type_t type) 3796 re_token_type_t type)
3801{ 3797{
3802 re_token_t t; 3798 re_token_t t = { .type = type };
3803 t.type = type;
3804 return create_token_tree (dfa, left, right, &t); 3799 return create_token_tree (dfa, left, right, &t);
3805} 3800}
3806 3801
@@ -3809,7 +3804,7 @@ create_token_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right,
3809 const re_token_t *token) 3804 const re_token_t *token)
3810{ 3805{
3811 bin_tree_t *tree; 3806 bin_tree_t *tree;
3812 if (BE (dfa->str_tree_storage_idx == BIN_TREE_STORAGE_SIZE, 0)) 3807 if (__glibc_unlikely (dfa->str_tree_storage_idx == BIN_TREE_STORAGE_SIZE))
3813 { 3808 {
3814 bin_tree_storage_t *storage = re_malloc (bin_tree_storage_t, 1); 3809 bin_tree_storage_t *storage = re_malloc (bin_tree_storage_t, 1);
3815 3810
@@ -3829,7 +3824,7 @@ create_token_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right,
3829 tree->token.opt_subexp = 0; 3824 tree->token.opt_subexp = 0;
3830 tree->first = NULL; 3825 tree->first = NULL;
3831 tree->next = NULL; 3826 tree->next = NULL;
3832 tree->node_idx = REG_MISSING; 3827 tree->node_idx = -1;
3833 3828
3834 if (left != NULL) 3829 if (left != NULL)
3835 left->parent = tree; 3830 left->parent = tree;
diff --git a/gl/regex.c b/gl/regex.c
index 5a0332e..d328639 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-2021 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..adb6976 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-2021 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..aefcfa2 100644
--- a/gl/regex_internal.c
+++ b/gl/regex_internal.c
@@ -1,33 +1,43 @@
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-2021 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);
33#ifdef RE_ENABLE_I18N
34static void build_wcs_buffer (re_string_t *pstr);
35static reg_errcode_t build_wcs_upper_buffer (re_string_t *pstr);
36#endif /* RE_ENABLE_I18N */
37static void build_upper_buffer (re_string_t *pstr);
38static void re_string_translate_buffer (re_string_t *pstr);
39static unsigned int re_string_context_at (const re_string_t *input, Idx idx,
40 int eflags) __attribute__ ((pure));
31 41
32/* Functions for string operation. */ 42/* Functions for string operation. */
33 43
@@ -35,7 +45,7 @@ static re_dfastate_t *create_cd_newstate (const re_dfa_t *dfa,
35 re_string_reconstruct before using the object. */ 45 re_string_reconstruct before using the object. */
36 46
37static reg_errcode_t 47static reg_errcode_t
38internal_function __attribute_warn_unused_result__ 48__attribute_warn_unused_result__
39re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len, 49re_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) 50 RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
41{ 51{
@@ -49,7 +59,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); 59 re_string_construct_common (str, len, pstr, trans, icase, dfa);
50 60
51 ret = re_string_realloc_buffers (pstr, init_buf_len); 61 ret = re_string_realloc_buffers (pstr, init_buf_len);
52 if (BE (ret != REG_NOERROR, 0)) 62 if (__glibc_unlikely (ret != REG_NOERROR))
53 return ret; 63 return ret;
54 64
55 pstr->word_char = dfa->word_char; 65 pstr->word_char = dfa->word_char;
@@ -63,7 +73,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. */ 73/* This function allocate the buffers, and initialize them. */
64 74
65static reg_errcode_t 75static reg_errcode_t
66internal_function __attribute_warn_unused_result__ 76__attribute_warn_unused_result__
67re_string_construct (re_string_t *pstr, const char *str, Idx len, 77re_string_construct (re_string_t *pstr, const char *str, Idx len,
68 RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa) 78 RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
69{ 79{
@@ -74,7 +84,7 @@ re_string_construct (re_string_t *pstr, const char *str, Idx len,
74 if (len > 0) 84 if (len > 0)
75 { 85 {
76 ret = re_string_realloc_buffers (pstr, len + 1); 86 ret = re_string_realloc_buffers (pstr, len + 1);
77 if (BE (ret != REG_NOERROR, 0)) 87 if (__glibc_unlikely (ret != REG_NOERROR))
78 return ret; 88 return ret;
79 } 89 }
80 pstr->mbs = pstr->mbs_allocated ? pstr->mbs : (unsigned char *) str; 90 pstr->mbs = pstr->mbs_allocated ? pstr->mbs : (unsigned char *) str;
@@ -87,14 +97,14 @@ re_string_construct (re_string_t *pstr, const char *str, Idx len,
87 while (1) 97 while (1)
88 { 98 {
89 ret = build_wcs_upper_buffer (pstr); 99 ret = build_wcs_upper_buffer (pstr);
90 if (BE (ret != REG_NOERROR, 0)) 100 if (__glibc_unlikely (ret != REG_NOERROR))
91 return ret; 101 return ret;
92 if (pstr->valid_raw_len >= len) 102 if (pstr->valid_raw_len >= len)
93 break; 103 break;
94 if (pstr->bufs_len > pstr->valid_len + dfa->mb_cur_max) 104 if (pstr->bufs_len > pstr->valid_len + dfa->mb_cur_max)
95 break; 105 break;
96 ret = re_string_realloc_buffers (pstr, pstr->bufs_len * 2); 106 ret = re_string_realloc_buffers (pstr, pstr->bufs_len * 2);
97 if (BE (ret != REG_NOERROR, 0)) 107 if (__glibc_unlikely (ret != REG_NOERROR))
98 return ret; 108 return ret;
99 } 109 }
100 } 110 }
@@ -126,7 +136,7 @@ re_string_construct (re_string_t *pstr, const char *str, Idx len,
126/* Helper functions for re_string_allocate, and re_string_construct. */ 136/* Helper functions for re_string_allocate, and re_string_construct. */
127 137
128static reg_errcode_t 138static reg_errcode_t
129internal_function __attribute_warn_unused_result__ 139__attribute_warn_unused_result__
130re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len) 140re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len)
131{ 141{
132#ifdef RE_ENABLE_I18N 142#ifdef RE_ENABLE_I18N
@@ -136,17 +146,18 @@ re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len)
136 146
137 /* Avoid overflow in realloc. */ 147 /* Avoid overflow in realloc. */
138 const size_t max_object_size = MAX (sizeof (wint_t), sizeof (Idx)); 148 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)) 149 if (__glibc_unlikely (MIN (IDX_MAX, SIZE_MAX / max_object_size)
150 < new_buf_len))
140 return REG_ESPACE; 151 return REG_ESPACE;
141 152
142 new_wcs = re_realloc (pstr->wcs, wint_t, new_buf_len); 153 new_wcs = re_realloc (pstr->wcs, wint_t, new_buf_len);
143 if (BE (new_wcs == NULL, 0)) 154 if (__glibc_unlikely (new_wcs == NULL))
144 return REG_ESPACE; 155 return REG_ESPACE;
145 pstr->wcs = new_wcs; 156 pstr->wcs = new_wcs;
146 if (pstr->offsets != NULL) 157 if (pstr->offsets != NULL)
147 { 158 {
148 Idx *new_offsets = re_realloc (pstr->offsets, Idx, new_buf_len); 159 Idx *new_offsets = re_realloc (pstr->offsets, Idx, new_buf_len);
149 if (BE (new_offsets == NULL, 0)) 160 if (__glibc_unlikely (new_offsets == NULL))
150 return REG_ESPACE; 161 return REG_ESPACE;
151 pstr->offsets = new_offsets; 162 pstr->offsets = new_offsets;
152 } 163 }
@@ -156,7 +167,7 @@ re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len)
156 { 167 {
157 unsigned char *new_mbs = re_realloc (pstr->mbs, unsigned char, 168 unsigned char *new_mbs = re_realloc (pstr->mbs, unsigned char,
158 new_buf_len); 169 new_buf_len);
159 if (BE (new_mbs == NULL, 0)) 170 if (__glibc_unlikely (new_mbs == NULL))
160 return REG_ESPACE; 171 return REG_ESPACE;
161 pstr->mbs = new_mbs; 172 pstr->mbs = new_mbs;
162 } 173 }
@@ -166,7 +177,6 @@ re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len)
166 177
167 178
168static void 179static void
169internal_function
170re_string_construct_common (const char *str, Idx len, re_string_t *pstr, 180re_string_construct_common (const char *str, Idx len, re_string_t *pstr,
171 RE_TRANSLATE_TYPE trans, bool icase, 181 RE_TRANSLATE_TYPE trans, bool icase,
172 const re_dfa_t *dfa) 182 const re_dfa_t *dfa)
@@ -198,12 +208,11 @@ re_string_construct_common (const char *str, Idx len, re_string_t *pstr,
198 built and starts from PSTR->VALID_LEN. */ 208 built and starts from PSTR->VALID_LEN. */
199 209
200static void 210static void
201internal_function
202build_wcs_buffer (re_string_t *pstr) 211build_wcs_buffer (re_string_t *pstr)
203{ 212{
204#ifdef _LIBC 213#ifdef _LIBC
205 unsigned char buf[MB_LEN_MAX]; 214 unsigned char buf[MB_LEN_MAX];
206 assert (MB_LEN_MAX >= pstr->mb_cur_max); 215 DEBUG_ASSERT (MB_LEN_MAX >= pstr->mb_cur_max);
207#else 216#else
208 unsigned char buf[64]; 217 unsigned char buf[64];
209#endif 218#endif
@@ -222,7 +231,7 @@ build_wcs_buffer (re_string_t *pstr)
222 remain_len = end_idx - byte_idx; 231 remain_len = end_idx - byte_idx;
223 prev_st = pstr->cur_state; 232 prev_st = pstr->cur_state;
224 /* Apply the translation if we need. */ 233 /* Apply the translation if we need. */
225 if (BE (pstr->trans != NULL, 0)) 234 if (__glibc_unlikely (pstr->trans != NULL))
226 { 235 {
227 int i, ch; 236 int i, ch;
228 237
@@ -236,17 +245,18 @@ build_wcs_buffer (re_string_t *pstr)
236 else 245 else
237 p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + byte_idx; 246 p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + byte_idx;
238 mbclen = __mbrtowc (&wc, p, remain_len, &pstr->cur_state); 247 mbclen = __mbrtowc (&wc, p, remain_len, &pstr->cur_state);
239 if (BE (mbclen == (size_t) -1 || mbclen == 0 248 if (__glibc_unlikely (mbclen == (size_t) -1 || mbclen == 0
240 || (mbclen == (size_t) -2 && pstr->bufs_len >= pstr->len), 0)) 249 || (mbclen == (size_t) -2
250 && pstr->bufs_len >= pstr->len)))
241 { 251 {
242 /* We treat these cases as a singlebyte character. */ 252 /* We treat these cases as a singlebyte character. */
243 mbclen = 1; 253 mbclen = 1;
244 wc = (wchar_t) pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]; 254 wc = (wchar_t) pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx];
245 if (BE (pstr->trans != NULL, 0)) 255 if (__glibc_unlikely (pstr->trans != NULL))
246 wc = pstr->trans[wc]; 256 wc = pstr->trans[wc];
247 pstr->cur_state = prev_st; 257 pstr->cur_state = prev_st;
248 } 258 }
249 else if (BE (mbclen == (size_t) -2, 0)) 259 else if (__glibc_unlikely (mbclen == (size_t) -2))
250 { 260 {
251 /* The buffer doesn't have enough space, finish to build. */ 261 /* The buffer doesn't have enough space, finish to build. */
252 pstr->cur_state = prev_st; 262 pstr->cur_state = prev_st;
@@ -267,7 +277,7 @@ build_wcs_buffer (re_string_t *pstr)
267 but for REG_ICASE. */ 277 but for REG_ICASE. */
268 278
269static reg_errcode_t 279static reg_errcode_t
270internal_function __attribute_warn_unused_result__ 280__attribute_warn_unused_result__
271build_wcs_upper_buffer (re_string_t *pstr) 281build_wcs_upper_buffer (re_string_t *pstr)
272{ 282{
273 mbstate_t prev_st; 283 mbstate_t prev_st;
@@ -275,7 +285,7 @@ build_wcs_upper_buffer (re_string_t *pstr)
275 size_t mbclen; 285 size_t mbclen;
276#ifdef _LIBC 286#ifdef _LIBC
277 char buf[MB_LEN_MAX]; 287 char buf[MB_LEN_MAX];
278 assert (MB_LEN_MAX >= pstr->mb_cur_max); 288 DEBUG_ASSERT (pstr->mb_cur_max <= MB_LEN_MAX);
279#else 289#else
280 char buf[64]; 290 char buf[64];
281#endif 291#endif
@@ -290,18 +300,20 @@ build_wcs_upper_buffer (re_string_t *pstr)
290 while (byte_idx < end_idx) 300 while (byte_idx < end_idx)
291 { 301 {
292 wchar_t wc; 302 wchar_t wc;
303 unsigned char ch = pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx];
293 304
294 if (isascii (pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]) 305 if (isascii (ch) && mbsinit (&pstr->cur_state))
295 && mbsinit (&pstr->cur_state))
296 { 306 {
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 307 /* The next step uses the assumption that wchar_t is encoded
301 ASCII-safe: all ASCII values can be converted like this. */ 308 ASCII-safe: all ASCII values can be converted like this. */
302 pstr->wcs[byte_idx] = (wchar_t) pstr->mbs[byte_idx]; 309 wchar_t wcu = __towupper (ch);
303 ++byte_idx; 310 if (isascii (wcu))
304 continue; 311 {
312 pstr->mbs[byte_idx] = wcu;
313 pstr->wcs[byte_idx] = wcu;
314 byte_idx++;
315 continue;
316 }
305 } 317 }
306 318
307 remain_len = end_idx - byte_idx; 319 remain_len = end_idx - byte_idx;
@@ -309,16 +321,15 @@ build_wcs_upper_buffer (re_string_t *pstr)
309 mbclen = __mbrtowc (&wc, 321 mbclen = __mbrtowc (&wc,
310 ((const char *) pstr->raw_mbs + pstr->raw_mbs_idx 322 ((const char *) pstr->raw_mbs + pstr->raw_mbs_idx
311 + byte_idx), remain_len, &pstr->cur_state); 323 + byte_idx), remain_len, &pstr->cur_state);
312 if (BE (mbclen < (size_t) -2, 1)) 324 if (__glibc_likely (0 < mbclen && mbclen < (size_t) -2))
313 { 325 {
314 wchar_t wcu = wc; 326 wchar_t wcu = __towupper (wc);
315 if (iswlower (wc)) 327 if (wcu != wc)
316 { 328 {
317 size_t mbcdlen; 329 size_t mbcdlen;
318 330
319 wcu = towupper (wc); 331 mbcdlen = __wcrtomb (buf, wcu, &prev_st);
320 mbcdlen = wcrtomb (buf, wcu, &prev_st); 332 if (__glibc_likely (mbclen == mbcdlen))
321 if (BE (mbclen == mbcdlen, 1))
322 memcpy (pstr->mbs + byte_idx, buf, mbclen); 333 memcpy (pstr->mbs + byte_idx, buf, mbclen);
323 else 334 else
324 { 335 {
@@ -339,11 +350,10 @@ build_wcs_upper_buffer (re_string_t *pstr)
339 { 350 {
340 /* It is an invalid character, an incomplete character 351 /* It is an invalid character, an incomplete character
341 at the end of the string, or '\0'. Just use the byte. */ 352 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; 353 pstr->mbs[byte_idx] = ch;
344 /* And also cast it to wide char. */ 354 /* And also cast it to wide char. */
345 pstr->wcs[byte_idx++] = (wchar_t) ch; 355 pstr->wcs[byte_idx++] = (wchar_t) ch;
346 if (BE (mbclen == (size_t) -1, 0)) 356 if (__glibc_unlikely (mbclen == (size_t) -1))
347 pstr->cur_state = prev_st; 357 pstr->cur_state = prev_st;
348 } 358 }
349 else 359 else
@@ -365,7 +375,7 @@ build_wcs_upper_buffer (re_string_t *pstr)
365 offsets_needed: 375 offsets_needed:
366 remain_len = end_idx - byte_idx; 376 remain_len = end_idx - byte_idx;
367 prev_st = pstr->cur_state; 377 prev_st = pstr->cur_state;
368 if (BE (pstr->trans != NULL, 0)) 378 if (__glibc_unlikely (pstr->trans != NULL))
369 { 379 {
370 int i, ch; 380 int i, ch;
371 381
@@ -379,16 +389,15 @@ build_wcs_upper_buffer (re_string_t *pstr)
379 else 389 else
380 p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + src_idx; 390 p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + src_idx;
381 mbclen = __mbrtowc (&wc, p, remain_len, &pstr->cur_state); 391 mbclen = __mbrtowc (&wc, p, remain_len, &pstr->cur_state);
382 if (BE (mbclen < (size_t) -2, 1)) 392 if (__glibc_likely (0 < mbclen && mbclen < (size_t) -2))
383 { 393 {
384 wchar_t wcu = wc; 394 wchar_t wcu = __towupper (wc);
385 if (iswlower (wc)) 395 if (wcu != wc)
386 { 396 {
387 size_t mbcdlen; 397 size_t mbcdlen;
388 398
389 wcu = towupper (wc); 399 mbcdlen = __wcrtomb ((char *) buf, wcu, &prev_st);
390 mbcdlen = wcrtomb ((char *) buf, wcu, &prev_st); 400 if (__glibc_likely (mbclen == mbcdlen))
391 if (BE (mbclen == mbcdlen, 1))
392 memcpy (pstr->mbs + byte_idx, buf, mbclen); 401 memcpy (pstr->mbs + byte_idx, buf, mbclen);
393 else if (mbcdlen != (size_t) -1) 402 else if (mbcdlen != (size_t) -1)
394 { 403 {
@@ -438,7 +447,7 @@ build_wcs_upper_buffer (re_string_t *pstr)
438 else 447 else
439 memcpy (pstr->mbs + byte_idx, p, mbclen); 448 memcpy (pstr->mbs + byte_idx, p, mbclen);
440 449
441 if (BE (pstr->offsets_needed != 0, 0)) 450 if (__glibc_unlikely (pstr->offsets_needed != 0))
442 { 451 {
443 size_t i; 452 size_t i;
444 for (i = 0; i < mbclen; ++i) 453 for (i = 0; i < mbclen; ++i)
@@ -457,17 +466,17 @@ build_wcs_upper_buffer (re_string_t *pstr)
457 /* It is an invalid character or '\0'. Just use the byte. */ 466 /* It is an invalid character or '\0'. Just use the byte. */
458 int ch = pstr->raw_mbs[pstr->raw_mbs_idx + src_idx]; 467 int ch = pstr->raw_mbs[pstr->raw_mbs_idx + src_idx];
459 468
460 if (BE (pstr->trans != NULL, 0)) 469 if (__glibc_unlikely (pstr->trans != NULL))
461 ch = pstr->trans [ch]; 470 ch = pstr->trans [ch];
462 pstr->mbs[byte_idx] = ch; 471 pstr->mbs[byte_idx] = ch;
463 472
464 if (BE (pstr->offsets_needed != 0, 0)) 473 if (__glibc_unlikely (pstr->offsets_needed != 0))
465 pstr->offsets[byte_idx] = src_idx; 474 pstr->offsets[byte_idx] = src_idx;
466 ++src_idx; 475 ++src_idx;
467 476
468 /* And also cast it to wide char. */ 477 /* And also cast it to wide char. */
469 pstr->wcs[byte_idx++] = (wchar_t) ch; 478 pstr->wcs[byte_idx++] = (wchar_t) ch;
470 if (BE (mbclen == (size_t) -1, 0)) 479 if (__glibc_unlikely (mbclen == (size_t) -1))
471 pstr->cur_state = prev_st; 480 pstr->cur_state = prev_st;
472 } 481 }
473 else 482 else
@@ -486,7 +495,6 @@ build_wcs_upper_buffer (re_string_t *pstr)
486 Return the index. */ 495 Return the index. */
487 496
488static Idx 497static Idx
489internal_function
490re_string_skip_chars (re_string_t *pstr, Idx new_raw_idx, wint_t *last_wc) 498re_string_skip_chars (re_string_t *pstr, Idx new_raw_idx, wint_t *last_wc)
491{ 499{
492 mbstate_t prev_st; 500 mbstate_t prev_st;
@@ -503,7 +511,8 @@ re_string_skip_chars (re_string_t *pstr, Idx new_raw_idx, wint_t *last_wc)
503 prev_st = pstr->cur_state; 511 prev_st = pstr->cur_state;
504 mbclen = __mbrtowc (&wc2, (const char *) pstr->raw_mbs + rawbuf_idx, 512 mbclen = __mbrtowc (&wc2, (const char *) pstr->raw_mbs + rawbuf_idx,
505 remain_len, &pstr->cur_state); 513 remain_len, &pstr->cur_state);
506 if (BE (mbclen == (size_t) -2 || mbclen == (size_t) -1 || mbclen == 0, 0)) 514 if (__glibc_unlikely (mbclen == (size_t) -2 || mbclen == (size_t) -1
515 || mbclen == 0))
507 { 516 {
508 /* We treat these cases as a single byte character. */ 517 /* We treat these cases as a single byte character. */
509 if (mbclen == 0 || remain_len == 0) 518 if (mbclen == 0 || remain_len == 0)
@@ -527,7 +536,6 @@ re_string_skip_chars (re_string_t *pstr, Idx new_raw_idx, wint_t *last_wc)
527 This function is used in case of REG_ICASE. */ 536 This function is used in case of REG_ICASE. */
528 537
529static void 538static void
530internal_function
531build_upper_buffer (re_string_t *pstr) 539build_upper_buffer (re_string_t *pstr)
532{ 540{
533 Idx char_idx, end_idx; 541 Idx char_idx, end_idx;
@@ -536,12 +544,9 @@ build_upper_buffer (re_string_t *pstr)
536 for (char_idx = pstr->valid_len; char_idx < end_idx; ++char_idx) 544 for (char_idx = pstr->valid_len; char_idx < end_idx; ++char_idx)
537 { 545 {
538 int ch = pstr->raw_mbs[pstr->raw_mbs_idx + char_idx]; 546 int ch = pstr->raw_mbs[pstr->raw_mbs_idx + char_idx];
539 if (BE (pstr->trans != NULL, 0)) 547 if (__glibc_unlikely (pstr->trans != NULL))
540 ch = pstr->trans[ch]; 548 ch = pstr->trans[ch];
541 if (islower (ch)) 549 pstr->mbs[char_idx] = toupper (ch);
542 pstr->mbs[char_idx] = toupper (ch);
543 else
544 pstr->mbs[char_idx] = ch;
545 } 550 }
546 pstr->valid_len = char_idx; 551 pstr->valid_len = char_idx;
547 pstr->valid_raw_len = char_idx; 552 pstr->valid_raw_len = char_idx;
@@ -550,7 +555,6 @@ build_upper_buffer (re_string_t *pstr)
550/* Apply TRANS to the buffer in PSTR. */ 555/* Apply TRANS to the buffer in PSTR. */
551 556
552static void 557static void
553internal_function
554re_string_translate_buffer (re_string_t *pstr) 558re_string_translate_buffer (re_string_t *pstr)
555{ 559{
556 Idx buf_idx, end_idx; 560 Idx buf_idx, end_idx;
@@ -571,12 +575,12 @@ re_string_translate_buffer (re_string_t *pstr)
571 convert to upper case in case of REG_ICASE, apply translation. */ 575 convert to upper case in case of REG_ICASE, apply translation. */
572 576
573static reg_errcode_t 577static reg_errcode_t
574internal_function __attribute_warn_unused_result__ 578__attribute_warn_unused_result__
575re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags) 579re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
576{ 580{
577 Idx offset; 581 Idx offset;
578 582
579 if (BE (pstr->raw_mbs_idx <= idx, 0)) 583 if (__glibc_unlikely (pstr->raw_mbs_idx <= idx))
580 offset = idx - pstr->raw_mbs_idx; 584 offset = idx - pstr->raw_mbs_idx;
581 else 585 else
582 { 586 {
@@ -598,14 +602,14 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
598 offset = idx; 602 offset = idx;
599 } 603 }
600 604
601 if (BE (offset != 0, 1)) 605 if (__glibc_likely (offset != 0))
602 { 606 {
603 /* Should the already checked characters be kept? */ 607 /* Should the already checked characters be kept? */
604 if (BE (offset < pstr->valid_raw_len, 1)) 608 if (__glibc_likely (offset < pstr->valid_raw_len))
605 { 609 {
606 /* Yes, move them to the front of the buffer. */ 610 /* Yes, move them to the front of the buffer. */
607#ifdef RE_ENABLE_I18N 611#ifdef RE_ENABLE_I18N
608 if (BE (pstr->offsets_needed, 0)) 612 if (__glibc_unlikely (pstr->offsets_needed))
609 { 613 {
610 Idx low = 0, high = pstr->valid_len, mid; 614 Idx low = 0, high = pstr->valid_len, mid;
611 do 615 do
@@ -677,14 +681,12 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
677 memmove (pstr->wcs, pstr->wcs + offset, 681 memmove (pstr->wcs, pstr->wcs + offset,
678 (pstr->valid_len - offset) * sizeof (wint_t)); 682 (pstr->valid_len - offset) * sizeof (wint_t));
679#endif /* RE_ENABLE_I18N */ 683#endif /* RE_ENABLE_I18N */
680 if (BE (pstr->mbs_allocated, 0)) 684 if (__glibc_unlikely (pstr->mbs_allocated))
681 memmove (pstr->mbs, pstr->mbs + offset, 685 memmove (pstr->mbs, pstr->mbs + offset,
682 pstr->valid_len - offset); 686 pstr->valid_len - offset);
683 pstr->valid_len -= offset; 687 pstr->valid_len -= offset;
684 pstr->valid_raw_len -= offset; 688 pstr->valid_raw_len -= offset;
685#if DEBUG 689 DEBUG_ASSERT (pstr->valid_len > 0);
686 assert (pstr->valid_len > 0);
687#endif
688 } 690 }
689 } 691 }
690 else 692 else
@@ -693,7 +695,7 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
693 /* No, skip all characters until IDX. */ 695 /* No, skip all characters until IDX. */
694 Idx prev_valid_len = pstr->valid_len; 696 Idx prev_valid_len = pstr->valid_len;
695 697
696 if (BE (pstr->offsets_needed, 0)) 698 if (__glibc_unlikely (pstr->offsets_needed))
697 { 699 {
698 pstr->len = pstr->raw_len - idx + offset; 700 pstr->len = pstr->raw_len - idx + offset;
699 pstr->stop = pstr->raw_stop - idx + offset; 701 pstr->stop = pstr->raw_stop - idx + offset;
@@ -721,7 +723,7 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
721#ifdef _LIBC 723#ifdef _LIBC
722 /* We know the wchar_t encoding is UCS4, so for the simple 724 /* We know the wchar_t encoding is UCS4, so for the simple
723 case, ASCII characters, skip the conversion step. */ 725 case, ASCII characters, skip the conversion step. */
724 if (isascii (*p) && BE (pstr->trans == NULL, 1)) 726 if (isascii (*p) && __glibc_likely (pstr->trans == NULL))
725 { 727 {
726 memset (&pstr->cur_state, '\0', sizeof (mbstate_t)); 728 memset (&pstr->cur_state, '\0', sizeof (mbstate_t));
727 /* pstr->valid_len = 0; */ 729 /* pstr->valid_len = 0; */
@@ -739,7 +741,7 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
739 size_t mbclen; 741 size_t mbclen;
740 742
741 const unsigned char *pp = p; 743 const unsigned char *pp = p;
742 if (BE (pstr->trans != NULL, 0)) 744 if (__glibc_unlikely (pstr->trans != NULL))
743 { 745 {
744 int i = mlen < 6 ? mlen : 6; 746 int i = mlen < 6 ? mlen : 6;
745 while (--i >= 0) 747 while (--i >= 0)
@@ -769,13 +771,13 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
769 pstr->tip_context 771 pstr->tip_context
770 = re_string_context_at (pstr, prev_valid_len - 1, eflags); 772 = re_string_context_at (pstr, prev_valid_len - 1, eflags);
771 else 773 else
772 pstr->tip_context = ((BE (pstr->word_ops_used != 0, 0) 774 pstr->tip_context = ((__glibc_unlikely (pstr->word_ops_used != 0)
773 && IS_WIDE_WORD_CHAR (wc)) 775 && IS_WIDE_WORD_CHAR (wc))
774 ? CONTEXT_WORD 776 ? CONTEXT_WORD
775 : ((IS_WIDE_NEWLINE (wc) 777 : ((IS_WIDE_NEWLINE (wc)
776 && pstr->newline_anchor) 778 && pstr->newline_anchor)
777 ? CONTEXT_NEWLINE : 0)); 779 ? CONTEXT_NEWLINE : 0));
778 if (BE (pstr->valid_len, 0)) 780 if (__glibc_unlikely (pstr->valid_len))
779 { 781 {
780 for (wcs_idx = 0; wcs_idx < pstr->valid_len; ++wcs_idx) 782 for (wcs_idx = 0; wcs_idx < pstr->valid_len; ++wcs_idx)
781 pstr->wcs[wcs_idx] = WEOF; 783 pstr->wcs[wcs_idx] = WEOF;
@@ -797,7 +799,7 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
797 ? CONTEXT_NEWLINE : 0)); 799 ? CONTEXT_NEWLINE : 0));
798 } 800 }
799 } 801 }
800 if (!BE (pstr->mbs_allocated, 0)) 802 if (!__glibc_unlikely (pstr->mbs_allocated))
801 pstr->mbs += offset; 803 pstr->mbs += offset;
802 } 804 }
803 pstr->raw_mbs_idx = idx; 805 pstr->raw_mbs_idx = idx;
@@ -811,7 +813,7 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
811 if (pstr->icase) 813 if (pstr->icase)
812 { 814 {
813 reg_errcode_t ret = build_wcs_upper_buffer (pstr); 815 reg_errcode_t ret = build_wcs_upper_buffer (pstr);
814 if (BE (ret != REG_NOERROR, 0)) 816 if (__glibc_unlikely (ret != REG_NOERROR))
815 return ret; 817 return ret;
816 } 818 }
817 else 819 else
@@ -819,7 +821,7 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
819 } 821 }
820 else 822 else
821#endif /* RE_ENABLE_I18N */ 823#endif /* RE_ENABLE_I18N */
822 if (BE (pstr->mbs_allocated, 0)) 824 if (__glibc_unlikely (pstr->mbs_allocated))
823 { 825 {
824 if (pstr->icase) 826 if (pstr->icase)
825 build_upper_buffer (pstr); 827 build_upper_buffer (pstr);
@@ -834,14 +836,14 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
834} 836}
835 837
836static unsigned char 838static unsigned char
837internal_function __attribute__ ((pure)) 839__attribute__ ((pure))
838re_string_peek_byte_case (const re_string_t *pstr, Idx idx) 840re_string_peek_byte_case (const re_string_t *pstr, Idx idx)
839{ 841{
840 int ch; 842 int ch;
841 Idx off; 843 Idx off;
842 844
843 /* Handle the common (easiest) cases first. */ 845 /* Handle the common (easiest) cases first. */
844 if (BE (!pstr->mbs_allocated, 1)) 846 if (__glibc_likely (!pstr->mbs_allocated))
845 return re_string_peek_byte (pstr, idx); 847 return re_string_peek_byte (pstr, idx);
846 848
847#ifdef RE_ENABLE_I18N 849#ifdef RE_ENABLE_I18N
@@ -871,10 +873,9 @@ re_string_peek_byte_case (const re_string_t *pstr, Idx idx)
871} 873}
872 874
873static unsigned char 875static unsigned char
874internal_function
875re_string_fetch_byte_case (re_string_t *pstr) 876re_string_fetch_byte_case (re_string_t *pstr)
876{ 877{
877 if (BE (!pstr->mbs_allocated, 1)) 878 if (__glibc_likely (!pstr->mbs_allocated))
878 return re_string_fetch_byte (pstr); 879 return re_string_fetch_byte (pstr);
879 880
880#ifdef RE_ENABLE_I18N 881#ifdef RE_ENABLE_I18N
@@ -909,7 +910,6 @@ re_string_fetch_byte_case (re_string_t *pstr)
909} 910}
910 911
911static void 912static void
912internal_function
913re_string_destruct (re_string_t *pstr) 913re_string_destruct (re_string_t *pstr)
914{ 914{
915#ifdef RE_ENABLE_I18N 915#ifdef RE_ENABLE_I18N
@@ -923,15 +923,14 @@ re_string_destruct (re_string_t *pstr)
923/* Return the context at IDX in INPUT. */ 923/* Return the context at IDX in INPUT. */
924 924
925static unsigned int 925static unsigned int
926internal_function
927re_string_context_at (const re_string_t *input, Idx idx, int eflags) 926re_string_context_at (const re_string_t *input, Idx idx, int eflags)
928{ 927{
929 int c; 928 int c;
930 if (BE (! REG_VALID_INDEX (idx), 0)) 929 if (__glibc_unlikely (idx < 0))
931 /* In this case, we use the value stored in input->tip_context, 930 /* 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. */ 931 since we can't know the character in input->mbs[-1] here. */
933 return input->tip_context; 932 return input->tip_context;
934 if (BE (idx == input->len, 0)) 933 if (__glibc_unlikely (idx == input->len))
935 return ((eflags & REG_NOTEOL) ? CONTEXT_ENDBUF 934 return ((eflags & REG_NOTEOL) ? CONTEXT_ENDBUF
936 : CONTEXT_NEWLINE | CONTEXT_ENDBUF); 935 : CONTEXT_NEWLINE | CONTEXT_ENDBUF);
937#ifdef RE_ENABLE_I18N 936#ifdef RE_ENABLE_I18N
@@ -941,16 +940,14 @@ re_string_context_at (const re_string_t *input, Idx idx, int eflags)
941 Idx wc_idx = idx; 940 Idx wc_idx = idx;
942 while(input->wcs[wc_idx] == WEOF) 941 while(input->wcs[wc_idx] == WEOF)
943 { 942 {
944#ifdef DEBUG 943 DEBUG_ASSERT (wc_idx >= 0);
945 /* It must not happen. */
946 assert (REG_VALID_INDEX (wc_idx));
947#endif
948 --wc_idx; 944 --wc_idx;
949 if (! REG_VALID_INDEX (wc_idx)) 945 if (wc_idx < 0)
950 return input->tip_context; 946 return input->tip_context;
951 } 947 }
952 wc = input->wcs[wc_idx]; 948 wc = input->wcs[wc_idx];
953 if (BE (input->word_ops_used != 0, 0) && IS_WIDE_WORD_CHAR (wc)) 949 if (__glibc_unlikely (input->word_ops_used != 0)
950 && IS_WIDE_WORD_CHAR (wc))
954 return CONTEXT_WORD; 951 return CONTEXT_WORD;
955 return (IS_WIDE_NEWLINE (wc) && input->newline_anchor 952 return (IS_WIDE_NEWLINE (wc) && input->newline_anchor
956 ? CONTEXT_NEWLINE : 0); 953 ? CONTEXT_NEWLINE : 0);
@@ -968,25 +965,26 @@ re_string_context_at (const re_string_t *input, Idx idx, int eflags)
968/* Functions for set operation. */ 965/* Functions for set operation. */
969 966
970static reg_errcode_t 967static reg_errcode_t
971internal_function __attribute_warn_unused_result__ 968__attribute_warn_unused_result__
972re_node_set_alloc (re_node_set *set, Idx size) 969re_node_set_alloc (re_node_set *set, Idx size)
973{ 970{
974 set->alloc = size; 971 set->alloc = size;
975 set->nelem = 0; 972 set->nelem = 0;
976 set->elems = re_malloc (Idx, size); 973 set->elems = re_malloc (Idx, size);
977 if (BE (set->elems == NULL, 0) && (MALLOC_0_IS_NONNULL || size != 0)) 974 if (__glibc_unlikely (set->elems == NULL)
975 && (MALLOC_0_IS_NONNULL || size != 0))
978 return REG_ESPACE; 976 return REG_ESPACE;
979 return REG_NOERROR; 977 return REG_NOERROR;
980} 978}
981 979
982static reg_errcode_t 980static reg_errcode_t
983internal_function __attribute_warn_unused_result__ 981__attribute_warn_unused_result__
984re_node_set_init_1 (re_node_set *set, Idx elem) 982re_node_set_init_1 (re_node_set *set, Idx elem)
985{ 983{
986 set->alloc = 1; 984 set->alloc = 1;
987 set->nelem = 1; 985 set->nelem = 1;
988 set->elems = re_malloc (Idx, 1); 986 set->elems = re_malloc (Idx, 1);
989 if (BE (set->elems == NULL, 0)) 987 if (__glibc_unlikely (set->elems == NULL))
990 { 988 {
991 set->alloc = set->nelem = 0; 989 set->alloc = set->nelem = 0;
992 return REG_ESPACE; 990 return REG_ESPACE;
@@ -996,12 +994,12 @@ re_node_set_init_1 (re_node_set *set, Idx elem)
996} 994}
997 995
998static reg_errcode_t 996static reg_errcode_t
999internal_function __attribute_warn_unused_result__ 997__attribute_warn_unused_result__
1000re_node_set_init_2 (re_node_set *set, Idx elem1, Idx elem2) 998re_node_set_init_2 (re_node_set *set, Idx elem1, Idx elem2)
1001{ 999{
1002 set->alloc = 2; 1000 set->alloc = 2;
1003 set->elems = re_malloc (Idx, 2); 1001 set->elems = re_malloc (Idx, 2);
1004 if (BE (set->elems == NULL, 0)) 1002 if (__glibc_unlikely (set->elems == NULL))
1005 return REG_ESPACE; 1003 return REG_ESPACE;
1006 if (elem1 == elem2) 1004 if (elem1 == elem2)
1007 { 1005 {
@@ -1026,7 +1024,7 @@ re_node_set_init_2 (re_node_set *set, Idx elem1, Idx elem2)
1026} 1024}
1027 1025
1028static reg_errcode_t 1026static reg_errcode_t
1029internal_function __attribute_warn_unused_result__ 1027__attribute_warn_unused_result__
1030re_node_set_init_copy (re_node_set *dest, const re_node_set *src) 1028re_node_set_init_copy (re_node_set *dest, const re_node_set *src)
1031{ 1029{
1032 dest->nelem = src->nelem; 1030 dest->nelem = src->nelem;
@@ -1034,7 +1032,7 @@ re_node_set_init_copy (re_node_set *dest, const re_node_set *src)
1034 { 1032 {
1035 dest->alloc = dest->nelem; 1033 dest->alloc = dest->nelem;
1036 dest->elems = re_malloc (Idx, dest->alloc); 1034 dest->elems = re_malloc (Idx, dest->alloc);
1037 if (BE (dest->elems == NULL, 0)) 1035 if (__glibc_unlikely (dest->elems == NULL))
1038 { 1036 {
1039 dest->alloc = dest->nelem = 0; 1037 dest->alloc = dest->nelem = 0;
1040 return REG_ESPACE; 1038 return REG_ESPACE;
@@ -1051,7 +1049,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. */ 1049 Note: We assume dest->elems is NULL, when dest->alloc is 0. */
1052 1050
1053static reg_errcode_t 1051static reg_errcode_t
1054internal_function __attribute_warn_unused_result__ 1052__attribute_warn_unused_result__
1055re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1, 1053re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1,
1056 const re_node_set *src2) 1054 const re_node_set *src2)
1057{ 1055{
@@ -1065,7 +1063,7 @@ re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1,
1065 { 1063 {
1066 Idx new_alloc = src1->nelem + src2->nelem + dest->alloc; 1064 Idx new_alloc = src1->nelem + src2->nelem + dest->alloc;
1067 Idx *new_elems = re_realloc (dest->elems, Idx, new_alloc); 1065 Idx *new_elems = re_realloc (dest->elems, Idx, new_alloc);
1068 if (BE (new_elems == NULL, 0)) 1066 if (__glibc_unlikely (new_elems == NULL))
1069 return REG_ESPACE; 1067 return REG_ESPACE;
1070 dest->elems = new_elems; 1068 dest->elems = new_elems;
1071 dest->alloc = new_alloc; 1069 dest->alloc = new_alloc;
@@ -1082,25 +1080,25 @@ re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1,
1082 if (src1->elems[i1] == src2->elems[i2]) 1080 if (src1->elems[i1] == src2->elems[i2])
1083 { 1081 {
1084 /* Try to find the item in DEST. Maybe we could binary search? */ 1082 /* Try to find the item in DEST. Maybe we could binary search? */
1085 while (REG_VALID_INDEX (id) && dest->elems[id] > src1->elems[i1]) 1083 while (id >= 0 && dest->elems[id] > src1->elems[i1])
1086 --id; 1084 --id;
1087 1085
1088 if (! REG_VALID_INDEX (id) || dest->elems[id] != src1->elems[i1]) 1086 if (id < 0 || dest->elems[id] != src1->elems[i1])
1089 dest->elems[--sbase] = src1->elems[i1]; 1087 dest->elems[--sbase] = src1->elems[i1];
1090 1088
1091 if (! REG_VALID_INDEX (--i1) || ! REG_VALID_INDEX (--i2)) 1089 if (--i1 < 0 || --i2 < 0)
1092 break; 1090 break;
1093 } 1091 }
1094 1092
1095 /* Lower the highest of the two items. */ 1093 /* Lower the highest of the two items. */
1096 else if (src1->elems[i1] < src2->elems[i2]) 1094 else if (src1->elems[i1] < src2->elems[i2])
1097 { 1095 {
1098 if (! REG_VALID_INDEX (--i2)) 1096 if (--i2 < 0)
1099 break; 1097 break;
1100 } 1098 }
1101 else 1099 else
1102 { 1100 {
1103 if (! REG_VALID_INDEX (--i1)) 1101 if (--i1 < 0)
1104 break; 1102 break;
1105 } 1103 }
1106 } 1104 }
@@ -1113,7 +1111,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 1111 DEST elements are already in place; this is more or
1114 less the same loop that is in re_node_set_merge. */ 1112 less the same loop that is in re_node_set_merge. */
1115 dest->nelem += delta; 1113 dest->nelem += delta;
1116 if (delta > 0 && REG_VALID_INDEX (id)) 1114 if (delta > 0 && id >= 0)
1117 for (;;) 1115 for (;;)
1118 { 1116 {
1119 if (dest->elems[is] > dest->elems[id]) 1117 if (dest->elems[is] > dest->elems[id])
@@ -1127,7 +1125,7 @@ re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1,
1127 { 1125 {
1128 /* Slide from the bottom. */ 1126 /* Slide from the bottom. */
1129 dest->elems[id + delta] = dest->elems[id]; 1127 dest->elems[id + delta] = dest->elems[id];
1130 if (! REG_VALID_INDEX (--id)) 1128 if (--id < 0)
1131 break; 1129 break;
1132 } 1130 }
1133 } 1131 }
@@ -1142,7 +1140,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. */ 1140 DEST. Return value indicate the error code or REG_NOERROR if succeeded. */
1143 1141
1144static reg_errcode_t 1142static reg_errcode_t
1145internal_function __attribute_warn_unused_result__ 1143__attribute_warn_unused_result__
1146re_node_set_init_union (re_node_set *dest, const re_node_set *src1, 1144re_node_set_init_union (re_node_set *dest, const re_node_set *src1,
1147 const re_node_set *src2) 1145 const re_node_set *src2)
1148{ 1146{
@@ -1151,7 +1149,7 @@ re_node_set_init_union (re_node_set *dest, const re_node_set *src1,
1151 { 1149 {
1152 dest->alloc = src1->nelem + src2->nelem; 1150 dest->alloc = src1->nelem + src2->nelem;
1153 dest->elems = re_malloc (Idx, dest->alloc); 1151 dest->elems = re_malloc (Idx, dest->alloc);
1154 if (BE (dest->elems == NULL, 0)) 1152 if (__glibc_unlikely (dest->elems == NULL))
1155 return REG_ESPACE; 1153 return REG_ESPACE;
1156 } 1154 }
1157 else 1155 else
@@ -1195,7 +1193,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. */ 1193 DEST. Return value indicate the error code or REG_NOERROR if succeeded. */
1196 1194
1197static reg_errcode_t 1195static reg_errcode_t
1198internal_function __attribute_warn_unused_result__ 1196__attribute_warn_unused_result__
1199re_node_set_merge (re_node_set *dest, const re_node_set *src) 1197re_node_set_merge (re_node_set *dest, const re_node_set *src)
1200{ 1198{
1201 Idx is, id, sbase, delta; 1199 Idx is, id, sbase, delta;
@@ -1205,14 +1203,18 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
1205 { 1203 {
1206 Idx new_alloc = 2 * (src->nelem + dest->alloc); 1204 Idx new_alloc = 2 * (src->nelem + dest->alloc);
1207 Idx *new_buffer = re_realloc (dest->elems, Idx, new_alloc); 1205 Idx *new_buffer = re_realloc (dest->elems, Idx, new_alloc);
1208 if (BE (new_buffer == NULL, 0)) 1206 if (__glibc_unlikely (new_buffer == NULL))
1209 return REG_ESPACE; 1207 return REG_ESPACE;
1210 dest->elems = new_buffer; 1208 dest->elems = new_buffer;
1211 dest->alloc = new_alloc; 1209 dest->alloc = new_alloc;
1212 } 1210 }
1213 1211
1214 if (BE (dest->nelem == 0, 0)) 1212 if (__glibc_unlikely (dest->nelem == 0))
1215 { 1213 {
1214 /* Although we already guaranteed above that dest->alloc != 0 and
1215 therefore dest->elems != NULL, add a debug assertion to pacify
1216 GCC 11.2.1's -fanalyzer. */
1217 DEBUG_ASSERT (dest->elems);
1216 dest->nelem = src->nelem; 1218 dest->nelem = src->nelem;
1217 memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx)); 1219 memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx));
1218 return REG_NOERROR; 1220 return REG_NOERROR;
@@ -1221,8 +1223,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 1223 /* Copy into the top of DEST the items of SRC that are not
1222 found in DEST. Maybe we could binary search in DEST? */ 1224 found in DEST. Maybe we could binary search in DEST? */
1223 for (sbase = dest->nelem + 2 * src->nelem, 1225 for (sbase = dest->nelem + 2 * src->nelem,
1224 is = src->nelem - 1, id = dest->nelem - 1; 1226 is = src->nelem - 1, id = dest->nelem - 1; is >= 0 && id >= 0; )
1225 REG_VALID_INDEX (is) && REG_VALID_INDEX (id); )
1226 { 1227 {
1227 if (dest->elems[id] == src->elems[is]) 1228 if (dest->elems[id] == src->elems[is])
1228 is--, id--; 1229 is--, id--;
@@ -1232,7 +1233,7 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
1232 --id; 1233 --id;
1233 } 1234 }
1234 1235
1235 if (REG_VALID_INDEX (is)) 1236 if (is >= 0)
1236 { 1237 {
1237 /* If DEST is exhausted, the remaining items of SRC must be unique. */ 1238 /* If DEST is exhausted, the remaining items of SRC must be unique. */
1238 sbase -= is + 1; 1239 sbase -= is + 1;
@@ -1261,7 +1262,7 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
1261 { 1262 {
1262 /* Slide from the bottom. */ 1263 /* Slide from the bottom. */
1263 dest->elems[id + delta] = dest->elems[id]; 1264 dest->elems[id + delta] = dest->elems[id];
1264 if (! REG_VALID_INDEX (--id)) 1265 if (--id < 0)
1265 { 1266 {
1266 /* Copy remaining SRC elements. */ 1267 /* Copy remaining SRC elements. */
1267 memcpy (dest->elems, dest->elems + sbase, 1268 memcpy (dest->elems, dest->elems + sbase,
@@ -1279,17 +1280,20 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
1279 Return true if successful. */ 1280 Return true if successful. */
1280 1281
1281static bool 1282static bool
1282internal_function __attribute_warn_unused_result__ 1283__attribute_warn_unused_result__
1283re_node_set_insert (re_node_set *set, Idx elem) 1284re_node_set_insert (re_node_set *set, Idx elem)
1284{ 1285{
1285 Idx idx; 1286 Idx idx;
1286 /* In case the set is empty. */ 1287 /* In case the set is empty. */
1287 if (set->alloc == 0) 1288 if (set->alloc == 0)
1288 return BE (re_node_set_init_1 (set, elem) == REG_NOERROR, 1); 1289 return __glibc_likely (re_node_set_init_1 (set, elem) == REG_NOERROR);
1289 1290
1290 if (BE (set->nelem, 0) == 0) 1291 if (__glibc_unlikely (set->nelem) == 0)
1291 { 1292 {
1292 /* We already guaranteed above that set->alloc != 0. */ 1293 /* Although we already guaranteed above that set->alloc != 0 and
1294 therefore set->elems != NULL, add a debug assertion to pacify
1295 GCC 11.2 -fanalyzer. */
1296 DEBUG_ASSERT (set->elems);
1293 set->elems[0] = elem; 1297 set->elems[0] = elem;
1294 ++set->nelem; 1298 ++set->nelem;
1295 return true; 1299 return true;
@@ -1301,7 +1305,7 @@ re_node_set_insert (re_node_set *set, Idx elem)
1301 Idx *new_elems; 1305 Idx *new_elems;
1302 set->alloc = set->alloc * 2; 1306 set->alloc = set->alloc * 2;
1303 new_elems = re_realloc (set->elems, Idx, set->alloc); 1307 new_elems = re_realloc (set->elems, Idx, set->alloc);
1304 if (BE (new_elems == NULL, 0)) 1308 if (__glibc_unlikely (new_elems == NULL))
1305 return false; 1309 return false;
1306 set->elems = new_elems; 1310 set->elems = new_elems;
1307 } 1311 }
@@ -1310,7 +1314,6 @@ re_node_set_insert (re_node_set *set, Idx elem)
1310 first element separately to skip a check in the inner loop. */ 1314 first element separately to skip a check in the inner loop. */
1311 if (elem < set->elems[0]) 1315 if (elem < set->elems[0])
1312 { 1316 {
1313 idx = 0;
1314 for (idx = set->nelem; idx > 0; idx--) 1317 for (idx = set->nelem; idx > 0; idx--)
1315 set->elems[idx] = set->elems[idx - 1]; 1318 set->elems[idx] = set->elems[idx - 1];
1316 } 1319 }
@@ -1318,6 +1321,7 @@ re_node_set_insert (re_node_set *set, Idx elem)
1318 { 1321 {
1319 for (idx = set->nelem; set->elems[idx - 1] > elem; idx--) 1322 for (idx = set->nelem; set->elems[idx - 1] > elem; idx--)
1320 set->elems[idx] = set->elems[idx - 1]; 1323 set->elems[idx] = set->elems[idx - 1];
1324 DEBUG_ASSERT (set->elems[idx - 1] < elem);
1321 } 1325 }
1322 1326
1323 /* Insert the new element. */ 1327 /* Insert the new element. */
@@ -1331,7 +1335,7 @@ re_node_set_insert (re_node_set *set, Idx elem)
1331 Return true if successful. */ 1335 Return true if successful. */
1332 1336
1333static bool 1337static bool
1334internal_function __attribute_warn_unused_result__ 1338__attribute_warn_unused_result__
1335re_node_set_insert_last (re_node_set *set, Idx elem) 1339re_node_set_insert_last (re_node_set *set, Idx elem)
1336{ 1340{
1337 /* Realloc if we need. */ 1341 /* Realloc if we need. */
@@ -1340,7 +1344,7 @@ re_node_set_insert_last (re_node_set *set, Idx elem)
1340 Idx *new_elems; 1344 Idx *new_elems;
1341 set->alloc = (set->alloc + 1) * 2; 1345 set->alloc = (set->alloc + 1) * 2;
1342 new_elems = re_realloc (set->elems, Idx, set->alloc); 1346 new_elems = re_realloc (set->elems, Idx, set->alloc);
1343 if (BE (new_elems == NULL, 0)) 1347 if (__glibc_unlikely (new_elems == NULL))
1344 return false; 1348 return false;
1345 set->elems = new_elems; 1349 set->elems = new_elems;
1346 } 1350 }
@@ -1354,13 +1358,13 @@ re_node_set_insert_last (re_node_set *set, Idx elem)
1354 Return true if SET1 and SET2 are equivalent. */ 1358 Return true if SET1 and SET2 are equivalent. */
1355 1359
1356static bool 1360static bool
1357internal_function __attribute__ ((pure)) 1361__attribute__ ((pure))
1358re_node_set_compare (const re_node_set *set1, const re_node_set *set2) 1362re_node_set_compare (const re_node_set *set1, const re_node_set *set2)
1359{ 1363{
1360 Idx i; 1364 Idx i;
1361 if (set1 == NULL || set2 == NULL || set1->nelem != set2->nelem) 1365 if (set1 == NULL || set2 == NULL || set1->nelem != set2->nelem)
1362 return false; 1366 return false;
1363 for (i = set1->nelem ; REG_VALID_INDEX (--i) ; ) 1367 for (i = set1->nelem ; --i >= 0 ; )
1364 if (set1->elems[i] != set2->elems[i]) 1368 if (set1->elems[i] != set2->elems[i])
1365 return false; 1369 return false;
1366 return true; 1370 return true;
@@ -1369,11 +1373,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. */ 1373/* Return (idx + 1) if SET contains the element ELEM, return 0 otherwise. */
1370 1374
1371static Idx 1375static Idx
1372internal_function __attribute__ ((pure)) 1376__attribute__ ((pure))
1373re_node_set_contains (const re_node_set *set, Idx elem) 1377re_node_set_contains (const re_node_set *set, Idx elem)
1374{ 1378{
1375 __re_size_t idx, right, mid; 1379 __re_size_t idx, right, mid;
1376 if (! REG_VALID_NONZERO_INDEX (set->nelem)) 1380 if (set->nelem <= 0)
1377 return 0; 1381 return 0;
1378 1382
1379 /* Binary search the element. */ 1383 /* Binary search the element. */
@@ -1391,7 +1395,6 @@ re_node_set_contains (const re_node_set *set, Idx elem)
1391} 1395}
1392 1396
1393static void 1397static void
1394internal_function
1395re_node_set_remove_at (re_node_set *set, Idx idx) 1398re_node_set_remove_at (re_node_set *set, Idx idx)
1396{ 1399{
1397 if (idx < 0 || idx >= set->nelem) 1400 if (idx < 0 || idx >= set->nelem)
@@ -1403,13 +1406,12 @@ re_node_set_remove_at (re_node_set *set, Idx idx)
1403 1406
1404 1407
1405/* Add the token TOKEN to dfa->nodes, and return the index of the token. 1408/* Add the token TOKEN to dfa->nodes, and return the index of the token.
1406 Or return REG_MISSING if an error occurred. */ 1409 Or return -1 if an error occurred. */
1407 1410
1408static Idx 1411static Idx
1409internal_function
1410re_dfa_add_node (re_dfa_t *dfa, re_token_t token) 1412re_dfa_add_node (re_dfa_t *dfa, re_token_t token)
1411{ 1413{
1412 if (BE (dfa->nodes_len >= dfa->nodes_alloc, 0)) 1414 if (__glibc_unlikely (dfa->nodes_len >= dfa->nodes_alloc))
1413 { 1415 {
1414 size_t new_nodes_alloc = dfa->nodes_alloc * 2; 1416 size_t new_nodes_alloc = dfa->nodes_alloc * 2;
1415 Idx *new_nexts, *new_indices; 1417 Idx *new_nexts, *new_indices;
@@ -1420,20 +1422,27 @@ re_dfa_add_node (re_dfa_t *dfa, re_token_t token)
1420 const size_t max_object_size = MAX (sizeof (re_token_t), 1422 const size_t max_object_size = MAX (sizeof (re_token_t),
1421 MAX (sizeof (re_node_set), 1423 MAX (sizeof (re_node_set),
1422 sizeof (Idx))); 1424 sizeof (Idx)));
1423 if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) < new_nodes_alloc, 0)) 1425 if (__glibc_unlikely (MIN (IDX_MAX, SIZE_MAX / max_object_size)
1424 return REG_MISSING; 1426 < new_nodes_alloc))
1427 return -1;
1425 1428
1426 new_nodes = re_realloc (dfa->nodes, re_token_t, new_nodes_alloc); 1429 new_nodes = re_realloc (dfa->nodes, re_token_t, new_nodes_alloc);
1427 if (BE (new_nodes == NULL, 0)) 1430 if (__glibc_unlikely (new_nodes == NULL))
1428 return REG_MISSING; 1431 return -1;
1429 dfa->nodes = new_nodes; 1432 dfa->nodes = new_nodes;
1430 new_nexts = re_realloc (dfa->nexts, Idx, new_nodes_alloc); 1433 new_nexts = re_realloc (dfa->nexts, Idx, new_nodes_alloc);
1431 new_indices = re_realloc (dfa->org_indices, Idx, new_nodes_alloc); 1434 new_indices = re_realloc (dfa->org_indices, Idx, new_nodes_alloc);
1432 new_edests = re_realloc (dfa->edests, re_node_set, new_nodes_alloc); 1435 new_edests = re_realloc (dfa->edests, re_node_set, new_nodes_alloc);
1433 new_eclosures = re_realloc (dfa->eclosures, re_node_set, new_nodes_alloc); 1436 new_eclosures = re_realloc (dfa->eclosures, re_node_set, new_nodes_alloc);
1434 if (BE (new_nexts == NULL || new_indices == NULL 1437 if (__glibc_unlikely (new_nexts == NULL || new_indices == NULL
1435 || new_edests == NULL || new_eclosures == NULL, 0)) 1438 || new_edests == NULL || new_eclosures == NULL))
1436 return REG_MISSING; 1439 {
1440 re_free (new_nexts);
1441 re_free (new_indices);
1442 re_free (new_edests);
1443 re_free (new_eclosures);
1444 return -1;
1445 }
1437 dfa->nexts = new_nexts; 1446 dfa->nexts = new_nexts;
1438 dfa->org_indices = new_indices; 1447 dfa->org_indices = new_indices;
1439 dfa->edests = new_edests; 1448 dfa->edests = new_edests;
@@ -1447,14 +1456,13 @@ re_dfa_add_node (re_dfa_t *dfa, re_token_t token)
1447 ((token.type == OP_PERIOD && dfa->mb_cur_max > 1) 1456 ((token.type == OP_PERIOD && dfa->mb_cur_max > 1)
1448 || token.type == COMPLEX_BRACKET); 1457 || token.type == COMPLEX_BRACKET);
1449#endif 1458#endif
1450 dfa->nexts[dfa->nodes_len] = REG_MISSING; 1459 dfa->nexts[dfa->nodes_len] = -1;
1451 re_node_set_init_empty (dfa->edests + dfa->nodes_len); 1460 re_node_set_init_empty (dfa->edests + dfa->nodes_len);
1452 re_node_set_init_empty (dfa->eclosures + dfa->nodes_len); 1461 re_node_set_init_empty (dfa->eclosures + dfa->nodes_len);
1453 return dfa->nodes_len++; 1462 return dfa->nodes_len++;
1454} 1463}
1455 1464
1456static re_hashval_t 1465static re_hashval_t
1457internal_function
1458calc_state_hash (const re_node_set *nodes, unsigned int context) 1466calc_state_hash (const re_node_set *nodes, unsigned int context)
1459{ 1467{
1460 re_hashval_t hash = nodes->nelem + context; 1468 re_hashval_t hash = nodes->nelem + context;
@@ -1474,7 +1482,7 @@ calc_state_hash (const re_node_set *nodes, unsigned int context)
1474 optimization. */ 1482 optimization. */
1475 1483
1476static re_dfastate_t * 1484static re_dfastate_t *
1477internal_function __attribute_warn_unused_result__ 1485__attribute_warn_unused_result__
1478re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa, 1486re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa,
1479 const re_node_set *nodes) 1487 const re_node_set *nodes)
1480{ 1488{
@@ -1482,11 +1490,11 @@ re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa,
1482 re_dfastate_t *new_state; 1490 re_dfastate_t *new_state;
1483 struct re_state_table_entry *spot; 1491 struct re_state_table_entry *spot;
1484 Idx i; 1492 Idx i;
1485#ifdef lint 1493#if defined GCC_LINT || defined lint
1486 /* Suppress bogus uninitialized-variable warnings. */ 1494 /* Suppress bogus uninitialized-variable warnings. */
1487 *err = REG_NOERROR; 1495 *err = REG_NOERROR;
1488#endif 1496#endif
1489 if (BE (nodes->nelem == 0, 0)) 1497 if (__glibc_unlikely (nodes->nelem == 0))
1490 { 1498 {
1491 *err = REG_NOERROR; 1499 *err = REG_NOERROR;
1492 return NULL; 1500 return NULL;
@@ -1505,7 +1513,7 @@ re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa,
1505 1513
1506 /* There are no appropriate state in the dfa, create the new one. */ 1514 /* There are no appropriate state in the dfa, create the new one. */
1507 new_state = create_ci_newstate (dfa, nodes, hash); 1515 new_state = create_ci_newstate (dfa, nodes, hash);
1508 if (BE (new_state == NULL, 0)) 1516 if (__glibc_unlikely (new_state == NULL))
1509 *err = REG_ESPACE; 1517 *err = REG_ESPACE;
1510 1518
1511 return new_state; 1519 return new_state;
@@ -1522,7 +1530,7 @@ re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa,
1522 optimization. */ 1530 optimization. */
1523 1531
1524static re_dfastate_t * 1532static re_dfastate_t *
1525internal_function __attribute_warn_unused_result__ 1533__attribute_warn_unused_result__
1526re_acquire_state_context (reg_errcode_t *err, const re_dfa_t *dfa, 1534re_acquire_state_context (reg_errcode_t *err, const re_dfa_t *dfa,
1527 const re_node_set *nodes, unsigned int context) 1535 const re_node_set *nodes, unsigned int context)
1528{ 1536{
@@ -1530,7 +1538,7 @@ re_acquire_state_context (reg_errcode_t *err, const re_dfa_t *dfa,
1530 re_dfastate_t *new_state; 1538 re_dfastate_t *new_state;
1531 struct re_state_table_entry *spot; 1539 struct re_state_table_entry *spot;
1532 Idx i; 1540 Idx i;
1533#ifdef lint 1541#if defined GCC_LINT || defined lint
1534 /* Suppress bogus uninitialized-variable warnings. */ 1542 /* Suppress bogus uninitialized-variable warnings. */
1535 *err = REG_NOERROR; 1543 *err = REG_NOERROR;
1536#endif 1544#endif
@@ -1552,7 +1560,7 @@ re_acquire_state_context (reg_errcode_t *err, const re_dfa_t *dfa,
1552 } 1560 }
1553 /* There are no appropriate state in 'dfa', create the new one. */ 1561 /* There are no appropriate state in 'dfa', create the new one. */
1554 new_state = create_cd_newstate (dfa, nodes, context, hash); 1562 new_state = create_cd_newstate (dfa, nodes, context, hash);
1555 if (BE (new_state == NULL, 0)) 1563 if (__glibc_unlikely (new_state == NULL))
1556 *err = REG_ESPACE; 1564 *err = REG_ESPACE;
1557 1565
1558 return new_state; 1566 return new_state;
@@ -1573,7 +1581,7 @@ register_state (const re_dfa_t *dfa, re_dfastate_t *newstate,
1573 1581
1574 newstate->hash = hash; 1582 newstate->hash = hash;
1575 err = re_node_set_alloc (&newstate->non_eps_nodes, newstate->nodes.nelem); 1583 err = re_node_set_alloc (&newstate->non_eps_nodes, newstate->nodes.nelem);
1576 if (BE (err != REG_NOERROR, 0)) 1584 if (__glibc_unlikely (err != REG_NOERROR))
1577 return REG_ESPACE; 1585 return REG_ESPACE;
1578 for (i = 0; i < newstate->nodes.nelem; i++) 1586 for (i = 0; i < newstate->nodes.nelem; i++)
1579 { 1587 {
@@ -1584,12 +1592,12 @@ register_state (const re_dfa_t *dfa, re_dfastate_t *newstate,
1584 } 1592 }
1585 1593
1586 spot = dfa->state_table + (hash & dfa->state_hash_mask); 1594 spot = dfa->state_table + (hash & dfa->state_hash_mask);
1587 if (BE (spot->alloc <= spot->num, 0)) 1595 if (__glibc_unlikely (spot->alloc <= spot->num))
1588 { 1596 {
1589 Idx new_alloc = 2 * spot->num + 2; 1597 Idx new_alloc = 2 * spot->num + 2;
1590 re_dfastate_t **new_array = re_realloc (spot->array, re_dfastate_t *, 1598 re_dfastate_t **new_array = re_realloc (spot->array, re_dfastate_t *,
1591 new_alloc); 1599 new_alloc);
1592 if (BE (new_array == NULL, 0)) 1600 if (__glibc_unlikely (new_array == NULL))
1593 return REG_ESPACE; 1601 return REG_ESPACE;
1594 spot->array = new_array; 1602 spot->array = new_array;
1595 spot->alloc = new_alloc; 1603 spot->alloc = new_alloc;
@@ -1618,7 +1626,7 @@ free_state (re_dfastate_t *state)
1618 Return the new state if succeeded, otherwise return NULL. */ 1626 Return the new state if succeeded, otherwise return NULL. */
1619 1627
1620static re_dfastate_t * 1628static re_dfastate_t *
1621internal_function __attribute_warn_unused_result__ 1629__attribute_warn_unused_result__
1622create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes, 1630create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1623 re_hashval_t hash) 1631 re_hashval_t hash)
1624{ 1632{
@@ -1627,10 +1635,10 @@ create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1627 re_dfastate_t *newstate; 1635 re_dfastate_t *newstate;
1628 1636
1629 newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1); 1637 newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);
1630 if (BE (newstate == NULL, 0)) 1638 if (__glibc_unlikely (newstate == NULL))
1631 return NULL; 1639 return NULL;
1632 err = re_node_set_init_copy (&newstate->nodes, nodes); 1640 err = re_node_set_init_copy (&newstate->nodes, nodes);
1633 if (BE (err != REG_NOERROR, 0)) 1641 if (__glibc_unlikely (err != REG_NOERROR))
1634 { 1642 {
1635 re_free (newstate); 1643 re_free (newstate);
1636 return NULL; 1644 return NULL;
@@ -1656,7 +1664,7 @@ create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1656 newstate->has_constraint = 1; 1664 newstate->has_constraint = 1;
1657 } 1665 }
1658 err = register_state (dfa, newstate, hash); 1666 err = register_state (dfa, newstate, hash);
1659 if (BE (err != REG_NOERROR, 0)) 1667 if (__glibc_unlikely (err != REG_NOERROR))
1660 { 1668 {
1661 free_state (newstate); 1669 free_state (newstate);
1662 newstate = NULL; 1670 newstate = NULL;
@@ -1668,7 +1676,7 @@ create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1668 Return the new state if succeeded, otherwise return NULL. */ 1676 Return the new state if succeeded, otherwise return NULL. */
1669 1677
1670static re_dfastate_t * 1678static re_dfastate_t *
1671internal_function __attribute_warn_unused_result__ 1679__attribute_warn_unused_result__
1672create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes, 1680create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1673 unsigned int context, re_hashval_t hash) 1681 unsigned int context, re_hashval_t hash)
1674{ 1682{
@@ -1677,10 +1685,10 @@ create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1677 re_dfastate_t *newstate; 1685 re_dfastate_t *newstate;
1678 1686
1679 newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1); 1687 newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);
1680 if (BE (newstate == NULL, 0)) 1688 if (__glibc_unlikely (newstate == NULL))
1681 return NULL; 1689 return NULL;
1682 err = re_node_set_init_copy (&newstate->nodes, nodes); 1690 err = re_node_set_init_copy (&newstate->nodes, nodes);
1683 if (BE (err != REG_NOERROR, 0)) 1691 if (__glibc_unlikely (err != REG_NOERROR))
1684 { 1692 {
1685 re_free (newstate); 1693 re_free (newstate);
1686 return NULL; 1694 return NULL;
@@ -1711,15 +1719,19 @@ create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1711 { 1719 {
1712 if (newstate->entrance_nodes == &newstate->nodes) 1720 if (newstate->entrance_nodes == &newstate->nodes)
1713 { 1721 {
1714 newstate->entrance_nodes = re_malloc (re_node_set, 1); 1722 re_node_set *entrance_nodes = re_malloc (re_node_set, 1);
1715 if (BE (newstate->entrance_nodes == NULL, 0)) 1723 if (__glibc_unlikely (entrance_nodes == NULL))
1716 { 1724 {
1717 free_state (newstate); 1725 free_state (newstate);
1718 return NULL; 1726 return NULL;
1719 } 1727 }
1728 newstate->entrance_nodes = entrance_nodes;
1720 if (re_node_set_init_copy (newstate->entrance_nodes, nodes) 1729 if (re_node_set_init_copy (newstate->entrance_nodes, nodes)
1721 != REG_NOERROR) 1730 != REG_NOERROR)
1722 return NULL; 1731 {
1732 free_state (newstate);
1733 return NULL;
1734 }
1723 nctx_nodes = 0; 1735 nctx_nodes = 0;
1724 newstate->has_constraint = 1; 1736 newstate->has_constraint = 1;
1725 } 1737 }
@@ -1732,7 +1744,7 @@ create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1732 } 1744 }
1733 } 1745 }
1734 err = register_state (dfa, newstate, hash); 1746 err = register_state (dfa, newstate, hash);
1735 if (BE (err != REG_NOERROR, 0)) 1747 if (__glibc_unlikely (err != REG_NOERROR))
1736 { 1748 {
1737 free_state (newstate); 1749 free_state (newstate);
1738 newstate = NULL; 1750 newstate = NULL;
diff --git a/gl/regex_internal.h b/gl/regex_internal.h
index a2b8f16..1245e78 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-2021 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>
@@ -33,36 +32,35 @@
33#include <stdbool.h> 32#include <stdbool.h>
34#include <stdint.h> 33#include <stdint.h>
35 34
35#ifndef _LIBC
36# include <dynarray.h>
37#endif
38
39#include <intprops.h>
40#include <verify.h>
41
42#if defined DEBUG && DEBUG != 0
43# include <assert.h>
44# define DEBUG_ASSERT(x) assert (x)
45#else
46# define DEBUG_ASSERT(x) assume (x)
47#endif
48
36#ifdef _LIBC 49#ifdef _LIBC
37# include <bits/libc-lock.h> 50# include <libc-lock.h>
38# define lock_define(name) __libc_lock_define (, name) 51# define lock_define(name) __libc_lock_define (, name)
39# define lock_init(lock) (__libc_lock_init (lock), 0) 52# define lock_init(lock) (__libc_lock_init (lock), 0)
40# define lock_fini(lock) 0 53# define lock_fini(lock) ((void) 0)
41# define lock_lock(lock) __libc_lock_lock (lock) 54# define lock_lock(lock) __libc_lock_lock (lock)
42# define lock_unlock(lock) __libc_lock_unlock (lock) 55# define lock_unlock(lock) __libc_lock_unlock (lock)
43#elif defined GNULIB_LOCK 56#elif defined GNULIB_LOCK && !defined GNULIB_REGEX_SINGLE_THREAD
44# include "glthread/lock.h" 57# include "glthread/lock.h"
45 /* Use gl_lock_define if empty macro arguments are known to work. 58# 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)) 59# define lock_init(lock) glthread_lock_init (&(lock))
62# define lock_fini(lock) glthread_lock_destroy (&(lock)) 60# define lock_fini(lock) glthread_lock_destroy (&(lock))
63# define lock_lock(lock) glthread_lock_lock (&(lock)) 61# define lock_lock(lock) glthread_lock_lock (&(lock))
64# define lock_unlock(lock) glthread_lock_unlock (&(lock)) 62# define lock_unlock(lock) glthread_lock_unlock (&(lock))
65#elif defined GNULIB_PTHREAD 63#elif defined GNULIB_PTHREAD && !defined GNULIB_REGEX_SINGLE_THREAD
66# include <pthread.h> 64# include <pthread.h>
67# define lock_define(name) pthread_mutex_t name; 65# define lock_define(name) pthread_mutex_t name;
68# define lock_init(lock) pthread_mutex_init (&(lock), 0) 66# define lock_init(lock) pthread_mutex_init (&(lock), 0)
@@ -83,11 +81,18 @@
83# define isblank(ch) ((ch) == ' ' || (ch) == '\t') 81# define isblank(ch) ((ch) == ' ' || (ch) == '\t')
84#endif 82#endif
85 83
84/* regex code assumes isascii has its usual numeric meaning,
85 even if the portable character set uses EBCDIC encoding,
86 and even if wint_t is wider than int. */
87#ifndef _LIBC
88# undef isascii
89# define isascii(c) (((c) & ~0x7f) == 0)
90#endif
91
86#ifdef _LIBC 92#ifdef _LIBC
87# ifndef _RE_DEFINE_LOCALE_FUNCTIONS 93# ifndef _RE_DEFINE_LOCALE_FUNCTIONS
88# define _RE_DEFINE_LOCALE_FUNCTIONS 1 94# define _RE_DEFINE_LOCALE_FUNCTIONS 1
89# include <locale/localeinfo.h> 95# include <locale/localeinfo.h>
90# include <locale/elem-hash.h>
91# include <locale/coll-lookup.h> 96# include <locale/coll-lookup.h>
92# endif 97# endif
93#endif 98#endif
@@ -101,6 +106,7 @@
101 __dcgettext (_libc_intl_domainname, msgid, LC_MESSAGES) 106 __dcgettext (_libc_intl_domainname, msgid, LC_MESSAGES)
102# endif 107# endif
103#else 108#else
109# undef gettext
104# define gettext(msgid) (msgid) 110# define gettext(msgid) (msgid)
105#endif 111#endif
106 112
@@ -110,16 +116,10 @@
110# define gettext_noop(String) String 116# define gettext_noop(String) String
111#endif 117#endif
112 118
113#if (defined MB_CUR_MAX && HAVE_WCTYPE_H && HAVE_ISWCTYPE && HAVE_WCSCOLL) || _LIBC 119#if (defined MB_CUR_MAX && HAVE_WCTYPE_H && HAVE_ISWCTYPE) || _LIBC
114# define RE_ENABLE_I18N 120# define RE_ENABLE_I18N
115#endif 121#endif
116 122
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. */ 123/* Number of ASCII characters. */
124#define ASCII_CHARS 0x80 124#define ASCII_CHARS 0x80
125 125
@@ -135,45 +135,55 @@
135/* Rename to standard API for using out of glibc. */ 135/* Rename to standard API for using out of glibc. */
136#ifndef _LIBC 136#ifndef _LIBC
137# undef __wctype 137# undef __wctype
138# undef __iswalnum
138# undef __iswctype 139# undef __iswctype
140# undef __towlower
141# undef __towupper
139# define __wctype wctype 142# define __wctype wctype
143# define __iswalnum iswalnum
140# define __iswctype iswctype 144# define __iswctype iswctype
145# define __towlower towlower
146# define __towupper towupper
141# define __btowc btowc 147# define __btowc btowc
142# define __mbrtowc mbrtowc 148# define __mbrtowc mbrtowc
143# define __wcrtomb wcrtomb 149# define __wcrtomb wcrtomb
144# define __regfree regfree 150# define __regfree regfree
145# define attribute_hidden
146#endif /* not _LIBC */ 151#endif /* not _LIBC */
147 152
148#if __GNUC__ < 3 + (__GNUC_MINOR__ < 1) 153#ifndef SSIZE_MAX
149# define __attribute__(arg) 154# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
150#endif
151
152typedef __re_idx_t Idx;
153#ifdef _REGEX_LARGE_OFFSETS
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)
@@ -365,7 +347,7 @@ typedef struct
365 Idx idx; /* for BACK_REF */ 347 Idx idx; /* for BACK_REF */
366 re_context_type ctx_type; /* for ANCHOR */ 348 re_context_type ctx_type; /* for ANCHOR */
367 } opr; 349 } opr;
368#if __GNUC__ >= 2 && !defined __STRICT_ANSI__ 350#if (__GNUC__ >= 2 || defined __clang__) && !defined __STRICT_ANSI__
369 re_token_type_t type : 8; 351 re_token_type_t type : 8;
370#else 352#else
371 re_token_type_t type; 353 re_token_type_t type;
@@ -446,24 +428,9 @@ struct re_dfa_t;
446typedef struct re_dfa_t re_dfa_t; 428typedef struct re_dfa_t re_dfa_t;
447 429
448#ifndef _LIBC 430#ifndef _LIBC
449# define internal_function 431# define IS_IN(libc) false
450#endif 432#endif
451 433
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) \ 434#define re_string_peek_byte(pstr, offset) \
468 ((pstr)->mbs[(pstr)->cur_idx + offset]) 435 ((pstr)->mbs[(pstr)->cur_idx + offset])
469#define re_string_fetch_byte(pstr) \ 436#define re_string_fetch_byte(pstr) \
@@ -481,25 +448,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)) 448#define re_string_skip_bytes(pstr,idx) ((pstr)->cur_idx += (idx))
482#define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx)) 449#define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx))
483 450
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 451#ifdef _LIBC
504# define MALLOC_0_IS_NONNULL 1 452# define MALLOC_0_IS_NONNULL 1
505#elif !defined MALLOC_0_IS_NONNULL 453#elif !defined MALLOC_0_IS_NONNULL
@@ -556,7 +504,7 @@ typedef struct bin_tree_storage_t bin_tree_storage_t;
556 504
557#define IS_WORD_CHAR(ch) (isalnum (ch) || (ch) == '_') 505#define IS_WORD_CHAR(ch) (isalnum (ch) || (ch) == '_')
558#define IS_NEWLINE(ch) ((ch) == NEWLINE_CHAR) 506#define IS_NEWLINE(ch) ((ch) == NEWLINE_CHAR)
559#define IS_WIDE_WORD_CHAR(ch) (iswalnum (ch) || (ch) == L'_') 507#define IS_WIDE_WORD_CHAR(ch) (__iswalnum (ch) || (ch) == L'_')
560#define IS_WIDE_NEWLINE(ch) ((ch) == WIDE_NEWLINE_CHAR) 508#define IS_WIDE_NEWLINE(ch) ((ch) == WIDE_NEWLINE_CHAR)
561 509
562#define NOT_SATISFY_PREV_CONSTRAINT(constraint,context) \ 510#define NOT_SATISFY_PREV_CONSTRAINT(constraint,context) \
@@ -636,20 +584,15 @@ struct re_backref_cache_entry
636 Idx str_idx; 584 Idx str_idx;
637 Idx subexp_from; 585 Idx subexp_from;
638 Idx subexp_to; 586 Idx subexp_to;
587 bitset_word_t eps_reachable_subexps_map;
639 char more; 588 char more;
640 char unused;
641 unsigned short int eps_reachable_subexps_map;
642}; 589};
643 590
644typedef struct 591typedef struct
645{ 592{
646 /* The string object corresponding to the input string. */ 593 /* The string object corresponding to the input string. */
647 re_string_t input; 594 re_string_t input;
648#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
649 const re_dfa_t *const dfa; 595 const re_dfa_t *const dfa;
650#else
651 const re_dfa_t *dfa;
652#endif
653 /* EFLAGS of the argument of regexec. */ 596 /* EFLAGS of the argument of regexec. */
654 int eflags; 597 int eflags;
655 /* Where the matching ends. */ 598 /* Where the matching ends. */
@@ -769,31 +712,31 @@ typedef struct
769 712
770/* Functions for bitset_t operation. */ 713/* Functions for bitset_t operation. */
771 714
772static void 715static inline void
773bitset_set (bitset_t set, Idx i) 716bitset_set (bitset_t set, Idx i)
774{ 717{
775 set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS; 718 set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS;
776} 719}
777 720
778static void 721static inline void
779bitset_clear (bitset_t set, Idx i) 722bitset_clear (bitset_t set, Idx i)
780{ 723{
781 set[i / BITSET_WORD_BITS] &= ~ ((bitset_word_t) 1 << i % BITSET_WORD_BITS); 724 set[i / BITSET_WORD_BITS] &= ~ ((bitset_word_t) 1 << i % BITSET_WORD_BITS);
782} 725}
783 726
784static bool 727static inline bool
785bitset_contain (const bitset_t set, Idx i) 728bitset_contain (const bitset_t set, Idx i)
786{ 729{
787 return (set[i / BITSET_WORD_BITS] >> i % BITSET_WORD_BITS) & 1; 730 return (set[i / BITSET_WORD_BITS] >> i % BITSET_WORD_BITS) & 1;
788} 731}
789 732
790static void 733static inline void
791bitset_empty (bitset_t set) 734bitset_empty (bitset_t set)
792{ 735{
793 memset (set, '\0', sizeof (bitset_t)); 736 memset (set, '\0', sizeof (bitset_t));
794} 737}
795 738
796static void 739static inline void
797bitset_set_all (bitset_t set) 740bitset_set_all (bitset_t set)
798{ 741{
799 memset (set, -1, sizeof (bitset_word_t) * (SBC_MAX / BITSET_WORD_BITS)); 742 memset (set, -1, sizeof (bitset_word_t) * (SBC_MAX / BITSET_WORD_BITS));
@@ -802,13 +745,13 @@ bitset_set_all (bitset_t set)
802 ((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1; 745 ((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1;
803} 746}
804 747
805static void 748static inline void
806bitset_copy (bitset_t dest, const bitset_t src) 749bitset_copy (bitset_t dest, const bitset_t src)
807{ 750{
808 memcpy (dest, src, sizeof (bitset_t)); 751 memcpy (dest, src, sizeof (bitset_t));
809} 752}
810 753
811static void __attribute__ ((unused)) 754static inline void
812bitset_not (bitset_t set) 755bitset_not (bitset_t set)
813{ 756{
814 int bitset_i; 757 int bitset_i;
@@ -820,7 +763,7 @@ bitset_not (bitset_t set)
820 & ~set[BITSET_WORDS - 1]); 763 & ~set[BITSET_WORDS - 1]);
821} 764}
822 765
823static void __attribute__ ((unused)) 766static inline void
824bitset_merge (bitset_t dest, const bitset_t src) 767bitset_merge (bitset_t dest, const bitset_t src)
825{ 768{
826 int bitset_i; 769 int bitset_i;
@@ -828,7 +771,7 @@ bitset_merge (bitset_t dest, const bitset_t src)
828 dest[bitset_i] |= src[bitset_i]; 771 dest[bitset_i] |= src[bitset_i];
829} 772}
830 773
831static void __attribute__ ((unused)) 774static inline void
832bitset_mask (bitset_t dest, const bitset_t src) 775bitset_mask (bitset_t dest, const bitset_t src)
833{ 776{
834 int bitset_i; 777 int bitset_i;
@@ -839,7 +782,7 @@ bitset_mask (bitset_t dest, const bitset_t src)
839#ifdef RE_ENABLE_I18N 782#ifdef RE_ENABLE_I18N
840/* Functions for re_string. */ 783/* Functions for re_string. */
841static int 784static int
842internal_function __attribute__ ((pure, unused)) 785__attribute__ ((pure, unused))
843re_string_char_size_at (const re_string_t *pstr, Idx idx) 786re_string_char_size_at (const re_string_t *pstr, Idx idx)
844{ 787{
845 int byte_idx; 788 int byte_idx;
@@ -852,7 +795,7 @@ re_string_char_size_at (const re_string_t *pstr, Idx idx)
852} 795}
853 796
854static wint_t 797static wint_t
855internal_function __attribute__ ((pure, unused)) 798__attribute__ ((pure, unused))
856re_string_wchar_at (const re_string_t *pstr, Idx idx) 799re_string_wchar_at (const re_string_t *pstr, Idx idx)
857{ 800{
858 if (pstr->mb_cur_max == 1) 801 if (pstr->mb_cur_max == 1)
@@ -860,15 +803,17 @@ re_string_wchar_at (const re_string_t *pstr, Idx idx)
860 return (wint_t) pstr->wcs[idx]; 803 return (wint_t) pstr->wcs[idx];
861} 804}
862 805
863# ifndef NOT_IN_libc 806# ifdef _LIBC
807# include <locale/weight.h>
808# endif
809
864static int 810static int
865internal_function __attribute__ ((pure, unused)) 811__attribute__ ((pure, unused))
866re_string_elem_size_at (const re_string_t *pstr, Idx idx) 812re_string_elem_size_at (const re_string_t *pstr, Idx idx)
867{ 813{
868# ifdef _LIBC 814# ifdef _LIBC
869 const unsigned char *p, *extra; 815 const unsigned char *p, *extra;
870 const int32_t *table, *indirect; 816 const int32_t *table, *indirect;
871# include <locale/weight.h>
872 uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); 817 uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
873 818
874 if (nrules != 0) 819 if (nrules != 0)
@@ -879,31 +824,23 @@ re_string_elem_size_at (const re_string_t *pstr, Idx idx)
879 indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE, 824 indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE,
880 _NL_COLLATE_INDIRECTMB); 825 _NL_COLLATE_INDIRECTMB);
881 p = pstr->mbs + idx; 826 p = pstr->mbs + idx;
882 findidx (&p, pstr->len - idx); 827 findidx (table, indirect, extra, &p, pstr->len - idx);
883 return p - pstr->mbs - idx; 828 return p - pstr->mbs - idx;
884 } 829 }
885 else 830 else
886# endif /* _LIBC */ 831# endif /* _LIBC */
887 return 1; 832 return 1;
888} 833}
889# endif
890#endif /* RE_ENABLE_I18N */ 834#endif /* RE_ENABLE_I18N */
891 835
892#ifndef __GNUC_PREREQ 836#ifdef _LIBC
893# if defined __GNUC__ && defined __GNUC_MINOR__ 837# if __GNUC__ >= 7
894# define __GNUC_PREREQ(maj, min) \ 838# define FALLTHROUGH __attribute__ ((__fallthrough__))
895 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
896# else 839# else
897# define __GNUC_PREREQ(maj, min) 0 840# define FALLTHROUGH ((void) 0)
898# endif 841# 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 842#else
906# define __attribute_warn_unused_result__ /* empty */ 843# include "attribute.h"
907#endif 844#endif
908 845
909#endif /* _REGEX_INTERNAL_H */ 846#endif /* _REGEX_INTERNAL_H */
diff --git a/gl/regexec.c b/gl/regexec.c
index d29d442..6aeba3c 100644
--- a/gl/regexec.c
+++ b/gl/regexec.c
@@ -1,206 +1,176 @@
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-2021 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 70#ifdef RE_ENABLE_I18N
79static int sift_states_iter_mb (const re_match_context_t *mctx, 71static int sift_states_iter_mb (const re_match_context_t *mctx,
80 re_sift_context_t *sctx, 72 re_sift_context_t *sctx,
81 Idx node_idx, Idx str_idx, Idx max_str_idx) 73 Idx node_idx, Idx str_idx, Idx max_str_idx);
82 internal_function;
83#endif /* RE_ENABLE_I18N */ 74#endif /* RE_ENABLE_I18N */
84static reg_errcode_t sift_states_backward (const re_match_context_t *mctx, 75static reg_errcode_t sift_states_backward (const re_match_context_t *mctx,
85 re_sift_context_t *sctx) 76 re_sift_context_t *sctx);
86 internal_function;
87static reg_errcode_t build_sifted_states (const re_match_context_t *mctx, 77static reg_errcode_t build_sifted_states (const re_match_context_t *mctx,
88 re_sift_context_t *sctx, Idx str_idx, 78 re_sift_context_t *sctx, Idx str_idx,
89 re_node_set *cur_dest) 79 re_node_set *cur_dest);
90 internal_function;
91static reg_errcode_t update_cur_sifted_state (const re_match_context_t *mctx, 80static reg_errcode_t update_cur_sifted_state (const re_match_context_t *mctx,
92 re_sift_context_t *sctx, 81 re_sift_context_t *sctx,
93 Idx str_idx, 82 Idx str_idx,
94 re_node_set *dest_nodes) 83 re_node_set *dest_nodes);
95 internal_function;
96static reg_errcode_t add_epsilon_src_nodes (const re_dfa_t *dfa, 84static reg_errcode_t add_epsilon_src_nodes (const re_dfa_t *dfa,
97 re_node_set *dest_nodes, 85 re_node_set *dest_nodes,
98 const re_node_set *candidates) 86 const re_node_set *candidates);
99 internal_function;
100static bool check_dst_limits (const re_match_context_t *mctx, 87static bool check_dst_limits (const re_match_context_t *mctx,
101 const re_node_set *limits, 88 const re_node_set *limits,
102 Idx dst_node, Idx dst_idx, Idx src_node, 89 Idx dst_node, Idx dst_idx, Idx src_node,
103 Idx src_idx) internal_function; 90 Idx src_idx);
104static int check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, 91static int check_dst_limits_calc_pos_1 (const re_match_context_t *mctx,
105 int boundaries, Idx subexp_idx, 92 int boundaries, Idx subexp_idx,
106 Idx from_node, Idx bkref_idx) 93 Idx from_node, Idx bkref_idx);
107 internal_function;
108static int check_dst_limits_calc_pos (const re_match_context_t *mctx, 94static int check_dst_limits_calc_pos (const re_match_context_t *mctx,
109 Idx limit, Idx subexp_idx, 95 Idx limit, Idx subexp_idx,
110 Idx node, Idx str_idx, 96 Idx node, Idx str_idx,
111 Idx bkref_idx) internal_function; 97 Idx bkref_idx);
112static reg_errcode_t check_subexp_limits (const re_dfa_t *dfa, 98static reg_errcode_t check_subexp_limits (const re_dfa_t *dfa,
113 re_node_set *dest_nodes, 99 re_node_set *dest_nodes,
114 const re_node_set *candidates, 100 const re_node_set *candidates,
115 re_node_set *limits, 101 re_node_set *limits,
116 struct re_backref_cache_entry *bkref_ents, 102 struct re_backref_cache_entry *bkref_ents,
117 Idx str_idx) internal_function; 103 Idx str_idx);
118static reg_errcode_t sift_states_bkref (const re_match_context_t *mctx, 104static reg_errcode_t sift_states_bkref (const re_match_context_t *mctx,
119 re_sift_context_t *sctx, 105 re_sift_context_t *sctx,
120 Idx str_idx, const re_node_set *candidates) 106 Idx str_idx, const re_node_set *candidates);
121 internal_function;
122static reg_errcode_t merge_state_array (const re_dfa_t *dfa, 107static reg_errcode_t merge_state_array (const re_dfa_t *dfa,
123 re_dfastate_t **dst, 108 re_dfastate_t **dst,
124 re_dfastate_t **src, Idx num) 109 re_dfastate_t **src, Idx num);
125 internal_function;
126static re_dfastate_t *find_recover_state (reg_errcode_t *err, 110static re_dfastate_t *find_recover_state (reg_errcode_t *err,
127 re_match_context_t *mctx) internal_function; 111 re_match_context_t *mctx);
128static re_dfastate_t *transit_state (reg_errcode_t *err, 112static re_dfastate_t *transit_state (reg_errcode_t *err,
129 re_match_context_t *mctx, 113 re_match_context_t *mctx,
130 re_dfastate_t *state) internal_function; 114 re_dfastate_t *state);
131static re_dfastate_t *merge_state_with_log (reg_errcode_t *err, 115static re_dfastate_t *merge_state_with_log (reg_errcode_t *err,
132 re_match_context_t *mctx, 116 re_match_context_t *mctx,
133 re_dfastate_t *next_state) 117 re_dfastate_t *next_state);
134 internal_function;
135static reg_errcode_t check_subexp_matching_top (re_match_context_t *mctx, 118static reg_errcode_t check_subexp_matching_top (re_match_context_t *mctx,
136 re_node_set *cur_nodes, 119 re_node_set *cur_nodes,
137 Idx str_idx) internal_function; 120 Idx str_idx);
138#if 0 121#if 0
139static re_dfastate_t *transit_state_sb (reg_errcode_t *err, 122static re_dfastate_t *transit_state_sb (reg_errcode_t *err,
140 re_match_context_t *mctx, 123 re_match_context_t *mctx,
141 re_dfastate_t *pstate) 124 re_dfastate_t *pstate);
142 internal_function;
143#endif 125#endif
144#ifdef RE_ENABLE_I18N 126#ifdef RE_ENABLE_I18N
145static reg_errcode_t transit_state_mb (re_match_context_t *mctx, 127static reg_errcode_t transit_state_mb (re_match_context_t *mctx,
146 re_dfastate_t *pstate) 128 re_dfastate_t *pstate);
147 internal_function;
148#endif /* RE_ENABLE_I18N */ 129#endif /* RE_ENABLE_I18N */
149static reg_errcode_t transit_state_bkref (re_match_context_t *mctx, 130static reg_errcode_t transit_state_bkref (re_match_context_t *mctx,
150 const re_node_set *nodes) 131 const re_node_set *nodes);
151 internal_function;
152static reg_errcode_t get_subexp (re_match_context_t *mctx, 132static reg_errcode_t get_subexp (re_match_context_t *mctx,
153 Idx bkref_node, Idx bkref_str_idx) 133 Idx bkref_node, Idx bkref_str_idx);
154 internal_function;
155static reg_errcode_t get_subexp_sub (re_match_context_t *mctx, 134static reg_errcode_t get_subexp_sub (re_match_context_t *mctx,
156 const re_sub_match_top_t *sub_top, 135 const re_sub_match_top_t *sub_top,
157 re_sub_match_last_t *sub_last, 136 re_sub_match_last_t *sub_last,
158 Idx bkref_node, Idx bkref_str) 137 Idx bkref_node, Idx bkref_str);
159 internal_function;
160static Idx find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes, 138static Idx find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
161 Idx subexp_idx, int type) internal_function; 139 Idx subexp_idx, int type);
162static reg_errcode_t check_arrival (re_match_context_t *mctx, 140static reg_errcode_t check_arrival (re_match_context_t *mctx,
163 state_array_t *path, Idx top_node, 141 state_array_t *path, Idx top_node,
164 Idx top_str, Idx last_node, Idx last_str, 142 Idx top_str, Idx last_node, Idx last_str,
165 int type) internal_function; 143 int type);
166static reg_errcode_t check_arrival_add_next_nodes (re_match_context_t *mctx, 144static reg_errcode_t check_arrival_add_next_nodes (re_match_context_t *mctx,
167 Idx str_idx, 145 Idx str_idx,
168 re_node_set *cur_nodes, 146 re_node_set *cur_nodes,
169 re_node_set *next_nodes) 147 re_node_set *next_nodes);
170 internal_function;
171static reg_errcode_t check_arrival_expand_ecl (const re_dfa_t *dfa, 148static reg_errcode_t check_arrival_expand_ecl (const re_dfa_t *dfa,
172 re_node_set *cur_nodes, 149 re_node_set *cur_nodes,
173 Idx ex_subexp, int type) 150 Idx ex_subexp, int type);
174 internal_function;
175static reg_errcode_t check_arrival_expand_ecl_sub (const re_dfa_t *dfa, 151static reg_errcode_t check_arrival_expand_ecl_sub (const re_dfa_t *dfa,
176 re_node_set *dst_nodes, 152 re_node_set *dst_nodes,
177 Idx target, Idx ex_subexp, 153 Idx target, Idx ex_subexp,
178 int type) internal_function; 154 int type);
179static reg_errcode_t expand_bkref_cache (re_match_context_t *mctx, 155static reg_errcode_t expand_bkref_cache (re_match_context_t *mctx,
180 re_node_set *cur_nodes, Idx cur_str, 156 re_node_set *cur_nodes, Idx cur_str,
181 Idx subexp_num, int type) 157 Idx subexp_num, int type);
182 internal_function; 158static 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 159#ifdef RE_ENABLE_I18N
186static int check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx, 160static int check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
187 const re_string_t *input, Idx idx) 161 const re_string_t *input, Idx idx);
188 internal_function;
189# ifdef _LIBC 162# ifdef _LIBC
190static unsigned int find_collation_sequence_value (const unsigned char *mbs, 163static unsigned int find_collation_sequence_value (const unsigned char *mbs,
191 size_t name_len) 164 size_t name_len);
192 internal_function;
193# endif /* _LIBC */ 165# endif /* _LIBC */
194#endif /* RE_ENABLE_I18N */ 166#endif /* RE_ENABLE_I18N */
195static Idx group_nodes_into_DFAstates (const re_dfa_t *dfa, 167static Idx group_nodes_into_DFAstates (const re_dfa_t *dfa,
196 const re_dfastate_t *state, 168 const re_dfastate_t *state,
197 re_node_set *states_node, 169 re_node_set *states_node,
198 bitset_t *states_ch) internal_function; 170 bitset_t *states_ch);
199static bool check_node_accept (const re_match_context_t *mctx, 171static bool check_node_accept (const re_match_context_t *mctx,
200 const re_token_t *node, Idx idx) 172 const re_token_t *node, Idx idx);
201 internal_function; 173static 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 174
205/* Entry point for POSIX code. */ 175/* Entry point for POSIX code. */
206 176
@@ -216,15 +186,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 186 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. 187 string; if REG_NOTEOL is set, then $ does not match at the end.
218 188
219 We return 0 if we find a match and REG_NOMATCH if not. */ 189 Return 0 if a match is found, REG_NOMATCH if not, REG_BADPAT if
190 EFLAGS is invalid. */
220 191
221int 192int
222regexec (preg, string, nmatch, pmatch, eflags) 193regexec (const regex_t *__restrict preg, const char *__restrict string,
223 const regex_t *_Restrict_ preg; 194 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{ 195{
229 reg_errcode_t err; 196 reg_errcode_t err;
230 Idx start, length; 197 Idx start, length;
@@ -256,6 +223,8 @@ regexec (preg, string, nmatch, pmatch, eflags)
256} 223}
257 224
258#ifdef _LIBC 225#ifdef _LIBC
226libc_hidden_def (__regexec)
227
259# include <shlib-compat.h> 228# include <shlib-compat.h>
260versioned_symbol (libc, __regexec, regexec, GLIBC_2_3_4); 229versioned_symbol (libc, __regexec, regexec, GLIBC_2_3_4);
261 230
@@ -264,9 +233,9 @@ __typeof__ (__regexec) __compat_regexec;
264 233
265int 234int
266attribute_compat_text_section 235attribute_compat_text_section
267__compat_regexec (const regex_t *_Restrict_ preg, 236__compat_regexec (const regex_t *__restrict preg,
268 const char *_Restrict_ string, size_t nmatch, 237 const char *__restrict string, size_t nmatch,
269 regmatch_t pmatch[], int eflags) 238 regmatch_t pmatch[_REGEX_NELTS (nmatch)], int eflags)
270{ 239{
271 return regexec (preg, string, nmatch, pmatch, 240 return regexec (preg, string, nmatch, pmatch,
272 eflags & (REG_NOTBOL | REG_NOTEOL)); 241 eflags & (REG_NOTBOL | REG_NOTEOL));
@@ -301,15 +270,12 @@ compat_symbol (libc, __compat_regexec, regexec, GLIBC_2_0);
301 strings.) 270 strings.)
302 271
303 On success, re_match* functions return the length of the match, re_search* 272 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 273 return the position of the start of the match. They return -1 on
305 match was found and -2 indicates an internal error. */ 274 match failure, -2 on error. */
306 275
307regoff_t 276regoff_t
308re_match (bufp, string, length, start, regs) 277re_match (struct re_pattern_buffer *bufp, const char *string, Idx length,
309 struct re_pattern_buffer *bufp; 278 Idx start, struct re_registers *regs)
310 const char *string;
311 Idx length, start;
312 struct re_registers *regs;
313{ 279{
314 return re_search_stub (bufp, string, length, start, 0, length, regs, true); 280 return re_search_stub (bufp, string, length, start, 0, length, regs, true);
315} 281}
@@ -318,12 +284,8 @@ weak_alias (__re_match, re_match)
318#endif 284#endif
319 285
320regoff_t 286regoff_t
321re_search (bufp, string, length, start, range, regs) 287re_search (struct re_pattern_buffer *bufp, const char *string, Idx length,
322 struct re_pattern_buffer *bufp; 288 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{ 289{
328 return re_search_stub (bufp, string, length, start, range, length, regs, 290 return re_search_stub (bufp, string, length, start, range, length, regs,
329 false); 291 false);
@@ -333,11 +295,9 @@ weak_alias (__re_search, re_search)
333#endif 295#endif
334 296
335regoff_t 297regoff_t
336re_match_2 (bufp, string1, length1, string2, length2, start, regs, stop) 298re_match_2 (struct re_pattern_buffer *bufp, const char *string1, Idx length1,
337 struct re_pattern_buffer *bufp; 299 const char *string2, Idx length2, Idx start,
338 const char *string1, *string2; 300 struct re_registers *regs, Idx stop)
339 Idx length1, length2, start, stop;
340 struct re_registers *regs;
341{ 301{
342 return re_search_2_stub (bufp, string1, length1, string2, length2, 302 return re_search_2_stub (bufp, string1, length1, string2, length2,
343 start, 0, regs, stop, true); 303 start, 0, regs, stop, true);
@@ -347,12 +307,9 @@ weak_alias (__re_match_2, re_match_2)
347#endif 307#endif
348 308
349regoff_t 309regoff_t
350re_search_2 (bufp, string1, length1, string2, length2, start, range, regs, stop) 310re_search_2 (struct re_pattern_buffer *bufp, const char *string1, Idx length1,
351 struct re_pattern_buffer *bufp; 311 const char *string2, Idx length2, Idx start, regoff_t range,
352 const char *string1, *string2; 312 struct re_registers *regs, Idx stop)
353 Idx length1, length2, start, stop;
354 regoff_t range;
355 struct re_registers *regs;
356{ 313{
357 return re_search_2_stub (bufp, string1, length1, string2, length2, 314 return re_search_2_stub (bufp, string1, length1, string2, length2,
358 start, range, regs, stop, false); 315 start, range, regs, stop, false);
@@ -362,18 +319,18 @@ weak_alias (__re_search_2, re_search_2)
362#endif 319#endif
363 320
364static regoff_t 321static regoff_t
365re_search_2_stub (struct re_pattern_buffer *bufp, 322re_search_2_stub (struct re_pattern_buffer *bufp, const char *string1,
366 const char *string1, Idx length1, 323 Idx length1, const char *string2, Idx length2, Idx start,
367 const char *string2, Idx length2, 324 regoff_t range, struct re_registers *regs,
368 Idx start, regoff_t range, struct re_registers *regs,
369 Idx stop, bool ret_len) 325 Idx stop, bool ret_len)
370{ 326{
371 const char *str; 327 const char *str;
372 regoff_t rval; 328 regoff_t rval;
373 Idx len = length1 + length2; 329 Idx len;
374 char *s = NULL; 330 char *s = NULL;
375 331
376 if (BE (length1 < 0 || length2 < 0 || stop < 0 || len < length1, 0)) 332 if (__glibc_unlikely ((length1 < 0 || length2 < 0 || stop < 0
333 || INT_ADD_WRAPV (length1, length2, &len))))
377 return -2; 334 return -2;
378 335
379 /* Concatenate the strings. */ 336 /* Concatenate the strings. */
@@ -382,7 +339,7 @@ re_search_2_stub (struct re_pattern_buffer *bufp,
382 { 339 {
383 s = re_malloc (char, len); 340 s = re_malloc (char, len);
384 341
385 if (BE (s == NULL, 0)) 342 if (__glibc_unlikely (s == NULL))
386 return -2; 343 return -2;
387#ifdef _LIBC 344#ifdef _LIBC
388 memcpy (__mempcpy (s, string1, length1), string2, length2); 345 memcpy (__mempcpy (s, string1, length1), string2, length2);
@@ -409,8 +366,7 @@ re_search_2_stub (struct re_pattern_buffer *bufp,
409 otherwise the position of the match is returned. */ 366 otherwise the position of the match is returned. */
410 367
411static regoff_t 368static regoff_t
412re_search_stub (struct re_pattern_buffer *bufp, 369re_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, 370 Idx start, regoff_t range, Idx stop, struct re_registers *regs,
415 bool ret_len) 371 bool ret_len)
416{ 372{
@@ -423,11 +379,13 @@ re_search_stub (struct re_pattern_buffer *bufp,
423 Idx last_start = start + range; 379 Idx last_start = start + range;
424 380
425 /* Check for out-of-range. */ 381 /* Check for out-of-range. */
426 if (BE (start < 0 || start > length, 0)) 382 if (__glibc_unlikely (start < 0 || start > length))
427 return -1; 383 return -1;
428 if (BE (length < last_start || (0 <= range && last_start < start), 0)) 384 if (__glibc_unlikely (length < last_start
385 || (0 <= range && last_start < start)))
429 last_start = length; 386 last_start = length;
430 else if (BE (last_start < 0 || (range < 0 && start <= last_start), 0)) 387 else if (__glibc_unlikely (last_start < 0
388 || (range < 0 && start <= last_start)))
431 last_start = 0; 389 last_start = 0;
432 390
433 lock_lock (dfa->lock); 391 lock_lock (dfa->lock);
@@ -439,17 +397,17 @@ re_search_stub (struct re_pattern_buffer *bufp,
439 if (start < last_start && bufp->fastmap != NULL && !bufp->fastmap_accurate) 397 if (start < last_start && bufp->fastmap != NULL && !bufp->fastmap_accurate)
440 re_compile_fastmap (bufp); 398 re_compile_fastmap (bufp);
441 399
442 if (BE (bufp->no_sub, 0)) 400 if (__glibc_unlikely (bufp->no_sub))
443 regs = NULL; 401 regs = NULL;
444 402
445 /* We need at least 1 register. */ 403 /* We need at least 1 register. */
446 if (regs == NULL) 404 if (regs == NULL)
447 nregs = 1; 405 nregs = 1;
448 else if (BE (bufp->regs_allocated == REGS_FIXED 406 else if (__glibc_unlikely (bufp->regs_allocated == REGS_FIXED
449 && regs->num_regs <= bufp->re_nsub, 0)) 407 && regs->num_regs <= bufp->re_nsub))
450 { 408 {
451 nregs = regs->num_regs; 409 nregs = regs->num_regs;
452 if (BE (nregs < 1, 0)) 410 if (__glibc_unlikely (nregs < 1))
453 { 411 {
454 /* Nothing can be copied to regs. */ 412 /* Nothing can be copied to regs. */
455 regs = NULL; 413 regs = NULL;
@@ -459,7 +417,7 @@ re_search_stub (struct re_pattern_buffer *bufp,
459 else 417 else
460 nregs = bufp->re_nsub + 1; 418 nregs = bufp->re_nsub + 1;
461 pmatch = re_malloc (regmatch_t, nregs); 419 pmatch = re_malloc (regmatch_t, nregs);
462 if (BE (pmatch == NULL, 0)) 420 if (__glibc_unlikely (pmatch == NULL))
463 { 421 {
464 rval = -2; 422 rval = -2;
465 goto out; 423 goto out;
@@ -478,15 +436,15 @@ re_search_stub (struct re_pattern_buffer *bufp,
478 /* If caller wants register contents data back, copy them. */ 436 /* If caller wants register contents data back, copy them. */
479 bufp->regs_allocated = re_copy_regs (regs, pmatch, nregs, 437 bufp->regs_allocated = re_copy_regs (regs, pmatch, nregs,
480 bufp->regs_allocated); 438 bufp->regs_allocated);
481 if (BE (bufp->regs_allocated == REGS_UNALLOCATED, 0)) 439 if (__glibc_unlikely (bufp->regs_allocated == REGS_UNALLOCATED))
482 rval = -2; 440 rval = -2;
483 } 441 }
484 442
485 if (BE (rval == 0, 1)) 443 if (__glibc_likely (rval == 0))
486 { 444 {
487 if (ret_len) 445 if (ret_len)
488 { 446 {
489 assert (pmatch[0].rm_so == start); 447 DEBUG_ASSERT (pmatch[0].rm_so == start);
490 rval = pmatch[0].rm_eo - start; 448 rval = pmatch[0].rm_eo - start;
491 } 449 }
492 else 450 else
@@ -512,10 +470,10 @@ re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs,
512 if (regs_allocated == REGS_UNALLOCATED) 470 if (regs_allocated == REGS_UNALLOCATED)
513 { /* No. So allocate them with malloc. */ 471 { /* No. So allocate them with malloc. */
514 regs->start = re_malloc (regoff_t, need_regs); 472 regs->start = re_malloc (regoff_t, need_regs);
515 if (BE (regs->start == NULL, 0)) 473 if (__glibc_unlikely (regs->start == NULL))
516 return REGS_UNALLOCATED; 474 return REGS_UNALLOCATED;
517 regs->end = re_malloc (regoff_t, need_regs); 475 regs->end = re_malloc (regoff_t, need_regs);
518 if (BE (regs->end == NULL, 0)) 476 if (__glibc_unlikely (regs->end == NULL))
519 { 477 {
520 re_free (regs->start); 478 re_free (regs->start);
521 return REGS_UNALLOCATED; 479 return REGS_UNALLOCATED;
@@ -526,14 +484,14 @@ re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs,
526 { /* Yes. If we need more elements than were already 484 { /* Yes. If we need more elements than were already
527 allocated, reallocate them. If we need fewer, just 485 allocated, reallocate them. If we need fewer, just
528 leave it alone. */ 486 leave it alone. */
529 if (BE (need_regs > regs->num_regs, 0)) 487 if (__glibc_unlikely (need_regs > regs->num_regs))
530 { 488 {
531 regoff_t *new_start = re_realloc (regs->start, regoff_t, need_regs); 489 regoff_t *new_start = re_realloc (regs->start, regoff_t, need_regs);
532 regoff_t *new_end; 490 regoff_t *new_end;
533 if (BE (new_start == NULL, 0)) 491 if (__glibc_unlikely (new_start == NULL))
534 return REGS_UNALLOCATED; 492 return REGS_UNALLOCATED;
535 new_end = re_realloc (regs->end, regoff_t, need_regs); 493 new_end = re_realloc (regs->end, regoff_t, need_regs);
536 if (BE (new_end == NULL, 0)) 494 if (__glibc_unlikely (new_end == NULL))
537 { 495 {
538 re_free (new_start); 496 re_free (new_start);
539 return REGS_UNALLOCATED; 497 return REGS_UNALLOCATED;
@@ -545,9 +503,9 @@ re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs,
545 } 503 }
546 else 504 else
547 { 505 {
548 assert (regs_allocated == REGS_FIXED); 506 DEBUG_ASSERT (regs_allocated == REGS_FIXED);
549 /* This function may not be called with REGS_FIXED and nregs too big. */ 507 /* This function may not be called with REGS_FIXED and nregs too big. */
550 assert (regs->num_regs >= nregs); 508 DEBUG_ASSERT (nregs <= regs->num_regs);
551 rval = REGS_FIXED; 509 rval = REGS_FIXED;
552 } 510 }
553 511
@@ -577,11 +535,8 @@ re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs,
577 freeing the old data. */ 535 freeing the old data. */
578 536
579void 537void
580re_set_registers (bufp, regs, num_regs, starts, ends) 538re_set_registers (struct re_pattern_buffer *bufp, struct re_registers *regs,
581 struct re_pattern_buffer *bufp; 539 __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{ 540{
586 if (num_regs) 541 if (num_regs)
587 { 542 {
@@ -609,8 +564,7 @@ int
609# ifdef _LIBC 564# ifdef _LIBC
610weak_function 565weak_function
611# endif 566# endif
612re_exec (s) 567re_exec (const char *s)
613 const char *s;
614{ 568{
615 return 0 == regexec (&re_comp_buf, s, 0, NULL, 0); 569 return 0 == regexec (&re_comp_buf, s, 0, NULL, 0);
616} 570}
@@ -629,11 +583,9 @@ re_exec (s)
629 583
630static reg_errcode_t 584static reg_errcode_t
631__attribute_warn_unused_result__ 585__attribute_warn_unused_result__
632re_search_internal (const regex_t *preg, 586re_search_internal (const regex_t *preg, const char *string, Idx length,
633 const char *string, Idx length, 587 Idx start, Idx last_start, Idx stop, size_t nmatch,
634 Idx start, Idx last_start, Idx stop, 588 regmatch_t pmatch[], int eflags)
635 size_t nmatch, regmatch_t pmatch[],
636 int eflags)
637{ 589{
638 reg_errcode_t err; 590 reg_errcode_t err;
639 const re_dfa_t *dfa = preg->buffer; 591 const re_dfa_t *dfa = preg->buffer;
@@ -642,38 +594,28 @@ re_search_internal (const regex_t *preg,
642 bool fl_longest_match; 594 bool fl_longest_match;
643 int match_kind; 595 int match_kind;
644 Idx match_first; 596 Idx match_first;
645 Idx match_last = REG_MISSING; 597 Idx match_last = -1;
646 Idx extra_nmatch; 598 Idx extra_nmatch;
647 bool sb; 599 bool sb;
648 int ch; 600 int ch;
649#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
650 re_match_context_t mctx = { .dfa = dfa }; 601 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 602 char *fastmap = ((preg->fastmap != NULL && preg->fastmap_accurate
655 && start != last_start && !preg->can_be_null) 603 && start != last_start && !preg->can_be_null)
656 ? preg->fastmap : NULL); 604 ? preg->fastmap : NULL);
657 RE_TRANSLATE_TYPE t = preg->translate; 605 RE_TRANSLATE_TYPE t = preg->translate;
658 606
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; 607 extra_nmatch = (nmatch > preg->re_nsub) ? nmatch - (preg->re_nsub + 1) : 0;
665 nmatch -= extra_nmatch; 608 nmatch -= extra_nmatch;
666 609
667 /* Check if the DFA haven't been compiled. */ 610 /* Check if the DFA haven't been compiled. */
668 if (BE (preg->used == 0 || dfa->init_state == NULL 611 if (__glibc_unlikely (preg->used == 0 || dfa->init_state == NULL
669 || dfa->init_state_word == NULL || dfa->init_state_nl == NULL 612 || dfa->init_state_word == NULL
670 || dfa->init_state_begbuf == NULL, 0)) 613 || dfa->init_state_nl == NULL
614 || dfa->init_state_begbuf == NULL))
671 return REG_NOMATCH; 615 return REG_NOMATCH;
672 616
673#ifdef DEBUG
674 /* We assume front-end functions already check them. */ 617 /* We assume front-end functions already check them. */
675 assert (0 <= last_start && last_start <= length); 618 DEBUG_ASSERT (0 <= last_start && last_start <= length);
676#endif
677 619
678 /* If initial states with non-begbuf contexts have no elements, 620 /* If initial states with non-begbuf contexts have no elements,
679 the regex must be anchored. If preg->newline_anchor is set, 621 the regex must be anchored. If preg->newline_anchor is set,
@@ -694,14 +636,14 @@ re_search_internal (const regex_t *preg,
694 err = re_string_allocate (&mctx.input, string, length, dfa->nodes_len + 1, 636 err = re_string_allocate (&mctx.input, string, length, dfa->nodes_len + 1,
695 preg->translate, (preg->syntax & RE_ICASE) != 0, 637 preg->translate, (preg->syntax & RE_ICASE) != 0,
696 dfa); 638 dfa);
697 if (BE (err != REG_NOERROR, 0)) 639 if (__glibc_unlikely (err != REG_NOERROR))
698 goto free_return; 640 goto free_return;
699 mctx.input.stop = stop; 641 mctx.input.stop = stop;
700 mctx.input.raw_stop = stop; 642 mctx.input.raw_stop = stop;
701 mctx.input.newline_anchor = preg->newline_anchor; 643 mctx.input.newline_anchor = preg->newline_anchor;
702 644
703 err = match_ctx_init (&mctx, eflags, dfa->nbackref * 2); 645 err = match_ctx_init (&mctx, eflags, dfa->nbackref * 2);
704 if (BE (err != REG_NOERROR, 0)) 646 if (__glibc_unlikely (err != REG_NOERROR))
705 goto free_return; 647 goto free_return;
706 648
707 /* We will log all the DFA states through which the dfa pass, 649 /* We will log all the DFA states through which the dfa pass,
@@ -711,22 +653,20 @@ re_search_internal (const regex_t *preg,
711 if (nmatch > 1 || dfa->has_mb_node) 653 if (nmatch > 1 || dfa->has_mb_node)
712 { 654 {
713 /* Avoid overflow. */ 655 /* Avoid overflow. */
714 if (BE ((MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) 656 if (__glibc_unlikely ((MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *))
715 <= mctx.input.bufs_len), 0)) 657 <= mctx.input.bufs_len)))
716 { 658 {
717 err = REG_ESPACE; 659 err = REG_ESPACE;
718 goto free_return; 660 goto free_return;
719 } 661 }
720 662
721 mctx.state_log = re_malloc (re_dfastate_t *, mctx.input.bufs_len + 1); 663 mctx.state_log = re_malloc (re_dfastate_t *, mctx.input.bufs_len + 1);
722 if (BE (mctx.state_log == NULL, 0)) 664 if (__glibc_unlikely (mctx.state_log == NULL))
723 { 665 {
724 err = REG_ESPACE; 666 err = REG_ESPACE;
725 goto free_return; 667 goto free_return;
726 } 668 }
727 } 669 }
728 else
729 mctx.state_log = NULL;
730 670
731 match_first = start; 671 match_first = start;
732 mctx.input.tip_context = (eflags & REG_NOTBOL) ? CONTEXT_BEGBUF 672 mctx.input.tip_context = (eflags & REG_NOTBOL) ? CONTEXT_BEGBUF
@@ -763,19 +703,19 @@ re_search_internal (const regex_t *preg,
763 703
764 case 7: 704 case 7:
765 /* Fastmap with single-byte translation, match forward. */ 705 /* Fastmap with single-byte translation, match forward. */
766 while (BE (match_first < right_lim, 1) 706 while (__glibc_likely (match_first < right_lim)
767 && !fastmap[t[(unsigned char) string[match_first]]]) 707 && !fastmap[t[(unsigned char) string[match_first]]])
768 ++match_first; 708 ++match_first;
769 goto forward_match_found_start_or_reached_end; 709 goto forward_match_found_start_or_reached_end;
770 710
771 case 6: 711 case 6:
772 /* Fastmap without translation, match forward. */ 712 /* Fastmap without translation, match forward. */
773 while (BE (match_first < right_lim, 1) 713 while (__glibc_likely (match_first < right_lim)
774 && !fastmap[(unsigned char) string[match_first]]) 714 && !fastmap[(unsigned char) string[match_first]])
775 ++match_first; 715 ++match_first;
776 716
777 forward_match_found_start_or_reached_end: 717 forward_match_found_start_or_reached_end:
778 if (BE (match_first == right_lim, 0)) 718 if (__glibc_unlikely (match_first == right_lim))
779 { 719 {
780 ch = match_first >= length 720 ch = match_first >= length
781 ? 0 : (unsigned char) string[match_first]; 721 ? 0 : (unsigned char) string[match_first];
@@ -808,19 +748,19 @@ re_search_internal (const regex_t *preg,
808 /* If MATCH_FIRST is out of the valid range, reconstruct the 748 /* If MATCH_FIRST is out of the valid range, reconstruct the
809 buffers. */ 749 buffers. */
810 __re_size_t offset = match_first - mctx.input.raw_mbs_idx; 750 __re_size_t offset = match_first - mctx.input.raw_mbs_idx;
811 if (BE (offset >= (__re_size_t) mctx.input.valid_raw_len, 0)) 751 if (__glibc_unlikely (offset
752 >= (__re_size_t) mctx.input.valid_raw_len))
812 { 753 {
813 err = re_string_reconstruct (&mctx.input, match_first, 754 err = re_string_reconstruct (&mctx.input, match_first,
814 eflags); 755 eflags);
815 if (BE (err != REG_NOERROR, 0)) 756 if (__glibc_unlikely (err != REG_NOERROR))
816 goto free_return; 757 goto free_return;
817 758
818 offset = match_first - mctx.input.raw_mbs_idx; 759 offset = match_first - mctx.input.raw_mbs_idx;
819 } 760 }
820 /* If MATCH_FIRST is out of the buffer, leave it as '\0'. 761 /* Use buffer byte if OFFSET is in buffer, otherwise '\0'. */
821 Note that MATCH_FIRST must not be smaller than 0. */ 762 ch = (offset < mctx.input.valid_len
822 ch = (match_first >= length 763 ? re_string_byte_at (&mctx.input, offset) : 0);
823 ? 0 : re_string_byte_at (&mctx.input, offset));
824 if (fastmap[ch]) 764 if (fastmap[ch])
825 break; 765 break;
826 match_first += incr; 766 match_first += incr;
@@ -836,7 +776,7 @@ re_search_internal (const regex_t *preg,
836 /* Reconstruct the buffers so that the matcher can assume that 776 /* Reconstruct the buffers so that the matcher can assume that
837 the matching starts from the beginning of the buffer. */ 777 the matching starts from the beginning of the buffer. */
838 err = re_string_reconstruct (&mctx.input, match_first, eflags); 778 err = re_string_reconstruct (&mctx.input, match_first, eflags);
839 if (BE (err != REG_NOERROR, 0)) 779 if (__glibc_unlikely (err != REG_NOERROR))
840 goto free_return; 780 goto free_return;
841 781
842#ifdef RE_ENABLE_I18N 782#ifdef RE_ENABLE_I18N
@@ -851,9 +791,9 @@ re_search_internal (const regex_t *preg,
851 mctx.state_log_top = mctx.nbkref_ents = mctx.max_mb_elem_len = 0; 791 mctx.state_log_top = mctx.nbkref_ents = mctx.max_mb_elem_len = 0;
852 match_last = check_matching (&mctx, fl_longest_match, 792 match_last = check_matching (&mctx, fl_longest_match,
853 start <= last_start ? &match_first : NULL); 793 start <= last_start ? &match_first : NULL);
854 if (match_last != REG_MISSING) 794 if (match_last != -1)
855 { 795 {
856 if (BE (match_last == REG_ERROR, 0)) 796 if (__glibc_unlikely (match_last == -2))
857 { 797 {
858 err = REG_ESPACE; 798 err = REG_ESPACE;
859 goto free_return; 799 goto free_return;
@@ -873,9 +813,9 @@ re_search_internal (const regex_t *preg,
873 err = prune_impossible_nodes (&mctx); 813 err = prune_impossible_nodes (&mctx);
874 if (err == REG_NOERROR) 814 if (err == REG_NOERROR)
875 break; 815 break;
876 if (BE (err != REG_NOMATCH, 0)) 816 if (__glibc_unlikely (err != REG_NOMATCH))
877 goto free_return; 817 goto free_return;
878 match_last = REG_MISSING; 818 match_last = -1;
879 } 819 }
880 else 820 else
881 break; /* We found a match. */ 821 break; /* We found a match. */
@@ -885,10 +825,8 @@ re_search_internal (const regex_t *preg,
885 match_ctx_clean (&mctx); 825 match_ctx_clean (&mctx);
886 } 826 }
887 827
888#ifdef DEBUG 828 DEBUG_ASSERT (match_last != -1);
889 assert (match_last != REG_MISSING); 829 DEBUG_ASSERT (err == REG_NOERROR);
890 assert (err == REG_NOERROR);
891#endif
892 830
893 /* Set pmatch[] if we need. */ 831 /* Set pmatch[] if we need. */
894 if (nmatch > 0) 832 if (nmatch > 0)
@@ -910,7 +848,7 @@ re_search_internal (const regex_t *preg,
910 { 848 {
911 err = set_regs (preg, &mctx, nmatch, pmatch, 849 err = set_regs (preg, &mctx, nmatch, pmatch,
912 dfa->has_plural_match && dfa->nbackref > 0); 850 dfa->has_plural_match && dfa->nbackref > 0);
913 if (BE (err != REG_NOERROR, 0)) 851 if (__glibc_unlikely (err != REG_NOERROR))
914 goto free_return; 852 goto free_return;
915 } 853 }
916 854
@@ -921,7 +859,7 @@ re_search_internal (const regex_t *preg,
921 if (pmatch[reg_idx].rm_so != -1) 859 if (pmatch[reg_idx].rm_so != -1)
922 { 860 {
923#ifdef RE_ENABLE_I18N 861#ifdef RE_ENABLE_I18N
924 if (BE (mctx.input.offsets_needed != 0, 0)) 862 if (__glibc_unlikely (mctx.input.offsets_needed != 0))
925 { 863 {
926 pmatch[reg_idx].rm_so = 864 pmatch[reg_idx].rm_so =
927 (pmatch[reg_idx].rm_so == mctx.input.valid_len 865 (pmatch[reg_idx].rm_so == mctx.input.valid_len
@@ -933,7 +871,7 @@ re_search_internal (const regex_t *preg,
933 : mctx.input.offsets[pmatch[reg_idx].rm_eo]); 871 : mctx.input.offsets[pmatch[reg_idx].rm_eo]);
934 } 872 }
935#else 873#else
936 assert (mctx.input.offsets_needed == 0); 874 DEBUG_ASSERT (mctx.input.offsets_needed == 0);
937#endif 875#endif
938 pmatch[reg_idx].rm_so += match_first; 876 pmatch[reg_idx].rm_so += match_first;
939 pmatch[reg_idx].rm_eo += match_first; 877 pmatch[reg_idx].rm_eo += match_first;
@@ -973,18 +911,17 @@ prune_impossible_nodes (re_match_context_t *mctx)
973 re_dfastate_t **sifted_states; 911 re_dfastate_t **sifted_states;
974 re_dfastate_t **lim_states = NULL; 912 re_dfastate_t **lim_states = NULL;
975 re_sift_context_t sctx; 913 re_sift_context_t sctx;
976#ifdef DEBUG 914 DEBUG_ASSERT (mctx->state_log != NULL);
977 assert (mctx->state_log != NULL);
978#endif
979 match_last = mctx->match_last; 915 match_last = mctx->match_last;
980 halt_node = mctx->last_node; 916 halt_node = mctx->last_node;
981 917
982 /* Avoid overflow. */ 918 /* Avoid overflow. */
983 if (BE (MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) <= match_last, 0)) 919 if (__glibc_unlikely (MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *))
920 <= match_last))
984 return REG_ESPACE; 921 return REG_ESPACE;
985 922
986 sifted_states = re_malloc (re_dfastate_t *, match_last + 1); 923 sifted_states = re_malloc (re_dfastate_t *, match_last + 1);
987 if (BE (sifted_states == NULL, 0)) 924 if (__glibc_unlikely (sifted_states == NULL))
988 { 925 {
989 ret = REG_ESPACE; 926 ret = REG_ESPACE;
990 goto free_return; 927 goto free_return;
@@ -992,7 +929,7 @@ prune_impossible_nodes (re_match_context_t *mctx)
992 if (dfa->nbackref) 929 if (dfa->nbackref)
993 { 930 {
994 lim_states = re_malloc (re_dfastate_t *, match_last + 1); 931 lim_states = re_malloc (re_dfastate_t *, match_last + 1);
995 if (BE (lim_states == NULL, 0)) 932 if (__glibc_unlikely (lim_states == NULL))
996 { 933 {
997 ret = REG_ESPACE; 934 ret = REG_ESPACE;
998 goto free_return; 935 goto free_return;
@@ -1005,14 +942,14 @@ prune_impossible_nodes (re_match_context_t *mctx)
1005 match_last); 942 match_last);
1006 ret = sift_states_backward (mctx, &sctx); 943 ret = sift_states_backward (mctx, &sctx);
1007 re_node_set_free (&sctx.limits); 944 re_node_set_free (&sctx.limits);
1008 if (BE (ret != REG_NOERROR, 0)) 945 if (__glibc_unlikely (ret != REG_NOERROR))
1009 goto free_return; 946 goto free_return;
1010 if (sifted_states[0] != NULL || lim_states[0] != NULL) 947 if (sifted_states[0] != NULL || lim_states[0] != NULL)
1011 break; 948 break;
1012 do 949 do
1013 { 950 {
1014 --match_last; 951 --match_last;
1015 if (! REG_VALID_INDEX (match_last)) 952 if (match_last < 0)
1016 { 953 {
1017 ret = REG_NOMATCH; 954 ret = REG_NOMATCH;
1018 goto free_return; 955 goto free_return;
@@ -1027,7 +964,7 @@ prune_impossible_nodes (re_match_context_t *mctx)
1027 match_last + 1); 964 match_last + 1);
1028 re_free (lim_states); 965 re_free (lim_states);
1029 lim_states = NULL; 966 lim_states = NULL;
1030 if (BE (ret != REG_NOERROR, 0)) 967 if (__glibc_unlikely (ret != REG_NOERROR))
1031 goto free_return; 968 goto free_return;
1032 } 969 }
1033 else 970 else
@@ -1035,7 +972,7 @@ prune_impossible_nodes (re_match_context_t *mctx)
1035 sift_ctx_init (&sctx, sifted_states, lim_states, halt_node, match_last); 972 sift_ctx_init (&sctx, sifted_states, lim_states, halt_node, match_last);
1036 ret = sift_states_backward (mctx, &sctx); 973 ret = sift_states_backward (mctx, &sctx);
1037 re_node_set_free (&sctx.limits); 974 re_node_set_free (&sctx.limits);
1038 if (BE (ret != REG_NOERROR, 0)) 975 if (__glibc_unlikely (ret != REG_NOERROR))
1039 goto free_return; 976 goto free_return;
1040 if (sifted_states[0] == NULL) 977 if (sifted_states[0] == NULL)
1041 { 978 {
@@ -1060,7 +997,7 @@ prune_impossible_nodes (re_match_context_t *mctx)
1060 since initial states may have constraints like "\<", "^", etc.. */ 997 since initial states may have constraints like "\<", "^", etc.. */
1061 998
1062static inline re_dfastate_t * 999static inline re_dfastate_t *
1063__attribute__ ((always_inline)) internal_function 1000__attribute__ ((always_inline))
1064acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx, 1001acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx,
1065 Idx idx) 1002 Idx idx)
1066{ 1003{
@@ -1093,8 +1030,8 @@ acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx,
1093} 1030}
1094 1031
1095/* Check whether the regular expression match input string INPUT or not, 1032/* Check whether the regular expression match input string INPUT or not,
1096 and return the index where the matching end. Return REG_MISSING if 1033 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. 1034 there is no match, and return -2 in case of an error.
1098 FL_LONGEST_MATCH means we want the POSIX longest matching. 1035 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 1036 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. 1037 next place where we may want to try matching.
@@ -1102,14 +1039,14 @@ acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx,
1102 index of the buffer. */ 1039 index of the buffer. */
1103 1040
1104static Idx 1041static Idx
1105internal_function __attribute_warn_unused_result__ 1042__attribute_warn_unused_result__
1106check_matching (re_match_context_t *mctx, bool fl_longest_match, 1043check_matching (re_match_context_t *mctx, bool fl_longest_match,
1107 Idx *p_match_first) 1044 Idx *p_match_first)
1108{ 1045{
1109 const re_dfa_t *const dfa = mctx->dfa; 1046 const re_dfa_t *const dfa = mctx->dfa;
1110 reg_errcode_t err; 1047 reg_errcode_t err;
1111 Idx match = 0; 1048 Idx match = 0;
1112 Idx match_last = REG_MISSING; 1049 Idx match_last = -1;
1113 Idx cur_str_idx = re_string_cur_idx (&mctx->input); 1050 Idx cur_str_idx = re_string_cur_idx (&mctx->input);
1114 re_dfastate_t *cur_state; 1051 re_dfastate_t *cur_state;
1115 bool at_init_state = p_match_first != NULL; 1052 bool at_init_state = p_match_first != NULL;
@@ -1118,10 +1055,10 @@ check_matching (re_match_context_t *mctx, bool fl_longest_match,
1118 err = REG_NOERROR; 1055 err = REG_NOERROR;
1119 cur_state = acquire_init_state_context (&err, mctx, cur_str_idx); 1056 cur_state = acquire_init_state_context (&err, mctx, cur_str_idx);
1120 /* An initial state must not be NULL (invalid). */ 1057 /* An initial state must not be NULL (invalid). */
1121 if (BE (cur_state == NULL, 0)) 1058 if (__glibc_unlikely (cur_state == NULL))
1122 { 1059 {
1123 assert (err == REG_ESPACE); 1060 DEBUG_ASSERT (err == REG_ESPACE);
1124 return REG_ERROR; 1061 return -2;
1125 } 1062 }
1126 1063
1127 if (mctx->state_log != NULL) 1064 if (mctx->state_log != NULL)
@@ -1130,24 +1067,24 @@ check_matching (re_match_context_t *mctx, bool fl_longest_match,
1130 1067
1131 /* Check OP_OPEN_SUBEXP in the initial state in case that we use them 1068 /* Check OP_OPEN_SUBEXP in the initial state in case that we use them
1132 later. E.g. Processing back references. */ 1069 later. E.g. Processing back references. */
1133 if (BE (dfa->nbackref, 0)) 1070 if (__glibc_unlikely (dfa->nbackref))
1134 { 1071 {
1135 at_init_state = false; 1072 at_init_state = false;
1136 err = check_subexp_matching_top (mctx, &cur_state->nodes, 0); 1073 err = check_subexp_matching_top (mctx, &cur_state->nodes, 0);
1137 if (BE (err != REG_NOERROR, 0)) 1074 if (__glibc_unlikely (err != REG_NOERROR))
1138 return err; 1075 return err;
1139 1076
1140 if (cur_state->has_backref) 1077 if (cur_state->has_backref)
1141 { 1078 {
1142 err = transit_state_bkref (mctx, &cur_state->nodes); 1079 err = transit_state_bkref (mctx, &cur_state->nodes);
1143 if (BE (err != REG_NOERROR, 0)) 1080 if (__glibc_unlikely (err != REG_NOERROR))
1144 return err; 1081 return err;
1145 } 1082 }
1146 } 1083 }
1147 } 1084 }
1148 1085
1149 /* If the RE accepts NULL string. */ 1086 /* If the RE accepts NULL string. */
1150 if (BE (cur_state->halt, 0)) 1087 if (__glibc_unlikely (cur_state->halt))
1151 { 1088 {
1152 if (!cur_state->has_constraint 1089 if (!cur_state->has_constraint
1153 || check_halt_state_context (mctx, cur_state, cur_str_idx)) 1090 || check_halt_state_context (mctx, cur_state, cur_str_idx))
@@ -1167,16 +1104,16 @@ check_matching (re_match_context_t *mctx, bool fl_longest_match,
1167 re_dfastate_t *old_state = cur_state; 1104 re_dfastate_t *old_state = cur_state;
1168 Idx next_char_idx = re_string_cur_idx (&mctx->input) + 1; 1105 Idx next_char_idx = re_string_cur_idx (&mctx->input) + 1;
1169 1106
1170 if ((BE (next_char_idx >= mctx->input.bufs_len, 0) 1107 if ((__glibc_unlikely (next_char_idx >= mctx->input.bufs_len)
1171 && mctx->input.bufs_len < mctx->input.len) 1108 && mctx->input.bufs_len < mctx->input.len)
1172 || (BE (next_char_idx >= mctx->input.valid_len, 0) 1109 || (__glibc_unlikely (next_char_idx >= mctx->input.valid_len)
1173 && mctx->input.valid_len < mctx->input.len)) 1110 && mctx->input.valid_len < mctx->input.len))
1174 { 1111 {
1175 err = extend_buffers (mctx, next_char_idx + 1); 1112 err = extend_buffers (mctx, next_char_idx + 1);
1176 if (BE (err != REG_NOERROR, 0)) 1113 if (__glibc_unlikely (err != REG_NOERROR))
1177 { 1114 {
1178 assert (err == REG_ESPACE); 1115 DEBUG_ASSERT (err == REG_ESPACE);
1179 return REG_ERROR; 1116 return -2;
1180 } 1117 }
1181 } 1118 }
1182 1119
@@ -1189,8 +1126,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 1126 /* 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 1127 state using the state log, if available and if we have not
1191 already found a valid (even if not the longest) match. */ 1128 already found a valid (even if not the longest) match. */
1192 if (BE (err != REG_NOERROR, 0)) 1129 if (__glibc_unlikely (err != REG_NOERROR))
1193 return REG_ERROR; 1130 return -2;
1194 1131
1195 if (mctx->state_log == NULL 1132 if (mctx->state_log == NULL
1196 || (match && !fl_longest_match) 1133 || (match && !fl_longest_match)
@@ -1198,7 +1135,7 @@ check_matching (re_match_context_t *mctx, bool fl_longest_match,
1198 break; 1135 break;
1199 } 1136 }
1200 1137
1201 if (BE (at_init_state, 0)) 1138 if (__glibc_unlikely (at_init_state))
1202 { 1139 {
1203 if (old_state == cur_state) 1140 if (old_state == cur_state)
1204 next_start_idx = next_char_idx; 1141 next_start_idx = next_char_idx;
@@ -1235,7 +1172,6 @@ check_matching (re_match_context_t *mctx, bool fl_longest_match,
1235/* Check NODE match the current context. */ 1172/* Check NODE match the current context. */
1236 1173
1237static bool 1174static bool
1238internal_function
1239check_halt_node_context (const re_dfa_t *dfa, Idx node, unsigned int context) 1175check_halt_node_context (const re_dfa_t *dfa, Idx node, unsigned int context)
1240{ 1176{
1241 re_token_type_t type = dfa->nodes[node].type; 1177 re_token_type_t type = dfa->nodes[node].type;
@@ -1254,15 +1190,12 @@ check_halt_node_context (const re_dfa_t *dfa, Idx node, unsigned int context)
1254 match the context, return the node. */ 1190 match the context, return the node. */
1255 1191
1256static Idx 1192static Idx
1257internal_function
1258check_halt_state_context (const re_match_context_t *mctx, 1193check_halt_state_context (const re_match_context_t *mctx,
1259 const re_dfastate_t *state, Idx idx) 1194 const re_dfastate_t *state, Idx idx)
1260{ 1195{
1261 Idx i; 1196 Idx i;
1262 unsigned int context; 1197 unsigned int context;
1263#ifdef DEBUG 1198 DEBUG_ASSERT (state->halt);
1264 assert (state->halt);
1265#endif
1266 context = re_string_context_at (&mctx->input, idx, mctx->eflags); 1199 context = re_string_context_at (&mctx->input, idx, mctx->eflags);
1267 for (i = 0; i < state->nodes.nelem; ++i) 1200 for (i = 0; i < state->nodes.nelem; ++i)
1268 if (check_halt_node_context (mctx->dfa, state->nodes.elems[i], context)) 1201 if (check_halt_node_context (mctx->dfa, state->nodes.elems[i], context))
@@ -1273,33 +1206,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 1206/* Compute the next node to which "NFA" transit from NODE("NFA" is a NFA
1274 corresponding to the DFA). 1207 corresponding to the DFA).
1275 Return the destination node, and update EPS_VIA_NODES; 1208 Return the destination node, and update EPS_VIA_NODES;
1276 return REG_MISSING in case of errors. */ 1209 return -1 on match failure, -2 on error. */
1277 1210
1278static Idx 1211static Idx
1279internal_function
1280proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs, 1212proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs,
1213 regmatch_t *prevregs,
1281 Idx *pidx, Idx node, re_node_set *eps_via_nodes, 1214 Idx *pidx, Idx node, re_node_set *eps_via_nodes,
1282 struct re_fail_stack_t *fs) 1215 struct re_fail_stack_t *fs)
1283{ 1216{
1284 const re_dfa_t *const dfa = mctx->dfa; 1217 const re_dfa_t *const dfa = mctx->dfa;
1285 Idx i;
1286 bool ok;
1287 if (IS_EPSILON_NODE (dfa->nodes[node].type)) 1218 if (IS_EPSILON_NODE (dfa->nodes[node].type))
1288 { 1219 {
1289 re_node_set *cur_nodes = &mctx->state_log[*pidx]->nodes; 1220 re_node_set *cur_nodes = &mctx->state_log[*pidx]->nodes;
1290 re_node_set *edests = &dfa->edests[node]; 1221 re_node_set *edests = &dfa->edests[node];
1291 Idx dest_node; 1222
1292 ok = re_node_set_insert (eps_via_nodes, node); 1223 if (! re_node_set_contains (eps_via_nodes, node))
1293 if (BE (! ok, 0)) 1224 {
1294 return REG_ERROR; 1225 bool ok = re_node_set_insert (eps_via_nodes, node);
1295 /* Pick up a valid destination, or return REG_MISSING if none 1226 if (__glibc_unlikely (! ok))
1296 is found. */ 1227 return -2;
1297 for (dest_node = REG_MISSING, i = 0; i < edests->nelem; ++i) 1228 }
1229
1230 /* Pick a valid destination, or return -1 if none is found. */
1231 Idx dest_node = -1;
1232 for (Idx i = 0; i < edests->nelem; i++)
1298 { 1233 {
1299 Idx candidate = edests->elems[i]; 1234 Idx candidate = edests->elems[i];
1300 if (!re_node_set_contains (cur_nodes, candidate)) 1235 if (!re_node_set_contains (cur_nodes, candidate))
1301 continue; 1236 continue;
1302 if (dest_node == REG_MISSING) 1237 if (dest_node == -1)
1303 dest_node = candidate; 1238 dest_node = candidate;
1304 1239
1305 else 1240 else
@@ -1312,8 +1247,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. */ 1247 /* Otherwise, push the second epsilon-transition on the fail stack. */
1313 else if (fs != NULL 1248 else if (fs != NULL
1314 && push_fail_stack (fs, *pidx, candidate, nregs, regs, 1249 && push_fail_stack (fs, *pidx, candidate, nregs, regs,
1315 eps_via_nodes)) 1250 prevregs, eps_via_nodes))
1316 return REG_ERROR; 1251 return -2;
1317 1252
1318 /* We know we are going to exit. */ 1253 /* We know we are going to exit. */
1319 break; 1254 break;
@@ -1334,26 +1269,31 @@ proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs,
1334 if (type == OP_BACK_REF) 1269 if (type == OP_BACK_REF)
1335 { 1270 {
1336 Idx subexp_idx = dfa->nodes[node].opr.idx + 1; 1271 Idx subexp_idx = dfa->nodes[node].opr.idx + 1;
1337 naccepted = regs[subexp_idx].rm_eo - regs[subexp_idx].rm_so; 1272 if (subexp_idx < nregs)
1273 naccepted = regs[subexp_idx].rm_eo - regs[subexp_idx].rm_so;
1338 if (fs != NULL) 1274 if (fs != NULL)
1339 { 1275 {
1340 if (regs[subexp_idx].rm_so == -1 || regs[subexp_idx].rm_eo == -1) 1276 if (subexp_idx >= nregs
1341 return REG_MISSING; 1277 || regs[subexp_idx].rm_so == -1
1278 || regs[subexp_idx].rm_eo == -1)
1279 return -1;
1342 else if (naccepted) 1280 else if (naccepted)
1343 { 1281 {
1344 char *buf = (char *) re_string_get_buffer (&mctx->input); 1282 char *buf = (char *) re_string_get_buffer (&mctx->input);
1345 if (memcmp (buf + regs[subexp_idx].rm_so, buf + *pidx, 1283 if (mctx->input.valid_len - *pidx < naccepted
1346 naccepted) != 0) 1284 || (memcmp (buf + regs[subexp_idx].rm_so, buf + *pidx,
1347 return REG_MISSING; 1285 naccepted)
1286 != 0))
1287 return -1;
1348 } 1288 }
1349 } 1289 }
1350 1290
1351 if (naccepted == 0) 1291 if (naccepted == 0)
1352 { 1292 {
1353 Idx dest_node; 1293 Idx dest_node;
1354 ok = re_node_set_insert (eps_via_nodes, node); 1294 bool ok = re_node_set_insert (eps_via_nodes, node);
1355 if (BE (! ok, 0)) 1295 if (__glibc_unlikely (! ok))
1356 return REG_ERROR; 1296 return -2;
1357 dest_node = dfa->edests[node].elems[0]; 1297 dest_node = dfa->edests[node].elems[0];
1358 if (re_node_set_contains (&mctx->state_log[*pidx]->nodes, 1298 if (re_node_set_contains (&mctx->state_log[*pidx]->nodes,
1359 dest_node)) 1299 dest_node))
@@ -1369,26 +1309,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 1309 if (fs && (*pidx > mctx->match_last || mctx->state_log[*pidx] == NULL
1370 || !re_node_set_contains (&mctx->state_log[*pidx]->nodes, 1310 || !re_node_set_contains (&mctx->state_log[*pidx]->nodes,
1371 dest_node))) 1311 dest_node)))
1372 return REG_MISSING; 1312 return -1;
1373 re_node_set_empty (eps_via_nodes); 1313 re_node_set_empty (eps_via_nodes);
1374 return dest_node; 1314 return dest_node;
1375 } 1315 }
1376 } 1316 }
1377 return REG_MISSING; 1317 return -1;
1378} 1318}
1379 1319
1380static reg_errcode_t 1320static reg_errcode_t
1381internal_function __attribute_warn_unused_result__ 1321__attribute_warn_unused_result__
1382push_fail_stack (struct re_fail_stack_t *fs, Idx str_idx, Idx dest_node, 1322push_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) 1323 Idx nregs, regmatch_t *regs, regmatch_t *prevregs,
1324 re_node_set *eps_via_nodes)
1384{ 1325{
1385 reg_errcode_t err; 1326 reg_errcode_t err;
1386 Idx num = fs->num++; 1327 Idx num = fs->num++;
1387 if (fs->num == fs->alloc) 1328 if (fs->num == fs->alloc)
1388 { 1329 {
1389 struct re_fail_stack_ent_t *new_array; 1330 struct re_fail_stack_ent_t *new_array;
1390 new_array = realloc (fs->stack, (sizeof (struct re_fail_stack_ent_t) 1331 new_array = re_realloc (fs->stack, struct re_fail_stack_ent_t,
1391 * fs->alloc * 2)); 1332 fs->alloc * 2);
1392 if (new_array == NULL) 1333 if (new_array == NULL)
1393 return REG_ESPACE; 1334 return REG_ESPACE;
1394 fs->alloc *= 2; 1335 fs->alloc *= 2;
@@ -1396,36 +1337,46 @@ push_fail_stack (struct re_fail_stack_t *fs, Idx str_idx, Idx dest_node,
1396 } 1337 }
1397 fs->stack[num].idx = str_idx; 1338 fs->stack[num].idx = str_idx;
1398 fs->stack[num].node = dest_node; 1339 fs->stack[num].node = dest_node;
1399 fs->stack[num].regs = re_malloc (regmatch_t, nregs); 1340 fs->stack[num].regs = re_malloc (regmatch_t, 2 * nregs);
1400 if (fs->stack[num].regs == NULL) 1341 if (fs->stack[num].regs == NULL)
1401 return REG_ESPACE; 1342 return REG_ESPACE;
1402 memcpy (fs->stack[num].regs, regs, sizeof (regmatch_t) * nregs); 1343 memcpy (fs->stack[num].regs, regs, sizeof (regmatch_t) * nregs);
1344 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); 1345 err = re_node_set_init_copy (&fs->stack[num].eps_via_nodes, eps_via_nodes);
1404 return err; 1346 return err;
1405} 1347}
1406 1348
1407static Idx 1349static Idx
1408internal_function
1409pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, Idx nregs, 1350pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, Idx nregs,
1410 regmatch_t *regs, re_node_set *eps_via_nodes) 1351 regmatch_t *regs, regmatch_t *prevregs,
1352 re_node_set *eps_via_nodes)
1411{ 1353{
1354 if (fs == NULL || fs->num == 0)
1355 return -1;
1412 Idx num = --fs->num; 1356 Idx num = --fs->num;
1413 assert (REG_VALID_INDEX (num));
1414 *pidx = fs->stack[num].idx; 1357 *pidx = fs->stack[num].idx;
1415 memcpy (regs, fs->stack[num].regs, sizeof (regmatch_t) * nregs); 1358 memcpy (regs, fs->stack[num].regs, sizeof (regmatch_t) * nregs);
1359 memcpy (prevregs, fs->stack[num].regs + nregs, sizeof (regmatch_t) * nregs);
1416 re_node_set_free (eps_via_nodes); 1360 re_node_set_free (eps_via_nodes);
1417 re_free (fs->stack[num].regs); 1361 re_free (fs->stack[num].regs);
1418 *eps_via_nodes = fs->stack[num].eps_via_nodes; 1362 *eps_via_nodes = fs->stack[num].eps_via_nodes;
1363 DEBUG_ASSERT (0 <= fs->stack[num].node);
1419 return fs->stack[num].node; 1364 return fs->stack[num].node;
1420} 1365}
1421 1366
1367
1368#define DYNARRAY_STRUCT regmatch_list
1369#define DYNARRAY_ELEMENT regmatch_t
1370#define DYNARRAY_PREFIX regmatch_list_
1371#include <malloc/dynarray-skeleton.c>
1372
1422/* Set the positions where the subexpressions are starts/ends to registers 1373/* Set the positions where the subexpressions are starts/ends to registers
1423 PMATCH. 1374 PMATCH.
1424 Note: We assume that pmatch[0] is already set, and 1375 Note: We assume that pmatch[0] is already set, and
1425 pmatch[i].rm_so == pmatch[i].rm_eo == -1 for 0 < i < nmatch. */ 1376 pmatch[i].rm_so == pmatch[i].rm_eo == -1 for 0 < i < nmatch. */
1426 1377
1427static reg_errcode_t 1378static reg_errcode_t
1428internal_function __attribute_warn_unused_result__ 1379__attribute_warn_unused_result__
1429set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch, 1380set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch,
1430 regmatch_t *pmatch, bool fl_backtrack) 1381 regmatch_t *pmatch, bool fl_backtrack)
1431{ 1382{
@@ -1434,13 +1385,11 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch,
1434 re_node_set eps_via_nodes; 1385 re_node_set eps_via_nodes;
1435 struct re_fail_stack_t *fs; 1386 struct re_fail_stack_t *fs;
1436 struct re_fail_stack_t fs_body = { 0, 2, NULL }; 1387 struct re_fail_stack_t fs_body = { 0, 2, NULL };
1437 regmatch_t *prev_idx_match; 1388 struct regmatch_list prev_match;
1438 bool prev_idx_match_malloced = false; 1389 regmatch_list_init (&prev_match);
1439 1390
1440#ifdef DEBUG 1391 DEBUG_ASSERT (nmatch > 1);
1441 assert (nmatch > 1); 1392 DEBUG_ASSERT (mctx->state_log != NULL);
1442 assert (mctx->state_log != NULL);
1443#endif
1444 if (fl_backtrack) 1393 if (fl_backtrack)
1445 { 1394 {
1446 fs = &fs_body; 1395 fs = &fs_body;
@@ -1454,85 +1403,73 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch,
1454 cur_node = dfa->init_node; 1403 cur_node = dfa->init_node;
1455 re_node_set_init_empty (&eps_via_nodes); 1404 re_node_set_init_empty (&eps_via_nodes);
1456 1405
1457 if (__libc_use_alloca (nmatch * sizeof (regmatch_t))) 1406 if (!regmatch_list_resize (&prev_match, nmatch))
1458 prev_idx_match = (regmatch_t *) alloca (nmatch * sizeof (regmatch_t));
1459 else
1460 { 1407 {
1461 prev_idx_match = re_malloc (regmatch_t, nmatch); 1408 regmatch_list_free (&prev_match);
1462 if (prev_idx_match == NULL) 1409 free_fail_stack_return (fs);
1463 { 1410 return REG_ESPACE;
1464 free_fail_stack_return (fs);
1465 return REG_ESPACE;
1466 }
1467 prev_idx_match_malloced = true;
1468 } 1411 }
1412 regmatch_t *prev_idx_match = regmatch_list_begin (&prev_match);
1469 memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch); 1413 memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch);
1470 1414
1471 for (idx = pmatch[0].rm_so; idx <= pmatch[0].rm_eo ;) 1415 for (idx = pmatch[0].rm_so; idx <= pmatch[0].rm_eo ;)
1472 { 1416 {
1473 update_regs (dfa, pmatch, prev_idx_match, cur_node, idx, nmatch); 1417 update_regs (dfa, pmatch, prev_idx_match, cur_node, idx, nmatch);
1474 1418
1475 if (idx == pmatch[0].rm_eo && cur_node == mctx->last_node) 1419 if ((idx == pmatch[0].rm_eo && cur_node == mctx->last_node)
1420 || (fs && re_node_set_contains (&eps_via_nodes, cur_node)))
1476 { 1421 {
1477 Idx reg_idx; 1422 Idx reg_idx;
1423 cur_node = -1;
1478 if (fs) 1424 if (fs)
1479 { 1425 {
1480 for (reg_idx = 0; reg_idx < nmatch; ++reg_idx) 1426 for (reg_idx = 0; reg_idx < nmatch; ++reg_idx)
1481 if (pmatch[reg_idx].rm_so > -1 && pmatch[reg_idx].rm_eo == -1) 1427 if (pmatch[reg_idx].rm_so > -1 && pmatch[reg_idx].rm_eo == -1)
1482 break; 1428 {
1483 if (reg_idx == nmatch) 1429 cur_node = pop_fail_stack (fs, &idx, nmatch, pmatch,
1484 { 1430 prev_idx_match, &eps_via_nodes);
1485 re_node_set_free (&eps_via_nodes); 1431 break;
1486 if (prev_idx_match_malloced) 1432 }
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 } 1433 }
1493 else 1434 if (cur_node < 0)
1494 { 1435 {
1495 re_node_set_free (&eps_via_nodes); 1436 re_node_set_free (&eps_via_nodes);
1496 if (prev_idx_match_malloced) 1437 regmatch_list_free (&prev_match);
1497 re_free (prev_idx_match); 1438 return free_fail_stack_return (fs);
1498 return REG_NOERROR;
1499 } 1439 }
1500 } 1440 }
1501 1441
1502 /* Proceed to next node. */ 1442 /* Proceed to next node. */
1503 cur_node = proceed_next_node (mctx, nmatch, pmatch, &idx, cur_node, 1443 cur_node = proceed_next_node (mctx, nmatch, pmatch, prev_idx_match,
1444 &idx, cur_node,
1504 &eps_via_nodes, fs); 1445 &eps_via_nodes, fs);
1505 1446
1506 if (BE (! REG_VALID_INDEX (cur_node), 0)) 1447 if (__glibc_unlikely (cur_node < 0))
1507 { 1448 {
1508 if (BE (cur_node == REG_ERROR, 0)) 1449 if (__glibc_unlikely (cur_node == -2))
1509 { 1450 {
1510 re_node_set_free (&eps_via_nodes); 1451 re_node_set_free (&eps_via_nodes);
1511 if (prev_idx_match_malloced) 1452 regmatch_list_free (&prev_match);
1512 re_free (prev_idx_match);
1513 free_fail_stack_return (fs); 1453 free_fail_stack_return (fs);
1514 return REG_ESPACE; 1454 return REG_ESPACE;
1515 } 1455 }
1516 if (fs) 1456 cur_node = pop_fail_stack (fs, &idx, nmatch, pmatch,
1517 cur_node = pop_fail_stack (fs, &idx, nmatch, pmatch, 1457 prev_idx_match, &eps_via_nodes);
1518 &eps_via_nodes); 1458 if (cur_node < 0)
1519 else
1520 { 1459 {
1521 re_node_set_free (&eps_via_nodes); 1460 re_node_set_free (&eps_via_nodes);
1522 if (prev_idx_match_malloced) 1461 regmatch_list_free (&prev_match);
1523 re_free (prev_idx_match); 1462 free_fail_stack_return (fs);
1524 return REG_NOMATCH; 1463 return REG_NOMATCH;
1525 } 1464 }
1526 } 1465 }
1527 } 1466 }
1528 re_node_set_free (&eps_via_nodes); 1467 re_node_set_free (&eps_via_nodes);
1529 if (prev_idx_match_malloced) 1468 regmatch_list_free (&prev_match);
1530 re_free (prev_idx_match);
1531 return free_fail_stack_return (fs); 1469 return free_fail_stack_return (fs);
1532} 1470}
1533 1471
1534static reg_errcode_t 1472static reg_errcode_t
1535internal_function
1536free_fail_stack_return (struct re_fail_stack_t *fs) 1473free_fail_stack_return (struct re_fail_stack_t *fs)
1537{ 1474{
1538 if (fs) 1475 if (fs)
@@ -1549,7 +1486,6 @@ free_fail_stack_return (struct re_fail_stack_t *fs)
1549} 1486}
1550 1487
1551static void 1488static void
1552internal_function
1553update_regs (const re_dfa_t *dfa, regmatch_t *pmatch, 1489update_regs (const re_dfa_t *dfa, regmatch_t *pmatch,
1554 regmatch_t *prev_idx_match, Idx cur_node, Idx cur_idx, Idx nmatch) 1490 regmatch_t *prev_idx_match, Idx cur_node, Idx cur_idx, Idx nmatch)
1555{ 1491{
@@ -1567,10 +1503,10 @@ update_regs (const re_dfa_t *dfa, regmatch_t *pmatch,
1567 } 1503 }
1568 else if (type == OP_CLOSE_SUBEXP) 1504 else if (type == OP_CLOSE_SUBEXP)
1569 { 1505 {
1506 /* We are at the last node of this sub expression. */
1570 Idx reg_num = dfa->nodes[cur_node].opr.idx + 1; 1507 Idx reg_num = dfa->nodes[cur_node].opr.idx + 1;
1571 if (reg_num < nmatch) 1508 if (reg_num < nmatch)
1572 { 1509 {
1573 /* We are at the last node of this sub expression. */
1574 if (pmatch[reg_num].rm_so < cur_idx) 1510 if (pmatch[reg_num].rm_so < cur_idx)
1575 { 1511 {
1576 pmatch[reg_num].rm_eo = cur_idx; 1512 pmatch[reg_num].rm_eo = cur_idx;
@@ -1621,7 +1557,6 @@ update_regs (const re_dfa_t *dfa, regmatch_t *pmatch,
1621 ((state) != NULL && re_node_set_contains (&(state)->nodes, node)) 1557 ((state) != NULL && re_node_set_contains (&(state)->nodes, node))
1622 1558
1623static reg_errcode_t 1559static reg_errcode_t
1624internal_function
1625sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx) 1560sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx)
1626{ 1561{
1627 reg_errcode_t err; 1562 reg_errcode_t err;
@@ -1629,17 +1564,15 @@ sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx)
1629 Idx str_idx = sctx->last_str_idx; 1564 Idx str_idx = sctx->last_str_idx;
1630 re_node_set cur_dest; 1565 re_node_set cur_dest;
1631 1566
1632#ifdef DEBUG 1567 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 1568
1636 /* Build sifted state_log[str_idx]. It has the nodes which can epsilon 1569 /* Build sifted state_log[str_idx]. It has the nodes which can epsilon
1637 transit to the last_node and the last_node itself. */ 1570 transit to the last_node and the last_node itself. */
1638 err = re_node_set_init_1 (&cur_dest, sctx->last_node); 1571 err = re_node_set_init_1 (&cur_dest, sctx->last_node);
1639 if (BE (err != REG_NOERROR, 0)) 1572 if (__glibc_unlikely (err != REG_NOERROR))
1640 return err; 1573 return err;
1641 err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest); 1574 err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest);
1642 if (BE (err != REG_NOERROR, 0)) 1575 if (__glibc_unlikely (err != REG_NOERROR))
1643 goto free_return; 1576 goto free_return;
1644 1577
1645 /* Then check each states in the state_log. */ 1578 /* Then check each states in the state_log. */
@@ -1660,7 +1593,7 @@ sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx)
1660 if (mctx->state_log[str_idx]) 1593 if (mctx->state_log[str_idx])
1661 { 1594 {
1662 err = build_sifted_states (mctx, sctx, str_idx, &cur_dest); 1595 err = build_sifted_states (mctx, sctx, str_idx, &cur_dest);
1663 if (BE (err != REG_NOERROR, 0)) 1596 if (__glibc_unlikely (err != REG_NOERROR))
1664 goto free_return; 1597 goto free_return;
1665 } 1598 }
1666 1599
@@ -1669,7 +1602,7 @@ sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx)
1669 - It is in CUR_SRC. 1602 - It is in CUR_SRC.
1670 And update state_log. */ 1603 And update state_log. */
1671 err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest); 1604 err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest);
1672 if (BE (err != REG_NOERROR, 0)) 1605 if (__glibc_unlikely (err != REG_NOERROR))
1673 goto free_return; 1606 goto free_return;
1674 } 1607 }
1675 err = REG_NOERROR; 1608 err = REG_NOERROR;
@@ -1679,7 +1612,7 @@ sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx)
1679} 1612}
1680 1613
1681static reg_errcode_t 1614static reg_errcode_t
1682internal_function __attribute_warn_unused_result__ 1615__attribute_warn_unused_result__
1683build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx, 1616build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx,
1684 Idx str_idx, re_node_set *cur_dest) 1617 Idx str_idx, re_node_set *cur_dest)
1685{ 1618{
@@ -1699,11 +1632,8 @@ build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx,
1699 Idx prev_node = cur_src->elems[i]; 1632 Idx prev_node = cur_src->elems[i];
1700 int naccepted = 0; 1633 int naccepted = 0;
1701 bool ok; 1634 bool ok;
1635 DEBUG_ASSERT (!IS_EPSILON_NODE (dfa->nodes[prev_node].type));
1702 1636
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 1637#ifdef RE_ENABLE_I18N
1708 /* If the node may accept "multi byte". */ 1638 /* If the node may accept "multi byte". */
1709 if (dfa->nodes[prev_node].accept_mb) 1639 if (dfa->nodes[prev_node].accept_mb)
@@ -1731,7 +1661,7 @@ build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx,
1731 continue; 1661 continue;
1732 } 1662 }
1733 ok = re_node_set_insert (cur_dest, prev_node); 1663 ok = re_node_set_insert (cur_dest, prev_node);
1734 if (BE (! ok, 0)) 1664 if (__glibc_unlikely (! ok))
1735 return REG_ESPACE; 1665 return REG_ESPACE;
1736 } 1666 }
1737 1667
@@ -1741,7 +1671,6 @@ build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx,
1741/* Helper functions. */ 1671/* Helper functions. */
1742 1672
1743static reg_errcode_t 1673static reg_errcode_t
1744internal_function
1745clean_state_log_if_needed (re_match_context_t *mctx, Idx next_state_log_idx) 1674clean_state_log_if_needed (re_match_context_t *mctx, Idx next_state_log_idx)
1746{ 1675{
1747 Idx top = mctx->state_log_top; 1676 Idx top = mctx->state_log_top;
@@ -1753,7 +1682,7 @@ clean_state_log_if_needed (re_match_context_t *mctx, Idx next_state_log_idx)
1753 { 1682 {
1754 reg_errcode_t err; 1683 reg_errcode_t err;
1755 err = extend_buffers (mctx, next_state_log_idx + 1); 1684 err = extend_buffers (mctx, next_state_log_idx + 1);
1756 if (BE (err != REG_NOERROR, 0)) 1685 if (__glibc_unlikely (err != REG_NOERROR))
1757 return err; 1686 return err;
1758 } 1687 }
1759 1688
@@ -1767,7 +1696,6 @@ clean_state_log_if_needed (re_match_context_t *mctx, Idx next_state_log_idx)
1767} 1696}
1768 1697
1769static reg_errcode_t 1698static reg_errcode_t
1770internal_function
1771merge_state_array (const re_dfa_t *dfa, re_dfastate_t **dst, 1699merge_state_array (const re_dfa_t *dfa, re_dfastate_t **dst,
1772 re_dfastate_t **src, Idx num) 1700 re_dfastate_t **src, Idx num)
1773{ 1701{
@@ -1782,11 +1710,11 @@ merge_state_array (const re_dfa_t *dfa, re_dfastate_t **dst,
1782 re_node_set merged_set; 1710 re_node_set merged_set;
1783 err = re_node_set_init_union (&merged_set, &dst[st_idx]->nodes, 1711 err = re_node_set_init_union (&merged_set, &dst[st_idx]->nodes,
1784 &src[st_idx]->nodes); 1712 &src[st_idx]->nodes);
1785 if (BE (err != REG_NOERROR, 0)) 1713 if (__glibc_unlikely (err != REG_NOERROR))
1786 return err; 1714 return err;
1787 dst[st_idx] = re_acquire_state (&err, dfa, &merged_set); 1715 dst[st_idx] = re_acquire_state (&err, dfa, &merged_set);
1788 re_node_set_free (&merged_set); 1716 re_node_set_free (&merged_set);
1789 if (BE (err != REG_NOERROR, 0)) 1717 if (__glibc_unlikely (err != REG_NOERROR))
1790 return err; 1718 return err;
1791 } 1719 }
1792 } 1720 }
@@ -1794,7 +1722,6 @@ merge_state_array (const re_dfa_t *dfa, re_dfastate_t **dst,
1794} 1722}
1795 1723
1796static reg_errcode_t 1724static reg_errcode_t
1797internal_function
1798update_cur_sifted_state (const re_match_context_t *mctx, 1725update_cur_sifted_state (const re_match_context_t *mctx,
1799 re_sift_context_t *sctx, Idx str_idx, 1726 re_sift_context_t *sctx, Idx str_idx,
1800 re_node_set *dest_nodes) 1727 re_node_set *dest_nodes)
@@ -1814,7 +1741,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 1741 /* At first, add the nodes which can epsilon transit to a node in
1815 DEST_NODE. */ 1742 DEST_NODE. */
1816 err = add_epsilon_src_nodes (dfa, dest_nodes, candidates); 1743 err = add_epsilon_src_nodes (dfa, dest_nodes, candidates);
1817 if (BE (err != REG_NOERROR, 0)) 1744 if (__glibc_unlikely (err != REG_NOERROR))
1818 return err; 1745 return err;
1819 1746
1820 /* Then, check the limitations in the current sift_context. */ 1747 /* Then, check the limitations in the current sift_context. */
@@ -1822,27 +1749,27 @@ update_cur_sifted_state (const re_match_context_t *mctx,
1822 { 1749 {
1823 err = check_subexp_limits (dfa, dest_nodes, candidates, &sctx->limits, 1750 err = check_subexp_limits (dfa, dest_nodes, candidates, &sctx->limits,
1824 mctx->bkref_ents, str_idx); 1751 mctx->bkref_ents, str_idx);
1825 if (BE (err != REG_NOERROR, 0)) 1752 if (__glibc_unlikely (err != REG_NOERROR))
1826 return err; 1753 return err;
1827 } 1754 }
1828 } 1755 }
1829 1756
1830 sctx->sifted_states[str_idx] = re_acquire_state (&err, dfa, dest_nodes); 1757 sctx->sifted_states[str_idx] = re_acquire_state (&err, dfa, dest_nodes);
1831 if (BE (err != REG_NOERROR, 0)) 1758 if (__glibc_unlikely (err != REG_NOERROR))
1832 return err; 1759 return err;
1833 } 1760 }
1834 1761
1835 if (candidates && mctx->state_log[str_idx]->has_backref) 1762 if (candidates && mctx->state_log[str_idx]->has_backref)
1836 { 1763 {
1837 err = sift_states_bkref (mctx, sctx, str_idx, candidates); 1764 err = sift_states_bkref (mctx, sctx, str_idx, candidates);
1838 if (BE (err != REG_NOERROR, 0)) 1765 if (__glibc_unlikely (err != REG_NOERROR))
1839 return err; 1766 return err;
1840 } 1767 }
1841 return REG_NOERROR; 1768 return REG_NOERROR;
1842} 1769}
1843 1770
1844static reg_errcode_t 1771static reg_errcode_t
1845internal_function __attribute_warn_unused_result__ 1772__attribute_warn_unused_result__
1846add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes, 1773add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes,
1847 const re_node_set *candidates) 1774 const re_node_set *candidates)
1848{ 1775{
@@ -1850,19 +1777,19 @@ add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes,
1850 Idx i; 1777 Idx i;
1851 1778
1852 re_dfastate_t *state = re_acquire_state (&err, dfa, dest_nodes); 1779 re_dfastate_t *state = re_acquire_state (&err, dfa, dest_nodes);
1853 if (BE (err != REG_NOERROR, 0)) 1780 if (__glibc_unlikely (err != REG_NOERROR))
1854 return err; 1781 return err;
1855 1782
1856 if (!state->inveclosure.alloc) 1783 if (!state->inveclosure.alloc)
1857 { 1784 {
1858 err = re_node_set_alloc (&state->inveclosure, dest_nodes->nelem); 1785 err = re_node_set_alloc (&state->inveclosure, dest_nodes->nelem);
1859 if (BE (err != REG_NOERROR, 0)) 1786 if (__glibc_unlikely (err != REG_NOERROR))
1860 return REG_ESPACE; 1787 return REG_ESPACE;
1861 for (i = 0; i < dest_nodes->nelem; i++) 1788 for (i = 0; i < dest_nodes->nelem; i++)
1862 { 1789 {
1863 err = re_node_set_merge (&state->inveclosure, 1790 err = re_node_set_merge (&state->inveclosure,
1864 dfa->inveclosures + dest_nodes->elems[i]); 1791 dfa->inveclosures + dest_nodes->elems[i]);
1865 if (BE (err != REG_NOERROR, 0)) 1792 if (__glibc_unlikely (err != REG_NOERROR))
1866 return REG_ESPACE; 1793 return REG_ESPACE;
1867 } 1794 }
1868 } 1795 }
@@ -1871,7 +1798,6 @@ add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes,
1871} 1798}
1872 1799
1873static reg_errcode_t 1800static reg_errcode_t
1874internal_function
1875sub_epsilon_src_nodes (const re_dfa_t *dfa, Idx node, re_node_set *dest_nodes, 1801sub_epsilon_src_nodes (const re_dfa_t *dfa, Idx node, re_node_set *dest_nodes,
1876 const re_node_set *candidates) 1802 const re_node_set *candidates)
1877{ 1803{
@@ -1889,16 +1815,16 @@ sub_epsilon_src_nodes (const re_dfa_t *dfa, Idx node, re_node_set *dest_nodes,
1889 { 1815 {
1890 Idx edst1 = dfa->edests[cur_node].elems[0]; 1816 Idx edst1 = dfa->edests[cur_node].elems[0];
1891 Idx edst2 = ((dfa->edests[cur_node].nelem > 1) 1817 Idx edst2 = ((dfa->edests[cur_node].nelem > 1)
1892 ? dfa->edests[cur_node].elems[1] : REG_MISSING); 1818 ? dfa->edests[cur_node].elems[1] : -1);
1893 if ((!re_node_set_contains (inv_eclosure, edst1) 1819 if ((!re_node_set_contains (inv_eclosure, edst1)
1894 && re_node_set_contains (dest_nodes, edst1)) 1820 && re_node_set_contains (dest_nodes, edst1))
1895 || (REG_VALID_NONZERO_INDEX (edst2) 1821 || (edst2 > 0
1896 && !re_node_set_contains (inv_eclosure, edst2) 1822 && !re_node_set_contains (inv_eclosure, edst2)
1897 && re_node_set_contains (dest_nodes, edst2))) 1823 && re_node_set_contains (dest_nodes, edst2)))
1898 { 1824 {
1899 err = re_node_set_add_intersect (&except_nodes, candidates, 1825 err = re_node_set_add_intersect (&except_nodes, candidates,
1900 dfa->inveclosures + cur_node); 1826 dfa->inveclosures + cur_node);
1901 if (BE (err != REG_NOERROR, 0)) 1827 if (__glibc_unlikely (err != REG_NOERROR))
1902 { 1828 {
1903 re_node_set_free (&except_nodes); 1829 re_node_set_free (&except_nodes);
1904 return err; 1830 return err;
@@ -1920,7 +1846,6 @@ sub_epsilon_src_nodes (const re_dfa_t *dfa, Idx node, re_node_set *dest_nodes,
1920} 1846}
1921 1847
1922static bool 1848static bool
1923internal_function
1924check_dst_limits (const re_match_context_t *mctx, const re_node_set *limits, 1849check_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) 1850 Idx dst_node, Idx dst_idx, Idx src_node, Idx src_idx)
1926{ 1851{
@@ -1956,7 +1881,6 @@ check_dst_limits (const re_match_context_t *mctx, const re_node_set *limits,
1956} 1881}
1957 1882
1958static int 1883static int
1959internal_function
1960check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries, 1884check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries,
1961 Idx subexp_idx, Idx from_node, Idx bkref_idx) 1885 Idx subexp_idx, Idx from_node, Idx bkref_idx)
1962{ 1886{
@@ -1972,7 +1896,7 @@ check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries,
1972 switch (dfa->nodes[node].type) 1896 switch (dfa->nodes[node].type)
1973 { 1897 {
1974 case OP_BACK_REF: 1898 case OP_BACK_REF:
1975 if (bkref_idx != REG_MISSING) 1899 if (bkref_idx != -1)
1976 { 1900 {
1977 struct re_backref_cache_entry *ent = mctx->bkref_ents + bkref_idx; 1901 struct re_backref_cache_entry *ent = mctx->bkref_ents + bkref_idx;
1978 do 1902 do
@@ -2038,7 +1962,6 @@ check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries,
2038} 1962}
2039 1963
2040static int 1964static int
2041internal_function
2042check_dst_limits_calc_pos (const re_match_context_t *mctx, Idx limit, 1965check_dst_limits_calc_pos (const re_match_context_t *mctx, Idx limit,
2043 Idx subexp_idx, Idx from_node, Idx str_idx, 1966 Idx subexp_idx, Idx from_node, Idx str_idx,
2044 Idx bkref_idx) 1967 Idx bkref_idx)
@@ -2068,7 +1991,6 @@ check_dst_limits_calc_pos (const re_match_context_t *mctx, Idx limit,
2068 which are against limitations from DEST_NODES. */ 1991 which are against limitations from DEST_NODES. */
2069 1992
2070static reg_errcode_t 1993static reg_errcode_t
2071internal_function
2072check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes, 1994check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes,
2073 const re_node_set *candidates, re_node_set *limits, 1995 const re_node_set *candidates, re_node_set *limits,
2074 struct re_backref_cache_entry *bkref_ents, Idx str_idx) 1996 struct re_backref_cache_entry *bkref_ents, Idx str_idx)
@@ -2088,8 +2010,8 @@ check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes,
2088 subexp_idx = dfa->nodes[ent->node].opr.idx; 2010 subexp_idx = dfa->nodes[ent->node].opr.idx;
2089 if (ent->subexp_to == str_idx) 2011 if (ent->subexp_to == str_idx)
2090 { 2012 {
2091 Idx ops_node = REG_MISSING; 2013 Idx ops_node = -1;
2092 Idx cls_node = REG_MISSING; 2014 Idx cls_node = -1;
2093 for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx) 2015 for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx)
2094 { 2016 {
2095 Idx node = dest_nodes->elems[node_idx]; 2017 Idx node = dest_nodes->elems[node_idx];
@@ -2104,16 +2026,16 @@ check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes,
2104 2026
2105 /* Check the limitation of the open subexpression. */ 2027 /* Check the limitation of the open subexpression. */
2106 /* Note that (ent->subexp_to = str_idx != ent->subexp_from). */ 2028 /* Note that (ent->subexp_to = str_idx != ent->subexp_from). */
2107 if (REG_VALID_INDEX (ops_node)) 2029 if (ops_node >= 0)
2108 { 2030 {
2109 err = sub_epsilon_src_nodes (dfa, ops_node, dest_nodes, 2031 err = sub_epsilon_src_nodes (dfa, ops_node, dest_nodes,
2110 candidates); 2032 candidates);
2111 if (BE (err != REG_NOERROR, 0)) 2033 if (__glibc_unlikely (err != REG_NOERROR))
2112 return err; 2034 return err;
2113 } 2035 }
2114 2036
2115 /* Check the limitation of the close subexpression. */ 2037 /* Check the limitation of the close subexpression. */
2116 if (REG_VALID_INDEX (cls_node)) 2038 if (cls_node >= 0)
2117 for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx) 2039 for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx)
2118 { 2040 {
2119 Idx node = dest_nodes->elems[node_idx]; 2041 Idx node = dest_nodes->elems[node_idx];
@@ -2126,7 +2048,7 @@ check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes,
2126 Remove it form the current sifted state. */ 2048 Remove it form the current sifted state. */
2127 err = sub_epsilon_src_nodes (dfa, node, dest_nodes, 2049 err = sub_epsilon_src_nodes (dfa, node, dest_nodes,
2128 candidates); 2050 candidates);
2129 if (BE (err != REG_NOERROR, 0)) 2051 if (__glibc_unlikely (err != REG_NOERROR))
2130 return err; 2052 return err;
2131 --node_idx; 2053 --node_idx;
2132 } 2054 }
@@ -2146,7 +2068,7 @@ check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes,
2146 Remove it form the current sifted state. */ 2068 Remove it form the current sifted state. */
2147 err = sub_epsilon_src_nodes (dfa, node, dest_nodes, 2069 err = sub_epsilon_src_nodes (dfa, node, dest_nodes,
2148 candidates); 2070 candidates);
2149 if (BE (err != REG_NOERROR, 0)) 2071 if (__glibc_unlikely (err != REG_NOERROR))
2150 return err; 2072 return err;
2151 } 2073 }
2152 } 2074 }
@@ -2156,7 +2078,7 @@ check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes,
2156} 2078}
2157 2079
2158static reg_errcode_t 2080static reg_errcode_t
2159internal_function __attribute_warn_unused_result__ 2081__attribute_warn_unused_result__
2160sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx, 2082sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx,
2161 Idx str_idx, const re_node_set *candidates) 2083 Idx str_idx, const re_node_set *candidates)
2162{ 2084{
@@ -2166,7 +2088,7 @@ sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx,
2166 re_sift_context_t local_sctx; 2088 re_sift_context_t local_sctx;
2167 Idx first_idx = search_cur_bkref_entry (mctx, str_idx); 2089 Idx first_idx = search_cur_bkref_entry (mctx, str_idx);
2168 2090
2169 if (first_idx == REG_MISSING) 2091 if (first_idx == -1)
2170 return REG_NOERROR; 2092 return REG_NOERROR;
2171 2093
2172 local_sctx.sifted_states = NULL; /* Mark that it hasn't been initialized. */ 2094 local_sctx.sifted_states = NULL; /* Mark that it hasn't been initialized. */
@@ -2212,27 +2134,27 @@ sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx,
2212 { 2134 {
2213 local_sctx = *sctx; 2135 local_sctx = *sctx;
2214 err = re_node_set_init_copy (&local_sctx.limits, &sctx->limits); 2136 err = re_node_set_init_copy (&local_sctx.limits, &sctx->limits);
2215 if (BE (err != REG_NOERROR, 0)) 2137 if (__glibc_unlikely (err != REG_NOERROR))
2216 goto free_return; 2138 goto free_return;
2217 } 2139 }
2218 local_sctx.last_node = node; 2140 local_sctx.last_node = node;
2219 local_sctx.last_str_idx = str_idx; 2141 local_sctx.last_str_idx = str_idx;
2220 ok = re_node_set_insert (&local_sctx.limits, enabled_idx); 2142 ok = re_node_set_insert (&local_sctx.limits, enabled_idx);
2221 if (BE (! ok, 0)) 2143 if (__glibc_unlikely (! ok))
2222 { 2144 {
2223 err = REG_ESPACE; 2145 err = REG_ESPACE;
2224 goto free_return; 2146 goto free_return;
2225 } 2147 }
2226 cur_state = local_sctx.sifted_states[str_idx]; 2148 cur_state = local_sctx.sifted_states[str_idx];
2227 err = sift_states_backward (mctx, &local_sctx); 2149 err = sift_states_backward (mctx, &local_sctx);
2228 if (BE (err != REG_NOERROR, 0)) 2150 if (__glibc_unlikely (err != REG_NOERROR))
2229 goto free_return; 2151 goto free_return;
2230 if (sctx->limited_states != NULL) 2152 if (sctx->limited_states != NULL)
2231 { 2153 {
2232 err = merge_state_array (dfa, sctx->limited_states, 2154 err = merge_state_array (dfa, sctx->limited_states,
2233 local_sctx.sifted_states, 2155 local_sctx.sifted_states,
2234 str_idx + 1); 2156 str_idx + 1);
2235 if (BE (err != REG_NOERROR, 0)) 2157 if (__glibc_unlikely (err != REG_NOERROR))
2236 goto free_return; 2158 goto free_return;
2237 } 2159 }
2238 local_sctx.sifted_states[str_idx] = cur_state; 2160 local_sctx.sifted_states[str_idx] = cur_state;
@@ -2256,7 +2178,6 @@ sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx,
2256 2178
2257#ifdef RE_ENABLE_I18N 2179#ifdef RE_ENABLE_I18N
2258static int 2180static int
2259internal_function
2260sift_states_iter_mb (const re_match_context_t *mctx, re_sift_context_t *sctx, 2181sift_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) 2182 Idx node_idx, Idx str_idx, Idx max_str_idx)
2262{ 2183{
@@ -2264,12 +2185,12 @@ sift_states_iter_mb (const re_match_context_t *mctx, re_sift_context_t *sctx,
2264 int naccepted; 2185 int naccepted;
2265 /* Check the node can accept "multi byte". */ 2186 /* Check the node can accept "multi byte". */
2266 naccepted = check_node_accept_bytes (dfa, node_idx, &mctx->input, str_idx); 2187 naccepted = check_node_accept_bytes (dfa, node_idx, &mctx->input, str_idx);
2267 if (naccepted > 0 && str_idx + naccepted <= max_str_idx && 2188 if (naccepted > 0 && str_idx + naccepted <= max_str_idx
2268 !STATE_NODE_CONTAINS (sctx->sifted_states[str_idx + naccepted], 2189 && !STATE_NODE_CONTAINS (sctx->sifted_states[str_idx + naccepted],
2269 dfa->nexts[node_idx])) 2190 dfa->nexts[node_idx]))
2270 /* The node can't accept the "multi byte", or the 2191 /* The node can't accept the "multi byte", or the
2271 destination was already thrown away, then the node 2192 destination was already thrown away, then the node
2272 could't accept the current input "multi byte". */ 2193 couldn't accept the current input "multi byte". */
2273 naccepted = 0; 2194 naccepted = 0;
2274 /* Otherwise, it is sure that the node could accept 2195 /* Otherwise, it is sure that the node could accept
2275 'naccepted' bytes input. */ 2196 'naccepted' bytes input. */
@@ -2282,11 +2203,12 @@ sift_states_iter_mb (const re_match_context_t *mctx, re_sift_context_t *sctx,
2282 2203
2283/* Return the next state to which the current state STATE will transit by 2204/* 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. 2205 accepting the current input byte, and update STATE_LOG if necessary.
2206 Return NULL on failure.
2285 If STATE can accept a multibyte char/collating element/back reference 2207 If STATE can accept a multibyte char/collating element/back reference
2286 update the destination of STATE_LOG. */ 2208 update the destination of STATE_LOG. */
2287 2209
2288static re_dfastate_t * 2210static re_dfastate_t *
2289internal_function __attribute_warn_unused_result__ 2211__attribute_warn_unused_result__
2290transit_state (reg_errcode_t *err, re_match_context_t *mctx, 2212transit_state (reg_errcode_t *err, re_match_context_t *mctx,
2291 re_dfastate_t *state) 2213 re_dfastate_t *state)
2292{ 2214{
@@ -2295,10 +2217,10 @@ transit_state (reg_errcode_t *err, re_match_context_t *mctx,
2295 2217
2296#ifdef RE_ENABLE_I18N 2218#ifdef RE_ENABLE_I18N
2297 /* If the current state can accept multibyte. */ 2219 /* If the current state can accept multibyte. */
2298 if (BE (state->accept_mb, 0)) 2220 if (__glibc_unlikely (state->accept_mb))
2299 { 2221 {
2300 *err = transit_state_mb (mctx, state); 2222 *err = transit_state_mb (mctx, state);
2301 if (BE (*err != REG_NOERROR, 0)) 2223 if (__glibc_unlikely (*err != REG_NOERROR))
2302 return NULL; 2224 return NULL;
2303 } 2225 }
2304#endif /* RE_ENABLE_I18N */ 2226#endif /* RE_ENABLE_I18N */
@@ -2315,11 +2237,11 @@ transit_state (reg_errcode_t *err, re_match_context_t *mctx,
2315 for (;;) 2237 for (;;)
2316 { 2238 {
2317 trtable = state->trtable; 2239 trtable = state->trtable;
2318 if (BE (trtable != NULL, 1)) 2240 if (__glibc_likely (trtable != NULL))
2319 return trtable[ch]; 2241 return trtable[ch];
2320 2242
2321 trtable = state->word_trtable; 2243 trtable = state->word_trtable;
2322 if (BE (trtable != NULL, 1)) 2244 if (__glibc_likely (trtable != NULL))
2323 { 2245 {
2324 unsigned int context; 2246 unsigned int context;
2325 context 2247 context
@@ -2344,7 +2266,6 @@ transit_state (reg_errcode_t *err, re_match_context_t *mctx,
2344 2266
2345/* Update the state_log if we need */ 2267/* Update the state_log if we need */
2346static re_dfastate_t * 2268static re_dfastate_t *
2347internal_function
2348merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx, 2269merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx,
2349 re_dfastate_t *next_state) 2270 re_dfastate_t *next_state)
2350{ 2271{
@@ -2376,7 +2297,7 @@ merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx,
2376 table_nodes = next_state->entrance_nodes; 2297 table_nodes = next_state->entrance_nodes;
2377 *err = re_node_set_init_union (&next_nodes, table_nodes, 2298 *err = re_node_set_init_union (&next_nodes, table_nodes,
2378 log_nodes); 2299 log_nodes);
2379 if (BE (*err != REG_NOERROR, 0)) 2300 if (__glibc_unlikely (*err != REG_NOERROR))
2380 return NULL; 2301 return NULL;
2381 } 2302 }
2382 else 2303 else
@@ -2396,21 +2317,21 @@ merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx,
2396 re_node_set_free (&next_nodes); 2317 re_node_set_free (&next_nodes);
2397 } 2318 }
2398 2319
2399 if (BE (dfa->nbackref, 0) && next_state != NULL) 2320 if (__glibc_unlikely (dfa->nbackref) && next_state != NULL)
2400 { 2321 {
2401 /* Check OP_OPEN_SUBEXP in the current state in case that we use them 2322 /* 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 2323 later. We must check them here, since the back references in the
2403 next state might use them. */ 2324 next state might use them. */
2404 *err = check_subexp_matching_top (mctx, &next_state->nodes, 2325 *err = check_subexp_matching_top (mctx, &next_state->nodes,
2405 cur_idx); 2326 cur_idx);
2406 if (BE (*err != REG_NOERROR, 0)) 2327 if (__glibc_unlikely (*err != REG_NOERROR))
2407 return NULL; 2328 return NULL;
2408 2329
2409 /* If the next state has back references. */ 2330 /* If the next state has back references. */
2410 if (next_state->has_backref) 2331 if (next_state->has_backref)
2411 { 2332 {
2412 *err = transit_state_bkref (mctx, &next_state->nodes); 2333 *err = transit_state_bkref (mctx, &next_state->nodes);
2413 if (BE (*err != REG_NOERROR, 0)) 2334 if (__glibc_unlikely (*err != REG_NOERROR))
2414 return NULL; 2335 return NULL;
2415 next_state = mctx->state_log[cur_idx]; 2336 next_state = mctx->state_log[cur_idx];
2416 } 2337 }
@@ -2423,7 +2344,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 2344 multi-byte match, then look in the log for a state
2424 from which to restart matching. */ 2345 from which to restart matching. */
2425static re_dfastate_t * 2346static re_dfastate_t *
2426internal_function
2427find_recover_state (reg_errcode_t *err, re_match_context_t *mctx) 2347find_recover_state (reg_errcode_t *err, re_match_context_t *mctx)
2428{ 2348{
2429 re_dfastate_t *cur_state; 2349 re_dfastate_t *cur_state;
@@ -2454,7 +2374,6 @@ find_recover_state (reg_errcode_t *err, re_match_context_t *mctx)
2454 corresponding back references. */ 2374 corresponding back references. */
2455 2375
2456static reg_errcode_t 2376static reg_errcode_t
2457internal_function
2458check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes, 2377check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes,
2459 Idx str_idx) 2378 Idx str_idx)
2460{ 2379{
@@ -2476,7 +2395,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))) 2395 & ((bitset_word_t) 1 << dfa->nodes[node].opr.idx)))
2477 { 2396 {
2478 err = match_ctx_add_subtop (mctx, node, str_idx); 2397 err = match_ctx_add_subtop (mctx, node, str_idx);
2479 if (BE (err != REG_NOERROR, 0)) 2398 if (__glibc_unlikely (err != REG_NOERROR))
2480 return err; 2399 return err;
2481 } 2400 }
2482 } 2401 }
@@ -2485,7 +2404,7 @@ check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes,
2485 2404
2486#if 0 2405#if 0
2487/* Return the next state to which the current state STATE will transit by 2406/* Return the next state to which the current state STATE will transit by
2488 accepting the current input byte. */ 2407 accepting the current input byte. Return NULL on failure. */
2489 2408
2490static re_dfastate_t * 2409static re_dfastate_t *
2491transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx, 2410transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx,
@@ -2498,7 +2417,7 @@ transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx,
2498 unsigned int context; 2417 unsigned int context;
2499 2418
2500 *err = re_node_set_alloc (&next_nodes, state->nodes.nelem + 1); 2419 *err = re_node_set_alloc (&next_nodes, state->nodes.nelem + 1);
2501 if (BE (*err != REG_NOERROR, 0)) 2420 if (__glibc_unlikely (*err != REG_NOERROR))
2502 return NULL; 2421 return NULL;
2503 for (node_cnt = 0; node_cnt < state->nodes.nelem; ++node_cnt) 2422 for (node_cnt = 0; node_cnt < state->nodes.nelem; ++node_cnt)
2504 { 2423 {
@@ -2507,7 +2426,7 @@ transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx,
2507 { 2426 {
2508 *err = re_node_set_merge (&next_nodes, 2427 *err = re_node_set_merge (&next_nodes,
2509 dfa->eclosures + dfa->nexts[cur_node]); 2428 dfa->eclosures + dfa->nexts[cur_node]);
2510 if (BE (*err != REG_NOERROR, 0)) 2429 if (__glibc_unlikely (*err != REG_NOERROR))
2511 { 2430 {
2512 re_node_set_free (&next_nodes); 2431 re_node_set_free (&next_nodes);
2513 return NULL; 2432 return NULL;
@@ -2527,7 +2446,6 @@ transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx,
2527 2446
2528#ifdef RE_ENABLE_I18N 2447#ifdef RE_ENABLE_I18N
2529static reg_errcode_t 2448static reg_errcode_t
2530internal_function
2531transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate) 2449transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate)
2532{ 2450{
2533 const re_dfa_t *const dfa = mctx->dfa; 2451 const re_dfa_t *const dfa = mctx->dfa;
@@ -2567,11 +2485,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 2485 mctx->max_mb_elem_len = ((mctx->max_mb_elem_len < naccepted) ? naccepted
2568 : mctx->max_mb_elem_len); 2486 : mctx->max_mb_elem_len);
2569 err = clean_state_log_if_needed (mctx, dest_idx); 2487 err = clean_state_log_if_needed (mctx, dest_idx);
2570 if (BE (err != REG_NOERROR, 0)) 2488 if (__glibc_unlikely (err != REG_NOERROR))
2571 return err; 2489 return err;
2572#ifdef DEBUG 2490 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]; 2491 new_nodes = dfa->eclosures + dfa->nexts[cur_node_idx];
2576 2492
2577 dest_state = mctx->state_log[dest_idx]; 2493 dest_state = mctx->state_log[dest_idx];
@@ -2581,7 +2497,7 @@ transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate)
2581 { 2497 {
2582 err = re_node_set_init_union (&dest_nodes, 2498 err = re_node_set_init_union (&dest_nodes,
2583 dest_state->entrance_nodes, new_nodes); 2499 dest_state->entrance_nodes, new_nodes);
2584 if (BE (err != REG_NOERROR, 0)) 2500 if (__glibc_unlikely (err != REG_NOERROR))
2585 return err; 2501 return err;
2586 } 2502 }
2587 context = re_string_context_at (&mctx->input, dest_idx - 1, 2503 context = re_string_context_at (&mctx->input, dest_idx - 1,
@@ -2590,7 +2506,8 @@ transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate)
2590 = re_acquire_state_context (&err, dfa, &dest_nodes, context); 2506 = re_acquire_state_context (&err, dfa, &dest_nodes, context);
2591 if (dest_state != NULL) 2507 if (dest_state != NULL)
2592 re_node_set_free (&dest_nodes); 2508 re_node_set_free (&dest_nodes);
2593 if (BE (mctx->state_log[dest_idx] == NULL && err != REG_NOERROR, 0)) 2509 if (__glibc_unlikely (mctx->state_log[dest_idx] == NULL
2510 && err != REG_NOERROR))
2594 return err; 2511 return err;
2595 } 2512 }
2596 return REG_NOERROR; 2513 return REG_NOERROR;
@@ -2598,7 +2515,6 @@ transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate)
2598#endif /* RE_ENABLE_I18N */ 2515#endif /* RE_ENABLE_I18N */
2599 2516
2600static reg_errcode_t 2517static reg_errcode_t
2601internal_function
2602transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes) 2518transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes)
2603{ 2519{
2604 const re_dfa_t *const dfa = mctx->dfa; 2520 const re_dfa_t *const dfa = mctx->dfa;
@@ -2630,14 +2546,12 @@ transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes)
2630 Check the substring which the substring matched. */ 2546 Check the substring which the substring matched. */
2631 bkc_idx = mctx->nbkref_ents; 2547 bkc_idx = mctx->nbkref_ents;
2632 err = get_subexp (mctx, node_idx, cur_str_idx); 2548 err = get_subexp (mctx, node_idx, cur_str_idx);
2633 if (BE (err != REG_NOERROR, 0)) 2549 if (__glibc_unlikely (err != REG_NOERROR))
2634 goto free_return; 2550 goto free_return;
2635 2551
2636 /* And add the epsilon closures (which is 'new_dest_nodes') of 2552 /* And add the epsilon closures (which is 'new_dest_nodes') of
2637 the backreference to appropriate state_log. */ 2553 the backreference to appropriate state_log. */
2638#ifdef DEBUG 2554 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) 2555 for (; bkc_idx < mctx->nbkref_ents; ++bkc_idx)
2642 { 2556 {
2643 Idx subexp_len; 2557 Idx subexp_len;
@@ -2663,8 +2577,8 @@ transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes)
2663 mctx->state_log[dest_str_idx] 2577 mctx->state_log[dest_str_idx]
2664 = re_acquire_state_context (&err, dfa, new_dest_nodes, 2578 = re_acquire_state_context (&err, dfa, new_dest_nodes,
2665 context); 2579 context);
2666 if (BE (mctx->state_log[dest_str_idx] == NULL 2580 if (__glibc_unlikely (mctx->state_log[dest_str_idx] == NULL
2667 && err != REG_NOERROR, 0)) 2581 && err != REG_NOERROR))
2668 goto free_return; 2582 goto free_return;
2669 } 2583 }
2670 else 2584 else
@@ -2673,7 +2587,7 @@ transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes)
2673 err = re_node_set_init_union (&dest_nodes, 2587 err = re_node_set_init_union (&dest_nodes,
2674 dest_state->entrance_nodes, 2588 dest_state->entrance_nodes,
2675 new_dest_nodes); 2589 new_dest_nodes);
2676 if (BE (err != REG_NOERROR, 0)) 2590 if (__glibc_unlikely (err != REG_NOERROR))
2677 { 2591 {
2678 re_node_set_free (&dest_nodes); 2592 re_node_set_free (&dest_nodes);
2679 goto free_return; 2593 goto free_return;
@@ -2681,8 +2595,8 @@ transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes)
2681 mctx->state_log[dest_str_idx] 2595 mctx->state_log[dest_str_idx]
2682 = re_acquire_state_context (&err, dfa, &dest_nodes, context); 2596 = re_acquire_state_context (&err, dfa, &dest_nodes, context);
2683 re_node_set_free (&dest_nodes); 2597 re_node_set_free (&dest_nodes);
2684 if (BE (mctx->state_log[dest_str_idx] == NULL 2598 if (__glibc_unlikely (mctx->state_log[dest_str_idx] == NULL
2685 && err != REG_NOERROR, 0)) 2599 && err != REG_NOERROR))
2686 goto free_return; 2600 goto free_return;
2687 } 2601 }
2688 /* We need to check recursively if the backreference can epsilon 2602 /* We need to check recursively if the backreference can epsilon
@@ -2692,10 +2606,10 @@ transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes)
2692 { 2606 {
2693 err = check_subexp_matching_top (mctx, new_dest_nodes, 2607 err = check_subexp_matching_top (mctx, new_dest_nodes,
2694 cur_str_idx); 2608 cur_str_idx);
2695 if (BE (err != REG_NOERROR, 0)) 2609 if (__glibc_unlikely (err != REG_NOERROR))
2696 goto free_return; 2610 goto free_return;
2697 err = transit_state_bkref (mctx, new_dest_nodes); 2611 err = transit_state_bkref (mctx, new_dest_nodes);
2698 if (BE (err != REG_NOERROR, 0)) 2612 if (__glibc_unlikely (err != REG_NOERROR))
2699 goto free_return; 2613 goto free_return;
2700 } 2614 }
2701 } 2615 }
@@ -2712,7 +2626,7 @@ transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes)
2712 delay these checking for prune_impossible_nodes(). */ 2626 delay these checking for prune_impossible_nodes(). */
2713 2627
2714static reg_errcode_t 2628static reg_errcode_t
2715internal_function __attribute_warn_unused_result__ 2629__attribute_warn_unused_result__
2716get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx) 2630get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
2717{ 2631{
2718 const re_dfa_t *const dfa = mctx->dfa; 2632 const re_dfa_t *const dfa = mctx->dfa;
@@ -2720,7 +2634,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); 2634 const char *buf = (const char *) re_string_get_buffer (&mctx->input);
2721 /* Return if we have already checked BKREF_NODE at BKREF_STR_IDX. */ 2635 /* Return if we have already checked BKREF_NODE at BKREF_STR_IDX. */
2722 Idx cache_idx = search_cur_bkref_entry (mctx, bkref_str_idx); 2636 Idx cache_idx = search_cur_bkref_entry (mctx, bkref_str_idx);
2723 if (cache_idx != REG_MISSING) 2637 if (cache_idx != -1)
2724 { 2638 {
2725 const struct re_backref_cache_entry *entry 2639 const struct re_backref_cache_entry *entry
2726 = mctx->bkref_ents + cache_idx; 2640 = mctx->bkref_ents + cache_idx;
@@ -2756,7 +2670,8 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
2756 at the back reference? */ 2670 at the back reference? */
2757 if (sl_str_diff > 0) 2671 if (sl_str_diff > 0)
2758 { 2672 {
2759 if (BE (bkref_str_off + sl_str_diff > mctx->input.valid_len, 0)) 2673 if (__glibc_unlikely (bkref_str_off + sl_str_diff
2674 > mctx->input.valid_len))
2760 { 2675 {
2761 /* Not enough chars for a successful match. */ 2676 /* Not enough chars for a successful match. */
2762 if (bkref_str_off + sl_str_diff > mctx->input.len) 2677 if (bkref_str_off + sl_str_diff > mctx->input.len)
@@ -2765,7 +2680,7 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
2765 err = clean_state_log_if_needed (mctx, 2680 err = clean_state_log_if_needed (mctx,
2766 bkref_str_off 2681 bkref_str_off
2767 + sl_str_diff); 2682 + sl_str_diff);
2768 if (BE (err != REG_NOERROR, 0)) 2683 if (__glibc_unlikely (err != REG_NOERROR))
2769 return err; 2684 return err;
2770 buf = (const char *) re_string_get_buffer (&mctx->input); 2685 buf = (const char *) re_string_get_buffer (&mctx->input);
2771 } 2686 }
@@ -2784,7 +2699,7 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
2784 2699
2785 if (err == REG_NOMATCH) 2700 if (err == REG_NOMATCH)
2786 continue; 2701 continue;
2787 if (BE (err != REG_NOERROR, 0)) 2702 if (__glibc_unlikely (err != REG_NOERROR))
2788 return err; 2703 return err;
2789 } 2704 }
2790 2705
@@ -2803,14 +2718,14 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
2803 at the back reference? */ 2718 at the back reference? */
2804 if (sl_str_off > 0) 2719 if (sl_str_off > 0)
2805 { 2720 {
2806 if (BE (bkref_str_off >= mctx->input.valid_len, 0)) 2721 if (__glibc_unlikely (bkref_str_off >= mctx->input.valid_len))
2807 { 2722 {
2808 /* If we are at the end of the input, we cannot match. */ 2723 /* If we are at the end of the input, we cannot match. */
2809 if (bkref_str_off >= mctx->input.len) 2724 if (bkref_str_off >= mctx->input.len)
2810 break; 2725 break;
2811 2726
2812 err = extend_buffers (mctx, bkref_str_off + 1); 2727 err = extend_buffers (mctx, bkref_str_off + 1);
2813 if (BE (err != REG_NOERROR, 0)) 2728 if (__glibc_unlikely (err != REG_NOERROR))
2814 return err; 2729 return err;
2815 2730
2816 buf = (const char *) re_string_get_buffer (&mctx->input); 2731 buf = (const char *) re_string_get_buffer (&mctx->input);
@@ -2825,7 +2740,7 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
2825 nodes = &mctx->state_log[sl_str]->nodes; 2740 nodes = &mctx->state_log[sl_str]->nodes;
2826 cls_node = find_subexp_node (dfa, nodes, subexp_num, 2741 cls_node = find_subexp_node (dfa, nodes, subexp_num,
2827 OP_CLOSE_SUBEXP); 2742 OP_CLOSE_SUBEXP);
2828 if (cls_node == REG_MISSING) 2743 if (cls_node == -1)
2829 continue; /* No. */ 2744 continue; /* No. */
2830 if (sub_top->path == NULL) 2745 if (sub_top->path == NULL)
2831 { 2746 {
@@ -2841,15 +2756,18 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
2841 OP_CLOSE_SUBEXP); 2756 OP_CLOSE_SUBEXP);
2842 if (err == REG_NOMATCH) 2757 if (err == REG_NOMATCH)
2843 continue; 2758 continue;
2844 if (BE (err != REG_NOERROR, 0)) 2759 if (__glibc_unlikely (err != REG_NOERROR))
2845 return err; 2760 return err;
2846 sub_last = match_ctx_add_sublast (sub_top, cls_node, sl_str); 2761 sub_last = match_ctx_add_sublast (sub_top, cls_node, sl_str);
2847 if (BE (sub_last == NULL, 0)) 2762 if (__glibc_unlikely (sub_last == NULL))
2848 return REG_ESPACE; 2763 return REG_ESPACE;
2849 err = get_subexp_sub (mctx, sub_top, sub_last, bkref_node, 2764 err = get_subexp_sub (mctx, sub_top, sub_last, bkref_node,
2850 bkref_str_idx); 2765 bkref_str_idx);
2766 buf = (const char *) re_string_get_buffer (&mctx->input);
2851 if (err == REG_NOMATCH) 2767 if (err == REG_NOMATCH)
2852 continue; 2768 continue;
2769 if (__glibc_unlikely (err != REG_NOERROR))
2770 return err;
2853 } 2771 }
2854 } 2772 }
2855 return REG_NOERROR; 2773 return REG_NOERROR;
@@ -2862,7 +2780,6 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
2862 and SUB_LAST. */ 2780 and SUB_LAST. */
2863 2781
2864static reg_errcode_t 2782static reg_errcode_t
2865internal_function
2866get_subexp_sub (re_match_context_t *mctx, const re_sub_match_top_t *sub_top, 2783get_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) 2784 re_sub_match_last_t *sub_last, Idx bkref_node, Idx bkref_str)
2868{ 2785{
@@ -2876,7 +2793,7 @@ get_subexp_sub (re_match_context_t *mctx, const re_sub_match_top_t *sub_top,
2876 return err; 2793 return err;
2877 err = match_ctx_add_entry (mctx, bkref_node, bkref_str, sub_top->str_idx, 2794 err = match_ctx_add_entry (mctx, bkref_node, bkref_str, sub_top->str_idx,
2878 sub_last->str_idx); 2795 sub_last->str_idx);
2879 if (BE (err != REG_NOERROR, 0)) 2796 if (__glibc_unlikely (err != REG_NOERROR))
2880 return err; 2797 return err;
2881 to_idx = bkref_str + sub_last->str_idx - sub_top->str_idx; 2798 to_idx = bkref_str + sub_last->str_idx - sub_top->str_idx;
2882 return clean_state_log_if_needed (mctx, to_idx); 2799 return clean_state_log_if_needed (mctx, to_idx);
@@ -2891,7 +2808,6 @@ get_subexp_sub (re_match_context_t *mctx, const re_sub_match_top_t *sub_top,
2891 E.g. RE: (a){2} */ 2808 E.g. RE: (a){2} */
2892 2809
2893static Idx 2810static Idx
2894internal_function
2895find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes, 2811find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
2896 Idx subexp_idx, int type) 2812 Idx subexp_idx, int type)
2897{ 2813{
@@ -2904,16 +2820,17 @@ find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
2904 && node->opr.idx == subexp_idx) 2820 && node->opr.idx == subexp_idx)
2905 return cls_node; 2821 return cls_node;
2906 } 2822 }
2907 return REG_MISSING; 2823 return -1;
2908} 2824}
2909 2825
2910/* Check whether the node TOP_NODE at TOP_STR can arrive to the node 2826/* 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 2827 LAST_NODE at LAST_STR. We record the path onto PATH since it will be
2912 heavily reused. 2828 heavily reused.
2913 Return REG_NOERROR if it can arrive, or REG_NOMATCH otherwise. */ 2829 Return REG_NOERROR if it can arrive, REG_NOMATCH if it cannot,
2830 REG_ESPACE if memory is exhausted. */
2914 2831
2915static reg_errcode_t 2832static reg_errcode_t
2916internal_function __attribute_warn_unused_result__ 2833__attribute_warn_unused_result__
2917check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node, 2834check_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) 2835 Idx top_str, Idx last_node, Idx last_str, int type)
2919{ 2836{
@@ -2927,19 +2844,19 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
2927 2844
2928 subexp_num = dfa->nodes[top_node].opr.idx; 2845 subexp_num = dfa->nodes[top_node].opr.idx;
2929 /* Extend the buffer if we need. */ 2846 /* Extend the buffer if we need. */
2930 if (BE (path->alloc < last_str + mctx->max_mb_elem_len + 1, 0)) 2847 if (__glibc_unlikely (path->alloc < last_str + mctx->max_mb_elem_len + 1))
2931 { 2848 {
2932 re_dfastate_t **new_array; 2849 re_dfastate_t **new_array;
2933 Idx old_alloc = path->alloc; 2850 Idx old_alloc = path->alloc;
2934 Idx incr_alloc = last_str + mctx->max_mb_elem_len + 1; 2851 Idx incr_alloc = last_str + mctx->max_mb_elem_len + 1;
2935 Idx new_alloc; 2852 Idx new_alloc;
2936 if (BE (IDX_MAX - old_alloc < incr_alloc, 0)) 2853 if (__glibc_unlikely (IDX_MAX - old_alloc < incr_alloc))
2937 return REG_ESPACE; 2854 return REG_ESPACE;
2938 new_alloc = old_alloc + incr_alloc; 2855 new_alloc = old_alloc + incr_alloc;
2939 if (BE (SIZE_MAX / sizeof (re_dfastate_t *) < new_alloc, 0)) 2856 if (__glibc_unlikely (SIZE_MAX / sizeof (re_dfastate_t *) < new_alloc))
2940 return REG_ESPACE; 2857 return REG_ESPACE;
2941 new_array = re_realloc (path->array, re_dfastate_t *, new_alloc); 2858 new_array = re_realloc (path->array, re_dfastate_t *, new_alloc);
2942 if (BE (new_array == NULL, 0)) 2859 if (__glibc_unlikely (new_array == NULL))
2943 return REG_ESPACE; 2860 return REG_ESPACE;
2944 path->array = new_array; 2861 path->array = new_array;
2945 path->alloc = new_alloc; 2862 path->alloc = new_alloc;
@@ -2960,10 +2877,10 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
2960 if (str_idx == top_str) 2877 if (str_idx == top_str)
2961 { 2878 {
2962 err = re_node_set_init_1 (&next_nodes, top_node); 2879 err = re_node_set_init_1 (&next_nodes, top_node);
2963 if (BE (err != REG_NOERROR, 0)) 2880 if (__glibc_unlikely (err != REG_NOERROR))
2964 return err; 2881 return err;
2965 err = check_arrival_expand_ecl (dfa, &next_nodes, subexp_num, type); 2882 err = check_arrival_expand_ecl (dfa, &next_nodes, subexp_num, type);
2966 if (BE (err != REG_NOERROR, 0)) 2883 if (__glibc_unlikely (err != REG_NOERROR))
2967 { 2884 {
2968 re_node_set_free (&next_nodes); 2885 re_node_set_free (&next_nodes);
2969 return err; 2886 return err;
@@ -2975,7 +2892,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
2975 if (cur_state && cur_state->has_backref) 2892 if (cur_state && cur_state->has_backref)
2976 { 2893 {
2977 err = re_node_set_init_copy (&next_nodes, &cur_state->nodes); 2894 err = re_node_set_init_copy (&next_nodes, &cur_state->nodes);
2978 if (BE (err != REG_NOERROR, 0)) 2895 if (__glibc_unlikely (err != REG_NOERROR))
2979 return err; 2896 return err;
2980 } 2897 }
2981 else 2898 else
@@ -2987,14 +2904,14 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
2987 { 2904 {
2988 err = expand_bkref_cache (mctx, &next_nodes, str_idx, 2905 err = expand_bkref_cache (mctx, &next_nodes, str_idx,
2989 subexp_num, type); 2906 subexp_num, type);
2990 if (BE (err != REG_NOERROR, 0)) 2907 if (__glibc_unlikely (err != REG_NOERROR))
2991 { 2908 {
2992 re_node_set_free (&next_nodes); 2909 re_node_set_free (&next_nodes);
2993 return err; 2910 return err;
2994 } 2911 }
2995 } 2912 }
2996 cur_state = re_acquire_state_context (&err, dfa, &next_nodes, context); 2913 cur_state = re_acquire_state_context (&err, dfa, &next_nodes, context);
2997 if (BE (cur_state == NULL && err != REG_NOERROR, 0)) 2914 if (__glibc_unlikely (cur_state == NULL && err != REG_NOERROR))
2998 { 2915 {
2999 re_node_set_free (&next_nodes); 2916 re_node_set_free (&next_nodes);
3000 return err; 2917 return err;
@@ -3009,7 +2926,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
3009 { 2926 {
3010 err = re_node_set_merge (&next_nodes, 2927 err = re_node_set_merge (&next_nodes,
3011 &mctx->state_log[str_idx + 1]->nodes); 2928 &mctx->state_log[str_idx + 1]->nodes);
3012 if (BE (err != REG_NOERROR, 0)) 2929 if (__glibc_unlikely (err != REG_NOERROR))
3013 { 2930 {
3014 re_node_set_free (&next_nodes); 2931 re_node_set_free (&next_nodes);
3015 return err; 2932 return err;
@@ -3020,7 +2937,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, 2937 err = check_arrival_add_next_nodes (mctx, str_idx,
3021 &cur_state->non_eps_nodes, 2938 &cur_state->non_eps_nodes,
3022 &next_nodes); 2939 &next_nodes);
3023 if (BE (err != REG_NOERROR, 0)) 2940 if (__glibc_unlikely (err != REG_NOERROR))
3024 { 2941 {
3025 re_node_set_free (&next_nodes); 2942 re_node_set_free (&next_nodes);
3026 return err; 2943 return err;
@@ -3030,14 +2947,14 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
3030 if (next_nodes.nelem) 2947 if (next_nodes.nelem)
3031 { 2948 {
3032 err = check_arrival_expand_ecl (dfa, &next_nodes, subexp_num, type); 2949 err = check_arrival_expand_ecl (dfa, &next_nodes, subexp_num, type);
3033 if (BE (err != REG_NOERROR, 0)) 2950 if (__glibc_unlikely (err != REG_NOERROR))
3034 { 2951 {
3035 re_node_set_free (&next_nodes); 2952 re_node_set_free (&next_nodes);
3036 return err; 2953 return err;
3037 } 2954 }
3038 err = expand_bkref_cache (mctx, &next_nodes, str_idx, 2955 err = expand_bkref_cache (mctx, &next_nodes, str_idx,
3039 subexp_num, type); 2956 subexp_num, type);
3040 if (BE (err != REG_NOERROR, 0)) 2957 if (__glibc_unlikely (err != REG_NOERROR))
3041 { 2958 {
3042 re_node_set_free (&next_nodes); 2959 re_node_set_free (&next_nodes);
3043 return err; 2960 return err;
@@ -3045,7 +2962,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
3045 } 2962 }
3046 context = re_string_context_at (&mctx->input, str_idx - 1, mctx->eflags); 2963 context = re_string_context_at (&mctx->input, str_idx - 1, mctx->eflags);
3047 cur_state = re_acquire_state_context (&err, dfa, &next_nodes, context); 2964 cur_state = re_acquire_state_context (&err, dfa, &next_nodes, context);
3048 if (BE (cur_state == NULL && err != REG_NOERROR, 0)) 2965 if (__glibc_unlikely (cur_state == NULL && err != REG_NOERROR))
3049 { 2966 {
3050 re_node_set_free (&next_nodes); 2967 re_node_set_free (&next_nodes);
3051 return err; 2968 return err;
@@ -3078,7 +2995,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
3078 Can't we unify them? */ 2995 Can't we unify them? */
3079 2996
3080static reg_errcode_t 2997static reg_errcode_t
3081internal_function __attribute_warn_unused_result__ 2998__attribute_warn_unused_result__
3082check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx, 2999check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx,
3083 re_node_set *cur_nodes, re_node_set *next_nodes) 3000 re_node_set *cur_nodes, re_node_set *next_nodes)
3084{ 3001{
@@ -3094,10 +3011,8 @@ check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx,
3094 { 3011 {
3095 int naccepted = 0; 3012 int naccepted = 0;
3096 Idx cur_node = cur_nodes->elems[cur_idx]; 3013 Idx cur_node = cur_nodes->elems[cur_idx];
3097#ifdef DEBUG 3014 DEBUG_ASSERT (!IS_EPSILON_NODE (dfa->nodes[cur_node].type));
3098 re_token_type_t type = dfa->nodes[cur_node].type; 3015
3099 assert (!IS_EPSILON_NODE (type));
3100#endif
3101#ifdef RE_ENABLE_I18N 3016#ifdef RE_ENABLE_I18N
3102 /* If the node may accept "multi byte". */ 3017 /* If the node may accept "multi byte". */
3103 if (dfa->nodes[cur_node].accept_mb) 3018 if (dfa->nodes[cur_node].accept_mb)
@@ -3114,22 +3029,22 @@ check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx,
3114 if (dest_state) 3029 if (dest_state)
3115 { 3030 {
3116 err = re_node_set_merge (&union_set, &dest_state->nodes); 3031 err = re_node_set_merge (&union_set, &dest_state->nodes);
3117 if (BE (err != REG_NOERROR, 0)) 3032 if (__glibc_unlikely (err != REG_NOERROR))
3118 { 3033 {
3119 re_node_set_free (&union_set); 3034 re_node_set_free (&union_set);
3120 return err; 3035 return err;
3121 } 3036 }
3122 } 3037 }
3123 ok = re_node_set_insert (&union_set, next_node); 3038 ok = re_node_set_insert (&union_set, next_node);
3124 if (BE (! ok, 0)) 3039 if (__glibc_unlikely (! ok))
3125 { 3040 {
3126 re_node_set_free (&union_set); 3041 re_node_set_free (&union_set);
3127 return REG_ESPACE; 3042 return REG_ESPACE;
3128 } 3043 }
3129 mctx->state_log[next_idx] = re_acquire_state (&err, dfa, 3044 mctx->state_log[next_idx] = re_acquire_state (&err, dfa,
3130 &union_set); 3045 &union_set);
3131 if (BE (mctx->state_log[next_idx] == NULL 3046 if (__glibc_unlikely (mctx->state_log[next_idx] == NULL
3132 && err != REG_NOERROR, 0)) 3047 && err != REG_NOERROR))
3133 { 3048 {
3134 re_node_set_free (&union_set); 3049 re_node_set_free (&union_set);
3135 return err; 3050 return err;
@@ -3141,7 +3056,7 @@ check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx,
3141 || check_node_accept (mctx, dfa->nodes + cur_node, str_idx)) 3056 || check_node_accept (mctx, dfa->nodes + cur_node, str_idx))
3142 { 3057 {
3143 ok = re_node_set_insert (next_nodes, dfa->nexts[cur_node]); 3058 ok = re_node_set_insert (next_nodes, dfa->nexts[cur_node]);
3144 if (BE (! ok, 0)) 3059 if (__glibc_unlikely (! ok))
3145 { 3060 {
3146 re_node_set_free (&union_set); 3061 re_node_set_free (&union_set);
3147 return REG_ESPACE; 3062 return REG_ESPACE;
@@ -3159,18 +3074,15 @@ check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx,
3159*/ 3074*/
3160 3075
3161static reg_errcode_t 3076static reg_errcode_t
3162internal_function
3163check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes, 3077check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes,
3164 Idx ex_subexp, int type) 3078 Idx ex_subexp, int type)
3165{ 3079{
3166 reg_errcode_t err; 3080 reg_errcode_t err;
3167 Idx idx, outside_node; 3081 Idx idx, outside_node;
3168 re_node_set new_nodes; 3082 re_node_set new_nodes;
3169#ifdef DEBUG 3083 DEBUG_ASSERT (cur_nodes->nelem);
3170 assert (cur_nodes->nelem);
3171#endif
3172 err = re_node_set_alloc (&new_nodes, cur_nodes->nelem); 3084 err = re_node_set_alloc (&new_nodes, cur_nodes->nelem);
3173 if (BE (err != REG_NOERROR, 0)) 3085 if (__glibc_unlikely (err != REG_NOERROR))
3174 return err; 3086 return err;
3175 /* Create a new node set NEW_NODES with the nodes which are epsilon 3087 /* Create a new node set NEW_NODES with the nodes which are epsilon
3176 closures of the node in CUR_NODES. */ 3088 closures of the node in CUR_NODES. */
@@ -3180,11 +3092,11 @@ check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes,
3180 Idx cur_node = cur_nodes->elems[idx]; 3092 Idx cur_node = cur_nodes->elems[idx];
3181 const re_node_set *eclosure = dfa->eclosures + cur_node; 3093 const re_node_set *eclosure = dfa->eclosures + cur_node;
3182 outside_node = find_subexp_node (dfa, eclosure, ex_subexp, type); 3094 outside_node = find_subexp_node (dfa, eclosure, ex_subexp, type);
3183 if (outside_node == REG_MISSING) 3095 if (outside_node == -1)
3184 { 3096 {
3185 /* There are no problematic nodes, just merge them. */ 3097 /* There are no problematic nodes, just merge them. */
3186 err = re_node_set_merge (&new_nodes, eclosure); 3098 err = re_node_set_merge (&new_nodes, eclosure);
3187 if (BE (err != REG_NOERROR, 0)) 3099 if (__glibc_unlikely (err != REG_NOERROR))
3188 { 3100 {
3189 re_node_set_free (&new_nodes); 3101 re_node_set_free (&new_nodes);
3190 return err; 3102 return err;
@@ -3195,7 +3107,7 @@ check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes,
3195 /* There are problematic nodes, re-calculate incrementally. */ 3107 /* There are problematic nodes, re-calculate incrementally. */
3196 err = check_arrival_expand_ecl_sub (dfa, &new_nodes, cur_node, 3108 err = check_arrival_expand_ecl_sub (dfa, &new_nodes, cur_node,
3197 ex_subexp, type); 3109 ex_subexp, type);
3198 if (BE (err != REG_NOERROR, 0)) 3110 if (__glibc_unlikely (err != REG_NOERROR))
3199 { 3111 {
3200 re_node_set_free (&new_nodes); 3112 re_node_set_free (&new_nodes);
3201 return err; 3113 return err;
@@ -3212,7 +3124,7 @@ check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes,
3212 problematic append it to DST_NODES. */ 3124 problematic append it to DST_NODES. */
3213 3125
3214static reg_errcode_t 3126static reg_errcode_t
3215internal_function __attribute_warn_unused_result__ 3127__attribute_warn_unused_result__
3216check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes, 3128check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes,
3217 Idx target, Idx ex_subexp, int type) 3129 Idx target, Idx ex_subexp, int type)
3218{ 3130{
@@ -3227,13 +3139,13 @@ check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes,
3227 if (type == OP_CLOSE_SUBEXP) 3139 if (type == OP_CLOSE_SUBEXP)
3228 { 3140 {
3229 ok = re_node_set_insert (dst_nodes, cur_node); 3141 ok = re_node_set_insert (dst_nodes, cur_node);
3230 if (BE (! ok, 0)) 3142 if (__glibc_unlikely (! ok))
3231 return REG_ESPACE; 3143 return REG_ESPACE;
3232 } 3144 }
3233 break; 3145 break;
3234 } 3146 }
3235 ok = re_node_set_insert (dst_nodes, cur_node); 3147 ok = re_node_set_insert (dst_nodes, cur_node);
3236 if (BE (! ok, 0)) 3148 if (__glibc_unlikely (! ok))
3237 return REG_ESPACE; 3149 return REG_ESPACE;
3238 if (dfa->edests[cur_node].nelem == 0) 3150 if (dfa->edests[cur_node].nelem == 0)
3239 break; 3151 break;
@@ -3243,7 +3155,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, 3155 err = check_arrival_expand_ecl_sub (dfa, dst_nodes,
3244 dfa->edests[cur_node].elems[1], 3156 dfa->edests[cur_node].elems[1],
3245 ex_subexp, type); 3157 ex_subexp, type);
3246 if (BE (err != REG_NOERROR, 0)) 3158 if (__glibc_unlikely (err != REG_NOERROR))
3247 return err; 3159 return err;
3248 } 3160 }
3249 cur_node = dfa->edests[cur_node].elems[0]; 3161 cur_node = dfa->edests[cur_node].elems[0];
@@ -3257,7 +3169,7 @@ check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes,
3257 in MCTX->BKREF_ENTS. */ 3169 in MCTX->BKREF_ENTS. */
3258 3170
3259static reg_errcode_t 3171static reg_errcode_t
3260internal_function __attribute_warn_unused_result__ 3172__attribute_warn_unused_result__
3261expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes, 3173expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes,
3262 Idx cur_str, Idx subexp_num, int type) 3174 Idx cur_str, Idx subexp_num, int type)
3263{ 3175{
@@ -3266,7 +3178,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); 3178 Idx cache_idx_start = search_cur_bkref_entry (mctx, cur_str);
3267 struct re_backref_cache_entry *ent; 3179 struct re_backref_cache_entry *ent;
3268 3180
3269 if (cache_idx_start == REG_MISSING) 3181 if (cache_idx_start == -1)
3270 return REG_NOERROR; 3182 return REG_NOERROR;
3271 3183
3272 restart: 3184 restart:
@@ -3295,8 +3207,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); 3207 err2 = check_arrival_expand_ecl (dfa, &new_dests, subexp_num, type);
3296 err3 = re_node_set_merge (cur_nodes, &new_dests); 3208 err3 = re_node_set_merge (cur_nodes, &new_dests);
3297 re_node_set_free (&new_dests); 3209 re_node_set_free (&new_dests);
3298 if (BE (err != REG_NOERROR || err2 != REG_NOERROR 3210 if (__glibc_unlikely (err != REG_NOERROR || err2 != REG_NOERROR
3299 || err3 != REG_NOERROR, 0)) 3211 || err3 != REG_NOERROR))
3300 { 3212 {
3301 err = (err != REG_NOERROR ? err 3213 err = (err != REG_NOERROR ? err
3302 : (err2 != REG_NOERROR ? err2 : err3)); 3214 : (err2 != REG_NOERROR ? err2 : err3));
@@ -3318,7 +3230,7 @@ expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes,
3318 err = re_node_set_init_copy (&union_set, 3230 err = re_node_set_init_copy (&union_set,
3319 &mctx->state_log[to_idx]->nodes); 3231 &mctx->state_log[to_idx]->nodes);
3320 ok = re_node_set_insert (&union_set, next_node); 3232 ok = re_node_set_insert (&union_set, next_node);
3321 if (BE (err != REG_NOERROR || ! ok, 0)) 3233 if (__glibc_unlikely (err != REG_NOERROR || ! ok))
3322 { 3234 {
3323 re_node_set_free (&union_set); 3235 re_node_set_free (&union_set);
3324 err = err != REG_NOERROR ? err : REG_ESPACE; 3236 err = err != REG_NOERROR ? err : REG_ESPACE;
@@ -3328,13 +3240,13 @@ expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes,
3328 else 3240 else
3329 { 3241 {
3330 err = re_node_set_init_1 (&union_set, next_node); 3242 err = re_node_set_init_1 (&union_set, next_node);
3331 if (BE (err != REG_NOERROR, 0)) 3243 if (__glibc_unlikely (err != REG_NOERROR))
3332 return err; 3244 return err;
3333 } 3245 }
3334 mctx->state_log[to_idx] = re_acquire_state (&err, dfa, &union_set); 3246 mctx->state_log[to_idx] = re_acquire_state (&err, dfa, &union_set);
3335 re_node_set_free (&union_set); 3247 re_node_set_free (&union_set);
3336 if (BE (mctx->state_log[to_idx] == NULL 3248 if (__glibc_unlikely (mctx->state_log[to_idx] == NULL
3337 && err != REG_NOERROR, 0)) 3249 && err != REG_NOERROR))
3338 return err; 3250 return err;
3339 } 3251 }
3340 } 3252 }
@@ -3345,8 +3257,7 @@ expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes,
3345/* Build transition table for the state. 3257/* Build transition table for the state.
3346 Return true if successful. */ 3258 Return true if successful. */
3347 3259
3348static bool 3260static bool __attribute_noinline__
3349internal_function
3350build_trtable (const re_dfa_t *dfa, re_dfastate_t *state) 3261build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)
3351{ 3262{
3352 reg_errcode_t err; 3263 reg_errcode_t err;
@@ -3354,36 +3265,20 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)
3354 int ch; 3265 int ch;
3355 bool need_word_trtable = false; 3266 bool need_word_trtable = false;
3356 bitset_word_t elem, mask; 3267 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'. */ 3268 Idx ndests; /* Number of the destination states from 'state'. */
3360 re_dfastate_t **trtable; 3269 re_dfastate_t **trtable;
3361 re_dfastate_t **dest_states = NULL, **dest_states_word, **dest_states_nl; 3270 re_dfastate_t *dest_states[SBC_MAX];
3362 re_node_set follows, *dests_node; 3271 re_dfastate_t *dest_states_word[SBC_MAX];
3363 bitset_t *dests_ch; 3272 re_dfastate_t *dest_states_nl[SBC_MAX];
3273 re_node_set follows;
3364 bitset_t acceptable; 3274 bitset_t acceptable;
3365 3275
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 3276 /* We build DFA states which corresponds to the destination nodes
3373 from 'state'. 'dests_node[i]' represents the nodes which i-th 3277 from 'state'. 'dests_node[i]' represents the nodes which i-th
3374 destination state contains, and 'dests_ch[i]' represents the 3278 destination state contains, and 'dests_ch[i]' represents the
3375 characters which i-th destination state accepts. */ 3279 characters which i-th destination state accepts. */
3376 if (__libc_use_alloca (sizeof (struct dests_alloc))) 3280 re_node_set dests_node[SBC_MAX];
3377 dests_alloc = (struct dests_alloc *) alloca (sizeof (struct dests_alloc)); 3281 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 3282
3388 /* Initialize transition table. */ 3283 /* Initialize transition table. */
3389 state->word_trtable = state->trtable = NULL; 3284 state->word_trtable = state->trtable = NULL;
@@ -3391,16 +3286,14 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)
3391 /* At first, group all nodes belonging to 'state' into several 3286 /* At first, group all nodes belonging to 'state' into several
3392 destinations. */ 3287 destinations. */
3393 ndests = group_nodes_into_DFAstates (dfa, state, dests_node, dests_ch); 3288 ndests = group_nodes_into_DFAstates (dfa, state, dests_node, dests_ch);
3394 if (BE (! REG_VALID_NONZERO_INDEX (ndests), 0)) 3289 if (__glibc_unlikely (ndests <= 0))
3395 { 3290 {
3396 if (dests_node_malloced)
3397 free (dests_alloc);
3398 /* Return false in case of an error, true otherwise. */ 3291 /* Return false in case of an error, true otherwise. */
3399 if (ndests == 0) 3292 if (ndests == 0)
3400 { 3293 {
3401 state->trtable = (re_dfastate_t **) 3294 state->trtable = (re_dfastate_t **)
3402 calloc (sizeof (re_dfastate_t *), SBC_MAX); 3295 calloc (sizeof (re_dfastate_t *), SBC_MAX);
3403 if (BE (state->trtable == NULL, 0)) 3296 if (__glibc_unlikely (state->trtable == NULL))
3404 return false; 3297 return false;
3405 return true; 3298 return true;
3406 } 3299 }
@@ -3408,40 +3301,15 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)
3408 } 3301 }
3409 3302
3410 err = re_node_set_alloc (&follows, ndests + 1); 3303 err = re_node_set_alloc (&follows, ndests + 1);
3411 if (BE (err != REG_NOERROR, 0)) 3304 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 { 3305 {
3427 dest_states = (re_dfastate_t **) 3306 out_free:
3428 malloc (ndests * 3 * sizeof (re_dfastate_t *)); 3307 re_node_set_free (&follows);
3429 if (BE (dest_states == NULL, 0)) 3308 for (i = 0; i < ndests; ++i)
3430 { 3309 re_node_set_free (dests_node + i);
3431out_free: 3310 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 } 3311 }
3443 dest_states_word = dest_states + ndests; 3312
3444 dest_states_nl = dest_states_word + ndests;
3445 bitset_empty (acceptable); 3313 bitset_empty (acceptable);
3446 3314
3447 /* Then build the states for all destinations. */ 3315 /* Then build the states for all destinations. */
@@ -3453,15 +3321,15 @@ out_free:
3453 for (j = 0; j < dests_node[i].nelem; ++j) 3321 for (j = 0; j < dests_node[i].nelem; ++j)
3454 { 3322 {
3455 next_node = dfa->nexts[dests_node[i].elems[j]]; 3323 next_node = dfa->nexts[dests_node[i].elems[j]];
3456 if (next_node != REG_MISSING) 3324 if (next_node != -1)
3457 { 3325 {
3458 err = re_node_set_merge (&follows, dfa->eclosures + next_node); 3326 err = re_node_set_merge (&follows, dfa->eclosures + next_node);
3459 if (BE (err != REG_NOERROR, 0)) 3327 if (__glibc_unlikely (err != REG_NOERROR))
3460 goto out_free; 3328 goto out_free;
3461 } 3329 }
3462 } 3330 }
3463 dest_states[i] = re_acquire_state_context (&err, dfa, &follows, 0); 3331 dest_states[i] = re_acquire_state_context (&err, dfa, &follows, 0);
3464 if (BE (dest_states[i] == NULL && err != REG_NOERROR, 0)) 3332 if (__glibc_unlikely (dest_states[i] == NULL && err != REG_NOERROR))
3465 goto out_free; 3333 goto out_free;
3466 /* If the new state has context constraint, 3334 /* If the new state has context constraint,
3467 build appropriate states for these contexts. */ 3335 build appropriate states for these contexts. */
@@ -3469,7 +3337,8 @@ out_free:
3469 { 3337 {
3470 dest_states_word[i] = re_acquire_state_context (&err, dfa, &follows, 3338 dest_states_word[i] = re_acquire_state_context (&err, dfa, &follows,
3471 CONTEXT_WORD); 3339 CONTEXT_WORD);
3472 if (BE (dest_states_word[i] == NULL && err != REG_NOERROR, 0)) 3340 if (__glibc_unlikely (dest_states_word[i] == NULL
3341 && err != REG_NOERROR))
3473 goto out_free; 3342 goto out_free;
3474 3343
3475 if (dest_states[i] != dest_states_word[i] && dfa->mb_cur_max > 1) 3344 if (dest_states[i] != dest_states_word[i] && dfa->mb_cur_max > 1)
@@ -3477,7 +3346,7 @@ out_free:
3477 3346
3478 dest_states_nl[i] = re_acquire_state_context (&err, dfa, &follows, 3347 dest_states_nl[i] = re_acquire_state_context (&err, dfa, &follows,
3479 CONTEXT_NEWLINE); 3348 CONTEXT_NEWLINE);
3480 if (BE (dest_states_nl[i] == NULL && err != REG_NOERROR, 0)) 3349 if (__glibc_unlikely (dest_states_nl[i] == NULL && err != REG_NOERROR))
3481 goto out_free; 3350 goto out_free;
3482 } 3351 }
3483 else 3352 else
@@ -3488,7 +3357,7 @@ out_free:
3488 bitset_merge (acceptable, dests_ch[i]); 3357 bitset_merge (acceptable, dests_ch[i]);
3489 } 3358 }
3490 3359
3491 if (!BE (need_word_trtable, 0)) 3360 if (!__glibc_unlikely (need_word_trtable))
3492 { 3361 {
3493 /* We don't care about whether the following character is a word 3362 /* 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 3363 character, or we are in a single-byte character set so we can
@@ -3496,7 +3365,7 @@ out_free:
3496 256-entry transition table. */ 3365 256-entry transition table. */
3497 trtable = state->trtable = 3366 trtable = state->trtable =
3498 (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), SBC_MAX); 3367 (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), SBC_MAX);
3499 if (BE (trtable == NULL, 0)) 3368 if (__glibc_unlikely (trtable == NULL))
3500 goto out_free; 3369 goto out_free;
3501 3370
3502 /* For all characters ch...: */ 3371 /* For all characters ch...: */
@@ -3504,7 +3373,7 @@ out_free:
3504 for (ch = i * BITSET_WORD_BITS, elem = acceptable[i], mask = 1; 3373 for (ch = i * BITSET_WORD_BITS, elem = acceptable[i], mask = 1;
3505 elem; 3374 elem;
3506 mask <<= 1, elem >>= 1, ++ch) 3375 mask <<= 1, elem >>= 1, ++ch)
3507 if (BE (elem & 1, 0)) 3376 if (__glibc_unlikely (elem & 1))
3508 { 3377 {
3509 /* There must be exactly one destination which accepts 3378 /* There must be exactly one destination which accepts
3510 character ch. See group_nodes_into_DFAstates. */ 3379 character ch. See group_nodes_into_DFAstates. */
@@ -3527,7 +3396,7 @@ out_free:
3527 starting at trtable[SBC_MAX]. */ 3396 starting at trtable[SBC_MAX]. */
3528 trtable = state->word_trtable = 3397 trtable = state->word_trtable =
3529 (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), 2 * SBC_MAX); 3398 (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), 2 * SBC_MAX);
3530 if (BE (trtable == NULL, 0)) 3399 if (__glibc_unlikely (trtable == NULL))
3531 goto out_free; 3400 goto out_free;
3532 3401
3533 /* For all characters ch...: */ 3402 /* For all characters ch...: */
@@ -3535,7 +3404,7 @@ out_free:
3535 for (ch = i * BITSET_WORD_BITS, elem = acceptable[i], mask = 1; 3404 for (ch = i * BITSET_WORD_BITS, elem = acceptable[i], mask = 1;
3536 elem; 3405 elem;
3537 mask <<= 1, elem >>= 1, ++ch) 3406 mask <<= 1, elem >>= 1, ++ch)
3538 if (BE (elem & 1, 0)) 3407 if (__glibc_unlikely (elem & 1))
3539 { 3408 {
3540 /* There must be exactly one destination which accepts 3409 /* There must be exactly one destination which accepts
3541 character ch. See group_nodes_into_DFAstates. */ 3410 character ch. See group_nodes_into_DFAstates. */
@@ -3565,26 +3434,19 @@ out_free:
3565 } 3434 }
3566 } 3435 }
3567 3436
3568 if (dest_states_malloced)
3569 free (dest_states);
3570
3571 re_node_set_free (&follows); 3437 re_node_set_free (&follows);
3572 for (i = 0; i < ndests; ++i) 3438 for (i = 0; i < ndests; ++i)
3573 re_node_set_free (dests_node + i); 3439 re_node_set_free (dests_node + i);
3574
3575 if (dests_node_malloced)
3576 free (dests_alloc);
3577
3578 return true; 3440 return true;
3579} 3441}
3580 3442
3581/* Group all nodes belonging to STATE into several destinations. 3443/* Group all nodes belonging to STATE into several destinations.
3582 Then for all destinations, set the nodes belonging to the destination 3444 Then for all destinations, set the nodes belonging to the destination
3583 to DESTS_NODE[i] and set the characters accepted by the destination 3445 to DESTS_NODE[i] and set the characters accepted by the destination
3584 to DEST_CH[i]. This function return the number of destinations. */ 3446 to DEST_CH[i]. Return the number of destinations if successful,
3447 -1 on internal error. */
3585 3448
3586static Idx 3449static Idx
3587internal_function
3588group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, 3450group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
3589 re_node_set *dests_node, bitset_t *dests_ch) 3451 re_node_set *dests_node, bitset_t *dests_ch)
3590{ 3452{
@@ -3735,14 +3597,14 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
3735 bitset_copy (dests_ch[ndests], remains); 3597 bitset_copy (dests_ch[ndests], remains);
3736 bitset_copy (dests_ch[j], intersec); 3598 bitset_copy (dests_ch[j], intersec);
3737 err = re_node_set_init_copy (dests_node + ndests, &dests_node[j]); 3599 err = re_node_set_init_copy (dests_node + ndests, &dests_node[j]);
3738 if (BE (err != REG_NOERROR, 0)) 3600 if (__glibc_unlikely (err != REG_NOERROR))
3739 goto error_return; 3601 goto error_return;
3740 ++ndests; 3602 ++ndests;
3741 } 3603 }
3742 3604
3743 /* Put the position in the current group. */ 3605 /* Put the position in the current group. */
3744 ok = re_node_set_insert (&dests_node[j], cur_nodes->elems[i]); 3606 ok = re_node_set_insert (&dests_node[j], cur_nodes->elems[i]);
3745 if (BE (! ok, 0)) 3607 if (__glibc_unlikely (! ok))
3746 goto error_return; 3608 goto error_return;
3747 3609
3748 /* If all characters are consumed, go to next node. */ 3610 /* If all characters are consumed, go to next node. */
@@ -3754,17 +3616,18 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
3754 { 3616 {
3755 bitset_copy (dests_ch[ndests], accepts); 3617 bitset_copy (dests_ch[ndests], accepts);
3756 err = re_node_set_init_1 (dests_node + ndests, cur_nodes->elems[i]); 3618 err = re_node_set_init_1 (dests_node + ndests, cur_nodes->elems[i]);
3757 if (BE (err != REG_NOERROR, 0)) 3619 if (__glibc_unlikely (err != REG_NOERROR))
3758 goto error_return; 3620 goto error_return;
3759 ++ndests; 3621 ++ndests;
3760 bitset_empty (accepts); 3622 bitset_empty (accepts);
3761 } 3623 }
3762 } 3624 }
3625 assume (ndests <= SBC_MAX);
3763 return ndests; 3626 return ndests;
3764 error_return: 3627 error_return:
3765 for (j = 0; j < ndests; ++j) 3628 for (j = 0; j < ndests; ++j)
3766 re_node_set_free (dests_node + j); 3629 re_node_set_free (dests_node + j);
3767 return REG_MISSING; 3630 return -1;
3768} 3631}
3769 3632
3770#ifdef RE_ENABLE_I18N 3633#ifdef RE_ENABLE_I18N
@@ -3776,8 +3639,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 3639 one collating element like '.', '[a-z]', opposite to the other nodes
3777 can only accept one byte. */ 3640 can only accept one byte. */
3778 3641
3642# ifdef _LIBC
3643# include <locale/weight.h>
3644# endif
3645
3779static int 3646static int
3780internal_function
3781check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx, 3647check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
3782 const re_string_t *input, Idx str_idx) 3648 const re_string_t *input, Idx str_idx)
3783{ 3649{
@@ -3785,10 +3651,10 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
3785 int char_len, elem_len; 3651 int char_len, elem_len;
3786 Idx i; 3652 Idx i;
3787 3653
3788 if (BE (node->type == OP_UTF8_PERIOD, 0)) 3654 if (__glibc_unlikely (node->type == OP_UTF8_PERIOD))
3789 { 3655 {
3790 unsigned char c = re_string_byte_at (input, str_idx), d; 3656 unsigned char c = re_string_byte_at (input, str_idx), d;
3791 if (BE (c < 0xc2, 1)) 3657 if (__glibc_likely (c < 0xc2))
3792 return 0; 3658 return 0;
3793 3659
3794 if (str_idx + 2 > input->len) 3660 if (str_idx + 2 > input->len)
@@ -3844,10 +3710,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' 3710 /* FIXME: I don't think this if is needed, as both '\n'
3845 and '\0' are char_len == 1. */ 3711 and '\0' are char_len == 1. */
3846 /* '.' accepts any one character except the following two cases. */ 3712 /* '.' accepts any one character except the following two cases. */
3847 if ((!(dfa->syntax & RE_DOT_NEWLINE) && 3713 if ((!(dfa->syntax & RE_DOT_NEWLINE)
3848 re_string_byte_at (input, str_idx) == '\n') || 3714 && re_string_byte_at (input, str_idx) == '\n')
3849 ((dfa->syntax & RE_DOT_NOT_NULL) && 3715 || ((dfa->syntax & RE_DOT_NOT_NULL)
3850 re_string_byte_at (input, str_idx) == '\0')) 3716 && re_string_byte_at (input, str_idx) == '\0'))
3851 return 0; 3717 return 0;
3852 return char_len; 3718 return char_len;
3853 } 3719 }
@@ -3895,8 +3761,6 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
3895 const int32_t *table, *indirect; 3761 const int32_t *table, *indirect;
3896 const unsigned char *weights, *extra; 3762 const unsigned char *weights, *extra;
3897 const char *collseqwc; 3763 const char *collseqwc;
3898 /* This #include defines a local function! */
3899# include <locale/weight.h>
3900 3764
3901 /* match with collating_symbol? */ 3765 /* match with collating_symbol? */
3902 if (cset->ncoll_syms) 3766 if (cset->ncoll_syms)
@@ -3953,31 +3817,28 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
3953 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB); 3817 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB);
3954 indirect = (const int32_t *) 3818 indirect = (const int32_t *)
3955 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTMB); 3819 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTMB);
3956 int32_t idx = findidx (&cp, elem_len); 3820 int32_t idx = findidx (table, indirect, extra, &cp, elem_len);
3821 int32_t rule = idx >> 24;
3822 idx &= 0xffffff;
3957 if (idx > 0) 3823 if (idx > 0)
3958 for (i = 0; i < cset->nequiv_classes; ++i) 3824 {
3959 { 3825 size_t weight_len = weights[idx];
3960 int32_t equiv_class_idx = cset->equiv_classes[i]; 3826 for (i = 0; i < cset->nequiv_classes; ++i)
3961 size_t weight_len = weights[idx & 0xffffff]; 3827 {
3962 if (weight_len == weights[equiv_class_idx & 0xffffff] 3828 int32_t equiv_class_idx = cset->equiv_classes[i];
3963 && (idx >> 24) == (equiv_class_idx >> 24)) 3829 int32_t equiv_class_rule = equiv_class_idx >> 24;
3964 { 3830 equiv_class_idx &= 0xffffff;
3965 Idx cnt = 0; 3831 if (weights[equiv_class_idx] == weight_len
3966 3832 && equiv_class_rule == rule
3967 idx &= 0xffffff; 3833 && memcmp (weights + idx + 1,
3968 equiv_class_idx &= 0xffffff; 3834 weights + equiv_class_idx + 1,
3969 3835 weight_len) == 0)
3970 while (cnt <= weight_len 3836 {
3971 && (weights[equiv_class_idx + 1 + cnt] 3837 match_len = elem_len;
3972 == weights[idx + 1 + cnt])) 3838 goto check_node_accept_bytes_match;
3973 ++cnt; 3839 }
3974 if (cnt > weight_len) 3840 }
3975 { 3841 }
3976 match_len = elem_len;
3977 goto check_node_accept_bytes_match;
3978 }
3979 }
3980 }
3981 } 3842 }
3982 } 3843 }
3983 else 3844 else
@@ -4009,7 +3870,6 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
4009 3870
4010# ifdef _LIBC 3871# ifdef _LIBC
4011static unsigned int 3872static unsigned int
4012internal_function
4013find_collation_sequence_value (const unsigned char *mbs, size_t mbs_len) 3873find_collation_sequence_value (const unsigned char *mbs, size_t mbs_len)
4014{ 3874{
4015 uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES); 3875 uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
@@ -4073,7 +3933,6 @@ find_collation_sequence_value (const unsigned char *mbs, size_t mbs_len)
4073 byte of the INPUT. */ 3933 byte of the INPUT. */
4074 3934
4075static bool 3935static bool
4076internal_function
4077check_node_accept (const re_match_context_t *mctx, const re_token_t *node, 3936check_node_accept (const re_match_context_t *mctx, const re_token_t *node,
4078 Idx idx) 3937 Idx idx)
4079{ 3938{
@@ -4095,7 +3954,7 @@ check_node_accept (const re_match_context_t *mctx, const re_token_t *node,
4095 case OP_UTF8_PERIOD: 3954 case OP_UTF8_PERIOD:
4096 if (ch >= ASCII_CHARS) 3955 if (ch >= ASCII_CHARS)
4097 return false; 3956 return false;
4098 /* FALLTHROUGH */ 3957 FALLTHROUGH;
4099#endif 3958#endif
4100 case OP_PERIOD: 3959 case OP_PERIOD:
4101 if ((ch == '\n' && !(mctx->dfa->syntax & RE_DOT_NEWLINE)) 3960 if ((ch == '\n' && !(mctx->dfa->syntax & RE_DOT_NEWLINE))
@@ -4123,22 +3982,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. */ 3982/* Extend the buffers, if the buffers have run out. */
4124 3983
4125static reg_errcode_t 3984static reg_errcode_t
4126internal_function __attribute_warn_unused_result__ 3985__attribute_warn_unused_result__
4127extend_buffers (re_match_context_t *mctx, int min_len) 3986extend_buffers (re_match_context_t *mctx, int min_len)
4128{ 3987{
4129 reg_errcode_t ret; 3988 reg_errcode_t ret;
4130 re_string_t *pstr = &mctx->input; 3989 re_string_t *pstr = &mctx->input;
4131 3990
4132 /* Avoid overflow. */ 3991 /* Avoid overflow. */
4133 if (BE (MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) / 2 3992 if (__glibc_unlikely (MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) / 2
4134 <= pstr->bufs_len, 0)) 3993 <= pstr->bufs_len))
4135 return REG_ESPACE; 3994 return REG_ESPACE;
4136 3995
4137 /* Double the lengths of the buffers, but allocate at least MIN_LEN. */ 3996 /* Double the lengths of the buffers, but allocate at least MIN_LEN. */
4138 ret = re_string_realloc_buffers (pstr, 3997 ret = re_string_realloc_buffers (pstr,
4139 MAX (min_len, 3998 MAX (min_len,
4140 MIN (pstr->len, pstr->bufs_len * 2))); 3999 MIN (pstr->len, pstr->bufs_len * 2)));
4141 if (BE (ret != REG_NOERROR, 0)) 4000 if (__glibc_unlikely (ret != REG_NOERROR))
4142 return ret; 4001 return ret;
4143 4002
4144 if (mctx->state_log != NULL) 4003 if (mctx->state_log != NULL)
@@ -4149,7 +4008,7 @@ extend_buffers (re_match_context_t *mctx, int min_len)
4149 does not have the right size. */ 4008 does not have the right size. */
4150 re_dfastate_t **new_array = re_realloc (mctx->state_log, re_dfastate_t *, 4009 re_dfastate_t **new_array = re_realloc (mctx->state_log, re_dfastate_t *,
4151 pstr->bufs_len + 1); 4010 pstr->bufs_len + 1);
4152 if (BE (new_array == NULL, 0)) 4011 if (__glibc_unlikely (new_array == NULL))
4153 return REG_ESPACE; 4012 return REG_ESPACE;
4154 mctx->state_log = new_array; 4013 mctx->state_log = new_array;
4155 } 4014 }
@@ -4161,7 +4020,7 @@ extend_buffers (re_match_context_t *mctx, int min_len)
4161 if (pstr->mb_cur_max > 1) 4020 if (pstr->mb_cur_max > 1)
4162 { 4021 {
4163 ret = build_wcs_upper_buffer (pstr); 4022 ret = build_wcs_upper_buffer (pstr);
4164 if (BE (ret != REG_NOERROR, 0)) 4023 if (__glibc_unlikely (ret != REG_NOERROR))
4165 return ret; 4024 return ret;
4166 } 4025 }
4167 else 4026 else
@@ -4189,23 +4048,23 @@ extend_buffers (re_match_context_t *mctx, int min_len)
4189/* Initialize MCTX. */ 4048/* Initialize MCTX. */
4190 4049
4191static reg_errcode_t 4050static reg_errcode_t
4192internal_function __attribute_warn_unused_result__ 4051__attribute_warn_unused_result__
4193match_ctx_init (re_match_context_t *mctx, int eflags, Idx n) 4052match_ctx_init (re_match_context_t *mctx, int eflags, Idx n)
4194{ 4053{
4195 mctx->eflags = eflags; 4054 mctx->eflags = eflags;
4196 mctx->match_last = REG_MISSING; 4055 mctx->match_last = -1;
4197 if (n > 0) 4056 if (n > 0)
4198 { 4057 {
4199 /* Avoid overflow. */ 4058 /* Avoid overflow. */
4200 size_t max_object_size = 4059 size_t max_object_size =
4201 MAX (sizeof (struct re_backref_cache_entry), 4060 MAX (sizeof (struct re_backref_cache_entry),
4202 sizeof (re_sub_match_top_t *)); 4061 sizeof (re_sub_match_top_t *));
4203 if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) < n, 0)) 4062 if (__glibc_unlikely (MIN (IDX_MAX, SIZE_MAX / max_object_size) < n))
4204 return REG_ESPACE; 4063 return REG_ESPACE;
4205 4064
4206 mctx->bkref_ents = re_malloc (struct re_backref_cache_entry, n); 4065 mctx->bkref_ents = re_malloc (struct re_backref_cache_entry, n);
4207 mctx->sub_tops = re_malloc (re_sub_match_top_t *, n); 4066 mctx->sub_tops = re_malloc (re_sub_match_top_t *, n);
4208 if (BE (mctx->bkref_ents == NULL || mctx->sub_tops == NULL, 0)) 4067 if (__glibc_unlikely (mctx->bkref_ents == NULL || mctx->sub_tops == NULL))
4209 return REG_ESPACE; 4068 return REG_ESPACE;
4210 } 4069 }
4211 /* Already zero-ed by the caller. 4070 /* Already zero-ed by the caller.
@@ -4224,7 +4083,6 @@ match_ctx_init (re_match_context_t *mctx, int eflags, Idx n)
4224 of the input, or changes the input string. */ 4083 of the input, or changes the input string. */
4225 4084
4226static void 4085static void
4227internal_function
4228match_ctx_clean (re_match_context_t *mctx) 4086match_ctx_clean (re_match_context_t *mctx)
4229{ 4087{
4230 Idx st_idx; 4088 Idx st_idx;
@@ -4244,7 +4102,7 @@ match_ctx_clean (re_match_context_t *mctx)
4244 re_free (top->path->array); 4102 re_free (top->path->array);
4245 re_free (top->path); 4103 re_free (top->path);
4246 } 4104 }
4247 free (top); 4105 re_free (top);
4248 } 4106 }
4249 4107
4250 mctx->nsub_tops = 0; 4108 mctx->nsub_tops = 0;
@@ -4254,7 +4112,6 @@ match_ctx_clean (re_match_context_t *mctx)
4254/* Free all the memory associated with MCTX. */ 4112/* Free all the memory associated with MCTX. */
4255 4113
4256static void 4114static void
4257internal_function
4258match_ctx_free (re_match_context_t *mctx) 4115match_ctx_free (re_match_context_t *mctx)
4259{ 4116{
4260 /* First, free all the memory associated with MCTX->SUB_TOPS. */ 4117 /* First, free all the memory associated with MCTX->SUB_TOPS. */
@@ -4269,7 +4126,7 @@ match_ctx_free (re_match_context_t *mctx)
4269*/ 4126*/
4270 4127
4271static reg_errcode_t 4128static reg_errcode_t
4272internal_function __attribute_warn_unused_result__ 4129__attribute_warn_unused_result__
4273match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from, 4130match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from,
4274 Idx to) 4131 Idx to)
4275{ 4132{
@@ -4278,7 +4135,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; 4135 struct re_backref_cache_entry* new_entry;
4279 new_entry = re_realloc (mctx->bkref_ents, struct re_backref_cache_entry, 4136 new_entry = re_realloc (mctx->bkref_ents, struct re_backref_cache_entry,
4280 mctx->abkref_ents * 2); 4137 mctx->abkref_ents * 2);
4281 if (BE (new_entry == NULL, 0)) 4138 if (__glibc_unlikely (new_entry == NULL))
4282 { 4139 {
4283 re_free (mctx->bkref_ents); 4140 re_free (mctx->bkref_ents);
4284 return REG_ESPACE; 4141 return REG_ESPACE;
@@ -4314,11 +4171,10 @@ match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from,
4314 return REG_NOERROR; 4171 return REG_NOERROR;
4315} 4172}
4316 4173
4317/* Return the first entry with the same str_idx, or REG_MISSING if none is 4174/* 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. */ 4175 found. Note that MCTX->BKREF_ENTS is already sorted by MCTX->STR_IDX. */
4319 4176
4320static Idx 4177static Idx
4321internal_function
4322search_cur_bkref_entry (const re_match_context_t *mctx, Idx str_idx) 4178search_cur_bkref_entry (const re_match_context_t *mctx, Idx str_idx)
4323{ 4179{
4324 Idx left, right, mid, last; 4180 Idx left, right, mid, last;
@@ -4334,33 +4190,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) 4190 if (left < last && mctx->bkref_ents[left].str_idx == str_idx)
4335 return left; 4191 return left;
4336 else 4192 else
4337 return REG_MISSING; 4193 return -1;
4338} 4194}
4339 4195
4340/* Register the node NODE, whose type is OP_OPEN_SUBEXP, and which matches 4196/* Register the node NODE, whose type is OP_OPEN_SUBEXP, and which matches
4341 at STR_IDX. */ 4197 at STR_IDX. */
4342 4198
4343static reg_errcode_t 4199static reg_errcode_t
4344internal_function __attribute_warn_unused_result__ 4200__attribute_warn_unused_result__
4345match_ctx_add_subtop (re_match_context_t *mctx, Idx node, Idx str_idx) 4201match_ctx_add_subtop (re_match_context_t *mctx, Idx node, Idx str_idx)
4346{ 4202{
4347#ifdef DEBUG 4203 DEBUG_ASSERT (mctx->sub_tops != NULL);
4348 assert (mctx->sub_tops != NULL); 4204 DEBUG_ASSERT (mctx->asub_tops > 0);
4349 assert (mctx->asub_tops > 0); 4205 if (__glibc_unlikely (mctx->nsub_tops == mctx->asub_tops))
4350#endif
4351 if (BE (mctx->nsub_tops == mctx->asub_tops, 0))
4352 { 4206 {
4353 Idx new_asub_tops = mctx->asub_tops * 2; 4207 Idx new_asub_tops = mctx->asub_tops * 2;
4354 re_sub_match_top_t **new_array = re_realloc (mctx->sub_tops, 4208 re_sub_match_top_t **new_array = re_realloc (mctx->sub_tops,
4355 re_sub_match_top_t *, 4209 re_sub_match_top_t *,
4356 new_asub_tops); 4210 new_asub_tops);
4357 if (BE (new_array == NULL, 0)) 4211 if (__glibc_unlikely (new_array == NULL))
4358 return REG_ESPACE; 4212 return REG_ESPACE;
4359 mctx->sub_tops = new_array; 4213 mctx->sub_tops = new_array;
4360 mctx->asub_tops = new_asub_tops; 4214 mctx->asub_tops = new_asub_tops;
4361 } 4215 }
4362 mctx->sub_tops[mctx->nsub_tops] = calloc (1, sizeof (re_sub_match_top_t)); 4216 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)) 4217 if (__glibc_unlikely (mctx->sub_tops[mctx->nsub_tops] == NULL))
4364 return REG_ESPACE; 4218 return REG_ESPACE;
4365 mctx->sub_tops[mctx->nsub_tops]->node = node; 4219 mctx->sub_tops[mctx->nsub_tops]->node = node;
4366 mctx->sub_tops[mctx->nsub_tops++]->str_idx = str_idx; 4220 mctx->sub_tops[mctx->nsub_tops++]->str_idx = str_idx;
@@ -4368,26 +4222,26 @@ match_ctx_add_subtop (re_match_context_t *mctx, Idx node, Idx str_idx)
4368} 4222}
4369 4223
4370/* Register the node NODE, whose type is OP_CLOSE_SUBEXP, and which matches 4224/* 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. */ 4225 at STR_IDX, whose corresponding OP_OPEN_SUBEXP is SUB_TOP.
4226 Return the new entry if successful, NULL if memory is exhausted. */
4372 4227
4373static re_sub_match_last_t * 4228static re_sub_match_last_t *
4374internal_function
4375match_ctx_add_sublast (re_sub_match_top_t *subtop, Idx node, Idx str_idx) 4229match_ctx_add_sublast (re_sub_match_top_t *subtop, Idx node, Idx str_idx)
4376{ 4230{
4377 re_sub_match_last_t *new_entry; 4231 re_sub_match_last_t *new_entry;
4378 if (BE (subtop->nlasts == subtop->alasts, 0)) 4232 if (__glibc_unlikely (subtop->nlasts == subtop->alasts))
4379 { 4233 {
4380 Idx new_alasts = 2 * subtop->alasts + 1; 4234 Idx new_alasts = 2 * subtop->alasts + 1;
4381 re_sub_match_last_t **new_array = re_realloc (subtop->lasts, 4235 re_sub_match_last_t **new_array = re_realloc (subtop->lasts,
4382 re_sub_match_last_t *, 4236 re_sub_match_last_t *,
4383 new_alasts); 4237 new_alasts);
4384 if (BE (new_array == NULL, 0)) 4238 if (__glibc_unlikely (new_array == NULL))
4385 return NULL; 4239 return NULL;
4386 subtop->lasts = new_array; 4240 subtop->lasts = new_array;
4387 subtop->alasts = new_alasts; 4241 subtop->alasts = new_alasts;
4388 } 4242 }
4389 new_entry = calloc (1, sizeof (re_sub_match_last_t)); 4243 new_entry = calloc (1, sizeof (re_sub_match_last_t));
4390 if (BE (new_entry != NULL, 1)) 4244 if (__glibc_likely (new_entry != NULL))
4391 { 4245 {
4392 subtop->lasts[subtop->nlasts] = new_entry; 4246 subtop->lasts[subtop->nlasts] = new_entry;
4393 new_entry->node = node; 4247 new_entry->node = node;
@@ -4398,7 +4252,6 @@ match_ctx_add_sublast (re_sub_match_top_t *subtop, Idx node, Idx str_idx)
4398} 4252}
4399 4253
4400static void 4254static void
4401internal_function
4402sift_ctx_init (re_sift_context_t *sctx, re_dfastate_t **sifted_sts, 4255sift_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) 4256 re_dfastate_t **limited_sts, Idx last_node, Idx last_str_idx)
4404{ 4257{
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..3ad3477 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-2021 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..53e231c
--- /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-2021 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..dbfda25
--- /dev/null
+++ b/gl/setlocale_null.c
@@ -0,0 +1,411 @@
1/* Query the name of the current global locale.
2 Copyright (C) 2019-2021 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..00c42e2
--- /dev/null
+++ b/gl/setlocale_null.h
@@ -0,0 +1,82 @@
1/* Query the name of the current global locale.
2 Copyright (C) 2019-2021 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-stream.c b/gl/sha1-stream.c
new file mode 100644
index 0000000..fbf8c7b
--- /dev/null
+++ b/gl/sha1-stream.c
@@ -0,0 +1,129 @@
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-2021 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 Scott G. Miller
20 Credits:
21 Robert Klep <robert@ilse.nl> -- Expansion function fix
22*/
23
24#include <config.h>
25
26/* Specification. */
27#if HAVE_OPENSSL_SHA1
28# define GL_OPENSSL_INLINE _GL_EXTERN_INLINE
29#endif
30#include "sha1.h"
31
32#include <stdlib.h>
33
34#if USE_UNLOCKED_IO
35# include "unlocked-io.h"
36#endif
37
38#include "af_alg.h"
39
40#define BLOCKSIZE 32768
41#if BLOCKSIZE % 64 != 0
42# error "invalid BLOCKSIZE"
43#endif
44
45/* Compute SHA1 message digest for bytes read from STREAM. The
46 resulting message digest number will be written into the 20 bytes
47 beginning at RESBLOCK. */
48int
49sha1_stream (FILE *stream, void *resblock)
50{
51 switch (afalg_stream (stream, "sha1", resblock, SHA1_DIGEST_SIZE))
52 {
53 case 0: return 0;
54 case -EIO: return 1;
55 }
56
57 char *buffer = malloc (BLOCKSIZE + 72);
58 if (!buffer)
59 return 1;
60
61 struct sha1_ctx ctx;
62 sha1_init_ctx (&ctx);
63 size_t sum;
64
65 /* Iterate over full file contents. */
66 while (1)
67 {
68 /* We read the file in blocks of BLOCKSIZE bytes. One call of the
69 computation function processes the whole buffer so that with the
70 next round of the loop another block can be read. */
71 size_t n;
72 sum = 0;
73
74 /* Read block. Take care for partial reads. */
75 while (1)
76 {
77 /* Either process a partial fread() from this loop,
78 or the fread() in afalg_stream may have gotten EOF.
79 We need to avoid a subsequent fread() as EOF may
80 not be sticky. For details of such systems, see:
81 https://sourceware.org/bugzilla/show_bug.cgi?id=1190 */
82 if (feof (stream))
83 goto process_partial_block;
84
85 n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
86
87 sum += n;
88
89 if (sum == BLOCKSIZE)
90 break;
91
92 if (n == 0)
93 {
94 /* Check for the error flag IFF N == 0, so that we don't
95 exit the loop after a partial read due to e.g., EAGAIN
96 or EWOULDBLOCK. */
97 if (ferror (stream))
98 {
99 free (buffer);
100 return 1;
101 }
102 goto process_partial_block;
103 }
104 }
105
106 /* Process buffer with BLOCKSIZE bytes. Note that
107 BLOCKSIZE % 64 == 0
108 */
109 sha1_process_block (buffer, BLOCKSIZE, &ctx);
110 }
111
112 process_partial_block:;
113
114 /* Process any remaining bytes. */
115 if (sum > 0)
116 sha1_process_bytes (buffer, sum, &ctx);
117
118 /* Construct result in desired memory. */
119 sha1_finish_ctx (&ctx, resblock);
120 free (buffer);
121 return 0;
122}
123
124/*
125 * Hey Emacs!
126 * Local Variables:
127 * coding: utf-8
128 * End:
129 */
diff --git a/gl/sha1.c b/gl/sha1.c
index 778389a..52b1020 100644
--- a/gl/sha1.c
+++ b/gl/sha1.c
@@ -1,20 +1,20 @@
1/* sha1.c - Functions to compute SHA1 message digest of files or 1/* sha1.c - Functions to compute SHA1 message digest of files or
2 memory blocks according to the NIST specification FIPS-180-1. 2 memory blocks according to the NIST specification FIPS-180-1.
3 3
4 Copyright (C) 2000-2001, 2003-2006, 2008-2013 Free Software Foundation, Inc. 4 Copyright (C) 2000-2001, 2003-2006, 2008-2021 Free Software Foundation, 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 by the 7 it under the terms of the GNU Lesser General Public License as
8 Free Software Foundation; either version 3, or (at your option) any 8 published by the Free Software Foundation; either version 2.1 of the
9 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/* Written by Scott G. Miller 19/* Written by Scott G. Miller
20 Credits: 20 Credits:
@@ -23,28 +23,24 @@
23 23
24#include <config.h> 24#include <config.h>
25 25
26/* Specification. */
27#if HAVE_OPENSSL_SHA1
28# define GL_OPENSSL_INLINE _GL_EXTERN_INLINE
29#endif
26#include "sha1.h" 30#include "sha1.h"
27 31
28#include <stdalign.h> 32#include <stdalign.h>
29#include <stdint.h> 33#include <stdint.h>
30#include <stdlib.h>
31#include <string.h> 34#include <string.h>
32 35
33#if USE_UNLOCKED_IO 36#include <byteswap.h>
34# include "unlocked-io.h"
35#endif
36
37#ifdef WORDS_BIGENDIAN 37#ifdef WORDS_BIGENDIAN
38# define SWAP(n) (n) 38# define SWAP(n) (n)
39#else 39#else
40# define SWAP(n) \ 40# define SWAP(n) bswap_32 (n)
41 (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
42#endif 41#endif
43 42
44#define BLOCKSIZE 32768 43#if ! HAVE_OPENSSL_SHA1
45#if BLOCKSIZE % 64 != 0
46# error "invalid BLOCKSIZE"
47#endif
48 44
49/* This array contains the bytes used to pad the buffer to the next 45/* This array contains the bytes used to pad the buffer to the next
50 64-byte boundary. (RFC 1321, 3.1: Step 1) */ 46 64-byte boundary. (RFC 1321, 3.1: Step 1) */
@@ -117,79 +113,6 @@ sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf)
117 return sha1_read_ctx (ctx, resbuf); 113 return sha1_read_ctx (ctx, resbuf);
118} 114}
119 115
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 116/* 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 117 result is always in little endian byte order, so that a byte-wise
195 output yields to the wanted ASCII representation of the message 118 output yields to the wanted ASCII representation of the message
@@ -227,7 +150,8 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
227 sha1_process_block (ctx->buffer, ctx->buflen & ~63, ctx); 150 sha1_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
228 151
229 ctx->buflen &= 63; 152 ctx->buflen &= 63;
230 /* The regions in the following copy operation cannot overlap. */ 153 /* The regions in the following copy operation cannot overlap,
154 because ctx->buflen < 64 ≤ (left_over + add) & ~63. */
231 memcpy (ctx->buffer, 155 memcpy (ctx->buffer,
232 &((char *) ctx->buffer)[(left_over + add) & ~63], 156 &((char *) ctx->buffer)[(left_over + add) & ~63],
233 ctx->buflen); 157 ctx->buflen);
@@ -240,7 +164,7 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
240 /* Process available complete blocks. */ 164 /* Process available complete blocks. */
241 if (len >= 64) 165 if (len >= 64)
242 { 166 {
243#if !_STRING_ARCH_unaligned 167#if !(_STRING_ARCH_unaligned || _STRING_INLINE_unaligned)
244# define UNALIGNED_P(p) ((uintptr_t) (p) % alignof (uint32_t) != 0) 168# define UNALIGNED_P(p) ((uintptr_t) (p) % alignof (uint32_t) != 0)
245 if (UNALIGNED_P (buffer)) 169 if (UNALIGNED_P (buffer))
246 while (len > 64) 170 while (len > 64)
@@ -269,6 +193,8 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
269 { 193 {
270 sha1_process_block (ctx->buffer, 64, ctx); 194 sha1_process_block (ctx->buffer, 64, ctx);
271 left_over -= 64; 195 left_over -= 64;
196 /* The regions in the following copy operation cannot overlap,
197 because left_over ≤ 64. */
272 memcpy (ctx->buffer, &ctx->buffer[16], left_over); 198 memcpy (ctx->buffer, &ctx->buffer[16], left_over);
273 } 199 }
274 ctx->buflen = left_over; 200 ctx->buflen = left_over;
@@ -424,3 +350,12 @@ sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx)
424 e = ctx->E += e; 350 e = ctx->E += e;
425 } 351 }
426} 352}
353
354#endif
355
356/*
357 * Hey Emacs!
358 * Local Variables:
359 * coding: utf-8
360 * End:
361 */
diff --git a/gl/sha1.h b/gl/sha1.h
index ddd386f..e12a23c 100644
--- a/gl/sha1.h
+++ b/gl/sha1.h
@@ -1,20 +1,20 @@
1/* Declarations of functions and data types used for SHA1 sum 1/* Declarations of functions and data types used for SHA1 sum
2 library functions. 2 library functions.
3 Copyright (C) 2000-2001, 2003, 2005-2006, 2008-2013 Free Software 3 Copyright (C) 2000-2001, 2003, 2005-2006, 2008-2021 Free Software
4 Foundation, Inc. 4 Foundation, Inc.
5 5
6 This program is free software; you can redistribute it and/or modify it 6 This file is free software: you can redistribute it and/or modify
7 under the terms of the GNU General Public License as published by the 7 it under the terms of the GNU Lesser General Public License as
8 Free Software Foundation; either version 3, or (at your option) any 8 published by the Free Software Foundation; either version 2.1 of the
9 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 SHA1_H 19#ifndef SHA1_H
20# define SHA1_H 1 20# define SHA1_H 1
@@ -22,12 +22,20 @@
22# include <stdio.h> 22# include <stdio.h>
23# include <stdint.h> 23# include <stdint.h>
24 24
25# if HAVE_OPENSSL_SHA1
26# include <openssl/sha.h>
27# endif
28
25# ifdef __cplusplus 29# ifdef __cplusplus
26extern "C" { 30extern "C" {
27# endif 31# endif
28 32
29#define SHA1_DIGEST_SIZE 20 33# define SHA1_DIGEST_SIZE 20
30 34
35# if HAVE_OPENSSL_SHA1
36# define GL_OPENSSL_NAME 1
37# include "gl_openssl.h"
38# else
31/* Structure to save state of computation between the single steps. */ 39/* Structure to save state of computation between the single steps. */
32struct sha1_ctx 40struct sha1_ctx
33{ 41{
@@ -38,11 +46,10 @@ struct sha1_ctx
38 uint32_t E; 46 uint32_t E;
39 47
40 uint32_t total[2]; 48 uint32_t total[2];
41 uint32_t buflen; 49 uint32_t buflen; /* ≥ 0, ≤ 128 */
42 uint32_t buffer[32]; 50 uint32_t buffer[32]; /* 128 bytes; the first buflen bytes are in use */
43}; 51};
44 52
45
46/* Initialize structure containing state of computation. */ 53/* Initialize structure containing state of computation. */
47extern void sha1_init_ctx (struct sha1_ctx *ctx); 54extern void sha1_init_ctx (struct sha1_ctx *ctx);
48 55
@@ -64,28 +71,42 @@ extern void sha1_process_bytes (const void *buffer, size_t len,
64 in first 20 bytes following RESBUF. The result is always in little 71 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 72 endian byte order, so that a byte-wise output yields to the wanted
66 ASCII representation of the message digest. */ 73 ASCII representation of the message digest. */
67extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf); 74extern void *sha1_finish_ctx (struct sha1_ctx *ctx, void *restrict resbuf);
68 75
69 76
70/* Put result from CTX in first 20 bytes following RESBUF. The result is 77/* 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 78 always in little endian byte order, so that a byte-wise output yields
72 to the wanted ASCII representation of the message digest. */ 79 to the wanted ASCII representation of the message digest. */
73extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf); 80extern void *sha1_read_ctx (const struct sha1_ctx *ctx, void *restrict resbuf);
74 81
75 82
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 83/* 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 84 result is always in little endian byte order, so that a byte-wise
83 output yields to the wanted ASCII representation of the message 85 output yields to the wanted ASCII representation of the message
84 digest. */ 86 digest. */
85extern void *sha1_buffer (const char *buffer, size_t len, void *resblock); 87extern void *sha1_buffer (const char *buffer, size_t len,
88 void *restrict resblock);
89
90# endif
91
92/* Compute SHA1 message digest for bytes read from STREAM.
93 STREAM is an open file stream. Regular files are handled more efficiently.
94 The contents of STREAM from its current position to its end will be read.
95 The case that the last operation on STREAM was an 'ungetc' is not supported.
96 The resulting message digest number will be written into the 20 bytes
97 beginning at RESBLOCK. */
98extern int sha1_stream (FILE *stream, void *resblock);
99
86 100
87# ifdef __cplusplus 101# ifdef __cplusplus
88} 102}
89# endif 103# endif
90 104
91#endif 105#endif
106
107/*
108 * Hey Emacs!
109 * Local Variables:
110 * coding: utf-8
111 * End:
112 */
diff --git a/gl/size_max.h b/gl/size_max.h
index 5f33124..1186ba9 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-2021 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..a589cf1 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-2021 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..f7846b3 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-2021 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..e70c2bb 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-2021 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..7b92792
--- /dev/null
+++ b/gl/stat-time.c
@@ -0,0 +1,21 @@
1/* stat-related time functions.
2
3 Copyright (C) 2012-2021 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..6b2cc68
--- /dev/null
+++ b/gl/stat-time.h
@@ -0,0 +1,252 @@
1/* stat-related time functions.
2
3 Copyright (C) 2005, 2007, 2009-2021 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 "intprops.h"
24
25#include <errno.h>
26#include <stddef.h>
27#include <sys/stat.h>
28#include <time.h>
29
30#ifndef _GL_INLINE_HEADER_BEGIN
31 #error "Please include config.h first."
32#endif
33_GL_INLINE_HEADER_BEGIN
34#ifndef _GL_STAT_TIME_INLINE
35# define _GL_STAT_TIME_INLINE _GL_INLINE
36#endif
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42/* STAT_TIMESPEC (ST, ST_XTIM) is the ST_XTIM member for *ST of type
43 struct timespec, if available. If not, then STAT_TIMESPEC_NS (ST,
44 ST_XTIM) is the nanosecond component of the ST_XTIM member for *ST,
45 if available. ST_XTIM can be st_atim, st_ctim, st_mtim, or st_birthtim
46 for access, status change, data modification, or birth (creation)
47 time respectively.
48
49 These macros are private to stat-time.h. */
50#if _GL_WINDOWS_STAT_TIMESPEC || defined HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC
51# if _GL_WINDOWS_STAT_TIMESPEC || defined TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC
52# define STAT_TIMESPEC(st, st_xtim) ((st)->st_xtim)
53# else
54# define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim.tv_nsec)
55# endif
56#elif defined HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC
57# define STAT_TIMESPEC(st, st_xtim) ((st)->st_xtim##espec)
58#elif defined HAVE_STRUCT_STAT_ST_ATIMENSEC
59# define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim##ensec)
60#elif defined HAVE_STRUCT_STAT_ST_ATIM_ST__TIM_TV_NSEC
61# define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim.st__tim.tv_nsec)
62#endif
63
64/* Return the nanosecond component of *ST's access time. */
65_GL_STAT_TIME_INLINE long int _GL_ATTRIBUTE_PURE
66get_stat_atime_ns (struct stat const *st)
67{
68# if defined STAT_TIMESPEC
69 return STAT_TIMESPEC (st, st_atim).tv_nsec;
70# elif defined STAT_TIMESPEC_NS
71 return STAT_TIMESPEC_NS (st, st_atim);
72# else
73 return 0;
74# endif
75}
76
77/* Return the nanosecond component of *ST's status change time. */
78_GL_STAT_TIME_INLINE long int _GL_ATTRIBUTE_PURE
79get_stat_ctime_ns (struct stat const *st)
80{
81# if defined STAT_TIMESPEC
82 return STAT_TIMESPEC (st, st_ctim).tv_nsec;
83# elif defined STAT_TIMESPEC_NS
84 return STAT_TIMESPEC_NS (st, st_ctim);
85# else
86 return 0;
87# endif
88}
89
90/* Return the nanosecond component of *ST's data modification time. */
91_GL_STAT_TIME_INLINE long int _GL_ATTRIBUTE_PURE
92get_stat_mtime_ns (struct stat const *st)
93{
94# if defined STAT_TIMESPEC
95 return STAT_TIMESPEC (st, st_mtim).tv_nsec;
96# elif defined STAT_TIMESPEC_NS
97 return STAT_TIMESPEC_NS (st, st_mtim);
98# else
99 return 0;
100# endif
101}
102
103/* Return the nanosecond component of *ST's birth time. */
104_GL_STAT_TIME_INLINE long int _GL_ATTRIBUTE_PURE
105get_stat_birthtime_ns (_GL_UNUSED struct stat const *st)
106{
107# if defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC
108 return STAT_TIMESPEC (st, st_birthtim).tv_nsec;
109# elif defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC
110 return STAT_TIMESPEC_NS (st, st_birthtim);
111# else
112 return 0;
113# endif
114}
115
116/* Return *ST's access time. */
117_GL_STAT_TIME_INLINE struct timespec _GL_ATTRIBUTE_PURE
118get_stat_atime (struct stat const *st)
119{
120#ifdef STAT_TIMESPEC
121 return STAT_TIMESPEC (st, st_atim);
122#else
123 struct timespec t;
124 t.tv_sec = st->st_atime;
125 t.tv_nsec = get_stat_atime_ns (st);
126 return t;
127#endif
128}
129
130/* Return *ST's status change time. */
131_GL_STAT_TIME_INLINE struct timespec _GL_ATTRIBUTE_PURE
132get_stat_ctime (struct stat const *st)
133{
134#ifdef STAT_TIMESPEC
135 return STAT_TIMESPEC (st, st_ctim);
136#else
137 struct timespec t;
138 t.tv_sec = st->st_ctime;
139 t.tv_nsec = get_stat_ctime_ns (st);
140 return t;
141#endif
142}
143
144/* Return *ST's data modification time. */
145_GL_STAT_TIME_INLINE struct timespec _GL_ATTRIBUTE_PURE
146get_stat_mtime (struct stat const *st)
147{
148#ifdef STAT_TIMESPEC
149 return STAT_TIMESPEC (st, st_mtim);
150#else
151 struct timespec t;
152 t.tv_sec = st->st_mtime;
153 t.tv_nsec = get_stat_mtime_ns (st);
154 return t;
155#endif
156}
157
158/* Return *ST's birth time, if available; otherwise return a value
159 with tv_sec and tv_nsec both equal to -1. */
160_GL_STAT_TIME_INLINE struct timespec _GL_ATTRIBUTE_PURE
161get_stat_birthtime (_GL_UNUSED struct stat const *st)
162{
163 struct timespec t;
164
165#if (defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC \
166 || defined HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC)
167 t = STAT_TIMESPEC (st, st_birthtim);
168#elif defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC
169 t.tv_sec = st->st_birthtime;
170 t.tv_nsec = st->st_birthtimensec;
171#elif defined _WIN32 && ! defined __CYGWIN__
172 /* Native Windows platforms (but not Cygwin) put the "file creation
173 time" in st_ctime (!). See
174 <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions>. */
175# if _GL_WINDOWS_STAT_TIMESPEC
176 t = st->st_ctim;
177# else
178 t.tv_sec = st->st_ctime;
179 t.tv_nsec = 0;
180# endif
181#else
182 /* Birth time is not supported. */
183 t.tv_sec = -1;
184 t.tv_nsec = -1;
185#endif
186
187#if (defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC \
188 || defined HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC \
189 || defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC)
190 /* FreeBSD and NetBSD sometimes signal the absence of knowledge by
191 using zero. Attempt to work around this problem. Alas, this can
192 report failure even for valid timestamps. Also, NetBSD
193 sometimes returns junk in the birth time fields; work around this
194 bug if it is detected. */
195 if (! (t.tv_sec && 0 <= t.tv_nsec && t.tv_nsec < 1000000000))
196 {
197 t.tv_sec = -1;
198 t.tv_nsec = -1;
199 }
200#endif
201
202 return t;
203}
204
205/* If a stat-like function returned RESULT, normalize the timestamps
206 in *ST, in case this platform suffers from the Solaris 11 bug where
207 tv_nsec might be negative. Return the adjusted RESULT, setting
208 errno to EOVERFLOW if normalization overflowed. This function
209 is intended to be private to this .h file. */
210_GL_STAT_TIME_INLINE int
211stat_time_normalize (int result, _GL_UNUSED struct stat *st)
212{
213#if defined __sun && defined STAT_TIMESPEC
214 if (result == 0)
215 {
216 long int timespec_hz = 1000000000;
217 short int const ts_off[] = { offsetof (struct stat, st_atim),
218 offsetof (struct stat, st_mtim),
219 offsetof (struct stat, st_ctim) };
220 int i;
221 for (i = 0; i < sizeof ts_off / sizeof *ts_off; i++)
222 {
223 struct timespec *ts = (struct timespec *) ((char *) st + ts_off[i]);
224 long int q = ts->tv_nsec / timespec_hz;
225 long int r = ts->tv_nsec % timespec_hz;
226 if (r < 0)
227 {
228 r += timespec_hz;
229 q--;
230 }
231 ts->tv_nsec = r;
232 /* Overflow is possible, as Solaris 11 stat can yield
233 tv_sec == TYPE_MINIMUM (time_t) && tv_nsec == -1000000000.
234 INT_ADD_WRAPV is OK, since time_t is signed on Solaris. */
235 if (INT_ADD_WRAPV (q, ts->tv_sec, &ts->tv_sec))
236 {
237 errno = EOVERFLOW;
238 return -1;
239 }
240 }
241 }
242#endif
243 return result;
244}
245
246#ifdef __cplusplus
247}
248#endif
249
250_GL_INLINE_HEADER_END
251
252#endif
diff --git a/gl/stat-w32.c b/gl/stat-w32.c
new file mode 100644
index 0000000..4164199
--- /dev/null
+++ b/gl/stat-w32.c
@@ -0,0 +1,461 @@
1/* Core of implementation of fstat and stat for native Windows.
2 Copyright (C) 2017-2021 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#include "verify.h"
54
55/* Don't assume that UNICODE is not defined. */
56#undef LoadLibrary
57#define LoadLibrary LoadLibraryA
58#undef GetFinalPathNameByHandle
59#define GetFinalPathNameByHandle GetFinalPathNameByHandleA
60
61/* Older mingw headers do not define VOLUME_NAME_NONE. */
62#ifndef VOLUME_NAME_NONE
63# define VOLUME_NAME_NONE 4
64#endif
65
66#if !WIN32_ASSUME_VISTA
67
68/* Avoid warnings from gcc -Wcast-function-type. */
69# define GetProcAddress \
70 (void *) GetProcAddress
71
72# if _GL_WINDOWS_STAT_INODES == 2
73/* GetFileInformationByHandleEx was introduced only in Windows Vista. */
74typedef DWORD (WINAPI * GetFileInformationByHandleExFuncType) (HANDLE hFile,
75 FILE_INFO_BY_HANDLE_CLASS fiClass,
76 LPVOID lpBuffer,
77 DWORD dwBufferSize);
78static GetFileInformationByHandleExFuncType GetFileInformationByHandleExFunc = NULL;
79# endif
80/* GetFinalPathNameByHandle was introduced only in Windows Vista. */
81typedef DWORD (WINAPI * GetFinalPathNameByHandleFuncType) (HANDLE hFile,
82 LPSTR lpFilePath,
83 DWORD lenFilePath,
84 DWORD dwFlags);
85static GetFinalPathNameByHandleFuncType GetFinalPathNameByHandleFunc = NULL;
86static BOOL initialized = FALSE;
87
88static void
89initialize (void)
90{
91 HMODULE kernel32 = LoadLibrary ("kernel32.dll");
92 if (kernel32 != NULL)
93 {
94# if _GL_WINDOWS_STAT_INODES == 2
95 GetFileInformationByHandleExFunc =
96 (GetFileInformationByHandleExFuncType) GetProcAddress (kernel32, "GetFileInformationByHandleEx");
97# endif
98 GetFinalPathNameByHandleFunc =
99 (GetFinalPathNameByHandleFuncType) GetProcAddress (kernel32, "GetFinalPathNameByHandleA");
100 }
101 initialized = TRUE;
102}
103
104#else
105
106# define GetFileInformationByHandleExFunc GetFileInformationByHandleEx
107# define GetFinalPathNameByHandleFunc GetFinalPathNameByHandle
108
109#endif
110
111/* Converts a FILETIME to GMT time since 1970-01-01 00:00:00. */
112#if _GL_WINDOWS_STAT_TIMESPEC
113struct timespec
114_gl_convert_FILETIME_to_timespec (const FILETIME *ft)
115{
116 struct timespec result;
117 /* FILETIME: <https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ns-minwinbase-filetime> */
118 unsigned long long since_1601 =
119 ((unsigned long long) ft->dwHighDateTime << 32)
120 | (unsigned long long) ft->dwLowDateTime;
121 if (since_1601 == 0)
122 {
123 result.tv_sec = 0;
124 result.tv_nsec = 0;
125 }
126 else
127 {
128 /* Between 1601-01-01 and 1970-01-01 there were 280 normal years and 89
129 leap years, in total 134774 days. */
130 unsigned long long since_1970 =
131 since_1601 - (unsigned long long) 134774 * (unsigned long long) 86400 * (unsigned long long) 10000000;
132 result.tv_sec = since_1970 / (unsigned long long) 10000000;
133 result.tv_nsec = (unsigned long) (since_1970 % (unsigned long long) 10000000) * 100;
134 }
135 return result;
136}
137#else
138time_t
139_gl_convert_FILETIME_to_POSIX (const FILETIME *ft)
140{
141 /* FILETIME: <https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ns-minwinbase-filetime> */
142 unsigned long long since_1601 =
143 ((unsigned long long) ft->dwHighDateTime << 32)
144 | (unsigned long long) ft->dwLowDateTime;
145 if (since_1601 == 0)
146 return 0;
147 else
148 {
149 /* Between 1601-01-01 and 1970-01-01 there were 280 normal years and 89
150 leap years, in total 134774 days. */
151 unsigned long long since_1970 =
152 since_1601 - (unsigned long long) 134774 * (unsigned long long) 86400 * (unsigned long long) 10000000;
153 return since_1970 / (unsigned long long) 10000000;
154 }
155}
156#endif
157
158/* Fill *BUF with information about the file designated by H.
159 PATH is the file name, if known, otherwise NULL.
160 Return 0 if successful, or -1 with errno set upon failure. */
161int
162_gl_fstat_by_handle (HANDLE h, const char *path, struct stat *buf)
163{
164 /* GetFileType
165 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfiletype> */
166 DWORD type = GetFileType (h);
167 if (type == FILE_TYPE_DISK)
168 {
169#if !WIN32_ASSUME_VISTA
170 if (!initialized)
171 initialize ();
172#endif
173
174 /* st_mode can be determined through
175 GetFileAttributesEx
176 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileattributesexa>
177 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_win32_file_attribute_data>
178 or through
179 GetFileInformationByHandle
180 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileinformationbyhandle>
181 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_by_handle_file_information>
182 or through
183 GetFileInformationByHandleEx with argument FileBasicInfo
184 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex>
185 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_basic_info>
186 The latter requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */
187 BY_HANDLE_FILE_INFORMATION info;
188 if (! GetFileInformationByHandle (h, &info))
189 goto failed;
190
191 /* Test for error conditions before starting to fill *buf. */
192 if (sizeof (buf->st_size) <= 4 && info.nFileSizeHigh > 0)
193 {
194 errno = EOVERFLOW;
195 return -1;
196 }
197
198#if _GL_WINDOWS_STAT_INODES
199 /* st_ino can be determined through
200 GetFileInformationByHandle
201 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileinformationbyhandle>
202 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_by_handle_file_information>
203 as 64 bits, or through
204 GetFileInformationByHandleEx with argument FileIdInfo
205 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex>
206 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_id_info>
207 as 128 bits.
208 The latter requires -D_WIN32_WINNT=_WIN32_WINNT_WIN8 or higher. */
209 /* Experiments show that GetFileInformationByHandleEx does not provide
210 much more information than GetFileInformationByHandle:
211 * The dwVolumeSerialNumber from GetFileInformationByHandle is equal
212 to the low 32 bits of the 64-bit VolumeSerialNumber from
213 GetFileInformationByHandleEx, and is apparently sufficient for
214 identifying the device.
215 * The nFileIndex from GetFileInformationByHandle is equal to the low
216 64 bits of the 128-bit FileId from GetFileInformationByHandleEx,
217 and the high 64 bits of this 128-bit FileId are zero.
218 * On a FAT file system, GetFileInformationByHandleEx fails with error
219 ERROR_INVALID_PARAMETER, whereas GetFileInformationByHandle
220 succeeds.
221 * On a CIFS/SMB file system, GetFileInformationByHandleEx fails with
222 error ERROR_INVALID_LEVEL, whereas GetFileInformationByHandle
223 succeeds. */
224# if _GL_WINDOWS_STAT_INODES == 2
225 if (GetFileInformationByHandleExFunc != NULL)
226 {
227 FILE_ID_INFO id;
228 if (GetFileInformationByHandleExFunc (h, FileIdInfo, &id, sizeof (id)))
229 {
230 buf->st_dev = id.VolumeSerialNumber;
231 verify (sizeof (ino_t) == sizeof (id.FileId));
232 memcpy (&buf->st_ino, &id.FileId, sizeof (ino_t));
233 goto ino_done;
234 }
235 else
236 {
237 switch (GetLastError ())
238 {
239 case ERROR_INVALID_PARAMETER: /* older Windows version, or FAT */
240 case ERROR_INVALID_LEVEL: /* CIFS/SMB file system */
241 goto fallback;
242 default:
243 goto failed;
244 }
245 }
246 }
247 fallback: ;
248 /* Fallback for older Windows versions. */
249 buf->st_dev = info.dwVolumeSerialNumber;
250 buf->st_ino._gl_ino[0] = ((ULONGLONG) info.nFileIndexHigh << 32) | (ULONGLONG) info.nFileIndexLow;
251 buf->st_ino._gl_ino[1] = 0;
252 ino_done: ;
253# else /* _GL_WINDOWS_STAT_INODES == 1 */
254 buf->st_dev = info.dwVolumeSerialNumber;
255 buf->st_ino = ((ULONGLONG) info.nFileIndexHigh << 32) | (ULONGLONG) info.nFileIndexLow;
256# endif
257#else
258 /* st_ino is not wide enough for identifying a file on a device.
259 Without st_ino, st_dev is pointless. */
260 buf->st_dev = 0;
261 buf->st_ino = 0;
262#endif
263
264 /* st_mode. */
265 unsigned int mode =
266 /* XXX How to handle FILE_ATTRIBUTE_REPARSE_POINT ? */
267 ((info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? _S_IFDIR | S_IEXEC_UGO : _S_IFREG)
268 | S_IREAD_UGO
269 | ((info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? 0 : S_IWRITE_UGO);
270 if (!(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
271 {
272 /* Determine whether the file is executable by looking at the file
273 name suffix.
274 If the file name is already known, use it. Otherwise, for
275 non-empty files, it can be determined through
276 GetFinalPathNameByHandle
277 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfinalpathnamebyhandlea>
278 or through
279 GetFileInformationByHandleEx with argument FileNameInfo
280 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex>
281 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_name_info>
282 Both require -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */
283 if (info.nFileSizeHigh > 0 || info.nFileSizeLow > 0)
284 {
285 char fpath[PATH_MAX];
286 if (path != NULL
287 || (GetFinalPathNameByHandleFunc != NULL
288 && GetFinalPathNameByHandleFunc (h, fpath, sizeof (fpath), VOLUME_NAME_NONE)
289 < sizeof (fpath)
290 && (path = fpath, 1)))
291 {
292 const char *last_dot = NULL;
293 const char *p;
294 for (p = path; *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 else
308 /* Cannot determine file name. Pretend that it is executable. */
309 mode |= S_IEXEC_UGO;
310 }
311 }
312 buf->st_mode = mode;
313
314 /* st_nlink can be determined through
315 GetFileInformationByHandle
316 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileinformationbyhandle>
317 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_by_handle_file_information>
318 or through
319 GetFileInformationByHandleEx with argument FileStandardInfo
320 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex>
321 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_standard_info>
322 The latter requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */
323 buf->st_nlink = (info.nNumberOfLinks > SHRT_MAX ? SHRT_MAX : info.nNumberOfLinks);
324
325 /* There's no easy way to map the Windows SID concept to an integer. */
326 buf->st_uid = 0;
327 buf->st_gid = 0;
328
329 /* st_rdev is irrelevant for normal files and directories. */
330 buf->st_rdev = 0;
331
332 /* st_size can be determined through
333 GetFileSizeEx
334 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfilesizeex>
335 or through
336 GetFileAttributesEx
337 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileattributesexa>
338 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_win32_file_attribute_data>
339 or through
340 GetFileInformationByHandle
341 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileinformationbyhandle>
342 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_by_handle_file_information>
343 or through
344 GetFileInformationByHandleEx with argument FileStandardInfo
345 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex>
346 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_standard_info>
347 The latter requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */
348 if (sizeof (buf->st_size) <= 4)
349 /* Range check already done above. */
350 buf->st_size = info.nFileSizeLow;
351 else
352 buf->st_size = ((long long) info.nFileSizeHigh << 32) | (long long) info.nFileSizeLow;
353
354 /* st_atime, st_mtime, st_ctime can be determined through
355 GetFileTime
356 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfiletime>
357 or through
358 GetFileAttributesEx
359 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileattributesexa>
360 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_win32_file_attribute_data>
361 or through
362 GetFileInformationByHandle
363 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfileinformationbyhandle>
364 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/ns-fileapi-_by_handle_file_information>
365 or through
366 GetFileInformationByHandleEx with argument FileBasicInfo
367 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getfileinformationbyhandleex>
368 <https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_basic_info>
369 The latter requires -D_WIN32_WINNT=_WIN32_WINNT_VISTA or higher. */
370#if _GL_WINDOWS_STAT_TIMESPEC
371 buf->st_atim = _gl_convert_FILETIME_to_timespec (&info.ftLastAccessTime);
372 buf->st_mtim = _gl_convert_FILETIME_to_timespec (&info.ftLastWriteTime);
373 buf->st_ctim = _gl_convert_FILETIME_to_timespec (&info.ftCreationTime);
374#else
375 buf->st_atime = _gl_convert_FILETIME_to_POSIX (&info.ftLastAccessTime);
376 buf->st_mtime = _gl_convert_FILETIME_to_POSIX (&info.ftLastWriteTime);
377 buf->st_ctime = _gl_convert_FILETIME_to_POSIX (&info.ftCreationTime);
378#endif
379
380 return 0;
381 }
382 else if (type == FILE_TYPE_CHAR || type == FILE_TYPE_PIPE)
383 {
384 buf->st_dev = 0;
385#if _GL_WINDOWS_STAT_INODES == 2
386 buf->st_ino._gl_ino[0] = buf->st_ino._gl_ino[1] = 0;
387#else
388 buf->st_ino = 0;
389#endif
390 buf->st_mode = (type == FILE_TYPE_PIPE ? _S_IFIFO : _S_IFCHR);
391 buf->st_nlink = 1;
392 buf->st_uid = 0;
393 buf->st_gid = 0;
394 buf->st_rdev = 0;
395 if (type == FILE_TYPE_PIPE)
396 {
397 /* PeekNamedPipe
398 <https://msdn.microsoft.com/en-us/library/aa365779.aspx> */
399 DWORD bytes_available;
400 if (PeekNamedPipe (h, NULL, 0, NULL, &bytes_available, NULL))
401 buf->st_size = bytes_available;
402 else
403 buf->st_size = 0;
404 }
405 else
406 buf->st_size = 0;
407#if _GL_WINDOWS_STAT_TIMESPEC
408 buf->st_atim.tv_sec = 0; buf->st_atim.tv_nsec = 0;
409 buf->st_mtim.tv_sec = 0; buf->st_mtim.tv_nsec = 0;
410 buf->st_ctim.tv_sec = 0; buf->st_ctim.tv_nsec = 0;
411#else
412 buf->st_atime = 0;
413 buf->st_mtime = 0;
414 buf->st_ctime = 0;
415#endif
416 return 0;
417 }
418 else
419 {
420 errno = ENOENT;
421 return -1;
422 }
423
424 failed:
425 {
426 DWORD error = GetLastError ();
427 #if 0
428 fprintf (stderr, "_gl_fstat_by_handle error 0x%x\n", (unsigned int) error);
429 #endif
430 switch (error)
431 {
432 case ERROR_ACCESS_DENIED:
433 case ERROR_SHARING_VIOLATION:
434 errno = EACCES;
435 break;
436
437 case ERROR_OUTOFMEMORY:
438 errno = ENOMEM;
439 break;
440
441 case ERROR_WRITE_FAULT:
442 case ERROR_READ_FAULT:
443 case ERROR_GEN_FAILURE:
444 errno = EIO;
445 break;
446
447 default:
448 errno = EINVAL;
449 break;
450 }
451 return -1;
452 }
453}
454
455#else
456
457/* This declaration is solely to ensure that after preprocessing
458 this file is never empty. */
459typedef int dummy;
460
461#endif
diff --git a/gl/stat-w32.h b/gl/stat-w32.h
new file mode 100644
index 0000000..5b56c09
--- /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-2021 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..bc9a767
--- /dev/null
+++ b/gl/stat.c
@@ -0,0 +1,440 @@
1/* Work around platform bugs in stat.
2 Copyright (C) 2009-2021 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 <stdbool.h>
59#include <string.h>
60#include "filename.h"
61#include "malloca.h"
62#include "verify.h"
63
64#ifdef WINDOWS_NATIVE
65# define WIN32_LEAN_AND_MEAN
66# include <windows.h>
67# include "stat-w32.h"
68/* Don't assume that UNICODE is not defined. */
69# undef WIN32_FIND_DATA
70# define WIN32_FIND_DATA WIN32_FIND_DATAA
71# undef CreateFile
72# define CreateFile CreateFileA
73# undef FindFirstFile
74# define FindFirstFile FindFirstFileA
75#endif
76
77#ifdef WINDOWS_NATIVE
78/* Return TRUE if the given file name denotes an UNC root. */
79static BOOL
80is_unc_root (const char *rname)
81{
82 /* Test whether it has the syntax '\\server\share'. */
83 if (ISSLASH (rname[0]) && ISSLASH (rname[1]))
84 {
85 /* It starts with two slashes. Find the next slash. */
86 const char *p = rname + 2;
87 const char *q = p;
88 while (*q != '\0' && !ISSLASH (*q))
89 q++;
90 if (q > p && *q != '\0')
91 {
92 /* Found the next slash at q. */
93 q++;
94 const char *r = q;
95 while (*r != '\0' && !ISSLASH (*r))
96 r++;
97 if (r > q && *r == '\0')
98 return TRUE;
99 }
100 }
101 return FALSE;
102}
103#endif
104
105/* Store information about NAME into ST. Work around bugs with
106 trailing slashes. Mingw has other bugs (such as st_ino always
107 being 0 on success) which this wrapper does not work around. But
108 at least this implementation provides the ability to emulate fchdir
109 correctly. */
110
111int
112rpl_stat (char const *name, struct stat *buf)
113{
114#ifdef WINDOWS_NATIVE
115 /* Fill the fields ourselves, because the original stat function returns
116 values for st_atime, st_mtime, st_ctime that depend on the current time
117 zone. See
118 <https://lists.gnu.org/r/bug-gnulib/2017-04/msg00134.html> */
119 /* XXX Should we convert to wchar_t* and prepend '\\?\', in order to work
120 around length limitations
121 <https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file> ? */
122
123 /* POSIX <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>
124 specifies: "More than two leading <slash> characters shall be treated as
125 a single <slash> character." */
126 if (ISSLASH (name[0]) && ISSLASH (name[1]) && ISSLASH (name[2]))
127 {
128 name += 2;
129 while (ISSLASH (name[1]))
130 name++;
131 }
132
133 size_t len = strlen (name);
134 size_t drive_prefix_len = (HAS_DEVICE (name) ? 2 : 0);
135
136 /* Remove trailing slashes (except the very first one, at position
137 drive_prefix_len), but remember their presence. */
138 size_t rlen;
139 bool check_dir = false;
140
141 rlen = len;
142 while (rlen > drive_prefix_len && ISSLASH (name[rlen-1]))
143 {
144 check_dir = true;
145 if (rlen == drive_prefix_len + 1)
146 break;
147 rlen--;
148 }
149
150 /* Handle '' and 'C:'. */
151 if (!check_dir && rlen == drive_prefix_len)
152 {
153 errno = ENOENT;
154 return -1;
155 }
156
157 /* Handle '\\'. */
158 if (rlen == 1 && ISSLASH (name[0]) && len >= 2)
159 {
160 errno = ENOENT;
161 return -1;
162 }
163
164 const char *rname;
165 char *malloca_rname;
166 if (rlen == len)
167 {
168 rname = name;
169 malloca_rname = NULL;
170 }
171 else
172 {
173 malloca_rname = malloca (rlen + 1);
174 if (malloca_rname == NULL)
175 {
176 errno = ENOMEM;
177 return -1;
178 }
179 memcpy (malloca_rname, name, rlen);
180 malloca_rname[rlen] = '\0';
181 rname = malloca_rname;
182 }
183
184 /* There are two ways to get at the requested information:
185 - by scanning the parent directory and examining the relevant
186 directory entry,
187 - by opening the file directly.
188 The first approach fails for root directories (e.g. 'C:\') and
189 UNC root directories (e.g. '\\server\share').
190 The second approach fails for some system files (e.g. 'C:\pagefile.sys'
191 and 'C:\hiberfil.sys'): ERROR_SHARING_VIOLATION.
192 The second approach gives more information (in particular, correct
193 st_dev, st_ino, st_nlink fields).
194 So we use the second approach and, as a fallback except for root and
195 UNC root directories, also the first approach. */
196 {
197 int ret;
198
199 {
200 /* Approach based on the file. */
201
202 /* Open a handle to the file.
203 CreateFile
204 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-createfilea>
205 <https://docs.microsoft.com/en-us/windows/desktop/FileIO/creating-and-opening-files> */
206 HANDLE h =
207 CreateFile (rname,
208 FILE_READ_ATTRIBUTES,
209 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
210 NULL,
211 OPEN_EXISTING,
212 /* FILE_FLAG_POSIX_SEMANTICS (treat file names that differ only
213 in case as different) makes sense only when applied to *all*
214 filesystem operations. */
215 FILE_FLAG_BACKUP_SEMANTICS /* | FILE_FLAG_POSIX_SEMANTICS */,
216 NULL);
217 if (h != INVALID_HANDLE_VALUE)
218 {
219 ret = _gl_fstat_by_handle (h, rname, buf);
220 CloseHandle (h);
221 goto done;
222 }
223 }
224
225 /* Test for root and UNC root directories. */
226 if ((rlen == drive_prefix_len + 1 && ISSLASH (rname[drive_prefix_len]))
227 || is_unc_root (rname))
228 goto failed;
229
230 /* Fallback. */
231 {
232 /* Approach based on the directory entry. */
233
234 if (strchr (rname, '?') != NULL || strchr (rname, '*') != NULL)
235 {
236 /* Other Windows API functions would fail with error
237 ERROR_INVALID_NAME. */
238 if (malloca_rname != NULL)
239 freea (malloca_rname);
240 errno = ENOENT;
241 return -1;
242 }
243
244 /* Get the details about the directory entry. This can be done through
245 FindFirstFile
246 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-findfirstfilea>
247 <https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ns-minwinbase-_win32_find_dataa>
248 or through
249 FindFirstFileEx with argument FindExInfoBasic
250 <https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-findfirstfileexa>
251 <https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ne-minwinbase-findex_info_levels>
252 <https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ns-minwinbase-_win32_find_dataa> */
253 WIN32_FIND_DATA info;
254 HANDLE h = FindFirstFile (rname, &info);
255 if (h == INVALID_HANDLE_VALUE)
256 goto failed;
257
258 /* Test for error conditions before starting to fill *buf. */
259 if (sizeof (buf->st_size) <= 4 && info.nFileSizeHigh > 0)
260 {
261 FindClose (h);
262 if (malloca_rname != NULL)
263 freea (malloca_rname);
264 errno = EOVERFLOW;
265 return -1;
266 }
267
268# if _GL_WINDOWS_STAT_INODES
269 buf->st_dev = 0;
270# if _GL_WINDOWS_STAT_INODES == 2
271 buf->st_ino._gl_ino[0] = buf->st_ino._gl_ino[1] = 0;
272# else /* _GL_WINDOWS_STAT_INODES == 1 */
273 buf->st_ino = 0;
274# endif
275# else
276 /* st_ino is not wide enough for identifying a file on a device.
277 Without st_ino, st_dev is pointless. */
278 buf->st_dev = 0;
279 buf->st_ino = 0;
280# endif
281
282 /* st_mode. */
283 unsigned int mode =
284 /* XXX How to handle FILE_ATTRIBUTE_REPARSE_POINT ? */
285 ((info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? _S_IFDIR | S_IEXEC_UGO : _S_IFREG)
286 | S_IREAD_UGO
287 | ((info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? 0 : S_IWRITE_UGO);
288 if (!(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
289 {
290 /* Determine whether the file is executable by looking at the file
291 name suffix. */
292 if (info.nFileSizeHigh > 0 || info.nFileSizeLow > 0)
293 {
294 const char *last_dot = NULL;
295 const char *p;
296 for (p = info.cFileName; *p != '\0'; p++)
297 if (*p == '.')
298 last_dot = p;
299 if (last_dot != NULL)
300 {
301 const char *suffix = last_dot + 1;
302 if (_stricmp (suffix, "exe") == 0
303 || _stricmp (suffix, "bat") == 0
304 || _stricmp (suffix, "cmd") == 0
305 || _stricmp (suffix, "com") == 0)
306 mode |= S_IEXEC_UGO;
307 }
308 }
309 }
310 buf->st_mode = mode;
311
312 /* st_nlink. Ignore hard links here. */
313 buf->st_nlink = 1;
314
315 /* There's no easy way to map the Windows SID concept to an integer. */
316 buf->st_uid = 0;
317 buf->st_gid = 0;
318
319 /* st_rdev is irrelevant for normal files and directories. */
320 buf->st_rdev = 0;
321
322 /* st_size. */
323 if (sizeof (buf->st_size) <= 4)
324 /* Range check already done above. */
325 buf->st_size = info.nFileSizeLow;
326 else
327 buf->st_size = ((long long) info.nFileSizeHigh << 32) | (long long) info.nFileSizeLow;
328
329 /* st_atime, st_mtime, st_ctime. */
330# if _GL_WINDOWS_STAT_TIMESPEC
331 buf->st_atim = _gl_convert_FILETIME_to_timespec (&info.ftLastAccessTime);
332 buf->st_mtim = _gl_convert_FILETIME_to_timespec (&info.ftLastWriteTime);
333 buf->st_ctim = _gl_convert_FILETIME_to_timespec (&info.ftCreationTime);
334# else
335 buf->st_atime = _gl_convert_FILETIME_to_POSIX (&info.ftLastAccessTime);
336 buf->st_mtime = _gl_convert_FILETIME_to_POSIX (&info.ftLastWriteTime);
337 buf->st_ctime = _gl_convert_FILETIME_to_POSIX (&info.ftCreationTime);
338# endif
339
340 FindClose (h);
341
342 ret = 0;
343 }
344
345 done:
346 if (ret >= 0 && check_dir && !S_ISDIR (buf->st_mode))
347 {
348 errno = ENOTDIR;
349 ret = -1;
350 }
351 if (malloca_rname != NULL)
352 {
353 int saved_errno = errno;
354 freea (malloca_rname);
355 errno = saved_errno;
356 }
357 return ret;
358 }
359
360 failed:
361 {
362 DWORD error = GetLastError ();
363 #if 0
364 fprintf (stderr, "rpl_stat error 0x%x\n", (unsigned int) error);
365 #endif
366
367 if (malloca_rname != NULL)
368 freea (malloca_rname);
369
370 switch (error)
371 {
372 /* Some of these errors probably cannot happen with the specific flags
373 that we pass to CreateFile. But who knows... */
374 case ERROR_FILE_NOT_FOUND: /* The last component of rname does not exist. */
375 case ERROR_PATH_NOT_FOUND: /* Some directory component in rname does not exist. */
376 case ERROR_BAD_PATHNAME: /* rname is such as '\\server'. */
377 case ERROR_BAD_NET_NAME: /* rname is such as '\\server\nonexistentshare'. */
378 case ERROR_INVALID_NAME: /* rname contains wildcards, misplaced colon, etc. */
379 case ERROR_DIRECTORY:
380 errno = ENOENT;
381 break;
382
383 case ERROR_ACCESS_DENIED: /* rname is such as 'C:\System Volume Information\foo'. */
384 case ERROR_SHARING_VIOLATION: /* rname is such as 'C:\pagefile.sys' (second approach only). */
385 /* XXX map to EACCES or EPERM? */
386 errno = EACCES;
387 break;
388
389 case ERROR_OUTOFMEMORY:
390 errno = ENOMEM;
391 break;
392
393 case ERROR_WRITE_PROTECT:
394 errno = EROFS;
395 break;
396
397 case ERROR_WRITE_FAULT:
398 case ERROR_READ_FAULT:
399 case ERROR_GEN_FAILURE:
400 errno = EIO;
401 break;
402
403 case ERROR_BUFFER_OVERFLOW:
404 case ERROR_FILENAME_EXCED_RANGE:
405 errno = ENAMETOOLONG;
406 break;
407
408 case ERROR_DELETE_PENDING: /* XXX map to EACCES or EPERM? */
409 errno = EPERM;
410 break;
411
412 default:
413 errno = EINVAL;
414 break;
415 }
416
417 return -1;
418 }
419#else
420 int result = orig_stat (name, buf);
421 if (result == 0)
422 {
423# if REPLACE_FUNC_STAT_FILE
424 /* Solaris 9 mistakenly succeeds when given a non-directory with a
425 trailing slash. */
426 if (!S_ISDIR (buf->st_mode))
427 {
428 size_t len = strlen (name);
429 if (ISSLASH (name[len - 1]))
430 {
431 errno = ENOTDIR;
432 return -1;
433 }
434 }
435# endif /* REPLACE_FUNC_STAT_FILE */
436 result = stat_time_normalize (result, buf);
437 }
438 return result;
439#endif
440}
diff --git a/gl/stdalign.in.h b/gl/stdalign.in.h
index 7254a3d..592d58e 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-2021 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,11 +34,12 @@
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.
@@ -52,7 +53,13 @@
52#undef _Alignas 53#undef _Alignas
53#undef _Alignof 54#undef _Alignof
54 55
55#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 56/* GCC releases before GCC 4.9 had a bug in _Alignof. See GCC bug 52023
57 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>.
58 clang versions < 8.0.0 have the same bug. */
59#if (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 \
60 || (defined __GNUC__ && __GNUC__ < 4 + (__GNUC_MINOR__ < 9) \
61 && !defined __clang__) \
62 || (defined __clang__ && __clang_major__ < 8))
56# ifdef __cplusplus 63# ifdef __cplusplus
57# if 201103 <= __cplusplus 64# if 201103 <= __cplusplus
58# define _Alignof(type) alignof (type) 65# define _Alignof(type) alignof (type)
@@ -64,7 +71,9 @@
64# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b) 71# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
65# endif 72# endif
66#endif 73#endif
67#define alignof _Alignof 74#if ! (defined __cplusplus && 201103 <= __cplusplus)
75# define alignof _Alignof
76#endif
68#define __alignof_is_defined 1 77#define __alignof_is_defined 1
69 78
70/* alignas (A), also known as _Alignas (A), aligns a variable or type 79/* alignas (A), also known as _Alignas (A), aligns a variable or type
@@ -95,14 +104,23 @@
95#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 104#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112
96# if defined __cplusplus && 201103 <= __cplusplus 105# if defined __cplusplus && 201103 <= __cplusplus
97# define _Alignas(a) alignas (a) 106# define _Alignas(a) alignas (a)
98# elif __GNUC__ || __IBMC__ || __IBMCPP__ || __ICC || 0x5110 <= __SUNPRO_C 107# elif (!defined __attribute__ \
108 && ((defined __APPLE__ && defined __MACH__ \
109 ? 4 < __GNUC__ + (1 <= __GNUC_MINOR__) \
110 : __GNUC__ && !defined __ibmxl__) \
111 || (4 <= __clang_major__) \
112 || (__ia64 && (61200 <= __HP_cc || 61200 <= __HP_aCC)) \
113 || __ICC || 0x590 <= __SUNPRO_C || 0x0600 <= __xlC__))
99# define _Alignas(a) __attribute__ ((__aligned__ (a))) 114# define _Alignas(a) __attribute__ ((__aligned__ (a)))
100# elif 1300 <= _MSC_VER 115# elif 1300 <= _MSC_VER
101# define _Alignas(a) __declspec (align (a)) 116# define _Alignas(a) __declspec (align (a))
102# endif 117# endif
103#endif 118#endif
104#if defined _Alignas || (defined __STDC_VERSION && 201112 <= __STDC_VERSION__) 119#if ((defined _Alignas && ! (defined __cplusplus && 201103 <= __cplusplus)) \
120 || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__))
105# define alignas _Alignas 121# define alignas _Alignas
122#endif
123#if defined alignas || (defined __cplusplus && 201103 <= __cplusplus)
106# define __alignas_is_defined 1 124# define __alignas_is_defined 1
107#endif 125#endif
108 126
diff --git a/gl/stdbool.in.h b/gl/stdbool.in.h
index 7c15772..2a1992d 100644
--- a/gl/stdbool.in.h
+++ b/gl/stdbool.in.h
@@ -1,18 +1,18 @@
1/* Copyright (C) 2001-2003, 2006-2013 Free Software Foundation, Inc. 1/* Copyright (C) 2001-2003, 2006-2021 Free Software Foundation, Inc.
2 Written by Bruno Haible <haible@clisp.cons.org>, 2001. 2 Written by Bruno Haible <haible@clisp.cons.org>, 2001.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This 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 _GL_STDBOOL_H 17#ifndef _GL_STDBOOL_H
18#define _GL_STDBOOL_H 18#define _GL_STDBOOL_H
@@ -82,9 +82,9 @@ typedef bool _Bool;
82 /* If @HAVE__BOOL@: 82 /* If @HAVE__BOOL@:
83 Some HP-UX cc and AIX IBM C compiler versions have compiler bugs when 83 Some HP-UX cc and AIX IBM C compiler versions have compiler bugs when
84 the built-in _Bool type is used. See 84 the built-in _Bool type is used. See
85 http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html 85 https://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
86 http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html 86 https://lists.gnu.org/r/bug-coreutils/2005-11/msg00161.html
87 http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html 87 https://lists.gnu.org/r/bug-coreutils/2005-10/msg00086.html
88 Similar bugs are likely with other compilers as well; this file 88 Similar bugs are likely with other compilers as well; this file
89 wouldn't be used if <stdbool.h> was working. 89 wouldn't be used if <stdbool.h> was working.
90 So we override the _Bool type. 90 So we override the _Bool type.
diff --git a/gl/stddef.in.h b/gl/stddef.in.h
index 40f0536..42290d4 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-2021 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..85c5418 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-2021 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..3fa94b4
--- /dev/null
+++ b/gl/stdio-impl.h
@@ -0,0 +1,212 @@
1/* Implementation details of FILE streams.
2 Copyright (C) 2007-2008, 2010-2021 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 /* Up to this commit from 2015-10-12
75 <https://android.googlesource.com/platform/bionic.git/+/f0141dfab10a4b332769d52fa76631a64741297a>
76 the innards of FILE were public, and fp_ub could be defined like for OpenBSD,
77 see <https://android.googlesource.com/platform/bionic.git/+/e78392637d5086384a5631ddfdfa8d7ec8326ee3/libc/stdio/fileext.h>
78 and <https://android.googlesource.com/platform/bionic.git/+/e78392637d5086384a5631ddfdfa8d7ec8326ee3/libc/stdio/local.h>.
79 After this commit, the innards of FILE are hidden. */
80# define fp_ ((struct { unsigned char *_p; \
81 int _r; \
82 int _w; \
83 _gl_flags_file_t _flags; \
84 _gl_flags_file_t _file; \
85 struct { unsigned char *_base; size_t _size; } _bf; \
86 int _lbfsize; \
87 void *_cookie; \
88 void *_close; \
89 void *_read; \
90 void *_seek; \
91 void *_write; \
92 struct { unsigned char *_base; size_t _size; } _ext; \
93 unsigned char *_up; \
94 int _ur; \
95 unsigned char _ubuf[3]; \
96 unsigned char _nbuf[1]; \
97 struct { unsigned char *_base; size_t _size; } _lb; \
98 int _blksize; \
99 fpos_t _offset; \
100 /* More fields, not relevant here. */ \
101 } *) fp)
102# else
103# define fp_ fp
104# endif
105
106# if (defined __NetBSD__ && __NetBSD_Version__ >= 105270000) || defined __OpenBSD__ || defined __minix /* NetBSD >= 1.5ZA, OpenBSD, Minix 3 */
107 /* See <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup>
108 and <https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup>
109 and <https://github.com/Stichting-MINIX-Research-Foundation/minix/blob/master/lib/libc/stdio/fileext.h> */
110 struct __sfileext
111 {
112 struct __sbuf _ub; /* ungetc buffer */
113 /* More fields, not relevant here. */
114 };
115# define fp_ub ((struct __sfileext *) fp->_ext._base)->_ub
116# elif defined __ANDROID__ /* Android */
117 struct __sfileext
118 {
119 struct { unsigned char *_base; size_t _size; } _ub; /* ungetc buffer */
120 /* More fields, not relevant here. */
121 };
122# define fp_ub ((struct __sfileext *) fp_->_ext._base)->_ub
123# else /* FreeBSD, NetBSD <= 1.5Z, DragonFly, Mac OS X, Cygwin */
124# define fp_ub fp_->_ub
125# endif
126
127# define HASUB(fp) (fp_ub._base != NULL)
128
129# if defined __ANDROID__ /* Android */
130 /* Needed after this commit from 2016-01-25
131 <https://android.googlesource.com/platform/bionic.git/+/e70e0e9267d069bf56a5078c99307e08a7280de7> */
132# ifndef __SEOF
133# define __SLBF 1
134# define __SNBF 2
135# define __SRD 4
136# define __SWR 8
137# define __SRW 0x10
138# define __SEOF 0x20
139# define __SERR 0x40
140# endif
141# ifndef __SOFF
142# define __SOFF 0x1000
143# endif
144# endif
145
146#endif
147
148
149/* SystemV derived implementations. */
150
151#ifdef __TANDEM /* NonStop Kernel */
152# ifndef _IOERR
153/* These values were determined by the program 'stdioext-flags' at
154 <https://lists.gnu.org/r/bug-gnulib/2010-12/msg00165.html>. */
155# define _IOERR 0x40
156# define _IOREAD 0x80
157# define _IOWRT 0x4
158# define _IORW 0x100
159# endif
160#endif
161
162#if defined _IOERR
163
164# if defined __sun && defined _LP64 /* Solaris/{SPARC,AMD64} 64-bit */
165# define fp_ ((struct { unsigned char *_ptr; \
166 unsigned char *_base; \
167 unsigned char *_end; \
168 long _cnt; \
169 int _file; \
170 unsigned int _flag; \
171 } *) fp)
172# elif defined __VMS /* OpenVMS */
173# define fp_ ((struct _iobuf *) fp)
174# else
175# define fp_ fp
176# endif
177
178# if defined _SCO_DS || (defined __SCO_VERSION__ || defined __sysv5__) /* OpenServer 5, OpenServer 6, UnixWare 7 */
179# define _cnt __cnt
180# define _ptr __ptr
181# define _base __base
182# define _flag __flag
183# endif
184
185#elif defined _WIN32 && ! defined __CYGWIN__ /* newer Windows with MSVC */
186
187/* <stdio.h> does not define the innards of FILE any more. */
188# define WINDOWS_OPAQUE_FILE
189
190struct _gl_real_FILE
191{
192 /* Note: Compared to older Windows and to mingw, it has the fields
193 _base and _cnt swapped. */
194 unsigned char *_ptr;
195 unsigned char *_base;
196 int _cnt;
197 int _flag;
198 int _file;
199 int _charbuf;
200 int _bufsiz;
201};
202# define fp_ ((struct _gl_real_FILE *) fp)
203
204/* These values were determined by a program similar to the one at
205 <https://lists.gnu.org/r/bug-gnulib/2010-12/msg00165.html>. */
206# define _IOREAD 0x1
207# define _IOWRT 0x2
208# define _IORW 0x4
209# define _IOEOF 0x8
210# define _IOERR 0x10
211
212#endif
diff --git a/gl/stdio.in.h b/gl/stdio.in.h
index 06cbad0..0ca2c8e 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-2021 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,13 +368,34 @@ _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@
@@ -249,18 +404,37 @@ _GL_CXXALIASWARN (fgets);
249# undef fopen 404# undef fopen
250# define fopen rpl_fopen 405# define fopen rpl_fopen
251# endif 406# endif
252_GL_FUNCDECL_RPL (fopen, FILE *, (const char *filename, const char *mode) 407_GL_FUNCDECL_RPL (fopen, FILE *,
253 _GL_ARG_NONNULL ((1, 2))); 408 (const char *restrict filename, const char *restrict mode)
254_GL_CXXALIAS_RPL (fopen, FILE *, (const char *filename, const char *mode)); 409 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1));
410_GL_CXXALIAS_RPL (fopen, FILE *,
411 (const char *restrict filename, const char *restrict mode));
255# else 412# else
256_GL_CXXALIAS_SYS (fopen, FILE *, (const char *filename, const char *mode)); 413# if __GNUC__ >= 11
414/* For -Wmismatched-dealloc: Associate fopen with fclose or rpl_fclose. */
415_GL_FUNCDECL_SYS (fopen, FILE *,
416 (const char *restrict filename, const char *restrict mode)
417 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1));
418# endif
419_GL_CXXALIAS_SYS (fopen, FILE *,
420 (const char *restrict filename, const char *restrict mode));
257# endif 421# endif
422# if __GLIBC__ >= 2
258_GL_CXXALIASWARN (fopen); 423_GL_CXXALIASWARN (fopen);
259#elif defined GNULIB_POSIXCHECK 424# endif
260# undef fopen 425#else
426# if @GNULIB_FCLOSE@ && __GNUC__ >= 11 && !defined fopen
427/* For -Wmismatched-dealloc: Associate fopen with fclose or rpl_fclose. */
428_GL_FUNCDECL_SYS (fopen, FILE *,
429 (const char *restrict filename, const char *restrict mode)
430 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1));
431# endif
432# if defined GNULIB_POSIXCHECK
433# undef fopen
261/* Assume fopen is always declared. */ 434/* Assume fopen is always declared. */
262_GL_WARN_ON_USE (fopen, "fopen on native Windows platforms is not POSIX compliant - " 435_GL_WARN_ON_USE (fopen, "fopen on native Windows platforms is not POSIX compliant - "
263 "use gnulib module fopen for portability"); 436 "use gnulib module fopen for portability");
437# endif
264#endif 438#endif
265 439
266#if @GNULIB_FPRINTF_POSIX@ || @GNULIB_FPRINTF@ 440#if @GNULIB_FPRINTF_POSIX@ || @GNULIB_FPRINTF@
@@ -271,19 +445,25 @@ _GL_WARN_ON_USE (fopen, "fopen on native Windows platforms is not POSIX complian
271# endif 445# endif
272# define GNULIB_overrides_fprintf 1 446# define GNULIB_overrides_fprintf 1
273# if @GNULIB_FPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@ 447# if @GNULIB_FPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@
274_GL_FUNCDECL_RPL (fprintf, int, (FILE *fp, const char *format, ...) 448_GL_FUNCDECL_RPL (fprintf, int,
275 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) 449 (FILE *restrict fp, const char *restrict format, ...)
276 _GL_ARG_NONNULL ((1, 2))); 450 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
451 _GL_ARG_NONNULL ((1, 2)));
277# else 452# else
278_GL_FUNCDECL_RPL (fprintf, int, (FILE *fp, const char *format, ...) 453_GL_FUNCDECL_RPL (fprintf, int,
279 _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (2, 3) 454 (FILE *restrict fp, const char *restrict format, ...)
280 _GL_ARG_NONNULL ((1, 2))); 455 _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (2, 3)
456 _GL_ARG_NONNULL ((1, 2)));
281# endif 457# endif
282_GL_CXXALIAS_RPL (fprintf, int, (FILE *fp, const char *format, ...)); 458_GL_CXXALIAS_RPL (fprintf, int,
459 (FILE *restrict fp, const char *restrict format, ...));
283# else 460# else
284_GL_CXXALIAS_SYS (fprintf, int, (FILE *fp, const char *format, ...)); 461_GL_CXXALIAS_SYS (fprintf, int,
462 (FILE *restrict fp, const char *restrict format, ...));
285# endif 463# endif
464# if __GLIBC__ >= 2
286_GL_CXXALIASWARN (fprintf); 465_GL_CXXALIASWARN (fprintf);
466# endif
287#endif 467#endif
288#if !@GNULIB_FPRINTF_POSIX@ && defined GNULIB_POSIXCHECK 468#if !@GNULIB_FPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
289# if !GNULIB_overrides_fprintf 469# if !GNULIB_overrides_fprintf
@@ -334,7 +514,9 @@ _GL_CXXALIAS_RPL (fputc, int, (int c, FILE *stream));
334# else 514# else
335_GL_CXXALIAS_SYS (fputc, int, (int c, FILE *stream)); 515_GL_CXXALIAS_SYS (fputc, int, (int c, FILE *stream));
336# endif 516# endif
517# if __GLIBC__ >= 2
337_GL_CXXALIASWARN (fputc); 518_GL_CXXALIASWARN (fputc);
519# endif
338#endif 520#endif
339 521
340#if @GNULIB_FPUTS@ 522#if @GNULIB_FPUTS@
@@ -343,13 +525,18 @@ _GL_CXXALIASWARN (fputc);
343# undef fputs 525# undef fputs
344# define fputs rpl_fputs 526# define fputs rpl_fputs
345# endif 527# endif
346_GL_FUNCDECL_RPL (fputs, int, (const char *string, FILE *stream) 528_GL_FUNCDECL_RPL (fputs, int,
347 _GL_ARG_NONNULL ((1, 2))); 529 (const char *restrict string, FILE *restrict stream)
348_GL_CXXALIAS_RPL (fputs, int, (const char *string, FILE *stream)); 530 _GL_ARG_NONNULL ((1, 2)));
531_GL_CXXALIAS_RPL (fputs, int,
532 (const char *restrict string, FILE *restrict stream));
349# else 533# else
350_GL_CXXALIAS_SYS (fputs, int, (const char *string, FILE *stream)); 534_GL_CXXALIAS_SYS (fputs, int,
535 (const char *restrict string, FILE *restrict stream));
351# endif 536# endif
537# if __GLIBC__ >= 2
352_GL_CXXALIASWARN (fputs); 538_GL_CXXALIASWARN (fputs);
539# endif
353#endif 540#endif
354 541
355#if @GNULIB_FREAD@ 542#if @GNULIB_FREAD@
@@ -358,13 +545,21 @@ _GL_CXXALIASWARN (fputs);
358# undef fread 545# undef fread
359# define fread rpl_fread 546# define fread rpl_fread
360# endif 547# endif
361_GL_FUNCDECL_RPL (fread, size_t, (void *ptr, size_t s, size_t n, FILE *stream) 548_GL_FUNCDECL_RPL (fread, size_t,
362 _GL_ARG_NONNULL ((4))); 549 (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)); 550 FILE *restrict stream)
551 _GL_ARG_NONNULL ((4)));
552_GL_CXXALIAS_RPL (fread, size_t,
553 (void *restrict ptr, size_t s, size_t n,
554 FILE *restrict stream));
364# else 555# else
365_GL_CXXALIAS_SYS (fread, size_t, (void *ptr, size_t s, size_t n, FILE *stream)); 556_GL_CXXALIAS_SYS (fread, size_t,
557 (void *restrict ptr, size_t s, size_t n,
558 FILE *restrict stream));
366# endif 559# endif
560# if __GLIBC__ >= 2
367_GL_CXXALIASWARN (fread); 561_GL_CXXALIASWARN (fread);
562# endif
368#endif 563#endif
369 564
370#if @GNULIB_FREOPEN@ 565#if @GNULIB_FREOPEN@
@@ -374,15 +569,20 @@ _GL_CXXALIASWARN (fread);
374# define freopen rpl_freopen 569# define freopen rpl_freopen
375# endif 570# endif
376_GL_FUNCDECL_RPL (freopen, FILE *, 571_GL_FUNCDECL_RPL (freopen, FILE *,
377 (const char *filename, const char *mode, FILE *stream) 572 (const char *restrict filename, const char *restrict mode,
573 FILE *restrict stream)
378 _GL_ARG_NONNULL ((2, 3))); 574 _GL_ARG_NONNULL ((2, 3)));
379_GL_CXXALIAS_RPL (freopen, FILE *, 575_GL_CXXALIAS_RPL (freopen, FILE *,
380 (const char *filename, const char *mode, FILE *stream)); 576 (const char *restrict filename, const char *restrict mode,
577 FILE *restrict stream));
381# else 578# else
382_GL_CXXALIAS_SYS (freopen, FILE *, 579_GL_CXXALIAS_SYS (freopen, FILE *,
383 (const char *filename, const char *mode, FILE *stream)); 580 (const char *restrict filename, const char *restrict mode,
581 FILE *restrict stream));
384# endif 582# endif
583# if __GLIBC__ >= 2
385_GL_CXXALIASWARN (freopen); 584_GL_CXXALIASWARN (freopen);
585# endif
386#elif defined GNULIB_POSIXCHECK 586#elif defined GNULIB_POSIXCHECK
387# undef freopen 587# undef freopen
388/* Assume freopen is always declared. */ 588/* Assume freopen is always declared. */
@@ -397,14 +597,19 @@ _GL_WARN_ON_USE (freopen,
397# undef fscanf 597# undef fscanf
398# define fscanf rpl_fscanf 598# define fscanf rpl_fscanf
399# endif 599# endif
400_GL_FUNCDECL_RPL (fscanf, int, (FILE *stream, const char *format, ...) 600_GL_FUNCDECL_RPL (fscanf, int,
401 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (2, 3) 601 (FILE *restrict stream, const char *restrict format, ...)
402 _GL_ARG_NONNULL ((1, 2))); 602 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (2, 3)
403_GL_CXXALIAS_RPL (fscanf, int, (FILE *stream, const char *format, ...)); 603 _GL_ARG_NONNULL ((1, 2)));
604_GL_CXXALIAS_RPL (fscanf, int,
605 (FILE *restrict stream, const char *restrict format, ...));
404# else 606# else
405_GL_CXXALIAS_SYS (fscanf, int, (FILE *stream, const char *format, ...)); 607_GL_CXXALIAS_SYS (fscanf, int,
608 (FILE *restrict stream, const char *restrict format, ...));
406# endif 609# endif
610# if __GLIBC__ >= 2
407_GL_CXXALIASWARN (fscanf); 611_GL_CXXALIASWARN (fscanf);
612# endif
408#endif 613#endif
409 614
410 615
@@ -455,7 +660,9 @@ _GL_CXXALIAS_RPL (fseek, int, (FILE *fp, long offset, int whence));
455# else 660# else
456_GL_CXXALIAS_SYS (fseek, int, (FILE *fp, long offset, int whence)); 661_GL_CXXALIAS_SYS (fseek, int, (FILE *fp, long offset, int whence));
457# endif 662# endif
663# if __GLIBC__ >= 2
458_GL_CXXALIASWARN (fseek); 664_GL_CXXALIASWARN (fseek);
665# endif
459#endif 666#endif
460 667
461#if @GNULIB_FSEEKO@ 668#if @GNULIB_FSEEKO@
@@ -518,7 +725,9 @@ _GL_CXXALIAS_RPL (ftell, long, (FILE *fp));
518# else 725# else
519_GL_CXXALIAS_SYS (ftell, long, (FILE *fp)); 726_GL_CXXALIAS_SYS (ftell, long, (FILE *fp));
520# endif 727# endif
728# if __GLIBC__ >= 2
521_GL_CXXALIASWARN (ftell); 729_GL_CXXALIASWARN (ftell);
730# endif
522#endif 731#endif
523 732
524#if @GNULIB_FTELLO@ 733#if @GNULIB_FTELLO@
@@ -567,16 +776,19 @@ _GL_WARN_ON_USE (ftell, "ftell cannot handle files larger than 4 GB "
567# define fwrite rpl_fwrite 776# define fwrite rpl_fwrite
568# endif 777# endif
569_GL_FUNCDECL_RPL (fwrite, size_t, 778_GL_FUNCDECL_RPL (fwrite, size_t,
570 (const void *ptr, size_t s, size_t n, FILE *stream) 779 (const void *restrict ptr, size_t s, size_t n,
780 FILE *restrict stream)
571 _GL_ARG_NONNULL ((1, 4))); 781 _GL_ARG_NONNULL ((1, 4)));
572_GL_CXXALIAS_RPL (fwrite, size_t, 782_GL_CXXALIAS_RPL (fwrite, size_t,
573 (const void *ptr, size_t s, size_t n, FILE *stream)); 783 (const void *restrict ptr, size_t s, size_t n,
784 FILE *restrict stream));
574# else 785# else
575_GL_CXXALIAS_SYS (fwrite, size_t, 786_GL_CXXALIAS_SYS (fwrite, size_t,
576 (const void *ptr, size_t s, size_t n, FILE *stream)); 787 (const void *restrict ptr, size_t s, size_t n,
788 FILE *restrict stream));
577 789
578/* Work around bug 11959 when fortifying glibc 2.4 through 2.15 790/* Work around bug 11959 when fortifying glibc 2.4 through 2.15
579 <http://sources.redhat.com/bugzilla/show_bug.cgi?id=11959>, 791 <https://sourceware.org/bugzilla/show_bug.cgi?id=11959>,
580 which sometimes causes an unwanted diagnostic for fwrite calls. 792 which sometimes causes an unwanted diagnostic for fwrite calls.
581 This affects only function declaration attributes under certain 793 This affects only function declaration attributes under certain
582 versions of gcc and clang, and is not needed for C++. */ 794 versions of gcc and clang, and is not needed for C++. */
@@ -598,7 +810,9 @@ extern size_t __REDIRECT (rpl_fwrite_unlocked,
598# define fwrite_unlocked rpl_fwrite_unlocked 810# define fwrite_unlocked rpl_fwrite_unlocked
599# endif 811# endif
600# endif 812# endif
813# if __GLIBC__ >= 2
601_GL_CXXALIASWARN (fwrite); 814_GL_CXXALIASWARN (fwrite);
815# endif
602#endif 816#endif
603 817
604#if @GNULIB_GETC@ 818#if @GNULIB_GETC@
@@ -612,7 +826,9 @@ _GL_CXXALIAS_RPL_1 (getc, rpl_fgetc, int, (FILE *stream));
612# else 826# else
613_GL_CXXALIAS_SYS (getc, int, (FILE *stream)); 827_GL_CXXALIAS_SYS (getc, int, (FILE *stream));
614# endif 828# endif
829# if __GLIBC__ >= 2
615_GL_CXXALIASWARN (getc); 830_GL_CXXALIASWARN (getc);
831# endif
616#endif 832#endif
617 833
618#if @GNULIB_GETCHAR@ 834#if @GNULIB_GETCHAR@
@@ -626,7 +842,9 @@ _GL_CXXALIAS_RPL (getchar, int, (void));
626# else 842# else
627_GL_CXXALIAS_SYS (getchar, int, (void)); 843_GL_CXXALIAS_SYS (getchar, int, (void));
628# endif 844# endif
845# if __GLIBC__ >= 2
629_GL_CXXALIASWARN (getchar); 846_GL_CXXALIASWARN (getchar);
847# endif
630#endif 848#endif
631 849
632#if @GNULIB_GETDELIM@ 850#if @GNULIB_GETDELIM@
@@ -642,22 +860,26 @@ _GL_CXXALIASWARN (getchar);
642# define getdelim rpl_getdelim 860# define getdelim rpl_getdelim
643# endif 861# endif
644_GL_FUNCDECL_RPL (getdelim, ssize_t, 862_GL_FUNCDECL_RPL (getdelim, ssize_t,
645 (char **lineptr, size_t *linesize, int delimiter, 863 (char **restrict lineptr, size_t *restrict linesize,
646 FILE *stream) 864 int delimiter,
865 FILE *restrict stream)
647 _GL_ARG_NONNULL ((1, 2, 4))); 866 _GL_ARG_NONNULL ((1, 2, 4)));
648_GL_CXXALIAS_RPL (getdelim, ssize_t, 867_GL_CXXALIAS_RPL (getdelim, ssize_t,
649 (char **lineptr, size_t *linesize, int delimiter, 868 (char **restrict lineptr, size_t *restrict linesize,
650 FILE *stream)); 869 int delimiter,
870 FILE *restrict stream));
651# else 871# else
652# if !@HAVE_DECL_GETDELIM@ 872# if !@HAVE_DECL_GETDELIM@
653_GL_FUNCDECL_SYS (getdelim, ssize_t, 873_GL_FUNCDECL_SYS (getdelim, ssize_t,
654 (char **lineptr, size_t *linesize, int delimiter, 874 (char **restrict lineptr, size_t *restrict linesize,
655 FILE *stream) 875 int delimiter,
876 FILE *restrict stream)
656 _GL_ARG_NONNULL ((1, 2, 4))); 877 _GL_ARG_NONNULL ((1, 2, 4)));
657# endif 878# endif
658_GL_CXXALIAS_SYS (getdelim, ssize_t, 879_GL_CXXALIAS_SYS (getdelim, ssize_t,
659 (char **lineptr, size_t *linesize, int delimiter, 880 (char **restrict lineptr, size_t *restrict linesize,
660 FILE *stream)); 881 int delimiter,
882 FILE *restrict stream));
661# endif 883# endif
662_GL_CXXALIASWARN (getdelim); 884_GL_CXXALIASWARN (getdelim);
663#elif defined GNULIB_POSIXCHECK 885#elif defined GNULIB_POSIXCHECK
@@ -681,18 +903,22 @@ _GL_WARN_ON_USE (getdelim, "getdelim is unportable - "
681# define getline rpl_getline 903# define getline rpl_getline
682# endif 904# endif
683_GL_FUNCDECL_RPL (getline, ssize_t, 905_GL_FUNCDECL_RPL (getline, ssize_t,
684 (char **lineptr, size_t *linesize, FILE *stream) 906 (char **restrict lineptr, size_t *restrict linesize,
907 FILE *restrict stream)
685 _GL_ARG_NONNULL ((1, 2, 3))); 908 _GL_ARG_NONNULL ((1, 2, 3)));
686_GL_CXXALIAS_RPL (getline, ssize_t, 909_GL_CXXALIAS_RPL (getline, ssize_t,
687 (char **lineptr, size_t *linesize, FILE *stream)); 910 (char **restrict lineptr, size_t *restrict linesize,
911 FILE *restrict stream));
688# else 912# else
689# if !@HAVE_DECL_GETLINE@ 913# if !@HAVE_DECL_GETLINE@
690_GL_FUNCDECL_SYS (getline, ssize_t, 914_GL_FUNCDECL_SYS (getline, ssize_t,
691 (char **lineptr, size_t *linesize, FILE *stream) 915 (char **restrict lineptr, size_t *restrict linesize,
916 FILE *restrict stream)
692 _GL_ARG_NONNULL ((1, 2, 3))); 917 _GL_ARG_NONNULL ((1, 2, 3)));
693# endif 918# endif
694_GL_CXXALIAS_SYS (getline, ssize_t, 919_GL_CXXALIAS_SYS (getline, ssize_t,
695 (char **lineptr, size_t *linesize, FILE *stream)); 920 (char **restrict lineptr, size_t *restrict linesize,
921 FILE *restrict stream));
696# endif 922# endif
697# if @HAVE_DECL_GETLINE@ 923# if @HAVE_DECL_GETLINE@
698_GL_CXXALIASWARN (getline); 924_GL_CXXALIASWARN (getline);
@@ -709,10 +935,25 @@ _GL_WARN_ON_USE (getline, "getline is unportable - "
709 so any use of gets warrants an unconditional warning; besides, C11 935 so any use of gets warrants an unconditional warning; besides, C11
710 removed it. */ 936 removed it. */
711#undef gets 937#undef gets
712#if HAVE_RAW_DECL_GETS 938#if HAVE_RAW_DECL_GETS && !defined __cplusplus
713_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); 939_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
714#endif 940#endif
715 941
942#if @GNULIB_MDA_GETW@
943/* On native Windows, map 'getw' to '_getw', so that -loldnames is not
944 required. In C++ with GNULIB_NAMESPACE, avoid differences between
945 platforms by defining GNULIB_NAMESPACE::getw always. */
946# if defined _WIN32 && !defined __CYGWIN__
947# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
948# undef getw
949# define getw _getw
950# endif
951_GL_CXXALIAS_MDA (getw, int, (FILE *restrict stream));
952# else
953_GL_CXXALIAS_SYS (getw, int, (FILE *restrict stream));
954# endif
955_GL_CXXALIASWARN (getw);
956#endif
716 957
717#if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@ 958#if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@
718struct obstack; 959struct obstack;
@@ -727,7 +968,7 @@ struct obstack;
727# endif 968# endif
728_GL_FUNCDECL_RPL (obstack_printf, int, 969_GL_FUNCDECL_RPL (obstack_printf, int,
729 (struct obstack *obs, const char *format, ...) 970 (struct obstack *obs, const char *format, ...)
730 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) 971 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
731 _GL_ARG_NONNULL ((1, 2))); 972 _GL_ARG_NONNULL ((1, 2)));
732_GL_CXXALIAS_RPL (obstack_printf, int, 973_GL_CXXALIAS_RPL (obstack_printf, int,
733 (struct obstack *obs, const char *format, ...)); 974 (struct obstack *obs, const char *format, ...));
@@ -735,7 +976,7 @@ _GL_CXXALIAS_RPL (obstack_printf, int,
735# if !@HAVE_DECL_OBSTACK_PRINTF@ 976# if !@HAVE_DECL_OBSTACK_PRINTF@
736_GL_FUNCDECL_SYS (obstack_printf, int, 977_GL_FUNCDECL_SYS (obstack_printf, int,
737 (struct obstack *obs, const char *format, ...) 978 (struct obstack *obs, const char *format, ...)
738 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) 979 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
739 _GL_ARG_NONNULL ((1, 2))); 980 _GL_ARG_NONNULL ((1, 2)));
740# endif 981# endif
741_GL_CXXALIAS_SYS (obstack_printf, int, 982_GL_CXXALIAS_SYS (obstack_printf, int,
@@ -748,7 +989,7 @@ _GL_CXXALIASWARN (obstack_printf);
748# endif 989# endif
749_GL_FUNCDECL_RPL (obstack_vprintf, int, 990_GL_FUNCDECL_RPL (obstack_vprintf, int,
750 (struct obstack *obs, const char *format, va_list args) 991 (struct obstack *obs, const char *format, va_list args)
751 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 992 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
752 _GL_ARG_NONNULL ((1, 2))); 993 _GL_ARG_NONNULL ((1, 2)));
753_GL_CXXALIAS_RPL (obstack_vprintf, int, 994_GL_CXXALIAS_RPL (obstack_vprintf, int,
754 (struct obstack *obs, const char *format, va_list args)); 995 (struct obstack *obs, const char *format, va_list args));
@@ -756,7 +997,7 @@ _GL_CXXALIAS_RPL (obstack_vprintf, int,
756# if !@HAVE_DECL_OBSTACK_PRINTF@ 997# if !@HAVE_DECL_OBSTACK_PRINTF@
757_GL_FUNCDECL_SYS (obstack_vprintf, int, 998_GL_FUNCDECL_SYS (obstack_vprintf, int,
758 (struct obstack *obs, const char *format, va_list args) 999 (struct obstack *obs, const char *format, va_list args)
759 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 1000 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
760 _GL_ARG_NONNULL ((1, 2))); 1001 _GL_ARG_NONNULL ((1, 2)));
761# endif 1002# endif
762_GL_CXXALIAS_SYS (obstack_vprintf, int, 1003_GL_CXXALIAS_SYS (obstack_vprintf, int,
@@ -792,7 +1033,9 @@ _GL_CXXALIAS_RPL (perror, void, (const char *string));
792# else 1033# else
793_GL_CXXALIAS_SYS (perror, void, (const char *string)); 1034_GL_CXXALIAS_SYS (perror, void, (const char *string));
794# endif 1035# endif
1036# if __GLIBC__ >= 2
795_GL_CXXALIASWARN (perror); 1037_GL_CXXALIASWARN (perror);
1038# endif
796#elif defined GNULIB_POSIXCHECK 1039#elif defined GNULIB_POSIXCHECK
797# undef perror 1040# undef perror
798/* Assume perror is always declared. */ 1041/* Assume perror is always declared. */
@@ -806,43 +1049,53 @@ _GL_WARN_ON_USE (perror, "perror is not always POSIX compliant - "
806# undef popen 1049# undef popen
807# define popen rpl_popen 1050# define popen rpl_popen
808# endif 1051# endif
809_GL_FUNCDECL_RPL (popen, FILE *, (const char *cmd, const char *mode) 1052_GL_FUNCDECL_RPL (popen, FILE *,
810 _GL_ARG_NONNULL ((1, 2))); 1053 (const char *cmd, const char *mode)
1054 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose, 1));
811_GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode)); 1055_GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode));
812# else 1056# else
813# if !@HAVE_POPEN@ 1057# if !@HAVE_POPEN@ || __GNUC__ >= 11
814_GL_FUNCDECL_SYS (popen, FILE *, (const char *cmd, const char *mode) 1058_GL_FUNCDECL_SYS (popen, FILE *,
815 _GL_ARG_NONNULL ((1, 2))); 1059 (const char *cmd, const char *mode)
1060 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose, 1));
816# endif 1061# endif
817_GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode)); 1062_GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode));
818# endif 1063# endif
819_GL_CXXALIASWARN (popen); 1064_GL_CXXALIASWARN (popen);
820#elif defined GNULIB_POSIXCHECK 1065#else
821# undef popen 1066# if @GNULIB_PCLOSE@ && __GNUC__ >= 11 && !defined popen
822# if HAVE_RAW_DECL_POPEN 1067/* For -Wmismatched-dealloc: Associate popen with pclose or rpl_pclose. */
1068_GL_FUNCDECL_SYS (popen, FILE *,
1069 (const char *cmd, const char *mode)
1070 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose, 1));
1071# endif
1072# if defined GNULIB_POSIXCHECK
1073# undef popen
1074# if HAVE_RAW_DECL_POPEN
823_GL_WARN_ON_USE (popen, "popen is buggy on some platforms - " 1075_GL_WARN_ON_USE (popen, "popen is buggy on some platforms - "
824 "use gnulib module popen or pipe for more portability"); 1076 "use gnulib module popen or pipe for more portability");
1077# endif
825# endif 1078# endif
826#endif 1079#endif
827 1080
828#if @GNULIB_PRINTF_POSIX@ || @GNULIB_PRINTF@ 1081#if @GNULIB_PRINTF_POSIX@ || @GNULIB_PRINTF@
829# if (@GNULIB_PRINTF_POSIX@ && @REPLACE_PRINTF@) \ 1082# if (@GNULIB_PRINTF_POSIX@ && @REPLACE_PRINTF@) \
830 || (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@)) 1083 || (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@))
831# if defined __GNUC__ 1084# if defined __GNUC__ || defined __clang__
832# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1085# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
833/* Don't break __attribute__((format(printf,M,N))). */ 1086/* Don't break __attribute__((format(printf,M,N))). */
834# define printf __printf__ 1087# define printf __printf__
835# endif 1088# endif
836# if @GNULIB_PRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@ 1089# if @GNULIB_PRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@
837_GL_FUNCDECL_RPL_1 (__printf__, int, 1090_GL_FUNCDECL_RPL_1 (__printf__, int,
838 (const char *format, ...) 1091 (const char *restrict format, ...)
839 __asm__ (@ASM_SYMBOL_PREFIX@ 1092 __asm__ (@ASM_SYMBOL_PREFIX@
840 _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf)) 1093 _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf))
841 _GL_ATTRIBUTE_FORMAT_PRINTF (1, 2) 1094 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 2)
842 _GL_ARG_NONNULL ((1))); 1095 _GL_ARG_NONNULL ((1)));
843# else 1096# else
844_GL_FUNCDECL_RPL_1 (__printf__, int, 1097_GL_FUNCDECL_RPL_1 (__printf__, int,
845 (const char *format, ...) 1098 (const char *restrict format, ...)
846 __asm__ (@ASM_SYMBOL_PREFIX@ 1099 __asm__ (@ASM_SYMBOL_PREFIX@
847 _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf)) 1100 _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf))
848 _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (1, 2) 1101 _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (1, 2)
@@ -854,16 +1107,18 @@ _GL_CXXALIAS_RPL_1 (printf, __printf__, int, (const char *format, ...));
854# define printf rpl_printf 1107# define printf rpl_printf
855# endif 1108# endif
856_GL_FUNCDECL_RPL (printf, int, 1109_GL_FUNCDECL_RPL (printf, int,
857 (const char *format, ...) 1110 (const char *restrict format, ...)
858 _GL_ATTRIBUTE_FORMAT_PRINTF (1, 2) 1111 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 2)
859 _GL_ARG_NONNULL ((1))); 1112 _GL_ARG_NONNULL ((1)));
860_GL_CXXALIAS_RPL (printf, int, (const char *format, ...)); 1113_GL_CXXALIAS_RPL (printf, int, (const char *restrict format, ...));
861# endif 1114# endif
862# define GNULIB_overrides_printf 1 1115# define GNULIB_overrides_printf 1
863# else 1116# else
864_GL_CXXALIAS_SYS (printf, int, (const char *format, ...)); 1117_GL_CXXALIAS_SYS (printf, int, (const char *restrict format, ...));
865# endif 1118# endif
1119# if __GLIBC__ >= 2
866_GL_CXXALIASWARN (printf); 1120_GL_CXXALIASWARN (printf);
1121# endif
867#endif 1122#endif
868#if !@GNULIB_PRINTF_POSIX@ && defined GNULIB_POSIXCHECK 1123#if !@GNULIB_PRINTF_POSIX@ && defined GNULIB_POSIXCHECK
869# if !GNULIB_overrides_printf 1124# if !GNULIB_overrides_printf
@@ -886,7 +1141,9 @@ _GL_CXXALIAS_RPL_1 (putc, rpl_fputc, int, (int c, FILE *stream));
886# else 1141# else
887_GL_CXXALIAS_SYS (putc, int, (int c, FILE *stream)); 1142_GL_CXXALIAS_SYS (putc, int, (int c, FILE *stream));
888# endif 1143# endif
1144# if __GLIBC__ >= 2
889_GL_CXXALIASWARN (putc); 1145_GL_CXXALIASWARN (putc);
1146# endif
890#endif 1147#endif
891 1148
892#if @GNULIB_PUTCHAR@ 1149#if @GNULIB_PUTCHAR@
@@ -900,7 +1157,9 @@ _GL_CXXALIAS_RPL (putchar, int, (int c));
900# else 1157# else
901_GL_CXXALIAS_SYS (putchar, int, (int c)); 1158_GL_CXXALIAS_SYS (putchar, int, (int c));
902# endif 1159# endif
1160# if __GLIBC__ >= 2
903_GL_CXXALIASWARN (putchar); 1161_GL_CXXALIASWARN (putchar);
1162# endif
904#endif 1163#endif
905 1164
906#if @GNULIB_PUTS@ 1165#if @GNULIB_PUTS@
@@ -914,7 +1173,25 @@ _GL_CXXALIAS_RPL (puts, int, (const char *string));
914# else 1173# else
915_GL_CXXALIAS_SYS (puts, int, (const char *string)); 1174_GL_CXXALIAS_SYS (puts, int, (const char *string));
916# endif 1175# endif
1176# if __GLIBC__ >= 2
917_GL_CXXALIASWARN (puts); 1177_GL_CXXALIASWARN (puts);
1178# endif
1179#endif
1180
1181#if @GNULIB_MDA_PUTW@
1182/* On native Windows, map 'putw' to '_putw', so that -loldnames is not
1183 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1184 platforms by defining GNULIB_NAMESPACE::putw always. */
1185# if defined _WIN32 && !defined __CYGWIN__
1186# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1187# undef putw
1188# define putw _putw
1189# endif
1190_GL_CXXALIAS_MDA (putw, int, (int w, FILE *restrict stream));
1191# else
1192_GL_CXXALIAS_SYS (putw, int, (int w, FILE *restrict stream));
1193# endif
1194_GL_CXXALIASWARN (putw);
918#endif 1195#endif
919 1196
920#if @GNULIB_REMOVE@ 1197#if @GNULIB_REMOVE@
@@ -928,7 +1205,9 @@ _GL_CXXALIAS_RPL (remove, int, (const char *name));
928# else 1205# else
929_GL_CXXALIAS_SYS (remove, int, (const char *name)); 1206_GL_CXXALIAS_SYS (remove, int, (const char *name));
930# endif 1207# endif
1208# if __GLIBC__ >= 2
931_GL_CXXALIASWARN (remove); 1209_GL_CXXALIASWARN (remove);
1210# endif
932#elif defined GNULIB_POSIXCHECK 1211#elif defined GNULIB_POSIXCHECK
933# undef remove 1212# undef remove
934/* Assume remove is always declared. */ 1213/* Assume remove is always declared. */
@@ -951,7 +1230,9 @@ _GL_CXXALIAS_RPL (rename, int,
951_GL_CXXALIAS_SYS (rename, int, 1230_GL_CXXALIAS_SYS (rename, int,
952 (const char *old_filename, const char *new_filename)); 1231 (const char *old_filename, const char *new_filename));
953# endif 1232# endif
1233# if __GLIBC__ >= 2
954_GL_CXXALIASWARN (rename); 1234_GL_CXXALIASWARN (rename);
1235# endif
955#elif defined GNULIB_POSIXCHECK 1236#elif defined GNULIB_POSIXCHECK
956# undef rename 1237# undef rename
957/* Assume rename is always declared. */ 1238/* Assume rename is always declared. */
@@ -990,33 +1271,35 @@ _GL_WARN_ON_USE (renameat, "renameat is not portable - "
990 1271
991#if @GNULIB_SCANF@ 1272#if @GNULIB_SCANF@
992# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@ 1273# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@
993# if defined __GNUC__ 1274# if defined __GNUC__ || defined __clang__
994# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1275# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
995# undef scanf 1276# undef scanf
996/* Don't break __attribute__((format(scanf,M,N))). */ 1277/* Don't break __attribute__((format(scanf,M,N))). */
997# define scanf __scanf__ 1278# define scanf __scanf__
998# endif 1279# endif
999_GL_FUNCDECL_RPL_1 (__scanf__, int, 1280_GL_FUNCDECL_RPL_1 (__scanf__, int,
1000 (const char *format, ...) 1281 (const char *restrict format, ...)
1001 __asm__ (@ASM_SYMBOL_PREFIX@ 1282 __asm__ (@ASM_SYMBOL_PREFIX@
1002 _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_scanf)) 1283 _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_scanf))
1003 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 2) 1284 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 2)
1004 _GL_ARG_NONNULL ((1))); 1285 _GL_ARG_NONNULL ((1)));
1005_GL_CXXALIAS_RPL_1 (scanf, __scanf__, int, (const char *format, ...)); 1286_GL_CXXALIAS_RPL_1 (scanf, __scanf__, int, (const char *restrict format, ...));
1006# else 1287# else
1007# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1288# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1008# undef scanf 1289# undef scanf
1009# define scanf rpl_scanf 1290# define scanf rpl_scanf
1010# endif 1291# endif
1011_GL_FUNCDECL_RPL (scanf, int, (const char *format, ...) 1292_GL_FUNCDECL_RPL (scanf, int, (const char *restrict format, ...)
1012 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 2) 1293 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 2)
1013 _GL_ARG_NONNULL ((1))); 1294 _GL_ARG_NONNULL ((1)));
1014_GL_CXXALIAS_RPL (scanf, int, (const char *format, ...)); 1295_GL_CXXALIAS_RPL (scanf, int, (const char *restrict format, ...));
1015# endif 1296# endif
1016# else 1297# else
1017_GL_CXXALIAS_SYS (scanf, int, (const char *format, ...)); 1298_GL_CXXALIAS_SYS (scanf, int, (const char *restrict format, ...));
1018# endif 1299# endif
1300# if __GLIBC__ >= 2
1019_GL_CXXALIASWARN (scanf); 1301_GL_CXXALIASWARN (scanf);
1302# endif
1020#endif 1303#endif
1021 1304
1022#if @GNULIB_SNPRINTF@ 1305#if @GNULIB_SNPRINTF@
@@ -1024,23 +1307,30 @@ _GL_CXXALIASWARN (scanf);
1024# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1307# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1025# define snprintf rpl_snprintf 1308# define snprintf rpl_snprintf
1026# endif 1309# endif
1310# define GNULIB_overrides_snprintf 1
1027_GL_FUNCDECL_RPL (snprintf, int, 1311_GL_FUNCDECL_RPL (snprintf, int,
1028 (char *str, size_t size, const char *format, ...) 1312 (char *restrict str, size_t size,
1029 _GL_ATTRIBUTE_FORMAT_PRINTF (3, 4) 1313 const char *restrict format, ...)
1314 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 4)
1030 _GL_ARG_NONNULL ((3))); 1315 _GL_ARG_NONNULL ((3)));
1031_GL_CXXALIAS_RPL (snprintf, int, 1316_GL_CXXALIAS_RPL (snprintf, int,
1032 (char *str, size_t size, const char *format, ...)); 1317 (char *restrict str, size_t size,
1318 const char *restrict format, ...));
1033# else 1319# else
1034# if !@HAVE_DECL_SNPRINTF@ 1320# if !@HAVE_DECL_SNPRINTF@
1035_GL_FUNCDECL_SYS (snprintf, int, 1321_GL_FUNCDECL_SYS (snprintf, int,
1036 (char *str, size_t size, const char *format, ...) 1322 (char *restrict str, size_t size,
1037 _GL_ATTRIBUTE_FORMAT_PRINTF (3, 4) 1323 const char *restrict format, ...)
1324 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 4)
1038 _GL_ARG_NONNULL ((3))); 1325 _GL_ARG_NONNULL ((3)));
1039# endif 1326# endif
1040_GL_CXXALIAS_SYS (snprintf, int, 1327_GL_CXXALIAS_SYS (snprintf, int,
1041 (char *str, size_t size, const char *format, ...)); 1328 (char *restrict str, size_t size,
1329 const char *restrict format, ...));
1042# endif 1330# endif
1331# if __GLIBC__ >= 2
1043_GL_CXXALIASWARN (snprintf); 1332_GL_CXXALIASWARN (snprintf);
1333# endif
1044#elif defined GNULIB_POSIXCHECK 1334#elif defined GNULIB_POSIXCHECK
1045# undef snprintf 1335# undef snprintf
1046# if HAVE_RAW_DECL_SNPRINTF 1336# if HAVE_RAW_DECL_SNPRINTF
@@ -1063,14 +1353,20 @@ _GL_WARN_ON_USE (snprintf, "snprintf is unportable - "
1063# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1353# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1064# define sprintf rpl_sprintf 1354# define sprintf rpl_sprintf
1065# endif 1355# endif
1066_GL_FUNCDECL_RPL (sprintf, int, (char *str, const char *format, ...) 1356# define GNULIB_overrides_sprintf 1
1067 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) 1357_GL_FUNCDECL_RPL (sprintf, int,
1068 _GL_ARG_NONNULL ((1, 2))); 1358 (char *restrict str, const char *restrict format, ...)
1069_GL_CXXALIAS_RPL (sprintf, int, (char *str, const char *format, ...)); 1359 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
1360 _GL_ARG_NONNULL ((1, 2)));
1361_GL_CXXALIAS_RPL (sprintf, int,
1362 (char *restrict str, const char *restrict format, ...));
1070# else 1363# else
1071_GL_CXXALIAS_SYS (sprintf, int, (char *str, const char *format, ...)); 1364_GL_CXXALIAS_SYS (sprintf, int,
1365 (char *restrict str, const char *restrict format, ...));
1072# endif 1366# endif
1367# if __GLIBC__ >= 2
1073_GL_CXXALIASWARN (sprintf); 1368_GL_CXXALIASWARN (sprintf);
1369# endif
1074#elif defined GNULIB_POSIXCHECK 1370#elif defined GNULIB_POSIXCHECK
1075# undef sprintf 1371# undef sprintf
1076/* Assume sprintf is always declared. */ 1372/* Assume sprintf is always declared. */
@@ -1079,22 +1375,53 @@ _GL_WARN_ON_USE (sprintf, "sprintf is not always POSIX compliant - "
1079 "POSIX compliance"); 1375 "POSIX compliance");
1080#endif 1376#endif
1081 1377
1378#if @GNULIB_MDA_TEMPNAM@
1379/* On native Windows, map 'tempnam' to '_tempnam', so that -loldnames is not
1380 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1381 platforms by defining GNULIB_NAMESPACE::tempnam always. */
1382# if defined _WIN32 && !defined __CYGWIN__
1383# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1384# undef tempnam
1385# define tempnam _tempnam
1386# endif
1387_GL_CXXALIAS_MDA (tempnam, char *, (const char *dir, const char *prefix));
1388# else
1389_GL_CXXALIAS_SYS (tempnam, char *, (const char *dir, const char *prefix));
1390# endif
1391_GL_CXXALIASWARN (tempnam);
1392#endif
1393
1082#if @GNULIB_TMPFILE@ 1394#if @GNULIB_TMPFILE@
1083# if @REPLACE_TMPFILE@ 1395# if @REPLACE_TMPFILE@
1084# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1396# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1085# define tmpfile rpl_tmpfile 1397# define tmpfile rpl_tmpfile
1086# endif 1398# endif
1087_GL_FUNCDECL_RPL (tmpfile, FILE *, (void)); 1399_GL_FUNCDECL_RPL (tmpfile, FILE *, (void)
1400 _GL_ATTRIBUTE_DEALLOC (fclose, 1));
1088_GL_CXXALIAS_RPL (tmpfile, FILE *, (void)); 1401_GL_CXXALIAS_RPL (tmpfile, FILE *, (void));
1089# else 1402# else
1403# if __GNUC__ >= 11
1404/* For -Wmismatched-dealloc: Associate tmpfile with fclose or rpl_fclose. */
1405_GL_FUNCDECL_SYS (tmpfile, FILE *, (void)
1406 _GL_ATTRIBUTE_DEALLOC (fclose, 1));
1407# endif
1090_GL_CXXALIAS_SYS (tmpfile, FILE *, (void)); 1408_GL_CXXALIAS_SYS (tmpfile, FILE *, (void));
1091# endif 1409# endif
1410# if __GLIBC__ >= 2
1092_GL_CXXALIASWARN (tmpfile); 1411_GL_CXXALIASWARN (tmpfile);
1093#elif defined GNULIB_POSIXCHECK 1412# endif
1094# undef tmpfile 1413#else
1095# if HAVE_RAW_DECL_TMPFILE 1414# if @GNULIB_FCLOSE@ && __GNUC__ >= 11 && !defined tmpfile
1415/* For -Wmismatched-dealloc: Associate tmpfile with fclose or rpl_fclose. */
1416_GL_FUNCDECL_SYS (tmpfile, FILE *, (void)
1417 _GL_ATTRIBUTE_DEALLOC (fclose, 1));
1418# endif
1419# if defined GNULIB_POSIXCHECK
1420# undef tmpfile
1421# if HAVE_RAW_DECL_TMPFILE
1096_GL_WARN_ON_USE (tmpfile, "tmpfile is not usable on mingw - " 1422_GL_WARN_ON_USE (tmpfile, "tmpfile is not usable on mingw - "
1097 "use gnulib module tmpfile for portability"); 1423 "use gnulib module tmpfile for portability");
1424# endif
1098# endif 1425# endif
1099#endif 1426#endif
1100 1427
@@ -1107,9 +1434,10 @@ _GL_WARN_ON_USE (tmpfile, "tmpfile is not usable on mingw - "
1107# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1434# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1108# define asprintf rpl_asprintf 1435# define asprintf rpl_asprintf
1109# endif 1436# endif
1437# define GNULIB_overrides_asprintf
1110_GL_FUNCDECL_RPL (asprintf, int, 1438_GL_FUNCDECL_RPL (asprintf, int,
1111 (char **result, const char *format, ...) 1439 (char **result, const char *format, ...)
1112 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) 1440 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
1113 _GL_ARG_NONNULL ((1, 2))); 1441 _GL_ARG_NONNULL ((1, 2)));
1114_GL_CXXALIAS_RPL (asprintf, int, 1442_GL_CXXALIAS_RPL (asprintf, int,
1115 (char **result, const char *format, ...)); 1443 (char **result, const char *format, ...));
@@ -1117,7 +1445,7 @@ _GL_CXXALIAS_RPL (asprintf, int,
1117# if !@HAVE_VASPRINTF@ 1445# if !@HAVE_VASPRINTF@
1118_GL_FUNCDECL_SYS (asprintf, int, 1446_GL_FUNCDECL_SYS (asprintf, int,
1119 (char **result, const char *format, ...) 1447 (char **result, const char *format, ...)
1120 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) 1448 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
1121 _GL_ARG_NONNULL ((1, 2))); 1449 _GL_ARG_NONNULL ((1, 2)));
1122# endif 1450# endif
1123_GL_CXXALIAS_SYS (asprintf, int, 1451_GL_CXXALIAS_SYS (asprintf, int,
@@ -1128,9 +1456,10 @@ _GL_CXXALIASWARN (asprintf);
1128# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1456# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1129# define vasprintf rpl_vasprintf 1457# define vasprintf rpl_vasprintf
1130# endif 1458# endif
1459# define GNULIB_overrides_vasprintf 1
1131_GL_FUNCDECL_RPL (vasprintf, int, 1460_GL_FUNCDECL_RPL (vasprintf, int,
1132 (char **result, const char *format, va_list args) 1461 (char **result, const char *format, va_list args)
1133 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 1462 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1134 _GL_ARG_NONNULL ((1, 2))); 1463 _GL_ARG_NONNULL ((1, 2)));
1135_GL_CXXALIAS_RPL (vasprintf, int, 1464_GL_CXXALIAS_RPL (vasprintf, int,
1136 (char **result, const char *format, va_list args)); 1465 (char **result, const char *format, va_list args));
@@ -1138,7 +1467,7 @@ _GL_CXXALIAS_RPL (vasprintf, int,
1138# if !@HAVE_VASPRINTF@ 1467# if !@HAVE_VASPRINTF@
1139_GL_FUNCDECL_SYS (vasprintf, int, 1468_GL_FUNCDECL_SYS (vasprintf, int,
1140 (char **result, const char *format, va_list args) 1469 (char **result, const char *format, va_list args)
1141 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 1470 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1142 _GL_ARG_NONNULL ((1, 2))); 1471 _GL_ARG_NONNULL ((1, 2)));
1143# endif 1472# endif
1144_GL_CXXALIAS_SYS (vasprintf, int, 1473_GL_CXXALIAS_SYS (vasprintf, int,
@@ -1152,22 +1481,27 @@ _GL_CXXALIASWARN (vasprintf);
1152# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1481# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1153# define vdprintf rpl_vdprintf 1482# define vdprintf rpl_vdprintf
1154# endif 1483# endif
1155_GL_FUNCDECL_RPL (vdprintf, int, (int fd, const char *format, va_list args) 1484_GL_FUNCDECL_RPL (vdprintf, int,
1156 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 1485 (int fd, const char *restrict format, va_list args)
1157 _GL_ARG_NONNULL ((2))); 1486 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1158_GL_CXXALIAS_RPL (vdprintf, int, (int fd, const char *format, va_list args)); 1487 _GL_ARG_NONNULL ((2)));
1488_GL_CXXALIAS_RPL (vdprintf, int,
1489 (int fd, const char *restrict format, va_list args));
1159# else 1490# else
1160# if !@HAVE_VDPRINTF@ 1491# if !@HAVE_VDPRINTF@
1161_GL_FUNCDECL_SYS (vdprintf, int, (int fd, const char *format, va_list args) 1492_GL_FUNCDECL_SYS (vdprintf, int,
1162 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 1493 (int fd, const char *restrict format, va_list args)
1163 _GL_ARG_NONNULL ((2))); 1494 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1495 _GL_ARG_NONNULL ((2)));
1164# endif 1496# endif
1165/* Need to cast, because on Solaris, the third parameter will likely be 1497/* Need to cast, because on Solaris, the third parameter will likely be
1166 __va_list args. */ 1498 __va_list args. */
1167_GL_CXXALIAS_SYS_CAST (vdprintf, int, 1499_GL_CXXALIAS_SYS_CAST (vdprintf, int,
1168 (int fd, const char *format, va_list args)); 1500 (int fd, const char *restrict format, va_list args));
1169# endif 1501# endif
1502# if __GLIBC__ >= 2
1170_GL_CXXALIASWARN (vdprintf); 1503_GL_CXXALIASWARN (vdprintf);
1504# endif
1171#elif defined GNULIB_POSIXCHECK 1505#elif defined GNULIB_POSIXCHECK
1172# undef vdprintf 1506# undef vdprintf
1173# if HAVE_RAW_DECL_VDPRINTF 1507# if HAVE_RAW_DECL_VDPRINTF
@@ -1184,23 +1518,32 @@ _GL_WARN_ON_USE (vdprintf, "vdprintf is unportable - "
1184# endif 1518# endif
1185# define GNULIB_overrides_vfprintf 1 1519# define GNULIB_overrides_vfprintf 1
1186# if @GNULIB_VFPRINTF_POSIX@ 1520# if @GNULIB_VFPRINTF_POSIX@
1187_GL_FUNCDECL_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args) 1521_GL_FUNCDECL_RPL (vfprintf, int,
1188 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 1522 (FILE *restrict fp,
1189 _GL_ARG_NONNULL ((1, 2))); 1523 const char *restrict format, va_list args)
1524 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1525 _GL_ARG_NONNULL ((1, 2)));
1190# else 1526# else
1191_GL_FUNCDECL_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args) 1527_GL_FUNCDECL_RPL (vfprintf, int,
1192 _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (2, 0) 1528 (FILE *restrict fp,
1193 _GL_ARG_NONNULL ((1, 2))); 1529 const char *restrict format, va_list args)
1530 _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (2, 0)
1531 _GL_ARG_NONNULL ((1, 2)));
1194# endif 1532# endif
1195_GL_CXXALIAS_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args)); 1533_GL_CXXALIAS_RPL (vfprintf, int,
1534 (FILE *restrict fp,
1535 const char *restrict format, va_list args));
1196# else 1536# else
1197/* Need to cast, because on Solaris, the third parameter is 1537/* Need to cast, because on Solaris, the third parameter is
1198 __va_list args 1538 __va_list args
1199 and GCC's fixincludes did not change this to __gnuc_va_list. */ 1539 and GCC's fixincludes did not change this to __gnuc_va_list. */
1200_GL_CXXALIAS_SYS_CAST (vfprintf, int, 1540_GL_CXXALIAS_SYS_CAST (vfprintf, int,
1201 (FILE *fp, const char *format, va_list args)); 1541 (FILE *restrict fp,
1542 const char *restrict format, va_list args));
1202# endif 1543# endif
1544# if __GLIBC__ >= 2
1203_GL_CXXALIASWARN (vfprintf); 1545_GL_CXXALIASWARN (vfprintf);
1546# endif
1204#endif 1547#endif
1205#if !@GNULIB_VFPRINTF_POSIX@ && defined GNULIB_POSIXCHECK 1548#if !@GNULIB_VFPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
1206# if !GNULIB_overrides_vfprintf 1549# if !GNULIB_overrides_vfprintf
@@ -1219,16 +1562,21 @@ _GL_WARN_ON_USE (vfprintf, "vfprintf is not always POSIX compliant - "
1219# define vfscanf rpl_vfscanf 1562# define vfscanf rpl_vfscanf
1220# endif 1563# endif
1221_GL_FUNCDECL_RPL (vfscanf, int, 1564_GL_FUNCDECL_RPL (vfscanf, int,
1222 (FILE *stream, const char *format, va_list args) 1565 (FILE *restrict stream,
1566 const char *restrict format, va_list args)
1223 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (2, 0) 1567 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (2, 0)
1224 _GL_ARG_NONNULL ((1, 2))); 1568 _GL_ARG_NONNULL ((1, 2)));
1225_GL_CXXALIAS_RPL (vfscanf, int, 1569_GL_CXXALIAS_RPL (vfscanf, int,
1226 (FILE *stream, const char *format, va_list args)); 1570 (FILE *restrict stream,
1571 const char *restrict format, va_list args));
1227# else 1572# else
1228_GL_CXXALIAS_SYS (vfscanf, int, 1573_GL_CXXALIAS_SYS (vfscanf, int,
1229 (FILE *stream, const char *format, va_list args)); 1574 (FILE *restrict stream,
1575 const char *restrict format, va_list args));
1230# endif 1576# endif
1577# if __GLIBC__ >= 2
1231_GL_CXXALIASWARN (vfscanf); 1578_GL_CXXALIASWARN (vfscanf);
1579# endif
1232#endif 1580#endif
1233 1581
1234#if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VPRINTF@ 1582#if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VPRINTF@
@@ -1239,22 +1587,25 @@ _GL_CXXALIASWARN (vfscanf);
1239# endif 1587# endif
1240# define GNULIB_overrides_vprintf 1 1588# define GNULIB_overrides_vprintf 1
1241# if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@ 1589# if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@
1242_GL_FUNCDECL_RPL (vprintf, int, (const char *format, va_list args) 1590_GL_FUNCDECL_RPL (vprintf, int, (const char *restrict format, va_list args)
1243 _GL_ATTRIBUTE_FORMAT_PRINTF (1, 0) 1591 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 0)
1244 _GL_ARG_NONNULL ((1))); 1592 _GL_ARG_NONNULL ((1)));
1245# else 1593# else
1246_GL_FUNCDECL_RPL (vprintf, int, (const char *format, va_list args) 1594_GL_FUNCDECL_RPL (vprintf, int, (const char *restrict format, va_list args)
1247 _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (1, 0) 1595 _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (1, 0)
1248 _GL_ARG_NONNULL ((1))); 1596 _GL_ARG_NONNULL ((1)));
1249# endif 1597# endif
1250_GL_CXXALIAS_RPL (vprintf, int, (const char *format, va_list args)); 1598_GL_CXXALIAS_RPL (vprintf, int, (const char *restrict format, va_list args));
1251# else 1599# else
1252/* Need to cast, because on Solaris, the second parameter is 1600/* Need to cast, because on Solaris, the second parameter is
1253 __va_list args 1601 __va_list args
1254 and GCC's fixincludes did not change this to __gnuc_va_list. */ 1602 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)); 1603_GL_CXXALIAS_SYS_CAST (vprintf, int,
1604 (const char *restrict format, va_list args));
1256# endif 1605# endif
1606# if __GLIBC__ >= 2
1257_GL_CXXALIASWARN (vprintf); 1607_GL_CXXALIASWARN (vprintf);
1608# endif
1258#endif 1609#endif
1259#if !@GNULIB_VPRINTF_POSIX@ && defined GNULIB_POSIXCHECK 1610#if !@GNULIB_VPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
1260# if !GNULIB_overrides_vprintf 1611# if !GNULIB_overrides_vprintf
@@ -1272,14 +1623,16 @@ _GL_WARN_ON_USE (vprintf, "vprintf is not always POSIX compliant - "
1272# undef vscanf 1623# undef vscanf
1273# define vscanf rpl_vscanf 1624# define vscanf rpl_vscanf
1274# endif 1625# endif
1275_GL_FUNCDECL_RPL (vscanf, int, (const char *format, va_list args) 1626_GL_FUNCDECL_RPL (vscanf, int, (const char *restrict format, va_list args)
1276 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 0) 1627 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 0)
1277 _GL_ARG_NONNULL ((1))); 1628 _GL_ARG_NONNULL ((1)));
1278_GL_CXXALIAS_RPL (vscanf, int, (const char *format, va_list args)); 1629_GL_CXXALIAS_RPL (vscanf, int, (const char *restrict format, va_list args));
1279# else 1630# else
1280_GL_CXXALIAS_SYS (vscanf, int, (const char *format, va_list args)); 1631_GL_CXXALIAS_SYS (vscanf, int, (const char *restrict format, va_list args));
1281# endif 1632# endif
1633# if __GLIBC__ >= 2
1282_GL_CXXALIASWARN (vscanf); 1634_GL_CXXALIASWARN (vscanf);
1635# endif
1283#endif 1636#endif
1284 1637
1285#if @GNULIB_VSNPRINTF@ 1638#if @GNULIB_VSNPRINTF@
@@ -1287,23 +1640,30 @@ _GL_CXXALIASWARN (vscanf);
1287# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1640# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1288# define vsnprintf rpl_vsnprintf 1641# define vsnprintf rpl_vsnprintf
1289# endif 1642# endif
1643# define GNULIB_overrides_vsnprintf 1
1290_GL_FUNCDECL_RPL (vsnprintf, int, 1644_GL_FUNCDECL_RPL (vsnprintf, int,
1291 (char *str, size_t size, const char *format, va_list args) 1645 (char *restrict str, size_t size,
1292 _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) 1646 const char *restrict format, va_list args)
1647 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 0)
1293 _GL_ARG_NONNULL ((3))); 1648 _GL_ARG_NONNULL ((3)));
1294_GL_CXXALIAS_RPL (vsnprintf, int, 1649_GL_CXXALIAS_RPL (vsnprintf, int,
1295 (char *str, size_t size, const char *format, va_list args)); 1650 (char *restrict str, size_t size,
1651 const char *restrict format, va_list args));
1296# else 1652# else
1297# if !@HAVE_DECL_VSNPRINTF@ 1653# if !@HAVE_DECL_VSNPRINTF@
1298_GL_FUNCDECL_SYS (vsnprintf, int, 1654_GL_FUNCDECL_SYS (vsnprintf, int,
1299 (char *str, size_t size, const char *format, va_list args) 1655 (char *restrict str, size_t size,
1300 _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) 1656 const char *restrict format, va_list args)
1657 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 0)
1301 _GL_ARG_NONNULL ((3))); 1658 _GL_ARG_NONNULL ((3)));
1302# endif 1659# endif
1303_GL_CXXALIAS_SYS (vsnprintf, int, 1660_GL_CXXALIAS_SYS (vsnprintf, int,
1304 (char *str, size_t size, const char *format, va_list args)); 1661 (char *restrict str, size_t size,
1662 const char *restrict format, va_list args));
1305# endif 1663# endif
1664# if __GLIBC__ >= 2
1306_GL_CXXALIASWARN (vsnprintf); 1665_GL_CXXALIASWARN (vsnprintf);
1666# endif
1307#elif defined GNULIB_POSIXCHECK 1667#elif defined GNULIB_POSIXCHECK
1308# undef vsnprintf 1668# undef vsnprintf
1309# if HAVE_RAW_DECL_VSNPRINTF 1669# if HAVE_RAW_DECL_VSNPRINTF
@@ -1317,20 +1677,26 @@ _GL_WARN_ON_USE (vsnprintf, "vsnprintf is unportable - "
1317# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1677# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1318# define vsprintf rpl_vsprintf 1678# define vsprintf rpl_vsprintf
1319# endif 1679# endif
1680# define GNULIB_overrides_vsprintf 1
1320_GL_FUNCDECL_RPL (vsprintf, int, 1681_GL_FUNCDECL_RPL (vsprintf, int,
1321 (char *str, const char *format, va_list args) 1682 (char *restrict str,
1322 _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) 1683 const char *restrict format, va_list args)
1684 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1323 _GL_ARG_NONNULL ((1, 2))); 1685 _GL_ARG_NONNULL ((1, 2)));
1324_GL_CXXALIAS_RPL (vsprintf, int, 1686_GL_CXXALIAS_RPL (vsprintf, int,
1325 (char *str, const char *format, va_list args)); 1687 (char *restrict str,
1688 const char *restrict format, va_list args));
1326# else 1689# else
1327/* Need to cast, because on Solaris, the third parameter is 1690/* Need to cast, because on Solaris, the third parameter is
1328 __va_list args 1691 __va_list args
1329 and GCC's fixincludes did not change this to __gnuc_va_list. */ 1692 and GCC's fixincludes did not change this to __gnuc_va_list. */
1330_GL_CXXALIAS_SYS_CAST (vsprintf, int, 1693_GL_CXXALIAS_SYS_CAST (vsprintf, int,
1331 (char *str, const char *format, va_list args)); 1694 (char *restrict str,
1695 const char *restrict format, va_list args));
1332# endif 1696# endif
1697# if __GLIBC__ >= 2
1333_GL_CXXALIASWARN (vsprintf); 1698_GL_CXXALIASWARN (vsprintf);
1699# endif
1334#elif defined GNULIB_POSIXCHECK 1700#elif defined GNULIB_POSIXCHECK
1335# undef vsprintf 1701# undef vsprintf
1336/* Assume vsprintf is always declared. */ 1702/* Assume vsprintf is always declared. */
diff --git a/gl/stdlib.in.h b/gl/stdlib.in.h
index c955248..0855112 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-2021 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,69 @@ _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_GL_FUNCDECL_RPL (free, void, (void *ptr));
188_GL_CXXALIAS_RPL (free, void, (void *ptr));
189# else
190_GL_CXXALIAS_SYS (free, void, (void *ptr));
191# endif
192# if __GLIBC__ >= 2
193_GL_CXXALIASWARN (free);
194# endif
195#elif defined GNULIB_POSIXCHECK
196# undef free
197/* Assume free is always declared. */
198_GL_WARN_ON_USE (free, "free is not future POSIX compliant everywhere - "
199 "use gnulib module free for portability");
200#endif
201
202
203/* Allocate memory with indefinite extent and specified alignment. */
204#if @GNULIB_ALIGNED_ALLOC@
205# if @REPLACE_ALIGNED_ALLOC@
206# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
207# undef aligned_alloc
208# define aligned_alloc rpl_aligned_alloc
209# endif
210_GL_FUNCDECL_RPL (aligned_alloc, void *,
211 (size_t alignment, size_t size)
212 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
213_GL_CXXALIAS_RPL (aligned_alloc, void *, (size_t alignment, size_t size));
214# else
215# if @HAVE_ALIGNED_ALLOC@
216# if __GNUC__ >= 11
217/* For -Wmismatched-dealloc: Associate aligned_alloc with free or rpl_free. */
218_GL_FUNCDECL_SYS (aligned_alloc, void *,
219 (size_t alignment, size_t size)
220 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
221# endif
222_GL_CXXALIAS_SYS (aligned_alloc, void *, (size_t alignment, size_t size));
223# endif
224# endif
225# if @HAVE_ALIGNED_ALLOC@
226_GL_CXXALIASWARN (aligned_alloc);
227# endif
228#else
229# if @GNULIB_FREE_POSIX@ && __GNUC__ >= 11 && !defined aligned_alloc
230/* For -Wmismatched-dealloc: Associate aligned_alloc with free or rpl_free. */
231_GL_FUNCDECL_SYS (aligned_alloc, void *,
232 (size_t alignment, size_t size)
233 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
234# endif
235# if defined GNULIB_POSIXCHECK
236# undef aligned_alloc
237# if HAVE_RAW_DECL_ALIGNED_ALLOC
238_GL_WARN_ON_USE (aligned_alloc, "aligned_alloc is not portable - "
239 "use gnulib module aligned_alloc for portability");
240# endif
241# endif
242#endif
243
146#if @GNULIB_ATOLL@ 244#if @GNULIB_ATOLL@
147/* Parse a signed decimal integer. 245/* Parse a signed decimal integer.
148 Returns the value of the integer. Errors are not detected. */ 246 Returns the value of the integer. Errors are not detected. */
@@ -167,17 +265,35 @@ _GL_WARN_ON_USE (atoll, "atoll is unportable - "
167# undef calloc 265# undef calloc
168# define calloc rpl_calloc 266# define calloc rpl_calloc
169# endif 267# endif
170_GL_FUNCDECL_RPL (calloc, void *, (size_t nmemb, size_t size)); 268_GL_FUNCDECL_RPL (calloc, void *,
269 (size_t nmemb, size_t size)
270 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
171_GL_CXXALIAS_RPL (calloc, void *, (size_t nmemb, size_t size)); 271_GL_CXXALIAS_RPL (calloc, void *, (size_t nmemb, size_t size));
172# else 272# else
273# if __GNUC__ >= 11
274/* For -Wmismatched-dealloc: Associate calloc with free or rpl_free. */
275_GL_FUNCDECL_SYS (calloc, void *,
276 (size_t nmemb, size_t size)
277 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
278# endif
173_GL_CXXALIAS_SYS (calloc, void *, (size_t nmemb, size_t size)); 279_GL_CXXALIAS_SYS (calloc, void *, (size_t nmemb, size_t size));
174# endif 280# endif
281# if __GLIBC__ >= 2
175_GL_CXXALIASWARN (calloc); 282_GL_CXXALIASWARN (calloc);
176#elif defined GNULIB_POSIXCHECK 283# endif
177# undef calloc 284#else
285# if @GNULIB_FREE_POSIX@ && __GNUC__ >= 11 && !defined calloc
286/* For -Wmismatched-dealloc: Associate calloc with free or rpl_free. */
287_GL_FUNCDECL_SYS (calloc, void *,
288 (size_t nmemb, size_t size)
289 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
290# endif
291# if defined GNULIB_POSIXCHECK
292# undef calloc
178/* Assume calloc is always declared. */ 293/* Assume calloc is always declared. */
179_GL_WARN_ON_USE (calloc, "calloc is not POSIX compliant everywhere - " 294_GL_WARN_ON_USE (calloc, "calloc is not POSIX compliant everywhere - "
180 "use gnulib module calloc-posix for portability"); 295 "use gnulib module calloc-posix for portability");
296# endif
181#endif 297#endif
182 298
183#if @GNULIB_CANONICALIZE_FILE_NAME@ 299#if @GNULIB_CANONICALIZE_FILE_NAME@
@@ -185,23 +301,108 @@ _GL_WARN_ON_USE (calloc, "calloc is not POSIX compliant everywhere - "
185# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 301# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
186# define canonicalize_file_name rpl_canonicalize_file_name 302# define canonicalize_file_name rpl_canonicalize_file_name
187# endif 303# endif
188_GL_FUNCDECL_RPL (canonicalize_file_name, char *, (const char *name) 304_GL_FUNCDECL_RPL (canonicalize_file_name, char *,
189 _GL_ARG_NONNULL ((1))); 305 (const char *name)
306 _GL_ARG_NONNULL ((1))
307 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
190_GL_CXXALIAS_RPL (canonicalize_file_name, char *, (const char *name)); 308_GL_CXXALIAS_RPL (canonicalize_file_name, char *, (const char *name));
191# else 309# else
192# if !@HAVE_CANONICALIZE_FILE_NAME@ 310# if !@HAVE_CANONICALIZE_FILE_NAME@ || __GNUC__ >= 11
193_GL_FUNCDECL_SYS (canonicalize_file_name, char *, (const char *name) 311_GL_FUNCDECL_SYS (canonicalize_file_name, char *,
194 _GL_ARG_NONNULL ((1))); 312 (const char *name)
313 _GL_ARG_NONNULL ((1))
314 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
195# endif 315# endif
196_GL_CXXALIAS_SYS (canonicalize_file_name, char *, (const char *name)); 316_GL_CXXALIAS_SYS (canonicalize_file_name, char *, (const char *name));
197# endif 317# endif
318# ifndef GNULIB_defined_canonicalize_file_name
319# define GNULIB_defined_canonicalize_file_name \
320 (!@HAVE_CANONICALIZE_FILE_NAME@ || @REPLACE_CANONICALIZE_FILE_NAME@)
321# endif
198_GL_CXXALIASWARN (canonicalize_file_name); 322_GL_CXXALIASWARN (canonicalize_file_name);
199#elif defined GNULIB_POSIXCHECK 323#else
200# undef canonicalize_file_name 324# if @GNULIB_FREE_POSIX@ && __GNUC__ >= 11 && !defined canonicalize_file_name
201# if HAVE_RAW_DECL_CANONICALIZE_FILE_NAME 325/* For -Wmismatched-dealloc: Associate canonicalize_file_name with free or
326 rpl_free. */
327_GL_FUNCDECL_SYS (canonicalize_file_name, char *,
328 (const char *name)
329 _GL_ARG_NONNULL ((1))
330 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
331# endif
332# if defined GNULIB_POSIXCHECK
333# undef canonicalize_file_name
334# if HAVE_RAW_DECL_CANONICALIZE_FILE_NAME
202_GL_WARN_ON_USE (canonicalize_file_name, 335_GL_WARN_ON_USE (canonicalize_file_name,
203 "canonicalize_file_name is unportable - " 336 "canonicalize_file_name is unportable - "
204 "use gnulib module canonicalize-lgpl for portability"); 337 "use gnulib module canonicalize-lgpl for portability");
338# endif
339# endif
340#endif
341
342#if @GNULIB_MDA_ECVT@
343/* On native Windows, map 'ecvt' to '_ecvt', so that -loldnames is not
344 required. In C++ with GNULIB_NAMESPACE, avoid differences between
345 platforms by defining GNULIB_NAMESPACE::ecvt on all platforms that have
346 it. */
347# if defined _WIN32 && !defined __CYGWIN__
348# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
349# undef ecvt
350# define ecvt _ecvt
351# endif
352_GL_CXXALIAS_MDA (ecvt, char *,
353 (double number, int ndigits, int *decptp, int *signp));
354# else
355# if @HAVE_DECL_ECVT@
356_GL_CXXALIAS_SYS (ecvt, char *,
357 (double number, int ndigits, int *decptp, int *signp));
358# endif
359# endif
360# if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_ECVT@
361_GL_CXXALIASWARN (ecvt);
362# endif
363#endif
364
365#if @GNULIB_MDA_FCVT@
366/* On native Windows, map 'fcvt' to '_fcvt', so that -loldnames is not
367 required. In C++ with GNULIB_NAMESPACE, avoid differences between
368 platforms by defining GNULIB_NAMESPACE::fcvt on all platforms that have
369 it. */
370# if defined _WIN32 && !defined __CYGWIN__
371# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
372# undef fcvt
373# define fcvt _fcvt
374# endif
375_GL_CXXALIAS_MDA (fcvt, char *,
376 (double number, int ndigits, int *decptp, int *signp));
377# else
378# if @HAVE_DECL_FCVT@
379_GL_CXXALIAS_SYS (fcvt, char *,
380 (double number, int ndigits, int *decptp, int *signp));
381# endif
382# endif
383# if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_FCVT@
384_GL_CXXALIASWARN (fcvt);
385# endif
386#endif
387
388#if @GNULIB_MDA_GCVT@
389/* On native Windows, map 'gcvt' to '_gcvt', so that -loldnames is not
390 required. In C++ with GNULIB_NAMESPACE, avoid differences between
391 platforms by defining GNULIB_NAMESPACE::gcvt on all platforms that have
392 it. */
393# if defined _WIN32 && !defined __CYGWIN__
394# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
395# undef gcvt
396# define gcvt _gcvt
397# endif
398_GL_CXXALIAS_MDA (gcvt, char *, (double number, int ndigits, char *buf));
399# else
400# if @HAVE_DECL_GCVT@
401_GL_CXXALIAS_SYS (gcvt, char *, (double number, int ndigits, char *buf));
402# endif
403# endif
404# if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_GCVT@
405_GL_CXXALIASWARN (gcvt);
205# endif 406# endif
206#endif 407#endif
207 408
@@ -234,8 +435,8 @@ _GL_WARN_ON_USE (getloadavg, "getloadavg is not portable - "
234 element (or NULL if it doesn't contain an "=" sign), 435 element (or NULL if it doesn't contain an "=" sign),
235 - It returns the index of the "token" in the given array of tokens. 436 - It returns the index of the "token" in the given array of tokens.
236 Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined. 437 Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined.
237 For more details see the POSIX:2001 specification. 438 For more details see the POSIX specification.
238 http://www.opengroup.org/susv3xsh/getsubopt.html */ 439 https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsubopt.html */
239# if !@HAVE_GETSUBOPT@ 440# if !@HAVE_GETSUBOPT@
240_GL_FUNCDECL_SYS (getsubopt, int, 441_GL_FUNCDECL_SYS (getsubopt, int,
241 (char **optionp, char *const *tokens, char **valuep) 442 (char **optionp, char *const *tokens, char **valuep)
@@ -279,17 +480,35 @@ _GL_WARN_ON_USE (grantpt, "grantpt is not portable - "
279# undef malloc 480# undef malloc
280# define malloc rpl_malloc 481# define malloc rpl_malloc
281# endif 482# endif
282_GL_FUNCDECL_RPL (malloc, void *, (size_t size)); 483_GL_FUNCDECL_RPL (malloc, void *,
484 (size_t size)
485 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
283_GL_CXXALIAS_RPL (malloc, void *, (size_t size)); 486_GL_CXXALIAS_RPL (malloc, void *, (size_t size));
284# else 487# else
488# if __GNUC__ >= 11
489/* For -Wmismatched-dealloc: Associate malloc with free or rpl_free. */
490_GL_FUNCDECL_SYS (malloc, void *,
491 (size_t size)
492 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
493# endif
285_GL_CXXALIAS_SYS (malloc, void *, (size_t size)); 494_GL_CXXALIAS_SYS (malloc, void *, (size_t size));
286# endif 495# endif
496# if __GLIBC__ >= 2
287_GL_CXXALIASWARN (malloc); 497_GL_CXXALIASWARN (malloc);
288#elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC 498# endif
289# undef malloc 499#else
500# if @GNULIB_FREE_POSIX@ && __GNUC__ >= 11 && !defined malloc
501/* For -Wmismatched-dealloc: Associate malloc with free or rpl_free. */
502_GL_FUNCDECL_SYS (malloc, void *,
503 (size_t size)
504 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
505# endif
506# if defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC
507# undef malloc
290/* Assume malloc is always declared. */ 508/* Assume malloc is always declared. */
291_GL_WARN_ON_USE (malloc, "malloc is not POSIX compliant everywhere - " 509_GL_WARN_ON_USE (malloc, "malloc is not POSIX compliant everywhere - "
292 "use gnulib module malloc-posix for portability"); 510 "use gnulib module malloc-posix for portability");
511# endif
293#endif 512#endif
294 513
295/* Convert a multibyte character to a wide character. */ 514/* Convert a multibyte character to a wide character. */
@@ -299,12 +518,27 @@ _GL_WARN_ON_USE (malloc, "malloc is not POSIX compliant everywhere - "
299# undef mbtowc 518# undef mbtowc
300# define mbtowc rpl_mbtowc 519# define mbtowc rpl_mbtowc
301# endif 520# endif
302_GL_FUNCDECL_RPL (mbtowc, int, (wchar_t *pwc, const char *s, size_t n)); 521_GL_FUNCDECL_RPL (mbtowc, int,
303_GL_CXXALIAS_RPL (mbtowc, int, (wchar_t *pwc, const char *s, size_t n)); 522 (wchar_t *restrict pwc, const char *restrict s, size_t n));
523_GL_CXXALIAS_RPL (mbtowc, int,
524 (wchar_t *restrict pwc, const char *restrict s, size_t n));
304# else 525# else
305_GL_CXXALIAS_SYS (mbtowc, int, (wchar_t *pwc, const char *s, size_t n)); 526# if !@HAVE_MBTOWC@
527_GL_FUNCDECL_SYS (mbtowc, int,
528 (wchar_t *restrict pwc, const char *restrict s, size_t n));
529# endif
530_GL_CXXALIAS_SYS (mbtowc, int,
531 (wchar_t *restrict pwc, const char *restrict s, size_t n));
306# endif 532# endif
533# if __GLIBC__ >= 2
307_GL_CXXALIASWARN (mbtowc); 534_GL_CXXALIASWARN (mbtowc);
535# endif
536#elif defined GNULIB_POSIXCHECK
537# undef mbtowc
538# if HAVE_RAW_DECL_MBTOWC
539_GL_WARN_ON_USE (mbtowc, "mbtowc is not portable - "
540 "use gnulib module mbtowc for portability");
541# endif
308#endif 542#endif
309 543
310#if @GNULIB_MKDTEMP@ 544#if @GNULIB_MKDTEMP@
@@ -439,6 +673,51 @@ _GL_WARN_ON_USE (mkstemps, "mkstemps is unportable - "
439# endif 673# endif
440#endif 674#endif
441 675
676#if @GNULIB_MDA_MKTEMP@
677/* On native Windows, map 'mktemp' to '_mktemp', so that -loldnames is not
678 required. In C++ with GNULIB_NAMESPACE, avoid differences between
679 platforms by defining GNULIB_NAMESPACE::mktemp always. */
680# if defined _WIN32 && !defined __CYGWIN__
681# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
682# undef mktemp
683# define mktemp _mktemp
684# endif
685_GL_CXXALIAS_MDA (mktemp, char *, (char * /*template*/));
686# else
687_GL_CXXALIAS_SYS (mktemp, char *, (char * /*template*/));
688# endif
689_GL_CXXALIASWARN (mktemp);
690#endif
691
692/* Allocate memory with indefinite extent and specified alignment. */
693#if @GNULIB_POSIX_MEMALIGN@
694# if @REPLACE_POSIX_MEMALIGN@
695# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
696# undef posix_memalign
697# define posix_memalign rpl_posix_memalign
698# endif
699_GL_FUNCDECL_RPL (posix_memalign, int,
700 (void **memptr, size_t alignment, size_t size)
701 _GL_ARG_NONNULL ((1)));
702_GL_CXXALIAS_RPL (posix_memalign, int,
703 (void **memptr, size_t alignment, size_t size));
704# else
705# if @HAVE_POSIX_MEMALIGN@
706_GL_CXXALIAS_SYS (posix_memalign, int,
707 (void **memptr, size_t alignment, size_t size));
708# endif
709# endif
710# if @HAVE_POSIX_MEMALIGN@
711_GL_CXXALIASWARN (posix_memalign);
712# endif
713#elif defined GNULIB_POSIXCHECK
714# undef posix_memalign
715# if HAVE_RAW_DECL_POSIX_MEMALIGN
716_GL_WARN_ON_USE (posix_memalign, "posix_memalign is not portable - "
717 "use gnulib module posix_memalign for portability");
718# endif
719#endif
720
442#if @GNULIB_POSIX_OPENPT@ 721#if @GNULIB_POSIX_OPENPT@
443/* Return an FD open to the master side of a pseudo-terminal. Flags should 722/* Return an FD open to the master side of a pseudo-terminal. Flags should
444 include O_RDWR, and may also include O_NOCTTY. */ 723 include O_RDWR, and may also include O_NOCTTY. */
@@ -497,6 +776,9 @@ _GL_FUNCDECL_SYS (ptsname_r, int, (int fd, char *buf, size_t len));
497# endif 776# endif
498_GL_CXXALIAS_SYS (ptsname_r, int, (int fd, char *buf, size_t len)); 777_GL_CXXALIAS_SYS (ptsname_r, int, (int fd, char *buf, size_t len));
499# endif 778# endif
779# ifndef GNULIB_defined_ptsname_r
780# define GNULIB_defined_ptsname_r (!@HAVE_PTSNAME_R@ || @REPLACE_PTSNAME_R@)
781# endif
500_GL_CXXALIASWARN (ptsname_r); 782_GL_CXXALIASWARN (ptsname_r);
501#elif defined GNULIB_POSIXCHECK 783#elif defined GNULIB_POSIXCHECK
502# undef ptsname_r 784# undef ptsname_r
@@ -514,12 +796,72 @@ _GL_WARN_ON_USE (ptsname_r, "ptsname_r is not portable - "
514# endif 796# endif
515_GL_FUNCDECL_RPL (putenv, int, (char *string) _GL_ARG_NONNULL ((1))); 797_GL_FUNCDECL_RPL (putenv, int, (char *string) _GL_ARG_NONNULL ((1)));
516_GL_CXXALIAS_RPL (putenv, int, (char *string)); 798_GL_CXXALIAS_RPL (putenv, int, (char *string));
799# elif defined _WIN32 && !defined __CYGWIN__
800# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
801# undef putenv
802# define putenv _putenv
803# endif
804_GL_CXXALIAS_MDA (putenv, int, (char *string));
805# else
806_GL_CXXALIAS_SYS (putenv, int, (char *string));
807# endif
808_GL_CXXALIASWARN (putenv);
809#elif @GNULIB_MDA_PUTENV@
810/* On native Windows, map 'putenv' to '_putenv', so that -loldnames is not
811 required. In C++ with GNULIB_NAMESPACE, avoid differences between
812 platforms by defining GNULIB_NAMESPACE::putenv always. */
813# if defined _WIN32 && !defined __CYGWIN__
814# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
815# undef putenv
816# define putenv _putenv
817# endif
818/* Need to cast, because on mingw, the parameter is either
819 'const char *string' or 'char *string'. */
820_GL_CXXALIAS_MDA_CAST (putenv, int, (char *string));
517# else 821# else
518_GL_CXXALIAS_SYS (putenv, int, (char *string)); 822_GL_CXXALIAS_SYS (putenv, int, (char *string));
519# endif 823# endif
520_GL_CXXALIASWARN (putenv); 824_GL_CXXALIASWARN (putenv);
521#endif 825#endif
522 826
827#if @GNULIB_QSORT_R@
828/* Sort an array of NMEMB elements, starting at address BASE, each element
829 occupying SIZE bytes, in ascending order according to the comparison
830 function COMPARE. */
831# if @REPLACE_QSORT_R@
832# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
833# undef qsort_r
834# define qsort_r rpl_qsort_r
835# endif
836_GL_FUNCDECL_RPL (qsort_r, void, (void *base, size_t nmemb, size_t size,
837 int (*compare) (void const *, void const *,
838 void *),
839 void *arg) _GL_ARG_NONNULL ((1, 4)));
840_GL_CXXALIAS_RPL (qsort_r, void, (void *base, size_t nmemb, size_t size,
841 int (*compare) (void const *, void const *,
842 void *),
843 void *arg));
844# else
845# if !@HAVE_QSORT_R@
846_GL_FUNCDECL_SYS (qsort_r, void, (void *base, size_t nmemb, size_t size,
847 int (*compare) (void const *, void const *,
848 void *),
849 void *arg) _GL_ARG_NONNULL ((1, 4)));
850# endif
851_GL_CXXALIAS_SYS (qsort_r, void, (void *base, size_t nmemb, size_t size,
852 int (*compare) (void const *, void const *,
853 void *),
854 void *arg));
855# endif
856_GL_CXXALIASWARN (qsort_r);
857#elif defined GNULIB_POSIXCHECK
858# undef qsort_r
859# if HAVE_RAW_DECL_QSORT_R
860_GL_WARN_ON_USE (qsort_r, "qsort_r is not portable - "
861 "use gnulib module qsort_r for portability");
862# endif
863#endif
864
523 865
524#if @GNULIB_RANDOM_R@ 866#if @GNULIB_RANDOM_R@
525# if !@HAVE_RANDOM_R@ 867# if !@HAVE_RANDOM_R@
@@ -531,10 +873,21 @@ _GL_CXXALIASWARN (putenv);
531 873
532 874
533#if @GNULIB_RANDOM@ 875#if @GNULIB_RANDOM@
534# if !@HAVE_RANDOM@ 876# if @REPLACE_RANDOM@
877# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
878# undef random
879# define random rpl_random
880# endif
881_GL_FUNCDECL_RPL (random, long, (void));
882_GL_CXXALIAS_RPL (random, long, (void));
883# else
884# if !@HAVE_RANDOM@
535_GL_FUNCDECL_SYS (random, long, (void)); 885_GL_FUNCDECL_SYS (random, long, (void));
886# endif
887/* Need to cast, because on Haiku, the return type is
888 int. */
889_GL_CXXALIAS_SYS_CAST (random, long, (void));
536# endif 890# endif
537_GL_CXXALIAS_SYS (random, long, (void));
538_GL_CXXALIASWARN (random); 891_GL_CXXALIASWARN (random);
539#elif defined GNULIB_POSIXCHECK 892#elif defined GNULIB_POSIXCHECK
540# undef random 893# undef random
@@ -545,10 +898,21 @@ _GL_WARN_ON_USE (random, "random is unportable - "
545#endif 898#endif
546 899
547#if @GNULIB_RANDOM@ 900#if @GNULIB_RANDOM@
548# if !@HAVE_RANDOM@ 901# if @REPLACE_RANDOM@
902# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
903# undef srandom
904# define srandom rpl_srandom
905# endif
906_GL_FUNCDECL_RPL (srandom, void, (unsigned int seed));
907_GL_CXXALIAS_RPL (srandom, void, (unsigned int seed));
908# else
909# if !@HAVE_RANDOM@
549_GL_FUNCDECL_SYS (srandom, void, (unsigned int seed)); 910_GL_FUNCDECL_SYS (srandom, void, (unsigned int seed));
911# endif
912/* Need to cast, because on FreeBSD, the first parameter is
913 unsigned long seed. */
914_GL_CXXALIAS_SYS_CAST (srandom, void, (unsigned int seed));
550# endif 915# endif
551_GL_CXXALIAS_SYS (srandom, void, (unsigned int seed));
552_GL_CXXALIASWARN (srandom); 916_GL_CXXALIASWARN (srandom);
553#elif defined GNULIB_POSIXCHECK 917#elif defined GNULIB_POSIXCHECK
554# undef srandom 918# undef srandom
@@ -559,31 +923,56 @@ _GL_WARN_ON_USE (srandom, "srandom is unportable - "
559#endif 923#endif
560 924
561#if @GNULIB_RANDOM@ 925#if @GNULIB_RANDOM@
562# if !@HAVE_RANDOM@ 926# if @REPLACE_INITSTATE@
927# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
928# undef initstate
929# define initstate rpl_initstate
930# endif
931_GL_FUNCDECL_RPL (initstate, char *,
932 (unsigned int seed, char *buf, size_t buf_size)
933 _GL_ARG_NONNULL ((2)));
934_GL_CXXALIAS_RPL (initstate, char *,
935 (unsigned int seed, char *buf, size_t buf_size));
936# else
937# if !@HAVE_INITSTATE@ || !@HAVE_DECL_INITSTATE@
563_GL_FUNCDECL_SYS (initstate, char *, 938_GL_FUNCDECL_SYS (initstate, char *,
564 (unsigned int seed, char *buf, size_t buf_size) 939 (unsigned int seed, char *buf, size_t buf_size)
565 _GL_ARG_NONNULL ((2))); 940 _GL_ARG_NONNULL ((2)));
941# endif
942/* Need to cast, because on FreeBSD, the first parameter is
943 unsigned long seed. */
944_GL_CXXALIAS_SYS_CAST (initstate, char *,
945 (unsigned int seed, char *buf, size_t buf_size));
566# endif 946# endif
567_GL_CXXALIAS_SYS (initstate, char *,
568 (unsigned int seed, char *buf, size_t buf_size));
569_GL_CXXALIASWARN (initstate); 947_GL_CXXALIASWARN (initstate);
570#elif defined GNULIB_POSIXCHECK 948#elif defined GNULIB_POSIXCHECK
571# undef initstate 949# undef initstate
572# if HAVE_RAW_DECL_INITSTATE_R 950# if HAVE_RAW_DECL_INITSTATE
573_GL_WARN_ON_USE (initstate, "initstate is unportable - " 951_GL_WARN_ON_USE (initstate, "initstate is unportable - "
574 "use gnulib module random for portability"); 952 "use gnulib module random for portability");
575# endif 953# endif
576#endif 954#endif
577 955
578#if @GNULIB_RANDOM@ 956#if @GNULIB_RANDOM@
579# if !@HAVE_RANDOM@ 957# if @REPLACE_SETSTATE@
958# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
959# undef setstate
960# define setstate rpl_setstate
961# endif
962_GL_FUNCDECL_RPL (setstate, char *, (char *arg_state) _GL_ARG_NONNULL ((1)));
963_GL_CXXALIAS_RPL (setstate, char *, (char *arg_state));
964# else
965# if !@HAVE_SETSTATE@ || !@HAVE_DECL_SETSTATE@
580_GL_FUNCDECL_SYS (setstate, char *, (char *arg_state) _GL_ARG_NONNULL ((1))); 966_GL_FUNCDECL_SYS (setstate, char *, (char *arg_state) _GL_ARG_NONNULL ((1)));
967# endif
968/* Need to cast, because on Mac OS X 10.13, HP-UX, Solaris the first parameter
969 is const char *arg_state. */
970_GL_CXXALIAS_SYS_CAST (setstate, char *, (char *arg_state));
581# endif 971# endif
582_GL_CXXALIAS_SYS (setstate, char *, (char *arg_state));
583_GL_CXXALIASWARN (setstate); 972_GL_CXXALIASWARN (setstate);
584#elif defined GNULIB_POSIXCHECK 973#elif defined GNULIB_POSIXCHECK
585# undef setstate 974# undef setstate
586# if HAVE_RAW_DECL_SETSTATE_R 975# if HAVE_RAW_DECL_SETSTATE
587_GL_WARN_ON_USE (setstate, "setstate is unportable - " 976_GL_WARN_ON_USE (setstate, "setstate is unportable - "
588 "use gnulib module random for portability"); 977 "use gnulib module random for portability");
589# endif 978# endif
@@ -664,9 +1053,11 @@ _GL_FUNCDECL_SYS (initstate_r, int,
664 struct random_data *rand_state) 1053 struct random_data *rand_state)
665 _GL_ARG_NONNULL ((2, 4))); 1054 _GL_ARG_NONNULL ((2, 4)));
666# endif 1055# endif
667_GL_CXXALIAS_SYS (initstate_r, int, 1056/* Need to cast, because on Haiku, the third parameter is
668 (unsigned int seed, char *buf, size_t buf_size, 1057 unsigned long buf_size. */
669 struct random_data *rand_state)); 1058_GL_CXXALIAS_SYS_CAST (initstate_r, int,
1059 (unsigned int seed, char *buf, size_t buf_size,
1060 struct random_data *rand_state));
670# endif 1061# endif
671_GL_CXXALIASWARN (initstate_r); 1062_GL_CXXALIASWARN (initstate_r);
672#elif defined GNULIB_POSIXCHECK 1063#elif defined GNULIB_POSIXCHECK
@@ -694,8 +1085,10 @@ _GL_FUNCDECL_SYS (setstate_r, int,
694 (char *arg_state, struct random_data *rand_state) 1085 (char *arg_state, struct random_data *rand_state)
695 _GL_ARG_NONNULL ((1, 2))); 1086 _GL_ARG_NONNULL ((1, 2)));
696# endif 1087# endif
697_GL_CXXALIAS_SYS (setstate_r, int, 1088/* Need to cast, because on Haiku, the first parameter is
698 (char *arg_state, struct random_data *rand_state)); 1089 void *arg_state. */
1090_GL_CXXALIAS_SYS_CAST (setstate_r, int,
1091 (char *arg_state, struct random_data *rand_state));
699# endif 1092# endif
700_GL_CXXALIASWARN (setstate_r); 1093_GL_CXXALIASWARN (setstate_r);
701#elif defined GNULIB_POSIXCHECK 1094#elif defined GNULIB_POSIXCHECK
@@ -714,17 +1107,60 @@ _GL_WARN_ON_USE (setstate_r, "setstate_r is unportable - "
714# undef realloc 1107# undef realloc
715# define realloc rpl_realloc 1108# define realloc rpl_realloc
716# endif 1109# endif
717_GL_FUNCDECL_RPL (realloc, void *, (void *ptr, size_t size)); 1110_GL_FUNCDECL_RPL (realloc, void *, (void *ptr, size_t size)
1111 _GL_ATTRIBUTE_DEALLOC_FREE);
718_GL_CXXALIAS_RPL (realloc, void *, (void *ptr, size_t size)); 1112_GL_CXXALIAS_RPL (realloc, void *, (void *ptr, size_t size));
719# else 1113# else
1114# if __GNUC__ >= 11
1115/* For -Wmismatched-dealloc: Associate realloc with free or rpl_free. */
1116_GL_FUNCDECL_SYS (realloc, void *, (void *ptr, size_t size)
1117 _GL_ATTRIBUTE_DEALLOC_FREE);
1118# endif
720_GL_CXXALIAS_SYS (realloc, void *, (void *ptr, size_t size)); 1119_GL_CXXALIAS_SYS (realloc, void *, (void *ptr, size_t size));
721# endif 1120# endif
1121# if __GLIBC__ >= 2
722_GL_CXXALIASWARN (realloc); 1122_GL_CXXALIASWARN (realloc);
723#elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC 1123# endif
724# undef realloc 1124#else
1125# if @GNULIB_FREE_POSIX@ && __GNUC__ >= 11 && !defined realloc
1126/* For -Wmismatched-dealloc: Associate realloc with free or rpl_free. */
1127_GL_FUNCDECL_SYS (realloc, void *, (void *ptr, size_t size)
1128 _GL_ATTRIBUTE_DEALLOC_FREE);
1129# endif
1130# if defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC
1131# undef realloc
725/* Assume realloc is always declared. */ 1132/* Assume realloc is always declared. */
726_GL_WARN_ON_USE (realloc, "realloc is not POSIX compliant everywhere - " 1133_GL_WARN_ON_USE (realloc, "realloc is not POSIX compliant everywhere - "
727 "use gnulib module realloc-posix for portability"); 1134 "use gnulib module realloc-posix for portability");
1135# endif
1136#endif
1137
1138
1139#if @GNULIB_REALLOCARRAY@
1140# if @REPLACE_REALLOCARRAY@
1141# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1142# undef reallocarray
1143# define reallocarray rpl_reallocarray
1144# endif
1145_GL_FUNCDECL_RPL (reallocarray, void *,
1146 (void *ptr, size_t nmemb, size_t size));
1147_GL_CXXALIAS_RPL (reallocarray, void *,
1148 (void *ptr, size_t nmemb, size_t size));
1149# else
1150# if ! @HAVE_REALLOCARRAY@
1151_GL_FUNCDECL_SYS (reallocarray, void *,
1152 (void *ptr, size_t nmemb, size_t size));
1153# endif
1154_GL_CXXALIAS_SYS (reallocarray, void *,
1155 (void *ptr, size_t nmemb, size_t size));
1156# endif
1157_GL_CXXALIASWARN (reallocarray);
1158#elif defined GNULIB_POSIXCHECK
1159# undef reallocarray
1160# if HAVE_RAW_DECL_REALLOCARRAY
1161_GL_WARN_ON_USE (reallocarray, "reallocarray is not portable - "
1162 "use gnulib module reallocarray for portability");
1163# endif
728#endif 1164#endif
729 1165
730#if @GNULIB_REALPATH@ 1166#if @GNULIB_REALPATH@
@@ -732,15 +1168,19 @@ _GL_WARN_ON_USE (realloc, "realloc is not POSIX compliant everywhere - "
732# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1168# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
733# define realpath rpl_realpath 1169# define realpath rpl_realpath
734# endif 1170# endif
735_GL_FUNCDECL_RPL (realpath, char *, (const char *name, char *resolved) 1171_GL_FUNCDECL_RPL (realpath, char *,
736 _GL_ARG_NONNULL ((1))); 1172 (const char *restrict name, char *restrict resolved)
737_GL_CXXALIAS_RPL (realpath, char *, (const char *name, char *resolved)); 1173 _GL_ARG_NONNULL ((1)));
1174_GL_CXXALIAS_RPL (realpath, char *,
1175 (const char *restrict name, char *restrict resolved));
738# else 1176# else
739# if !@HAVE_REALPATH@ 1177# if !@HAVE_REALPATH@
740_GL_FUNCDECL_SYS (realpath, char *, (const char *name, char *resolved) 1178_GL_FUNCDECL_SYS (realpath, char *,
741 _GL_ARG_NONNULL ((1))); 1179 (const char *restrict name, char *restrict resolved)
1180 _GL_ARG_NONNULL ((1)));
742# endif 1181# endif
743_GL_CXXALIAS_SYS (realpath, char *, (const char *name, char *resolved)); 1182_GL_CXXALIAS_SYS (realpath, char *,
1183 (const char *restrict name, char *restrict resolved));
744# endif 1184# endif
745_GL_CXXALIASWARN (realpath); 1185_GL_CXXALIASWARN (realpath);
746#elif defined GNULIB_POSIXCHECK 1186#elif defined GNULIB_POSIXCHECK
@@ -822,17 +1262,24 @@ _GL_WARN_ON_USE (setenv, "setenv is unportable - "
822# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1262# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
823# define strtod rpl_strtod 1263# define strtod rpl_strtod
824# endif 1264# endif
825_GL_FUNCDECL_RPL (strtod, double, (const char *str, char **endp) 1265# define GNULIB_defined_strtod_function 1
826 _GL_ARG_NONNULL ((1))); 1266_GL_FUNCDECL_RPL (strtod, double,
827_GL_CXXALIAS_RPL (strtod, double, (const char *str, char **endp)); 1267 (const char *restrict str, char **restrict endp)
1268 _GL_ARG_NONNULL ((1)));
1269_GL_CXXALIAS_RPL (strtod, double,
1270 (const char *restrict str, char **restrict endp));
828# else 1271# else
829# if !@HAVE_STRTOD@ 1272# if !@HAVE_STRTOD@
830_GL_FUNCDECL_SYS (strtod, double, (const char *str, char **endp) 1273_GL_FUNCDECL_SYS (strtod, double,
831 _GL_ARG_NONNULL ((1))); 1274 (const char *restrict str, char **restrict endp)
1275 _GL_ARG_NONNULL ((1)));
832# endif 1276# endif
833_GL_CXXALIAS_SYS (strtod, double, (const char *str, char **endp)); 1277_GL_CXXALIAS_SYS (strtod, double,
1278 (const char *restrict str, char **restrict endp));
834# endif 1279# endif
1280# if __GLIBC__ >= 2
835_GL_CXXALIASWARN (strtod); 1281_GL_CXXALIASWARN (strtod);
1282# endif
836#elif defined GNULIB_POSIXCHECK 1283#elif defined GNULIB_POSIXCHECK
837# undef strtod 1284# undef strtod
838# if HAVE_RAW_DECL_STRTOD 1285# if HAVE_RAW_DECL_STRTOD
@@ -841,6 +1288,77 @@ _GL_WARN_ON_USE (strtod, "strtod is unportable - "
841# endif 1288# endif
842#endif 1289#endif
843 1290
1291#if @GNULIB_STRTOLD@
1292 /* Parse a 'long double' from STRING, updating ENDP if appropriate. */
1293# if @REPLACE_STRTOLD@
1294# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1295# define strtold rpl_strtold
1296# endif
1297# define GNULIB_defined_strtold_function 1
1298_GL_FUNCDECL_RPL (strtold, long double,
1299 (const char *restrict str, char **restrict endp)
1300 _GL_ARG_NONNULL ((1)));
1301_GL_CXXALIAS_RPL (strtold, long double,
1302 (const char *restrict str, char **restrict endp));
1303# else
1304# if !@HAVE_STRTOLD@
1305_GL_FUNCDECL_SYS (strtold, long double,
1306 (const char *restrict str, char **restrict endp)
1307 _GL_ARG_NONNULL ((1)));
1308# endif
1309_GL_CXXALIAS_SYS (strtold, long double,
1310 (const char *restrict str, char **restrict endp));
1311# endif
1312_GL_CXXALIASWARN (strtold);
1313#elif defined GNULIB_POSIXCHECK
1314# undef strtold
1315# if HAVE_RAW_DECL_STRTOLD
1316_GL_WARN_ON_USE (strtold, "strtold is unportable - "
1317 "use gnulib module strtold for portability");
1318# endif
1319#endif
1320
1321#if @GNULIB_STRTOL@
1322/* Parse a signed integer whose textual representation starts at STRING.
1323 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
1324 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
1325 "0x").
1326 If ENDPTR is not NULL, the address of the first byte after the integer is
1327 stored in *ENDPTR.
1328 Upon overflow, the return value is LONG_MAX or LONG_MIN, and errno is set
1329 to ERANGE. */
1330# if @REPLACE_STRTOL@
1331# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1332# define strtol rpl_strtol
1333# endif
1334# define GNULIB_defined_strtol_function 1
1335_GL_FUNCDECL_RPL (strtol, long,
1336 (const char *restrict string, char **restrict endptr,
1337 int base)
1338 _GL_ARG_NONNULL ((1)));
1339_GL_CXXALIAS_RPL (strtol, long,
1340 (const char *restrict string, char **restrict endptr,
1341 int base));
1342# else
1343# if !@HAVE_STRTOL@
1344_GL_FUNCDECL_SYS (strtol, long,
1345 (const char *restrict string, char **restrict endptr,
1346 int base)
1347 _GL_ARG_NONNULL ((1)));
1348# endif
1349_GL_CXXALIAS_SYS (strtol, long,
1350 (const char *restrict string, char **restrict endptr,
1351 int base));
1352# endif
1353_GL_CXXALIASWARN (strtol);
1354#elif defined GNULIB_POSIXCHECK
1355# undef strtol
1356# if HAVE_RAW_DECL_STRTOL
1357_GL_WARN_ON_USE (strtol, "strtol is unportable - "
1358 "use gnulib module strtol for portability");
1359# endif
1360#endif
1361
844#if @GNULIB_STRTOLL@ 1362#if @GNULIB_STRTOLL@
845/* Parse a signed integer whose textual representation starts at STRING. 1363/* 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, 1364 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
@@ -850,13 +1368,29 @@ _GL_WARN_ON_USE (strtod, "strtod is unportable - "
850 stored in *ENDPTR. 1368 stored in *ENDPTR.
851 Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set 1369 Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set
852 to ERANGE. */ 1370 to ERANGE. */
853# if !@HAVE_STRTOLL@ 1371# if @REPLACE_STRTOLL@
1372# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1373# define strtoll rpl_strtoll
1374# endif
1375# define GNULIB_defined_strtoll_function 1
1376_GL_FUNCDECL_RPL (strtoll, long long,
1377 (const char *restrict string, char **restrict endptr,
1378 int base)
1379 _GL_ARG_NONNULL ((1)));
1380_GL_CXXALIAS_RPL (strtoll, long long,
1381 (const char *restrict string, char **restrict endptr,
1382 int base));
1383# else
1384# if !@HAVE_STRTOLL@
854_GL_FUNCDECL_SYS (strtoll, long long, 1385_GL_FUNCDECL_SYS (strtoll, long long,
855 (const char *string, char **endptr, int base) 1386 (const char *restrict string, char **restrict endptr,
1387 int base)
856 _GL_ARG_NONNULL ((1))); 1388 _GL_ARG_NONNULL ((1)));
857# endif 1389# endif
858_GL_CXXALIAS_SYS (strtoll, long long, 1390_GL_CXXALIAS_SYS (strtoll, long long,
859 (const char *string, char **endptr, int base)); 1391 (const char *restrict string, char **restrict endptr,
1392 int base));
1393# endif
860_GL_CXXALIASWARN (strtoll); 1394_GL_CXXALIASWARN (strtoll);
861#elif defined GNULIB_POSIXCHECK 1395#elif defined GNULIB_POSIXCHECK
862# undef strtoll 1396# undef strtoll
@@ -866,6 +1400,46 @@ _GL_WARN_ON_USE (strtoll, "strtoll is unportable - "
866# endif 1400# endif
867#endif 1401#endif
868 1402
1403#if @GNULIB_STRTOUL@
1404/* Parse an unsigned integer whose textual representation starts at STRING.
1405 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
1406 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
1407 "0x").
1408 If ENDPTR is not NULL, the address of the first byte after the integer is
1409 stored in *ENDPTR.
1410 Upon overflow, the return value is ULONG_MAX, and errno is set to ERANGE. */
1411# if @REPLACE_STRTOUL@
1412# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1413# define strtoul rpl_strtoul
1414# endif
1415# define GNULIB_defined_strtoul_function 1
1416_GL_FUNCDECL_RPL (strtoul, unsigned long,
1417 (const char *restrict string, char **restrict endptr,
1418 int base)
1419 _GL_ARG_NONNULL ((1)));
1420_GL_CXXALIAS_RPL (strtoul, unsigned long,
1421 (const char *restrict string, char **restrict endptr,
1422 int base));
1423# else
1424# if !@HAVE_STRTOUL@
1425_GL_FUNCDECL_SYS (strtoul, unsigned long,
1426 (const char *restrict string, char **restrict endptr,
1427 int base)
1428 _GL_ARG_NONNULL ((1)));
1429# endif
1430_GL_CXXALIAS_SYS (strtoul, unsigned long,
1431 (const char *restrict string, char **restrict endptr,
1432 int base));
1433# endif
1434_GL_CXXALIASWARN (strtoul);
1435#elif defined GNULIB_POSIXCHECK
1436# undef strtoul
1437# if HAVE_RAW_DECL_STRTOUL
1438_GL_WARN_ON_USE (strtoul, "strtoul is unportable - "
1439 "use gnulib module strtoul for portability");
1440# endif
1441#endif
1442
869#if @GNULIB_STRTOULL@ 1443#if @GNULIB_STRTOULL@
870/* Parse an unsigned integer whose textual representation starts at STRING. 1444/* 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, 1445 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
@@ -875,13 +1449,29 @@ _GL_WARN_ON_USE (strtoll, "strtoll is unportable - "
875 stored in *ENDPTR. 1449 stored in *ENDPTR.
876 Upon overflow, the return value is ULLONG_MAX, and errno is set to 1450 Upon overflow, the return value is ULLONG_MAX, and errno is set to
877 ERANGE. */ 1451 ERANGE. */
878# if !@HAVE_STRTOULL@ 1452# if @REPLACE_STRTOULL@
1453# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1454# define strtoull rpl_strtoull
1455# endif
1456# define GNULIB_defined_strtoull_function 1
1457_GL_FUNCDECL_RPL (strtoull, unsigned long long,
1458 (const char *restrict string, char **restrict endptr,
1459 int base)
1460 _GL_ARG_NONNULL ((1)));
1461_GL_CXXALIAS_RPL (strtoull, unsigned long long,
1462 (const char *restrict string, char **restrict endptr,
1463 int base));
1464# else
1465# if !@HAVE_STRTOULL@
879_GL_FUNCDECL_SYS (strtoull, unsigned long long, 1466_GL_FUNCDECL_SYS (strtoull, unsigned long long,
880 (const char *string, char **endptr, int base) 1467 (const char *restrict string, char **restrict endptr,
1468 int base)
881 _GL_ARG_NONNULL ((1))); 1469 _GL_ARG_NONNULL ((1)));
882# endif 1470# endif
883_GL_CXXALIAS_SYS (strtoull, unsigned long long, 1471_GL_CXXALIAS_SYS (strtoull, unsigned long long,
884 (const char *string, char **endptr, int base)); 1472 (const char *restrict string, char **restrict endptr,
1473 int base));
1474# endif
885_GL_CXXALIASWARN (strtoull); 1475_GL_CXXALIASWARN (strtoull);
886#elif defined GNULIB_POSIXCHECK 1476#elif defined GNULIB_POSIXCHECK
887# undef strtoull 1477# undef strtoull
@@ -945,7 +1535,9 @@ _GL_CXXALIAS_RPL (wctomb, int, (char *s, wchar_t wc));
945# else 1535# else
946_GL_CXXALIAS_SYS (wctomb, int, (char *s, wchar_t wc)); 1536_GL_CXXALIAS_SYS (wctomb, int, (char *s, wchar_t wc));
947# endif 1537# endif
1538# if __GLIBC__ >= 2
948_GL_CXXALIASWARN (wctomb); 1539_GL_CXXALIASWARN (wctomb);
1540# endif
949#endif 1541#endif
950 1542
951 1543
diff --git a/gl/str-two-way.h b/gl/str-two-way.h
index 707145d..fc2db03 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-2021 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
diff --git a/gl/strcasecmp.c b/gl/strcasecmp.c
index 0f0a742..c714270 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-2021 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..1935967 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-2021 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
diff --git a/gl/streq.h b/gl/streq.h
index 12c1867..adabd15 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-2021 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..e76d55d 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-2021 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..9cfc5ad 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-2021 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..83926df 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-2021 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
@@ -66,5 +66,6 @@ strerror (int n)
66 if (sizeof buf <= len) 66 if (sizeof buf <= len)
67 abort (); 67 abort ();
68 68
69 return memcpy (buf, msg, len + 1); 69 memcpy (buf, msg, len + 1);
70 return buf;
70} 71}
diff --git a/gl/string.in.h b/gl/string.in.h
index d7a6c9c..afe7350 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-2021 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,85 @@
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# define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (free, 1)
86#endif
87
88/* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly
89 allocated memory. */
90/* Applies to: functions. */
91#ifndef _GL_ATTRIBUTE_MALLOC
92# if __GNUC__ >= 3 || defined __clang__
93# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
94# else
95# define _GL_ATTRIBUTE_MALLOC
96# endif
97#endif
98
99/* The __attribute__ feature is available in gcc versions 2.5 and later.
100 The attribute __pure__ was added in gcc 2.96. */
101#ifndef _GL_ATTRIBUTE_PURE
102# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__
103# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
104# else
105# define _GL_ATTRIBUTE_PURE /* empty */
106# endif
107#endif
108
54/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ 109/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
55 110
56/* The definition of _GL_ARG_NONNULL is copied here. */ 111/* The definition of _GL_ARG_NONNULL is copied here. */
57 112
58/* The definition of _GL_WARN_ON_USE is copied here. */ 113/* The definition of _GL_WARN_ON_USE is copied here. */
59 114
115/* Declare 'free' if needed for _GL_ATTRIBUTE_DEALLOC_FREE. */
116_GL_EXTERN_C void free (void *);
117#if @GNULIB_FREE_POSIX@
118# if (@REPLACE_FREE@ && !defined free \
119 && !(defined __cplusplus && defined GNULIB_NAMESPACE))
120# define free rpl_free
121_GL_EXTERN_C void free (void *);
122# endif
123#endif
124
125/* Clear a block of memory. The compiler will not delete a call to
126 this function, even if the block is dead after the call. */
127#if @GNULIB_EXPLICIT_BZERO@
128# if ! @HAVE_EXPLICIT_BZERO@
129_GL_FUNCDECL_SYS (explicit_bzero, void,
130 (void *__dest, size_t __n) _GL_ARG_NONNULL ((1)));
131# endif
132_GL_CXXALIAS_SYS (explicit_bzero, void, (void *__dest, size_t __n));
133_GL_CXXALIASWARN (explicit_bzero);
134#elif defined GNULIB_POSIXCHECK
135# undef explicit_bzero
136# if HAVE_RAW_DECL_EXPLICIT_BZERO
137_GL_WARN_ON_USE (explicit_bzero, "explicit_bzero is unportable - "
138 "use gnulib module explicit_bzero for portability");
139# endif
140#endif
60 141
61/* Find the index of the least-significant set bit. */ 142/* Find the index of the least-significant set bit. */
62#if @GNULIB_FFSL@ 143#if @GNULIB_FFSL@
@@ -75,10 +156,18 @@ _GL_WARN_ON_USE (ffsl, "ffsl is not portable - use the ffsl module");
75 156
76/* Find the index of the least-significant set bit. */ 157/* Find the index of the least-significant set bit. */
77#if @GNULIB_FFSLL@ 158#if @GNULIB_FFSLL@
78# if !@HAVE_FFSLL@ 159# if @REPLACE_FFSLL@
160# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
161# define ffsll rpl_ffsll
162# endif
163_GL_FUNCDECL_RPL (ffsll, int, (long long int i));
164_GL_CXXALIAS_RPL (ffsll, int, (long long int i));
165# else
166# if !@HAVE_FFSLL@
79_GL_FUNCDECL_SYS (ffsll, int, (long long int i)); 167_GL_FUNCDECL_SYS (ffsll, int, (long long int i));
80# endif 168# endif
81_GL_CXXALIAS_SYS (ffsll, int, (long long int i)); 169_GL_CXXALIAS_SYS (ffsll, int, (long long int i));
170# endif
82_GL_CXXALIASWARN (ffsll); 171_GL_CXXALIASWARN (ffsll);
83#elif defined GNULIB_POSIXCHECK 172#elif defined GNULIB_POSIXCHECK
84# undef ffsll 173# undef ffsll
@@ -88,10 +177,30 @@ _GL_WARN_ON_USE (ffsll, "ffsll is not portable - use the ffsll module");
88#endif 177#endif
89 178
90 179
180#if @GNULIB_MDA_MEMCCPY@
181/* On native Windows, map 'memccpy' to '_memccpy', so that -loldnames is not
182 required. In C++ with GNULIB_NAMESPACE, avoid differences between
183 platforms by defining GNULIB_NAMESPACE::memccpy always. */
184# if defined _WIN32 && !defined __CYGWIN__
185# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
186# undef memccpy
187# define memccpy _memccpy
188# endif
189_GL_CXXALIAS_MDA (memccpy, void *,
190 (void *dest, const void *src, int c, size_t n));
191# else
192_GL_CXXALIAS_SYS (memccpy, void *,
193 (void *dest, const void *src, int c, size_t n));
194# endif
195_GL_CXXALIASWARN (memccpy);
196#endif
197
198
91/* Return the first instance of C within N bytes of S, or NULL. */ 199/* Return the first instance of C within N bytes of S, or NULL. */
92#if @GNULIB_MEMCHR@ 200#if @GNULIB_MEMCHR@
93# if @REPLACE_MEMCHR@ 201# if @REPLACE_MEMCHR@
94# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 202# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
203# undef memchr
95# define memchr rpl_memchr 204# define memchr rpl_memchr
96# endif 205# endif
97_GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n) 206_GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n)
@@ -99,11 +208,6 @@ _GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n)
99 _GL_ARG_NONNULL ((1))); 208 _GL_ARG_NONNULL ((1)));
100_GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n)); 209_GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n));
101# else 210# 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: 211 /* On some systems, this function is defined as an overloaded function:
108 extern "C" { const void * std::memchr (const void *, int, size_t); } 212 extern "C" { const void * std::memchr (const void *, int, size_t); }
109 extern "C++" { void * std::memchr (void *, int, size_t); } */ 213 extern "C++" { void * std::memchr (void *, int, size_t); } */
@@ -116,7 +220,7 @@ _GL_CXXALIAS_SYS_CAST2 (memchr,
116_GL_CXXALIASWARN1 (memchr, void *, (void *__s, int __c, size_t __n)); 220_GL_CXXALIASWARN1 (memchr, void *, (void *__s, int __c, size_t __n));
117_GL_CXXALIASWARN1 (memchr, void const *, 221_GL_CXXALIASWARN1 (memchr, void const *,
118 (void const *__s, int __c, size_t __n)); 222 (void const *__s, int __c, size_t __n));
119# else 223# elif __GLIBC__ >= 2
120_GL_CXXALIASWARN (memchr); 224_GL_CXXALIASWARN (memchr);
121# endif 225# endif
122#elif defined GNULIB_POSIXCHECK 226#elif defined GNULIB_POSIXCHECK
@@ -299,9 +403,11 @@ _GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - "
299 GB18030 and the character to be searched is a digit. */ 403 GB18030 and the character to be searched is a digit. */
300# undef strchr 404# undef strchr
301/* Assume strchr is always declared. */ 405/* Assume strchr is always declared. */
302_GL_WARN_ON_USE (strchr, "strchr cannot work correctly on character strings " 406_GL_WARN_ON_USE_CXX (strchr,
303 "in some multibyte locales - " 407 const char *, char *, (const char *, int),
304 "use mbschr if you care about internationalization"); 408 "strchr cannot work correctly on character strings "
409 "in some multibyte locales - "
410 "use mbschr if you care about internationalization");
305#endif 411#endif
306 412
307/* Find the first occurrence of C in S or the final NUL byte. */ 413/* Find the first occurrence of C in S or the final NUL byte. */
@@ -350,24 +456,62 @@ _GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - "
350# undef strdup 456# undef strdup
351# define strdup rpl_strdup 457# define strdup rpl_strdup
352# endif 458# endif
353_GL_FUNCDECL_RPL (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1))); 459_GL_FUNCDECL_RPL (strdup, char *,
460 (char const *__s)
461 _GL_ARG_NONNULL ((1))
462 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
354_GL_CXXALIAS_RPL (strdup, char *, (char const *__s)); 463_GL_CXXALIAS_RPL (strdup, char *, (char const *__s));
464# elif defined _WIN32 && !defined __CYGWIN__
465# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
466# undef strdup
467# define strdup _strdup
468# endif
469_GL_CXXALIAS_MDA (strdup, char *, (char const *__s));
355# else 470# else
356# if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup 471# if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
357 /* strdup exists as a function and as a macro. Get rid of the macro. */ 472 /* strdup exists as a function and as a macro. Get rid of the macro. */
358# undef strdup 473# undef strdup
359# endif 474# endif
360# if !(@HAVE_DECL_STRDUP@ || defined strdup) 475# if (!@HAVE_DECL_STRDUP@ || __GNUC__ >= 11) && !defined strdup
361_GL_FUNCDECL_SYS (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1))); 476_GL_FUNCDECL_SYS (strdup, char *,
477 (char const *__s)
478 _GL_ARG_NONNULL ((1))
479 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
362# endif 480# endif
363_GL_CXXALIAS_SYS (strdup, char *, (char const *__s)); 481_GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
364# endif 482# endif
365_GL_CXXALIASWARN (strdup); 483_GL_CXXALIASWARN (strdup);
366#elif defined GNULIB_POSIXCHECK 484#else
367# undef strdup 485# if __GNUC__ >= 11 && !defined strdup
368# if HAVE_RAW_DECL_STRDUP 486/* For -Wmismatched-dealloc: Associate strdup with free or rpl_free. */
487_GL_FUNCDECL_SYS (strdup, char *,
488 (char const *__s)
489 _GL_ARG_NONNULL ((1))
490 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
491# endif
492# if defined GNULIB_POSIXCHECK
493# undef strdup
494# if HAVE_RAW_DECL_STRDUP
369_GL_WARN_ON_USE (strdup, "strdup is unportable - " 495_GL_WARN_ON_USE (strdup, "strdup is unportable - "
370 "use gnulib module strdup for portability"); 496 "use gnulib module strdup for portability");
497# endif
498# elif @GNULIB_MDA_STRDUP@
499/* On native Windows, map 'creat' to '_creat', so that -loldnames is not
500 required. In C++ with GNULIB_NAMESPACE, avoid differences between
501 platforms by defining GNULIB_NAMESPACE::strdup always. */
502# if defined _WIN32 && !defined __CYGWIN__
503# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
504# undef strdup
505# define strdup _strdup
506# endif
507_GL_CXXALIAS_MDA (strdup, char *, (char const *__s));
508# else
509# if defined __cplusplus && defined GNULIB_NAMESPACE && defined strdup
510# undef strdup
511# endif
512_GL_CXXALIAS_SYS (strdup, char *, (char const *__s));
513# endif
514_GL_CXXALIASWARN (strdup);
371# endif 515# endif
372#endif 516#endif
373 517
@@ -378,13 +522,18 @@ _GL_WARN_ON_USE (strdup, "strdup is unportable - "
378# undef strncat 522# undef strncat
379# define strncat rpl_strncat 523# define strncat rpl_strncat
380# endif 524# endif
381_GL_FUNCDECL_RPL (strncat, char *, (char *dest, const char *src, size_t n) 525_GL_FUNCDECL_RPL (strncat, char *,
382 _GL_ARG_NONNULL ((1, 2))); 526 (char *restrict dest, const char *restrict src, size_t n)
383_GL_CXXALIAS_RPL (strncat, char *, (char *dest, const char *src, size_t n)); 527 _GL_ARG_NONNULL ((1, 2)));
528_GL_CXXALIAS_RPL (strncat, char *,
529 (char *restrict dest, const char *restrict src, size_t n));
384# else 530# else
385_GL_CXXALIAS_SYS (strncat, char *, (char *dest, const char *src, size_t n)); 531_GL_CXXALIAS_SYS (strncat, char *,
532 (char *restrict dest, const char *restrict src, size_t n));
386# endif 533# endif
534# if __GLIBC__ >= 2
387_GL_CXXALIASWARN (strncat); 535_GL_CXXALIASWARN (strncat);
536# endif
388#elif defined GNULIB_POSIXCHECK 537#elif defined GNULIB_POSIXCHECK
389# undef strncat 538# undef strncat
390# if HAVE_RAW_DECL_STRNCAT 539# if HAVE_RAW_DECL_STRNCAT
@@ -400,15 +549,15 @@ _GL_WARN_ON_USE (strncat, "strncat is unportable - "
400# undef strndup 549# undef strndup
401# define strndup rpl_strndup 550# define strndup rpl_strndup
402# endif 551# endif
403_GL_FUNCDECL_RPL (strndup, char *, (char const *__string, size_t __n) 552_GL_FUNCDECL_RPL (strndup, char *, (char const *__s, size_t __n)
404 _GL_ARG_NONNULL ((1))); 553 _GL_ARG_NONNULL ((1)));
405_GL_CXXALIAS_RPL (strndup, char *, (char const *__string, size_t __n)); 554_GL_CXXALIAS_RPL (strndup, char *, (char const *__s, size_t __n));
406# else 555# else
407# if ! @HAVE_DECL_STRNDUP@ 556# if ! @HAVE_DECL_STRNDUP@
408_GL_FUNCDECL_SYS (strndup, char *, (char const *__string, size_t __n) 557_GL_FUNCDECL_SYS (strndup, char *, (char const *__s, size_t __n)
409 _GL_ARG_NONNULL ((1))); 558 _GL_ARG_NONNULL ((1)));
410# endif 559# endif
411_GL_CXXALIAS_SYS (strndup, char *, (char const *__string, size_t __n)); 560_GL_CXXALIAS_SYS (strndup, char *, (char const *__s, size_t __n));
412# endif 561# endif
413_GL_CXXALIASWARN (strndup); 562_GL_CXXALIASWARN (strndup);
414#elif defined GNULIB_POSIXCHECK 563#elif defined GNULIB_POSIXCHECK
@@ -428,17 +577,17 @@ _GL_WARN_ON_USE (strndup, "strndup is unportable - "
428# undef strnlen 577# undef strnlen
429# define strnlen rpl_strnlen 578# define strnlen rpl_strnlen
430# endif 579# endif
431_GL_FUNCDECL_RPL (strnlen, size_t, (char const *__string, size_t __maxlen) 580_GL_FUNCDECL_RPL (strnlen, size_t, (char const *__s, size_t __maxlen)
432 _GL_ATTRIBUTE_PURE 581 _GL_ATTRIBUTE_PURE
433 _GL_ARG_NONNULL ((1))); 582 _GL_ARG_NONNULL ((1)));
434_GL_CXXALIAS_RPL (strnlen, size_t, (char const *__string, size_t __maxlen)); 583_GL_CXXALIAS_RPL (strnlen, size_t, (char const *__s, size_t __maxlen));
435# else 584# else
436# if ! @HAVE_DECL_STRNLEN@ 585# if ! @HAVE_DECL_STRNLEN@
437_GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen) 586_GL_FUNCDECL_SYS (strnlen, size_t, (char const *__s, size_t __maxlen)
438 _GL_ATTRIBUTE_PURE 587 _GL_ATTRIBUTE_PURE
439 _GL_ARG_NONNULL ((1))); 588 _GL_ARG_NONNULL ((1)));
440# endif 589# endif
441_GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)); 590_GL_CXXALIAS_SYS (strnlen, size_t, (char const *__s, size_t __maxlen));
442# endif 591# endif
443_GL_CXXALIASWARN (strnlen); 592_GL_CXXALIASWARN (strnlen);
444#elif defined GNULIB_POSIXCHECK 593#elif defined GNULIB_POSIXCHECK
@@ -479,7 +628,7 @@ _GL_CXXALIAS_SYS_CAST2 (strpbrk,
479_GL_CXXALIASWARN1 (strpbrk, char *, (char *__s, char const *__accept)); 628_GL_CXXALIASWARN1 (strpbrk, char *, (char *__s, char const *__accept));
480_GL_CXXALIASWARN1 (strpbrk, char const *, 629_GL_CXXALIASWARN1 (strpbrk, char const *,
481 (char const *__s, char const *__accept)); 630 (char const *__s, char const *__accept));
482# else 631# elif __GLIBC__ >= 2
483_GL_CXXALIASWARN (strpbrk); 632_GL_CXXALIASWARN (strpbrk);
484# endif 633# endif
485# if defined GNULIB_POSIXCHECK 634# if defined GNULIB_POSIXCHECK
@@ -488,15 +637,19 @@ _GL_CXXALIASWARN (strpbrk);
488 locale encoding is GB18030 and one of the characters to be searched is a 637 locale encoding is GB18030 and one of the characters to be searched is a
489 digit. */ 638 digit. */
490# undef strpbrk 639# undef strpbrk
491_GL_WARN_ON_USE (strpbrk, "strpbrk cannot work correctly on character strings " 640_GL_WARN_ON_USE_CXX (strpbrk,
492 "in multibyte locales - " 641 const char *, char *, (const char *, const char *),
493 "use mbspbrk if you care about internationalization"); 642 "strpbrk cannot work correctly on character strings "
643 "in multibyte locales - "
644 "use mbspbrk if you care about internationalization");
494# endif 645# endif
495#elif defined GNULIB_POSIXCHECK 646#elif defined GNULIB_POSIXCHECK
496# undef strpbrk 647# undef strpbrk
497# if HAVE_RAW_DECL_STRPBRK 648# if HAVE_RAW_DECL_STRPBRK
498_GL_WARN_ON_USE (strpbrk, "strpbrk is unportable - " 649_GL_WARN_ON_USE_CXX (strpbrk,
499 "use gnulib module strpbrk for portability"); 650 const char *, char *, (const char *, const char *),
651 "strpbrk is unportable - "
652 "use gnulib module strpbrk for portability");
500# endif 653# endif
501#endif 654#endif
502 655
@@ -515,9 +668,11 @@ _GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings "
515 GB18030 and the character to be searched is a digit. */ 668 GB18030 and the character to be searched is a digit. */
516# undef strrchr 669# undef strrchr
517/* Assume strrchr is always declared. */ 670/* Assume strrchr is always declared. */
518_GL_WARN_ON_USE (strrchr, "strrchr cannot work correctly on character strings " 671_GL_WARN_ON_USE_CXX (strrchr,
519 "in some multibyte locales - " 672 const char *, char *, (const char *, int),
520 "use mbsrchr if you care about internationalization"); 673 "strrchr cannot work correctly on character strings "
674 "in some multibyte locales - "
675 "use mbsrchr if you care about internationalization");
521#endif 676#endif
522 677
523/* Search the next delimiter (char listed in DELIM) starting at *STRINGP. 678/* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
@@ -581,7 +736,7 @@ _GL_CXXALIAS_SYS_CAST2 (strstr,
581_GL_CXXALIASWARN1 (strstr, char *, (char *haystack, const char *needle)); 736_GL_CXXALIASWARN1 (strstr, char *, (char *haystack, const char *needle));
582_GL_CXXALIASWARN1 (strstr, const char *, 737_GL_CXXALIASWARN1 (strstr, const char *,
583 (const char *haystack, const char *needle)); 738 (const char *haystack, const char *needle));
584# else 739# elif __GLIBC__ >= 2
585_GL_CXXALIASWARN (strstr); 740_GL_CXXALIASWARN (strstr);
586# endif 741# endif
587#elif defined GNULIB_POSIXCHECK 742#elif defined GNULIB_POSIXCHECK
@@ -660,7 +815,7 @@ _GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character "
660 This is a variant of strtok() that is multithread-safe. 815 This is a variant of strtok() that is multithread-safe.
661 816
662 For the POSIX documentation for this function, see: 817 For the POSIX documentation for this function, see:
663 http://www.opengroup.org/susv3xsh/strtok.html 818 https://pubs.opengroup.org/onlinepubs/9699919799/functions/strtok.html
664 819
665 Caveat: It modifies the original string. 820 Caveat: It modifies the original string.
666 Caveat: These functions cannot be used on constant strings. 821 Caveat: These functions cannot be used on constant strings.
@@ -931,7 +1086,8 @@ _GL_EXTERN_C char * mbssep (char **stringp, const char *delim)
931 Caveat: The identity of the delimiting character is lost. 1086 Caveat: The identity of the delimiting character is lost.
932 1087
933 See also mbssep(). */ 1088 See also mbssep(). */
934_GL_EXTERN_C char * mbstok_r (char *string, const char *delim, char **save_ptr) 1089_GL_EXTERN_C char * mbstok_r (char *restrict string, const char *delim,
1090 char **save_ptr)
935 _GL_ARG_NONNULL ((2, 3)); 1091 _GL_ARG_NONNULL ((2, 3));
936#endif 1092#endif
937 1093
@@ -947,7 +1103,9 @@ _GL_CXXALIAS_RPL (strerror, char *, (int));
947# else 1103# else
948_GL_CXXALIAS_SYS (strerror, char *, (int)); 1104_GL_CXXALIAS_SYS (strerror, char *, (int));
949# endif 1105# endif
1106# if __GLIBC__ >= 2
950_GL_CXXALIASWARN (strerror); 1107_GL_CXXALIASWARN (strerror);
1108# endif
951#elif defined GNULIB_POSIXCHECK 1109#elif defined GNULIB_POSIXCHECK
952# undef strerror 1110# undef strerror
953/* Assume strerror is always declared. */ 1111/* Assume strerror is always declared. */
@@ -984,6 +1142,60 @@ _GL_WARN_ON_USE (strerror_r, "strerror_r is unportable - "
984# endif 1142# endif
985#endif 1143#endif
986 1144
1145/* Return the name of the system error code ERRNUM. */
1146#if @GNULIB_STRERRORNAME_NP@
1147# if @REPLACE_STRERRORNAME_NP@
1148# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1149# undef strerrorname_np
1150# define strerrorname_np rpl_strerrorname_np
1151# endif
1152_GL_FUNCDECL_RPL (strerrorname_np, const char *, (int errnum));
1153_GL_CXXALIAS_RPL (strerrorname_np, const char *, (int errnum));
1154# else
1155# if !@HAVE_STRERRORNAME_NP@
1156_GL_FUNCDECL_SYS (strerrorname_np, const char *, (int errnum));
1157# endif
1158_GL_CXXALIAS_SYS (strerrorname_np, const char *, (int errnum));
1159# endif
1160_GL_CXXALIASWARN (strerrorname_np);
1161#elif defined GNULIB_POSIXCHECK
1162# undef strerrorname_np
1163# if HAVE_RAW_DECL_STRERRORNAME_NP
1164_GL_WARN_ON_USE (strerrorname_np, "strerrorname_np is unportable - "
1165 "use gnulib module strerrorname_np for portability");
1166# endif
1167#endif
1168
1169/* Return an abbreviation string for the signal number SIG. */
1170#if @GNULIB_SIGABBREV_NP@
1171# if ! @HAVE_SIGABBREV_NP@
1172_GL_FUNCDECL_SYS (sigabbrev_np, const char *, (int sig));
1173# endif
1174_GL_CXXALIAS_SYS (sigabbrev_np, const char *, (int sig));
1175_GL_CXXALIASWARN (sigabbrev_np);
1176#elif defined GNULIB_POSIXCHECK
1177# undef sigabbrev_np
1178# if HAVE_RAW_DECL_SIGABBREV_NP
1179_GL_WARN_ON_USE (sigabbrev_np, "sigabbrev_np is unportable - "
1180 "use gnulib module sigabbrev_np for portability");
1181# endif
1182#endif
1183
1184/* Return an English description string for the signal number SIG. */
1185#if @GNULIB_SIGDESCR_NP@
1186# if ! @HAVE_SIGDESCR_NP@
1187_GL_FUNCDECL_SYS (sigdescr_np, const char *, (int sig));
1188# endif
1189_GL_CXXALIAS_SYS (sigdescr_np, const char *, (int sig));
1190_GL_CXXALIASWARN (sigdescr_np);
1191#elif defined GNULIB_POSIXCHECK
1192# undef sigdescr_np
1193# if HAVE_RAW_DECL_SIGDESCR_NP
1194_GL_WARN_ON_USE (sigdescr_np, "sigdescr_np is unportable - "
1195 "use gnulib module sigdescr_np for portability");
1196# endif
1197#endif
1198
987#if @GNULIB_STRSIGNAL@ 1199#if @GNULIB_STRSIGNAL@
988# if @REPLACE_STRSIGNAL@ 1200# if @REPLACE_STRSIGNAL@
989# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1201# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -1027,3 +1239,4 @@ _GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - "
1027 1239
1028#endif /* _@GUARD_PREFIX@_STRING_H */ 1240#endif /* _@GUARD_PREFIX@_STRING_H */
1029#endif /* _@GUARD_PREFIX@_STRING_H */ 1241#endif /* _@GUARD_PREFIX@_STRING_H */
1242#endif
diff --git a/gl/strings.in.h b/gl/strings.in.h
index 4469f86..07aed18 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-2021 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..99bfbe6 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-2021 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..ccc0170 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-2021 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..3bd89f4 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-2021 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..2f62ce4 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-2021 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
@@ -26,10 +26,6 @@
26 26
27#include <stdbool.h> 27#include <stdbool.h>
28 28
29#ifndef _LIBC
30# define __builtin_expect(expr, val) (expr)
31#endif
32
33#define RETURN_TYPE char * 29#define RETURN_TYPE char *
34#define AVAILABLE(h, h_l, j, n_l) \ 30#define AVAILABLE(h, h_l, j, n_l) \
35 (!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \ 31 (!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..2d9784d
--- /dev/null
+++ b/gl/sys-limits.h
@@ -0,0 +1,42 @@
1/* System call limits
2
3 Copyright 2018-2021 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..d90b32c 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-2021 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..0a2c57d 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-2021 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
@@ -133,6 +141,15 @@ struct sockaddr_storage
133# define SHUT_RDWR 2 141# define SHUT_RDWR 2
134# endif 142# endif
135 143
144# ifdef __VMS /* OpenVMS */
145# ifndef CMSG_SPACE
146# define CMSG_SPACE(length) _CMSG_SPACE(length)
147# endif
148# ifndef CMSG_LEN
149# define CMSG_LEN(length) _CMSG_LEN(length)
150# endif
151# endif
152
136#else 153#else
137 154
138# ifdef __CYGWIN__ 155# ifdef __CYGWIN__
@@ -152,7 +169,7 @@ struct sockaddr_storage
152 code may not run on older Windows releases then. My Windows 2000 169 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 170 box was not able to run the code, for example. The situation is
154 slightly confusing because 171 slightly confusing because
155 <http://msdn.microsoft.com/en-us/library/ms738520> 172 <https://docs.microsoft.com/en-us/windows/desktop/api/ws2tcpip/nf-ws2tcpip-getaddrinfo>
156 suggests that getaddrinfo should be available on all Windows 173 suggests that getaddrinfo should be available on all Windows
157 releases. */ 174 releases. */
158 175
@@ -178,12 +195,7 @@ struct sockaddr_storage
178/* Include headers needed by the emulation code. */ 195/* Include headers needed by the emulation code. */
179# include <sys/types.h> 196# include <sys/types.h>
180# include <io.h> 197# include <io.h>
181 198/* 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 199# endif
188 200
189/* Rudimentary 'struct msghdr'; this works as long as you don't try to 201/* Rudimentary 'struct msghdr'; this works as long as you don't try to
@@ -198,6 +210,15 @@ struct msghdr {
198 210
199#endif 211#endif
200 212
213/* Ensure SO_REUSEPORT is defined. */
214/* For the subtle differences between SO_REUSEPORT and SO_REUSEADDR, see
215 https://stackoverflow.com/questions/14388706/socket-options-so-reuseaddr-and-so-reuseport-how-do-they-differ-do-they-mean-t
216 and https://lwn.net/Articles/542629/
217 */
218#ifndef SO_REUSEPORT
219# define SO_REUSEPORT SO_REUSEADDR
220#endif
221
201/* Fix some definitions from <winsock2.h>. */ 222/* Fix some definitions from <winsock2.h>. */
202 223
203#if @HAVE_WINSOCK2_H@ 224#if @HAVE_WINSOCK2_H@
@@ -235,7 +256,7 @@ rpl_fd_isset (SOCKET fd, fd_set * set)
235# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 256# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
236# undef close 257# undef close
237# define close close_used_without_including_unistd_h 258# define close close_used_without_including_unistd_h
238# else 259# elif !defined __clang__
239 _GL_WARN_ON_USE (close, 260 _GL_WARN_ON_USE (close,
240 "close() used without including <unistd.h>"); 261 "close() used without including <unistd.h>");
241# endif 262# endif
@@ -320,14 +341,20 @@ _GL_WARN_ON_USE (connect, "connect is not always POSIX compliant - "
320# define accept rpl_accept 341# define accept rpl_accept
321# endif 342# endif
322_GL_FUNCDECL_RPL (accept, int, 343_GL_FUNCDECL_RPL (accept, int,
323 (int fd, struct sockaddr *addr, socklen_t *addrlen)); 344 (int fd,
345 struct sockaddr *restrict addr,
346 socklen_t *restrict addrlen));
324_GL_CXXALIAS_RPL (accept, int, 347_GL_CXXALIAS_RPL (accept, int,
325 (int fd, struct sockaddr *addr, socklen_t *addrlen)); 348 (int fd,
349 struct sockaddr *restrict addr,
350 socklen_t *restrict addrlen));
326# else 351# else
327/* Need to cast, because on Solaris 10 systems, the third parameter is 352/* Need to cast, because on Solaris 10 systems, the third parameter is
328 void *addrlen. */ 353 void *addrlen. */
329_GL_CXXALIAS_SYS_CAST (accept, int, 354_GL_CXXALIAS_SYS_CAST (accept, int,
330 (int fd, struct sockaddr *addr, socklen_t *addrlen)); 355 (int fd,
356 struct sockaddr *restrict addr,
357 socklen_t *restrict addrlen));
331# endif 358# endif
332_GL_CXXALIASWARN (accept); 359_GL_CXXALIASWARN (accept);
333#elif @HAVE_WINSOCK2_H@ 360#elif @HAVE_WINSOCK2_H@
@@ -378,15 +405,18 @@ _GL_WARN_ON_USE (bind, "bind is not always POSIX compliant - "
378# define getpeername rpl_getpeername 405# define getpeername rpl_getpeername
379# endif 406# endif
380_GL_FUNCDECL_RPL (getpeername, int, 407_GL_FUNCDECL_RPL (getpeername, int,
381 (int fd, struct sockaddr *addr, socklen_t *addrlen) 408 (int fd, struct sockaddr *restrict addr,
409 socklen_t *restrict addrlen)
382 _GL_ARG_NONNULL ((2, 3))); 410 _GL_ARG_NONNULL ((2, 3)));
383_GL_CXXALIAS_RPL (getpeername, int, 411_GL_CXXALIAS_RPL (getpeername, int,
384 (int fd, struct sockaddr *addr, socklen_t *addrlen)); 412 (int fd, struct sockaddr *restrict addr,
413 socklen_t *restrict addrlen));
385# else 414# else
386/* Need to cast, because on Solaris 10 systems, the third parameter is 415/* Need to cast, because on Solaris 10 systems, the third parameter is
387 void *addrlen. */ 416 void *addrlen. */
388_GL_CXXALIAS_SYS_CAST (getpeername, int, 417_GL_CXXALIAS_SYS_CAST (getpeername, int,
389 (int fd, struct sockaddr *addr, socklen_t *addrlen)); 418 (int fd, struct sockaddr *restrict addr,
419 socklen_t *restrict addrlen));
390# endif 420# endif
391_GL_CXXALIASWARN (getpeername); 421_GL_CXXALIASWARN (getpeername);
392#elif @HAVE_WINSOCK2_H@ 422#elif @HAVE_WINSOCK2_H@
@@ -407,15 +437,18 @@ _GL_WARN_ON_USE (getpeername, "getpeername is not always POSIX compliant - "
407# define getsockname rpl_getsockname 437# define getsockname rpl_getsockname
408# endif 438# endif
409_GL_FUNCDECL_RPL (getsockname, int, 439_GL_FUNCDECL_RPL (getsockname, int,
410 (int fd, struct sockaddr *addr, socklen_t *addrlen) 440 (int fd, struct sockaddr *restrict addr,
441 socklen_t *restrict addrlen)
411 _GL_ARG_NONNULL ((2, 3))); 442 _GL_ARG_NONNULL ((2, 3)));
412_GL_CXXALIAS_RPL (getsockname, int, 443_GL_CXXALIAS_RPL (getsockname, int,
413 (int fd, struct sockaddr *addr, socklen_t *addrlen)); 444 (int fd, struct sockaddr *restrict addr,
445 socklen_t *restrict addrlen));
414# else 446# else
415/* Need to cast, because on Solaris 10 systems, the third parameter is 447/* Need to cast, because on Solaris 10 systems, the third parameter is
416 void *addrlen. */ 448 void *addrlen. */
417_GL_CXXALIAS_SYS_CAST (getsockname, int, 449_GL_CXXALIAS_SYS_CAST (getsockname, int,
418 (int fd, struct sockaddr *addr, socklen_t *addrlen)); 450 (int fd, struct sockaddr *restrict addr,
451 socklen_t *restrict addrlen));
419# endif 452# endif
420_GL_CXXALIASWARN (getsockname); 453_GL_CXXALIASWARN (getsockname);
421#elif @HAVE_WINSOCK2_H@ 454#elif @HAVE_WINSOCK2_H@
@@ -435,16 +468,19 @@ _GL_WARN_ON_USE (getsockname, "getsockname is not always POSIX compliant - "
435# undef getsockopt 468# undef getsockopt
436# define getsockopt rpl_getsockopt 469# define getsockopt rpl_getsockopt
437# endif 470# endif
438_GL_FUNCDECL_RPL (getsockopt, int, (int fd, int level, int optname, 471_GL_FUNCDECL_RPL (getsockopt, int,
439 void *optval, socklen_t *optlen) 472 (int fd, int level, int optname,
440 _GL_ARG_NONNULL ((4, 5))); 473 void *restrict optval, socklen_t *restrict optlen)
441_GL_CXXALIAS_RPL (getsockopt, int, (int fd, int level, int optname, 474 _GL_ARG_NONNULL ((4, 5)));
442 void *optval, socklen_t *optlen)); 475_GL_CXXALIAS_RPL (getsockopt, int,
476 (int fd, int level, int optname,
477 void *restrict optval, socklen_t *restrict optlen));
443# else 478# else
444/* Need to cast, because on Solaris 10 systems, the fifth parameter is 479/* Need to cast, because on Solaris 10 systems, the fifth parameter is
445 void *optlen. */ 480 void *optlen. */
446_GL_CXXALIAS_SYS_CAST (getsockopt, int, (int fd, int level, int optname, 481_GL_CXXALIAS_SYS_CAST (getsockopt, int,
447 void *optval, socklen_t *optlen)); 482 (int fd, int level, int optname,
483 void *restrict optval, socklen_t *restrict optlen));
448# endif 484# endif
449_GL_CXXALIASWARN (getsockopt); 485_GL_CXXALIASWARN (getsockopt);
450#elif @HAVE_WINSOCK2_H@ 486#elif @HAVE_WINSOCK2_H@
@@ -491,7 +527,10 @@ _GL_FUNCDECL_RPL (recv, ssize_t, (int fd, void *buf, size_t len, int flags)
491 _GL_ARG_NONNULL ((2))); 527 _GL_ARG_NONNULL ((2)));
492_GL_CXXALIAS_RPL (recv, ssize_t, (int fd, void *buf, size_t len, int flags)); 528_GL_CXXALIAS_RPL (recv, ssize_t, (int fd, void *buf, size_t len, int flags));
493# else 529# else
494_GL_CXXALIAS_SYS (recv, ssize_t, (int fd, void *buf, size_t len, int flags)); 530/* Need to cast, because on HP-UX 11.31 the return type may be
531 int,
532 depending on compiler options. */
533_GL_CXXALIAS_SYS_CAST (recv, ssize_t, (int fd, void *buf, size_t len, int flags));
495# endif 534# endif
496_GL_CXXALIASWARN (recv); 535_GL_CXXALIASWARN (recv);
497#elif @HAVE_WINSOCK2_H@ 536#elif @HAVE_WINSOCK2_H@
@@ -517,8 +556,11 @@ _GL_FUNCDECL_RPL (send, ssize_t,
517_GL_CXXALIAS_RPL (send, ssize_t, 556_GL_CXXALIAS_RPL (send, ssize_t,
518 (int fd, const void *buf, size_t len, int flags)); 557 (int fd, const void *buf, size_t len, int flags));
519# else 558# else
520_GL_CXXALIAS_SYS (send, ssize_t, 559/* 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)); 560 int,
561 depending on compiler options. */
562_GL_CXXALIAS_SYS_CAST (send, ssize_t,
563 (int fd, const void *buf, size_t len, int flags));
522# endif 564# endif
523_GL_CXXALIASWARN (send); 565_GL_CXXALIASWARN (send);
524#elif @HAVE_WINSOCK2_H@ 566#elif @HAVE_WINSOCK2_H@
@@ -539,18 +581,21 @@ _GL_WARN_ON_USE (send, "send is not always POSIX compliant - "
539# define recvfrom rpl_recvfrom 581# define recvfrom rpl_recvfrom
540# endif 582# endif
541_GL_FUNCDECL_RPL (recvfrom, ssize_t, 583_GL_FUNCDECL_RPL (recvfrom, ssize_t,
542 (int fd, void *buf, size_t len, int flags, 584 (int fd, void *restrict buf, size_t len, int flags,
543 struct sockaddr *from, socklen_t *fromlen) 585 struct sockaddr *restrict from,
586 socklen_t *restrict fromlen)
544 _GL_ARG_NONNULL ((2))); 587 _GL_ARG_NONNULL ((2)));
545_GL_CXXALIAS_RPL (recvfrom, ssize_t, 588_GL_CXXALIAS_RPL (recvfrom, ssize_t,
546 (int fd, void *buf, size_t len, int flags, 589 (int fd, void *restrict buf, size_t len, int flags,
547 struct sockaddr *from, socklen_t *fromlen)); 590 struct sockaddr *restrict from,
591 socklen_t *restrict fromlen));
548# else 592# else
549/* Need to cast, because on Solaris 10 systems, the sixth parameter is 593/* Need to cast, because on Solaris 10 systems, the sixth parameter is
550 void *fromlen. */ 594 void *fromlen. */
551_GL_CXXALIAS_SYS_CAST (recvfrom, ssize_t, 595_GL_CXXALIAS_SYS_CAST (recvfrom, ssize_t,
552 (int fd, void *buf, size_t len, int flags, 596 (int fd, void *restrict buf, size_t len, int flags,
553 struct sockaddr *from, socklen_t *fromlen)); 597 struct sockaddr *restrict from,
598 socklen_t *restrict fromlen));
554# endif 599# endif
555_GL_CXXALIASWARN (recvfrom); 600_GL_CXXALIASWARN (recvfrom);
556#elif @HAVE_WINSOCK2_H@ 601#elif @HAVE_WINSOCK2_H@
@@ -654,7 +699,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>) 699 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
655 and O_TEXT, O_BINARY (defined in "binary-io.h"). 700 and O_TEXT, O_BINARY (defined in "binary-io.h").
656 See also the Linux man page at 701 See also the Linux man page at
657 <http://www.kernel.org/doc/man-pages/online/pages/man2/accept4.2.html>. */ 702 <https://www.kernel.org/doc/man-pages/online/pages/man2/accept4.2.html>. */
658# if @HAVE_ACCEPT4@ 703# if @HAVE_ACCEPT4@
659# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 704# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
660# define accept4 rpl_accept4 705# define accept4 rpl_accept4
diff --git a/gl/sys_stat.in.h b/gl/sys_stat.in.h
new file mode 100644
index 0000000..babe3db
--- /dev/null
+++ b/gl/sys_stat.in.h
@@ -0,0 +1,928 @@
1/* Provide a more complete sys/stat.h header file.
2 Copyright (C) 2005-2021 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_MDA_CHMOD@
395/* On native Windows, map 'chmod' to '_chmod', so that -loldnames is not
396 required. In C++ with GNULIB_NAMESPACE, avoid differences between
397 platforms by defining GNULIB_NAMESPACE::chmod always. */
398# if defined _WIN32 && !defined __CYGWIN__
399# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
400# undef chmod
401# define chmod _chmod
402# endif
403/* Need to cast, because in mingw the last argument is 'int mode'. */
404_GL_CXXALIAS_MDA_CAST (chmod, int, (const char *filename, mode_t mode));
405# else
406_GL_CXXALIAS_SYS (chmod, int, (const char *filename, mode_t mode));
407# endif
408_GL_CXXALIASWARN (chmod);
409#endif
410
411
412#if @GNULIB_FCHMODAT@
413# if @REPLACE_FCHMODAT@
414# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
415# undef fchmodat
416# define fchmodat rpl_fchmodat
417# endif
418_GL_FUNCDECL_RPL (fchmodat, int,
419 (int fd, char const *file, mode_t mode, int flag)
420 _GL_ARG_NONNULL ((2)));
421_GL_CXXALIAS_RPL (fchmodat, int,
422 (int fd, char const *file, mode_t mode, int flag));
423# else
424# if !@HAVE_FCHMODAT@
425_GL_FUNCDECL_SYS (fchmodat, int,
426 (int fd, char const *file, mode_t mode, int flag)
427 _GL_ARG_NONNULL ((2)));
428# endif
429_GL_CXXALIAS_SYS (fchmodat, int,
430 (int fd, char const *file, mode_t mode, int flag));
431# endif
432_GL_CXXALIASWARN (fchmodat);
433#elif defined GNULIB_POSIXCHECK
434# undef fchmodat
435# if HAVE_RAW_DECL_FCHMODAT
436_GL_WARN_ON_USE (fchmodat, "fchmodat is not portable - "
437 "use gnulib module openat for portability");
438# endif
439#endif
440
441
442#if @GNULIB_FSTAT@
443# if @REPLACE_FSTAT@
444# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
445# undef fstat
446# define fstat rpl_fstat
447# endif
448_GL_FUNCDECL_RPL (fstat, int, (int fd, struct stat *buf) _GL_ARG_NONNULL ((2)));
449_GL_CXXALIAS_RPL (fstat, int, (int fd, struct stat *buf));
450# else
451_GL_CXXALIAS_SYS (fstat, int, (int fd, struct stat *buf));
452# endif
453# if __GLIBC__ >= 2
454_GL_CXXALIASWARN (fstat);
455# endif
456#elif @GNULIB_OVERRIDES_STRUCT_STAT@
457# undef fstat
458# define fstat fstat_used_without_requesting_gnulib_module_fstat
459#elif @WINDOWS_64_BIT_ST_SIZE@
460/* Above, we define stat to _stati64. */
461# define fstat _fstati64
462#elif defined GNULIB_POSIXCHECK
463# undef fstat
464# if HAVE_RAW_DECL_FSTAT
465_GL_WARN_ON_USE (fstat, "fstat has portability problems - "
466 "use gnulib module fstat for portability");
467# endif
468#endif
469
470
471#if @GNULIB_FSTATAT@
472# if @REPLACE_FSTATAT@
473# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
474# undef fstatat
475# define fstatat rpl_fstatat
476# endif
477_GL_FUNCDECL_RPL (fstatat, int,
478 (int fd, char const *restrict name, struct stat *restrict st,
479 int flags)
480 _GL_ARG_NONNULL ((2, 3)));
481_GL_CXXALIAS_RPL (fstatat, int,
482 (int fd, char const *restrict name, struct stat *restrict st,
483 int flags));
484# else
485# if !@HAVE_FSTATAT@
486_GL_FUNCDECL_SYS (fstatat, int,
487 (int fd, char const *restrict name, struct stat *restrict st,
488 int flags)
489 _GL_ARG_NONNULL ((2, 3)));
490# endif
491_GL_CXXALIAS_SYS (fstatat, int,
492 (int fd, char const *restrict name, struct stat *restrict st,
493 int flags));
494# endif
495_GL_CXXALIASWARN (fstatat);
496#elif @GNULIB_OVERRIDES_STRUCT_STAT@
497# undef fstatat
498# define fstatat fstatat_used_without_requesting_gnulib_module_fstatat
499#elif defined GNULIB_POSIXCHECK
500# undef fstatat
501# if HAVE_RAW_DECL_FSTATAT
502_GL_WARN_ON_USE (fstatat, "fstatat is not portable - "
503 "use gnulib module openat for portability");
504# endif
505#endif
506
507
508#if @GNULIB_FUTIMENS@
509/* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our futimens
510 implementation relies on futimesat, which on Solaris 10 makes an invocation
511 to futimens that is meant to invoke the libc's futimens(), not gnulib's
512 futimens(). */
513# if @REPLACE_FUTIMENS@ || (!@HAVE_FUTIMENS@ && defined __sun)
514# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
515# undef futimens
516# define futimens rpl_futimens
517# endif
518_GL_FUNCDECL_RPL (futimens, int, (int fd, struct timespec const times[2]));
519_GL_CXXALIAS_RPL (futimens, int, (int fd, struct timespec const times[2]));
520# else
521# if !@HAVE_FUTIMENS@
522_GL_FUNCDECL_SYS (futimens, int, (int fd, struct timespec const times[2]));
523# endif
524_GL_CXXALIAS_SYS (futimens, int, (int fd, struct timespec const times[2]));
525# endif
526# if @HAVE_FUTIMENS@
527_GL_CXXALIASWARN (futimens);
528# endif
529#elif defined GNULIB_POSIXCHECK
530# undef futimens
531# if HAVE_RAW_DECL_FUTIMENS
532_GL_WARN_ON_USE (futimens, "futimens is not portable - "
533 "use gnulib module futimens for portability");
534# endif
535#endif
536
537
538#if @GNULIB_GETUMASK@
539# if !@HAVE_GETUMASK@
540_GL_FUNCDECL_SYS (getumask, mode_t, (void));
541# endif
542_GL_CXXALIAS_SYS (getumask, mode_t, (void));
543# if @HAVE_GETUMASK@
544_GL_CXXALIASWARN (getumask);
545# endif
546#elif defined GNULIB_POSIXCHECK
547# undef getumask
548# if HAVE_RAW_DECL_GETUMASK
549_GL_WARN_ON_USE (getumask, "getumask is not portable - "
550 "use gnulib module getumask for portability");
551# endif
552#endif
553
554
555#if @GNULIB_LCHMOD@
556/* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
557 denotes a symbolic link. */
558# if !@HAVE_LCHMOD@ || defined __hpux
559_GL_FUNCDECL_SYS (lchmod, int, (const char *filename, mode_t mode)
560 _GL_ARG_NONNULL ((1)));
561# endif
562_GL_CXXALIAS_SYS (lchmod, int, (const char *filename, mode_t mode));
563_GL_CXXALIASWARN (lchmod);
564#elif defined GNULIB_POSIXCHECK
565# undef lchmod
566# if HAVE_RAW_DECL_LCHMOD
567_GL_WARN_ON_USE (lchmod, "lchmod is unportable - "
568 "use gnulib module lchmod for portability");
569# endif
570#endif
571
572
573#if @GNULIB_LSTAT@
574# if ! @HAVE_LSTAT@
575/* mingw does not support symlinks, therefore it does not have lstat. But
576 without links, stat does just fine. */
577# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
578# define lstat stat
579# endif
580_GL_CXXALIAS_RPL_1 (lstat, stat, int,
581 (const char *restrict name, struct stat *restrict buf));
582# elif @REPLACE_LSTAT@
583# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
584# undef lstat
585# define lstat rpl_lstat
586# endif
587_GL_FUNCDECL_RPL (lstat, int,
588 (const char *restrict name, struct stat *restrict buf)
589 _GL_ARG_NONNULL ((1, 2)));
590_GL_CXXALIAS_RPL (lstat, int,
591 (const char *restrict name, struct stat *restrict buf));
592# else
593_GL_CXXALIAS_SYS (lstat, int,
594 (const char *restrict name, struct stat *restrict buf));
595# endif
596# if @HAVE_LSTAT@
597_GL_CXXALIASWARN (lstat);
598# endif
599#elif @GNULIB_OVERRIDES_STRUCT_STAT@
600# undef lstat
601# define lstat lstat_used_without_requesting_gnulib_module_lstat
602#elif defined GNULIB_POSIXCHECK
603# undef lstat
604# if HAVE_RAW_DECL_LSTAT
605_GL_WARN_ON_USE (lstat, "lstat is unportable - "
606 "use gnulib module lstat for portability");
607# endif
608#endif
609
610
611#if @GNULIB_MKDIR@
612# if @REPLACE_MKDIR@
613# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
614# undef mkdir
615# define mkdir rpl_mkdir
616# endif
617_GL_FUNCDECL_RPL (mkdir, int, (char const *name, mode_t mode)
618 _GL_ARG_NONNULL ((1)));
619_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
620# elif defined _WIN32 && !defined __CYGWIN__
621/* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
622 Additionally, it declares _mkdir (and depending on compile flags, an
623 alias mkdir), only in the nonstandard includes <direct.h> and <io.h>,
624 which are included above. */
625# if !GNULIB_defined_rpl_mkdir
626static int
627rpl_mkdir (char const *name, mode_t mode)
628{
629 return _mkdir (name);
630}
631# define GNULIB_defined_rpl_mkdir 1
632# endif
633# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
634# undef mkdir
635# define mkdir rpl_mkdir
636# endif
637_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
638# else
639_GL_CXXALIAS_SYS (mkdir, int, (char const *name, mode_t mode));
640# endif
641_GL_CXXALIASWARN (mkdir);
642#elif defined GNULIB_POSIXCHECK
643# undef mkdir
644# if HAVE_RAW_DECL_MKDIR
645_GL_WARN_ON_USE (mkdir, "mkdir does not always support two parameters - "
646 "use gnulib module mkdir for portability");
647# endif
648#elif @GNULIB_MDA_MKDIR@
649/* On native Windows, map 'mkdir' to '_mkdir', so that -loldnames is not
650 required. In C++ with GNULIB_NAMESPACE, avoid differences between
651 platforms by defining GNULIB_NAMESPACE::mkdir always. */
652# if defined _WIN32 && !defined __CYGWIN__
653# if !GNULIB_defined_rpl_mkdir
654static int
655rpl_mkdir (char const *name, mode_t mode)
656{
657 return _mkdir (name);
658}
659# define GNULIB_defined_rpl_mkdir 1
660# endif
661# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
662# undef mkdir
663# define mkdir rpl_mkdir
664# endif
665_GL_CXXALIAS_RPL (mkdir, int, (char const *name, mode_t mode));
666# else
667_GL_CXXALIAS_SYS (mkdir, int, (char const *name, mode_t mode));
668# endif
669_GL_CXXALIASWARN (mkdir);
670#endif
671
672
673#if @GNULIB_MKDIRAT@
674# if !@HAVE_MKDIRAT@
675_GL_FUNCDECL_SYS (mkdirat, int, (int fd, char const *file, mode_t mode)
676 _GL_ARG_NONNULL ((2)));
677# endif
678_GL_CXXALIAS_SYS (mkdirat, int, (int fd, char const *file, mode_t mode));
679_GL_CXXALIASWARN (mkdirat);
680#elif defined GNULIB_POSIXCHECK
681# undef mkdirat
682# if HAVE_RAW_DECL_MKDIRAT
683_GL_WARN_ON_USE (mkdirat, "mkdirat is not portable - "
684 "use gnulib module openat for portability");
685# endif
686#endif
687
688
689#if @GNULIB_MKFIFO@
690# if @REPLACE_MKFIFO@
691# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
692# undef mkfifo
693# define mkfifo rpl_mkfifo
694# endif
695_GL_FUNCDECL_RPL (mkfifo, int, (char const *file, mode_t mode)
696 _GL_ARG_NONNULL ((1)));
697_GL_CXXALIAS_RPL (mkfifo, int, (char const *file, mode_t mode));
698# else
699# if !@HAVE_MKFIFO@
700_GL_FUNCDECL_SYS (mkfifo, int, (char const *file, mode_t mode)
701 _GL_ARG_NONNULL ((1)));
702# endif
703_GL_CXXALIAS_SYS (mkfifo, int, (char const *file, mode_t mode));
704# endif
705_GL_CXXALIASWARN (mkfifo);
706#elif defined GNULIB_POSIXCHECK
707# undef mkfifo
708# if HAVE_RAW_DECL_MKFIFO
709_GL_WARN_ON_USE (mkfifo, "mkfifo is not portable - "
710 "use gnulib module mkfifo for portability");
711# endif
712#endif
713
714
715#if @GNULIB_MKFIFOAT@
716# if @REPLACE_MKFIFOAT@
717# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
718# undef mkfifoat
719# define mkfifoat rpl_mkfifoat
720# endif
721_GL_FUNCDECL_RPL (mkfifoat, int, (int fd, char const *file, mode_t mode)
722 _GL_ARG_NONNULL ((2)));
723_GL_CXXALIAS_RPL (mkfifoat, int, (int fd, char const *file, mode_t mode));
724# else
725# if !@HAVE_MKFIFOAT@
726_GL_FUNCDECL_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode)
727 _GL_ARG_NONNULL ((2)));
728# endif
729_GL_CXXALIAS_SYS (mkfifoat, int, (int fd, char const *file, mode_t mode));
730# endif
731_GL_CXXALIASWARN (mkfifoat);
732#elif defined GNULIB_POSIXCHECK
733# undef mkfifoat
734# if HAVE_RAW_DECL_MKFIFOAT
735_GL_WARN_ON_USE (mkfifoat, "mkfifoat is not portable - "
736 "use gnulib module mkfifoat for portability");
737# endif
738#endif
739
740
741#if @GNULIB_MKNOD@
742# if @REPLACE_MKNOD@
743# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
744# undef mknod
745# define mknod rpl_mknod
746# endif
747_GL_FUNCDECL_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev)
748 _GL_ARG_NONNULL ((1)));
749_GL_CXXALIAS_RPL (mknod, int, (char const *file, mode_t mode, dev_t dev));
750# else
751# if !@HAVE_MKNOD@
752_GL_FUNCDECL_SYS (mknod, int, (char const *file, mode_t mode, dev_t dev)
753 _GL_ARG_NONNULL ((1)));
754# endif
755/* Need to cast, because on OSF/1 5.1, the third parameter is '...'. */
756_GL_CXXALIAS_SYS_CAST (mknod, int, (char const *file, mode_t mode, dev_t dev));
757# endif
758_GL_CXXALIASWARN (mknod);
759#elif defined GNULIB_POSIXCHECK
760# undef mknod
761# if HAVE_RAW_DECL_MKNOD
762_GL_WARN_ON_USE (mknod, "mknod is not portable - "
763 "use gnulib module mknod for portability");
764# endif
765#endif
766
767
768#if @GNULIB_MKNODAT@
769# if @REPLACE_MKNODAT@
770# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
771# undef mknodat
772# define mknodat rpl_mknodat
773# endif
774_GL_FUNCDECL_RPL (mknodat, int,
775 (int fd, char const *file, mode_t mode, dev_t dev)
776 _GL_ARG_NONNULL ((2)));
777_GL_CXXALIAS_RPL (mknodat, int,
778 (int fd, char const *file, mode_t mode, dev_t dev));
779# else
780# if !@HAVE_MKNODAT@
781_GL_FUNCDECL_SYS (mknodat, int,
782 (int fd, char const *file, mode_t mode, dev_t dev)
783 _GL_ARG_NONNULL ((2)));
784# endif
785_GL_CXXALIAS_SYS (mknodat, int,
786 (int fd, char const *file, mode_t mode, dev_t dev));
787# endif
788_GL_CXXALIASWARN (mknodat);
789#elif defined GNULIB_POSIXCHECK
790# undef mknodat
791# if HAVE_RAW_DECL_MKNODAT
792_GL_WARN_ON_USE (mknodat, "mknodat is not portable - "
793 "use gnulib module mkfifoat for portability");
794# endif
795#endif
796
797
798#if @GNULIB_STAT@
799# if @REPLACE_STAT@
800# if !@GNULIB_OVERRIDES_STRUCT_STAT@
801 /* We can't use the object-like #define stat rpl_stat, because of
802 struct stat. This means that rpl_stat will not be used if the user
803 does (stat)(a,b). Oh well. */
804# if defined _AIX && defined stat && defined _LARGE_FILES
805 /* With _LARGE_FILES defined, AIX (only) defines stat to stat64,
806 so we have to replace stat64() instead of stat(). */
807# undef stat64
808# define stat64(name, st) rpl_stat (name, st)
809# elif @WINDOWS_64_BIT_ST_SIZE@
810 /* Above, we define stat to _stati64. */
811# if defined __MINGW32__ && defined _stati64
812# ifndef _USE_32BIT_TIME_T
813 /* The system headers define _stati64 to _stat64. */
814# undef _stat64
815# define _stat64(name, st) rpl_stat (name, st)
816# endif
817# elif defined _MSC_VER && defined _stati64
818# ifdef _USE_32BIT_TIME_T
819 /* The system headers define _stati64 to _stat32i64. */
820# undef _stat32i64
821# define _stat32i64(name, st) rpl_stat (name, st)
822# else
823 /* The system headers define _stati64 to _stat64. */
824# undef _stat64
825# define _stat64(name, st) rpl_stat (name, st)
826# endif
827# else
828# undef _stati64
829# define _stati64(name, st) rpl_stat (name, st)
830# endif
831# elif defined __MINGW32__ && defined stat
832# ifdef _USE_32BIT_TIME_T
833 /* The system headers define stat to _stat32i64. */
834# undef _stat32i64
835# define _stat32i64(name, st) rpl_stat (name, st)
836# else
837 /* The system headers define stat to _stat64. */
838# undef _stat64
839# define _stat64(name, st) rpl_stat (name, st)
840# endif
841# elif defined _MSC_VER && defined stat
842# ifdef _USE_32BIT_TIME_T
843 /* The system headers define stat to _stat32. */
844# undef _stat32
845# define _stat32(name, st) rpl_stat (name, st)
846# else
847 /* The system headers define stat to _stat64i32. */
848# undef _stat64i32
849# define _stat64i32(name, st) rpl_stat (name, st)
850# endif
851# else /* !(_AIX || __MINGW32__ || _MSC_VER) */
852# undef stat
853# define stat(name, st) rpl_stat (name, st)
854# endif /* !_LARGE_FILES */
855# endif /* !@GNULIB_OVERRIDES_STRUCT_STAT@ */
856_GL_EXTERN_C int stat (const char *restrict name, struct stat *restrict buf)
857 _GL_ARG_NONNULL ((1, 2));
858# endif
859#elif @GNULIB_OVERRIDES_STRUCT_STAT@
860/* see above:
861 #define stat stat_used_without_requesting_gnulib_module_stat
862 */
863#elif defined GNULIB_POSIXCHECK
864# undef stat
865# if HAVE_RAW_DECL_STAT
866_GL_WARN_ON_USE (stat, "stat is unportable - "
867 "use gnulib module stat for portability");
868# endif
869#endif
870
871
872#if @GNULIB_MDA_UMASK@
873/* On native Windows, map 'umask' to '_umask', so that -loldnames is not
874 required. In C++ with GNULIB_NAMESPACE, avoid differences between
875 platforms by defining GNULIB_NAMESPACE::umask always. */
876# if defined _WIN32 && !defined __CYGWIN__
877# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
878# undef umask
879# define umask _umask
880# endif
881/* Need to cast, because in mingw the last argument is 'int mode'. */
882_GL_CXXALIAS_MDA_CAST (umask, mode_t, (mode_t mask));
883# else
884_GL_CXXALIAS_SYS (umask, mode_t, (mode_t mask));
885# endif
886_GL_CXXALIASWARN (umask);
887#endif
888
889
890#if @GNULIB_UTIMENSAT@
891/* Use the rpl_ prefix also on Solaris <= 9, because on Solaris 9 our utimensat
892 implementation relies on futimesat, which on Solaris 10 makes an invocation
893 to utimensat that is meant to invoke the libc's utimensat(), not gnulib's
894 utimensat(). */
895# if @REPLACE_UTIMENSAT@ || (!@HAVE_UTIMENSAT@ && defined __sun)
896# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
897# undef utimensat
898# define utimensat rpl_utimensat
899# endif
900_GL_FUNCDECL_RPL (utimensat, int, (int fd, char const *name,
901 struct timespec const times[2], int flag)
902 _GL_ARG_NONNULL ((2)));
903_GL_CXXALIAS_RPL (utimensat, int, (int fd, char const *name,
904 struct timespec const times[2], int flag));
905# else
906# if !@HAVE_UTIMENSAT@
907_GL_FUNCDECL_SYS (utimensat, int, (int fd, char const *name,
908 struct timespec const times[2], int flag)
909 _GL_ARG_NONNULL ((2)));
910# endif
911_GL_CXXALIAS_SYS (utimensat, int, (int fd, char const *name,
912 struct timespec const times[2], int flag));
913# endif
914# if @HAVE_UTIMENSAT@
915_GL_CXXALIASWARN (utimensat);
916# endif
917#elif defined GNULIB_POSIXCHECK
918# undef utimensat
919# if HAVE_RAW_DECL_UTIMENSAT
920_GL_WARN_ON_USE (utimensat, "utimensat is not portable - "
921 "use gnulib module utimensat for portability");
922# endif
923#endif
924
925
926#endif /* _@GUARD_PREFIX@_SYS_STAT_H */
927#endif /* _@GUARD_PREFIX@_SYS_STAT_H */
928#endif
diff --git a/gl/sys_types.in.h b/gl/sys_types.in.h
index d7da356..2079d72 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-2021 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..507ab01 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-2021 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..a73fe59 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-2021 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,28 @@ 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
101/* Sleep for at least RQTP seconds unless interrupted, If interrupted, 123/* Sleep for at least RQTP seconds unless interrupted, If interrupted,
102 return -1 and store the remaining time into RMTP. See 124 return -1 and store the remaining time into RMTP. See
103 <http://www.opengroup.org/susv3xsh/nanosleep.html>. */ 125 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/nanosleep.html>. */
104# if @GNULIB_NANOSLEEP@ 126# if @GNULIB_NANOSLEEP@
105# if @REPLACE_NANOSLEEP@ 127# if @REPLACE_NANOSLEEP@
106# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 128# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -123,6 +145,41 @@ _GL_CXXALIAS_SYS (nanosleep, int,
123_GL_CXXALIASWARN (nanosleep); 145_GL_CXXALIASWARN (nanosleep);
124# endif 146# endif
125 147
148/* Initialize time conversion information. */
149# if @GNULIB_TZSET@
150# if @REPLACE_TZSET@
151# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
152# undef tzset
153# define tzset rpl_tzset
154# endif
155_GL_FUNCDECL_RPL (tzset, void, (void));
156_GL_CXXALIAS_RPL (tzset, void, (void));
157# elif defined _WIN32 && !defined __CYGWIN__
158# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
159# undef tzset
160# define tzset _tzset
161# endif
162_GL_CXXALIAS_MDA (tzset, void, (void));
163# else
164_GL_CXXALIAS_SYS (tzset, void, (void));
165# endif
166_GL_CXXALIASWARN (tzset);
167# elif @GNULIB_MDA_TZSET@
168/* On native Windows, map 'tzset' to '_tzset', so that -loldnames is not
169 required. In C++ with GNULIB_NAMESPACE, avoid differences between
170 platforms by defining GNULIB_NAMESPACE::tzset always. */
171# if defined _WIN32 && !defined __CYGWIN__
172# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
173# undef tzset
174# define tzset _tzset
175# endif
176_GL_CXXALIAS_MDA (tzset, void, (void));
177# else
178_GL_CXXALIAS_SYS (tzset, void, (void));
179# endif
180_GL_CXXALIASWARN (tzset);
181# endif
182
126/* Return the 'time_t' representation of TP and normalize TP. */ 183/* Return the 'time_t' representation of TP and normalize TP. */
127# if @GNULIB_MKTIME@ 184# if @GNULIB_MKTIME@
128# if @REPLACE_MKTIME@ 185# if @REPLACE_MKTIME@
@@ -134,12 +191,14 @@ _GL_CXXALIAS_RPL (mktime, time_t, (struct tm *__tp));
134# else 191# else
135_GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp)); 192_GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp));
136# endif 193# endif
194# if __GLIBC__ >= 2
137_GL_CXXALIASWARN (mktime); 195_GL_CXXALIASWARN (mktime);
196# endif
138# endif 197# endif
139 198
140/* Convert TIMER to RESULT, assuming local time and UTC respectively. See 199/* Convert TIMER to RESULT, assuming local time and UTC respectively. See
141 <http://www.opengroup.org/susv3xsh/localtime_r.html> and 200 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/localtime_r.html> and
142 <http://www.opengroup.org/susv3xsh/gmtime_r.html>. */ 201 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/gmtime_r.html>. */
143# if @GNULIB_TIME_R@ 202# if @GNULIB_TIME_R@
144# if @REPLACE_LOCALTIME_R@ 203# if @REPLACE_LOCALTIME_R@
145# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 204# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -187,9 +246,44 @@ _GL_CXXALIASWARN (gmtime_r);
187# endif 246# endif
188# endif 247# endif
189 248
190/* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store 249/* Convert TIMER to RESULT, assuming local time and UTC respectively. See
250 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/localtime.html> and
251 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/gmtime.html>. */
252# if @GNULIB_LOCALTIME@ || @REPLACE_LOCALTIME@
253# if @REPLACE_LOCALTIME@
254# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
255# undef localtime
256# define localtime rpl_localtime
257# endif
258_GL_FUNCDECL_RPL (localtime, struct tm *, (time_t const *__timer)
259 _GL_ARG_NONNULL ((1)));
260_GL_CXXALIAS_RPL (localtime, struct tm *, (time_t const *__timer));
261# else
262_GL_CXXALIAS_SYS (localtime, struct tm *, (time_t const *__timer));
263# endif
264# if __GLIBC__ >= 2
265_GL_CXXALIASWARN (localtime);
266# endif
267# endif
268
269# if 0 || @REPLACE_GMTIME@
270# if @REPLACE_GMTIME@
271# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
272# undef gmtime
273# define gmtime rpl_gmtime
274# endif
275_GL_FUNCDECL_RPL (gmtime, struct tm *, (time_t const *__timer)
276 _GL_ARG_NONNULL ((1)));
277_GL_CXXALIAS_RPL (gmtime, struct tm *, (time_t const *__timer));
278# else
279_GL_CXXALIAS_SYS (gmtime, struct tm *, (time_t const *__timer));
280# endif
281_GL_CXXALIASWARN (gmtime);
282# endif
283
284/* Parse BUF as a timestamp, assuming FORMAT specifies its layout, and store
191 the resulting broken-down time into TM. See 285 the resulting broken-down time into TM. See
192 <http://www.opengroup.org/susv3xsh/strptime.html>. */ 286 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/strptime.html>. */
193# if @GNULIB_STRPTIME@ 287# if @GNULIB_STRPTIME@
194# if ! @HAVE_STRPTIME@ 288# if ! @HAVE_STRPTIME@
195_GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf, 289_GL_FUNCDECL_SYS (strptime, char *, (char const *restrict __buf,
@@ -203,6 +297,105 @@ _GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
203_GL_CXXALIASWARN (strptime); 297_GL_CXXALIASWARN (strptime);
204# endif 298# endif
205 299
300/* Convert *TP to a date and time string. See
301 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/ctime.html>. */
302# if @GNULIB_CTIME@
303# if @REPLACE_CTIME@
304# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
305# define ctime rpl_ctime
306# endif
307_GL_FUNCDECL_RPL (ctime, char *, (time_t const *__tp)
308 _GL_ARG_NONNULL ((1)));
309_GL_CXXALIAS_RPL (ctime, char *, (time_t const *__tp));
310# else
311_GL_CXXALIAS_SYS (ctime, char *, (time_t const *__tp));
312# endif
313# if __GLIBC__ >= 2
314_GL_CXXALIASWARN (ctime);
315# endif
316# endif
317
318/* Convert *TP to a date and time string. See
319 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html>. */
320# if @GNULIB_STRFTIME@
321# if @REPLACE_STRFTIME@
322# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
323# define strftime rpl_strftime
324# endif
325_GL_FUNCDECL_RPL (strftime, size_t,
326 (char *restrict __buf, size_t __bufsize,
327 const char *restrict __fmt, const struct tm *restrict __tp)
328 _GL_ARG_NONNULL ((1, 3, 4)));
329_GL_CXXALIAS_RPL (strftime, size_t,
330 (char *restrict __buf, size_t __bufsize,
331 const char *restrict __fmt, const struct tm *restrict __tp));
332# else
333_GL_CXXALIAS_SYS (strftime, size_t,
334 (char *restrict __buf, size_t __bufsize,
335 const char *restrict __fmt, const struct tm *restrict __tp));
336# endif
337# if __GLIBC__ >= 2
338_GL_CXXALIASWARN (strftime);
339# endif
340# endif
341
342# if defined _GNU_SOURCE && @GNULIB_TIME_RZ@ && ! @HAVE_TIMEZONE_T@
343/* Functions that use a first-class time zone data type, instead of
344 relying on an implicit global time zone.
345 Inspired by NetBSD. */
346
347/* Represents a time zone.
348 (timezone_t) NULL stands for UTC. */
349typedef struct tm_zone *timezone_t;
350
351/* tzalloc (name)
352 Returns a time zone object for the given time zone NAME. This object
353 represents the time zone that other functions would use it the TZ
354 environment variable was set to NAME.
355 If NAME is NULL, the result represents the time zone that other functions
356 would use it the TZ environment variable was unset.
357 May return NULL if NAME is invalid (this is platform dependent) or
358 upon memory allocation failure. */
359_GL_FUNCDECL_SYS (tzalloc, timezone_t, (char const *__name));
360_GL_CXXALIAS_SYS (tzalloc, timezone_t, (char const *__name));
361
362/* tzfree (tz)
363 Frees a time zone object.
364 The argument must have been returned by tzalloc(). */
365_GL_FUNCDECL_SYS (tzfree, void, (timezone_t __tz));
366_GL_CXXALIAS_SYS (tzfree, void, (timezone_t __tz));
367
368/* localtime_rz (tz, &t, &result)
369 Converts an absolute time T to a broken-down time RESULT, assuming the
370 time zone TZ.
371 This function is like 'localtime_r', but relies on the argument TZ instead
372 of an implicit global time zone. */
373_GL_FUNCDECL_SYS (localtime_rz, struct tm *,
374 (timezone_t __tz, time_t const *restrict __timer,
375 struct tm *restrict __result) _GL_ARG_NONNULL ((2, 3)));
376_GL_CXXALIAS_SYS (localtime_rz, struct tm *,
377 (timezone_t __tz, time_t const *restrict __timer,
378 struct tm *restrict __result));
379
380/* mktime_z (tz, &tm)
381 Normalizes the broken-down time TM and converts it to an absolute time,
382 assuming the time zone TZ. Returns the absolute time.
383 This function is like 'mktime', but relies on the argument TZ instead
384 of an implicit global time zone. */
385_GL_FUNCDECL_SYS (mktime_z, time_t,
386 (timezone_t __tz, struct tm *restrict __tm)
387 _GL_ARG_NONNULL ((2)));
388_GL_CXXALIAS_SYS (mktime_z, time_t,
389 (timezone_t __tz, struct tm *restrict __tm));
390
391/* Time zone abbreviation strings (returned by 'localtime_rz' or 'mktime_z'
392 in the 'tm_zone' member of 'struct tm') are valid as long as
393 - the 'struct tm' argument is not destroyed or overwritten,
394 and
395 - the 'timezone_t' argument is not freed through tzfree(). */
396
397# endif
398
206/* Convert TM to a time_t value, assuming UTC. */ 399/* Convert TM to a time_t value, assuming UTC. */
207# if @GNULIB_TIMEGM@ 400# if @GNULIB_TIMEGM@
208# if @REPLACE_TIMEGM@ 401# if @REPLACE_TIMEGM@
@@ -231,17 +424,17 @@ _GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - "
231# endif 424# endif
232# if defined GNULIB_POSIXCHECK 425# if defined GNULIB_POSIXCHECK
233# undef asctime_r 426# undef asctime_r
234_GL_WARN_ON_USE (asctime, "asctime_r can overrun buffers in some cases - " 427_GL_WARN_ON_USE (asctime_r, "asctime_r can overrun buffers in some cases - "
235 "better use strftime (or even sprintf) instead"); 428 "better use strftime (or even sprintf) instead");
236# endif 429# endif
237# if defined GNULIB_POSIXCHECK 430# if defined GNULIB_POSIXCHECK
238# undef ctime 431# undef ctime
239_GL_WARN_ON_USE (asctime, "ctime can overrun buffers in some cases - " 432_GL_WARN_ON_USE (ctime, "ctime can overrun buffers in some cases - "
240 "better use strftime (or even sprintf) instead"); 433 "better use strftime (or even sprintf) instead");
241# endif 434# endif
242# if defined GNULIB_POSIXCHECK 435# if defined GNULIB_POSIXCHECK
243# undef ctime_r 436# undef ctime_r
244_GL_WARN_ON_USE (asctime, "ctime_r can overrun buffers in some cases - " 437_GL_WARN_ON_USE (ctime_r, "ctime_r can overrun buffers in some cases - "
245 "better use strftime (or even sprintf) instead"); 438 "better use strftime (or even sprintf) instead");
246# endif 439# endif
247 440
diff --git a/gl/time_r.c b/gl/time_r.c
index 9866299..88d3c1c 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-2021 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..7e723e1 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-2021 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..0763456 100644
--- a/gl/unistd.c
+++ b/gl/unistd.c
@@ -1,3 +1,22 @@
1/* Inline functions for <unistd.h>.
2
3 Copyright (C) 2012-2021 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..73c882f 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-2021 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,39 @@ _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 !@HAVE_COPY_FILE_RANGE@
419_GL_FUNCDECL_SYS (copy_file_range, ssize_t, (int ifd, off_t *ipos,
420 int ofd, off_t *opos,
421 size_t len, unsigned flags));
422_GL_CXXALIAS_SYS (copy_file_range, ssize_t, (int ifd, off_t *ipos,
423 int ofd, off_t *opos,
424 size_t len, unsigned flags));
425# endif
426_GL_CXXALIASWARN (copy_file_range);
427#elif defined GNULIB_POSIXCHECK
428# if HAVE_RAW_DECL_COPY_FILE_RANGE
429_GL_WARN_ON_USE (copy_file_range,
430 "copy_file_range is unportable - "
431 "use gnulib module copy_file_range for portability");
432# endif
302#endif 433#endif
303 434
304 435
@@ -309,6 +440,12 @@ _GL_WARN_ON_USE (close, "close does not portably work on sockets - "
309# endif 440# endif
310_GL_FUNCDECL_RPL (dup, int, (int oldfd)); 441_GL_FUNCDECL_RPL (dup, int, (int oldfd));
311_GL_CXXALIAS_RPL (dup, int, (int oldfd)); 442_GL_CXXALIAS_RPL (dup, int, (int oldfd));
443# elif defined _WIN32 && !defined __CYGWIN__
444# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
445# undef dup
446# define dup _dup
447# endif
448_GL_CXXALIAS_MDA (dup, int, (int oldfd));
312# else 449# else
313_GL_CXXALIAS_SYS (dup, int, (int oldfd)); 450_GL_CXXALIAS_SYS (dup, int, (int oldfd));
314# endif 451# endif
@@ -319,6 +456,20 @@ _GL_CXXALIASWARN (dup);
319_GL_WARN_ON_USE (dup, "dup is unportable - " 456_GL_WARN_ON_USE (dup, "dup is unportable - "
320 "use gnulib module dup for portability"); 457 "use gnulib module dup for portability");
321# endif 458# endif
459#elif @GNULIB_MDA_DUP@
460/* On native Windows, map 'dup' to '_dup', so that -loldnames is not
461 required. In C++ with GNULIB_NAMESPACE, avoid differences between
462 platforms by defining GNULIB_NAMESPACE::dup always. */
463# if defined _WIN32 && !defined __CYGWIN__
464# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
465# undef dup
466# define dup _dup
467# endif
468_GL_CXXALIAS_MDA (dup, int, (int oldfd));
469# else
470_GL_CXXALIAS_SYS (dup, int, (int oldfd));
471# endif
472_GL_CXXALIASWARN (dup);
322#endif 473#endif
323 474
324 475
@@ -327,17 +478,20 @@ _GL_WARN_ON_USE (dup, "dup is unportable - "
327 NEWFD = OLDFD, otherwise close NEWFD first if it is open. 478 NEWFD = OLDFD, otherwise close NEWFD first if it is open.
328 Return newfd if successful, otherwise -1 and errno set. 479 Return newfd if successful, otherwise -1 and errno set.
329 See the POSIX:2008 specification 480 See the POSIX:2008 specification
330 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/dup2.html>. */ 481 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/dup2.html>. */
331# if @REPLACE_DUP2@ 482# if @REPLACE_DUP2@
332# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 483# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
333# define dup2 rpl_dup2 484# define dup2 rpl_dup2
334# endif 485# endif
335_GL_FUNCDECL_RPL (dup2, int, (int oldfd, int newfd)); 486_GL_FUNCDECL_RPL (dup2, int, (int oldfd, int newfd));
336_GL_CXXALIAS_RPL (dup2, int, (int oldfd, int newfd)); 487_GL_CXXALIAS_RPL (dup2, int, (int oldfd, int newfd));
337# else 488# elif defined _WIN32 && !defined __CYGWIN__
338# if !@HAVE_DUP2@ 489# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
339_GL_FUNCDECL_SYS (dup2, int, (int oldfd, int newfd)); 490# undef dup2
491# define dup2 _dup2
340# endif 492# endif
493_GL_CXXALIAS_MDA (dup2, int, (int oldfd, int newfd));
494# else
341_GL_CXXALIAS_SYS (dup2, int, (int oldfd, int newfd)); 495_GL_CXXALIAS_SYS (dup2, int, (int oldfd, int newfd));
342# endif 496# endif
343_GL_CXXALIASWARN (dup2); 497_GL_CXXALIASWARN (dup2);
@@ -347,6 +501,20 @@ _GL_CXXALIASWARN (dup2);
347_GL_WARN_ON_USE (dup2, "dup2 is unportable - " 501_GL_WARN_ON_USE (dup2, "dup2 is unportable - "
348 "use gnulib module dup2 for portability"); 502 "use gnulib module dup2 for portability");
349# endif 503# endif
504#elif @GNULIB_MDA_DUP2@
505/* On native Windows, map 'dup2' to '_dup2', so that -loldnames is not
506 required. In C++ with GNULIB_NAMESPACE, avoid differences between
507 platforms by defining GNULIB_NAMESPACE::dup2 always. */
508# if defined _WIN32 && !defined __CYGWIN__
509# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
510# undef dup2
511# define dup2 _dup2
512# endif
513_GL_CXXALIAS_MDA (dup2, int, (int oldfd, int newfd));
514# else
515_GL_CXXALIAS_SYS (dup2, int, (int oldfd, int newfd));
516# endif
517_GL_CXXALIASWARN (dup2);
350#endif 518#endif
351 519
352 520
@@ -358,7 +526,7 @@ _GL_WARN_ON_USE (dup2, "dup2 is unportable - "
358 Close NEWFD first if it is open. 526 Close NEWFD first if it is open.
359 Return newfd if successful, otherwise -1 and errno set. 527 Return newfd if successful, otherwise -1 and errno set.
360 See the Linux man page at 528 See the Linux man page at
361 <http://www.kernel.org/doc/man-pages/online/pages/man2/dup3.2.html>. */ 529 <https://www.kernel.org/doc/man-pages/online/pages/man2/dup3.2.html>. */
362# if @HAVE_DUP3@ 530# if @HAVE_DUP3@
363# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 531# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
364# define dup3 rpl_dup3 532# define dup3 rpl_dup3
@@ -380,10 +548,23 @@ _GL_WARN_ON_USE (dup3, "dup3 is unportable - "
380 548
381 549
382#if @GNULIB_ENVIRON@ 550#if @GNULIB_ENVIRON@
551# if defined __CYGWIN__ && !defined __i386__
552/* The 'environ' variable is defined in a DLL. Therefore its declaration needs
553 the '__declspec(dllimport)' attribute, but the system's <unistd.h> lacks it.
554 This leads to a link error on 64-bit Cygwin when the option
555 -Wl,--disable-auto-import is in use. */
556_GL_EXTERN_C __declspec(dllimport) char **environ;
557# endif
383# if !@HAVE_DECL_ENVIRON@ 558# if !@HAVE_DECL_ENVIRON@
384/* Set of environment variables and values. An array of strings of the form 559/* Set of environment variables and values. An array of strings of the form
385 "VARIABLE=VALUE", terminated with a NULL. */ 560 "VARIABLE=VALUE", terminated with a NULL. */
386# if defined __APPLE__ && defined __MACH__ 561# if defined __APPLE__ && defined __MACH__
562# include <TargetConditionals.h>
563# if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
564# define _GL_USE_CRT_EXTERNS
565# endif
566# endif
567# ifdef _GL_USE_CRT_EXTERNS
387# include <crt_externs.h> 568# include <crt_externs.h>
388# define environ (*_NSGetEnviron ()) 569# define environ (*_NSGetEnviron ())
389# else 570# else
@@ -399,12 +580,12 @@ extern char **environ;
399#elif defined GNULIB_POSIXCHECK 580#elif defined GNULIB_POSIXCHECK
400# if HAVE_RAW_DECL_ENVIRON 581# if HAVE_RAW_DECL_ENVIRON
401_GL_UNISTD_INLINE char *** 582_GL_UNISTD_INLINE char ***
583_GL_WARN_ON_USE_ATTRIBUTE ("environ is unportable - "
584 "use gnulib module environ for portability")
402rpl_environ (void) 585rpl_environ (void)
403{ 586{
404 return &environ; 587 return &environ;
405} 588}
406_GL_WARN_ON_USE (rpl_environ, "environ is unportable - "
407 "use gnulib module environ for portability");
408# undef environ 589# undef environ
409# define environ (*rpl_environ ()) 590# define environ (*rpl_environ ())
410# endif 591# endif
@@ -434,14 +615,302 @@ _GL_WARN_ON_USE (euidaccess, "euidaccess is unportable - "
434#endif 615#endif
435 616
436 617
618#if @GNULIB_EXECL@
619# if @REPLACE_EXECL@
620# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
621# undef execl
622# define execl rpl_execl
623# endif
624_GL_FUNCDECL_RPL (execl, int, (const char *program, const char *arg, ...)
625 _GL_ARG_NONNULL ((1)));
626_GL_CXXALIAS_RPL (execl, int, (const char *program, const char *arg, ...));
627# else
628_GL_CXXALIAS_SYS (execl, int, (const char *program, const char *arg, ...));
629# endif
630_GL_CXXALIASWARN (execl);
631#elif defined GNULIB_POSIXCHECK
632# undef execl
633# if HAVE_RAW_DECL_EXECL
634_GL_WARN_ON_USE (execl, "execl behaves very differently on mingw - "
635 "use gnulib module execl for portability");
636# endif
637#elif @GNULIB_MDA_EXECL@
638/* On native Windows, map 'execl' to '_execl', so that -loldnames is not
639 required. In C++ with GNULIB_NAMESPACE, avoid differences between
640 platforms by defining GNULIB_NAMESPACE::execl always. */
641# if defined _WIN32 && !defined __CYGWIN__
642# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
643# undef execl
644# define execl _execl
645# endif
646_GL_CXXALIAS_MDA (execl, intptr_t, (const char *program, const char *arg, ...));
647# else
648_GL_CXXALIAS_SYS (execl, int, (const char *program, const char *arg, ...));
649# endif
650_GL_CXXALIASWARN (execl);
651#endif
652
653#if @GNULIB_EXECLE@
654# if @REPLACE_EXECLE@
655# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
656# undef execle
657# define execle rpl_execle
658# endif
659_GL_FUNCDECL_RPL (execle, int, (const char *program, const char *arg, ...)
660 _GL_ARG_NONNULL ((1)));
661_GL_CXXALIAS_RPL (execle, int, (const char *program, const char *arg, ...));
662# else
663_GL_CXXALIAS_SYS (execle, int, (const char *program, const char *arg, ...));
664# endif
665_GL_CXXALIASWARN (execle);
666#elif defined GNULIB_POSIXCHECK
667# undef execle
668# if HAVE_RAW_DECL_EXECLE
669_GL_WARN_ON_USE (execle, "execle behaves very differently on mingw - "
670 "use gnulib module execle for portability");
671# endif
672#elif @GNULIB_MDA_EXECLE@
673/* On native Windows, map 'execle' to '_execle', so that -loldnames is not
674 required. In C++ with GNULIB_NAMESPACE, avoid differences between
675 platforms by defining GNULIB_NAMESPACE::execle always. */
676# if defined _WIN32 && !defined __CYGWIN__
677# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
678# undef execle
679# define execle _execle
680# endif
681_GL_CXXALIAS_MDA (execle, intptr_t,
682 (const char *program, const char *arg, ...));
683# else
684_GL_CXXALIAS_SYS (execle, int, (const char *program, const char *arg, ...));
685# endif
686_GL_CXXALIASWARN (execle);
687#endif
688
689#if @GNULIB_EXECLP@
690# if @REPLACE_EXECLP@
691# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
692# undef execlp
693# define execlp rpl_execlp
694# endif
695_GL_FUNCDECL_RPL (execlp, int, (const char *program, const char *arg, ...)
696 _GL_ARG_NONNULL ((1)));
697_GL_CXXALIAS_RPL (execlp, int, (const char *program, const char *arg, ...));
698# else
699_GL_CXXALIAS_SYS (execlp, int, (const char *program, const char *arg, ...));
700# endif
701_GL_CXXALIASWARN (execlp);
702#elif defined GNULIB_POSIXCHECK
703# undef execlp
704# if HAVE_RAW_DECL_EXECLP
705_GL_WARN_ON_USE (execlp, "execlp behaves very differently on mingw - "
706 "use gnulib module execlp for portability");
707# endif
708#elif @GNULIB_MDA_EXECLP@
709/* On native Windows, map 'execlp' to '_execlp', so that -loldnames is not
710 required. In C++ with GNULIB_NAMESPACE, avoid differences between
711 platforms by defining GNULIB_NAMESPACE::execlp always. */
712# if defined _WIN32 && !defined __CYGWIN__
713# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
714# undef execlp
715# define execlp _execlp
716# endif
717_GL_CXXALIAS_MDA (execlp, intptr_t,
718 (const char *program, const char *arg, ...));
719# else
720_GL_CXXALIAS_SYS (execlp, int, (const char *program, const char *arg, ...));
721# endif
722_GL_CXXALIASWARN (execlp);
723#endif
724
725
726#if @GNULIB_EXECV@
727# if @REPLACE_EXECV@
728# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
729# undef execv
730# define execv rpl_execv
731# endif
732_GL_FUNCDECL_RPL (execv, int, (const char *program, char * const *argv)
733 _GL_ARG_NONNULL ((1, 2)));
734_GL_CXXALIAS_RPL (execv, int, (const char *program, char * const *argv));
735# else
736_GL_CXXALIAS_SYS (execv, int, (const char *program, char * const *argv));
737# endif
738_GL_CXXALIASWARN (execv);
739#elif defined GNULIB_POSIXCHECK
740# undef execv
741# if HAVE_RAW_DECL_EXECV
742_GL_WARN_ON_USE (execv, "execv behaves very differently on mingw - "
743 "use gnulib module execv for portability");
744# endif
745#elif @GNULIB_MDA_EXECV@
746/* On native Windows, map 'execv' to '_execv', so that -loldnames is not
747 required. In C++ with GNULIB_NAMESPACE, avoid differences between
748 platforms by defining GNULIB_NAMESPACE::execv always. */
749# if defined _WIN32 && !defined __CYGWIN__
750# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
751# undef execv
752# define execv _execv
753# endif
754_GL_CXXALIAS_MDA_CAST (execv, intptr_t,
755 (const char *program, char * const *argv));
756# else
757_GL_CXXALIAS_SYS (execv, int, (const char *program, char * const *argv));
758# endif
759_GL_CXXALIASWARN (execv);
760#endif
761
762#if @GNULIB_EXECVE@
763# if @REPLACE_EXECVE@
764# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
765# undef execve
766# define execve rpl_execve
767# endif
768_GL_FUNCDECL_RPL (execve, int,
769 (const char *program, char * const *argv, char * const *env)
770 _GL_ARG_NONNULL ((1, 2)));
771_GL_CXXALIAS_RPL (execve, int,
772 (const char *program, char * const *argv, char * const *env));
773# else
774_GL_CXXALIAS_SYS (execve, int,
775 (const char *program, char * const *argv, char * const *env));
776# endif
777_GL_CXXALIASWARN (execve);
778#elif defined GNULIB_POSIXCHECK
779# undef execve
780# if HAVE_RAW_DECL_EXECVE
781_GL_WARN_ON_USE (execve, "execve behaves very differently on mingw - "
782 "use gnulib module execve for portability");
783# endif
784#elif @GNULIB_MDA_EXECVE@
785/* On native Windows, map 'execve' to '_execve', so that -loldnames is not
786 required. In C++ with GNULIB_NAMESPACE, avoid differences between
787 platforms by defining GNULIB_NAMESPACE::execve always. */
788# if defined _WIN32 && !defined __CYGWIN__
789# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
790# undef execve
791# define execve _execve
792# endif
793_GL_CXXALIAS_MDA_CAST (execve, intptr_t,
794 (const char *program, char * const *argv,
795 char * const *env));
796# else
797_GL_CXXALIAS_SYS (execve, int,
798 (const char *program, char * const *argv, char * const *env));
799# endif
800_GL_CXXALIASWARN (execve);
801#endif
802
803#if @GNULIB_EXECVP@
804# if @REPLACE_EXECVP@
805# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
806# undef execvp
807# define execvp rpl_execvp
808# endif
809_GL_FUNCDECL_RPL (execvp, int, (const char *program, char * const *argv)
810 _GL_ARG_NONNULL ((1, 2)));
811_GL_CXXALIAS_RPL (execvp, int, (const char *program, char * const *argv));
812# else
813_GL_CXXALIAS_SYS (execvp, int, (const char *program, char * const *argv));
814# endif
815_GL_CXXALIASWARN (execvp);
816#elif defined GNULIB_POSIXCHECK
817# undef execvp
818# if HAVE_RAW_DECL_EXECVP
819_GL_WARN_ON_USE (execvp, "execvp behaves very differently on mingw - "
820 "use gnulib module execvp for portability");
821# endif
822#elif @GNULIB_MDA_EXECVP@
823/* On native Windows, map 'execvp' to '_execvp', so that -loldnames is not
824 required. In C++ with GNULIB_NAMESPACE, avoid differences between
825 platforms by defining GNULIB_NAMESPACE::execvp always. */
826# if defined _WIN32 && !defined __CYGWIN__
827# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
828# undef execvp
829# define execvp _execvp
830# endif
831_GL_CXXALIAS_MDA_CAST (execvp, intptr_t,
832 (const char *program, char * const *argv));
833# else
834_GL_CXXALIAS_SYS (execvp, int, (const char *program, char * const *argv));
835# endif
836_GL_CXXALIASWARN (execvp);
837#endif
838
839#if @GNULIB_EXECVPE@
840# if @REPLACE_EXECVPE@
841# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
842# undef execvpe
843# define execvpe rpl_execvpe
844# endif
845_GL_FUNCDECL_RPL (execvpe, int,
846 (const char *program, char * const *argv, char * const *env)
847 _GL_ARG_NONNULL ((1, 2)));
848_GL_CXXALIAS_RPL (execvpe, int,
849 (const char *program, char * const *argv, char * const *env));
850# else
851# if !@HAVE_DECL_EXECVPE@
852_GL_FUNCDECL_SYS (execvpe, int,
853 (const char *program, char * const *argv, char * const *env)
854 _GL_ARG_NONNULL ((1, 2)));
855# endif
856_GL_CXXALIAS_SYS (execvpe, int,
857 (const char *program, char * const *argv, char * const *env));
858# endif
859_GL_CXXALIASWARN (execvpe);
860#elif defined GNULIB_POSIXCHECK
861# undef execvpe
862# if HAVE_RAW_DECL_EXECVPE
863_GL_WARN_ON_USE (execvpe, "execvpe behaves very differently on mingw - "
864 "use gnulib module execvpe for portability");
865# endif
866#elif @GNULIB_MDA_EXECVPE@
867/* On native Windows, map 'execvpe' to '_execvpe', so that -loldnames is not
868 required. In C++ with GNULIB_NAMESPACE, avoid differences between
869 platforms by defining GNULIB_NAMESPACE::execvpe on all platforms that have
870 it. */
871# if defined _WIN32 && !defined __CYGWIN__
872# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
873# undef execvpe
874# define execvpe _execvpe
875# endif
876_GL_CXXALIAS_MDA_CAST (execvpe, intptr_t,
877 (const char *program, char * const *argv,
878 char * const *env));
879# elif @HAVE_EXECVPE@
880# if !@HAVE_DECL_EXECVPE@
881_GL_FUNCDECL_SYS (execvpe, int,
882 (const char *program, char * const *argv, char * const *env)
883 _GL_ARG_NONNULL ((1, 2)));
884# endif
885_GL_CXXALIAS_SYS (execvpe, int,
886 (const char *program, char * const *argv, char * const *env));
887# endif
888# if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_EXECVPE@
889_GL_CXXALIASWARN (execvpe);
890# endif
891#endif
892
893
437#if @GNULIB_FACCESSAT@ 894#if @GNULIB_FACCESSAT@
438# if !@HAVE_FACCESSAT@ 895# if @REPLACE_FACCESSAT@
896# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
897# undef faccessat
898# define faccessat rpl_faccessat
899# endif
900_GL_FUNCDECL_RPL (faccessat, int,
901 (int fd, char const *name, int mode, int flag)
902 _GL_ARG_NONNULL ((2)));
903_GL_CXXALIAS_RPL (faccessat, int,
904 (int fd, char const *name, int mode, int flag));
905# else
906# if !@HAVE_FACCESSAT@
439_GL_FUNCDECL_SYS (faccessat, int, 907_GL_FUNCDECL_SYS (faccessat, int,
440 (int fd, char const *file, int mode, int flag) 908 (int fd, char const *file, int mode, int flag)
441 _GL_ARG_NONNULL ((2))); 909 _GL_ARG_NONNULL ((2)));
442# endif 910# endif
443_GL_CXXALIAS_SYS (faccessat, int, 911_GL_CXXALIAS_SYS (faccessat, int,
444 (int fd, char const *file, int mode, int flag)); 912 (int fd, char const *file, int mode, int flag));
913# endif
445_GL_CXXALIASWARN (faccessat); 914_GL_CXXALIASWARN (faccessat);
446#elif defined GNULIB_POSIXCHECK 915#elif defined GNULIB_POSIXCHECK
447# undef faccessat 916# undef faccessat
@@ -457,7 +926,7 @@ _GL_WARN_ON_USE (faccessat, "faccessat is not portable - "
457 the given file descriptor is open. 926 the given file descriptor is open.
458 Return 0 if successful, otherwise -1 and errno set. 927 Return 0 if successful, otherwise -1 and errno set.
459 See the POSIX:2008 specification 928 See the POSIX:2008 specification
460 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fchdir.html>. */ 929 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/fchdir.html>. */
461# if ! @HAVE_FCHDIR@ 930# if ! @HAVE_FCHDIR@
462_GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/)); 931_GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/));
463 932
@@ -509,7 +978,7 @@ _GL_CXXALIASWARN (fchownat);
509# undef fchownat 978# undef fchownat
510# if HAVE_RAW_DECL_FCHOWNAT 979# if HAVE_RAW_DECL_FCHOWNAT
511_GL_WARN_ON_USE (fchownat, "fchownat is not portable - " 980_GL_WARN_ON_USE (fchownat, "fchownat is not portable - "
512 "use gnulib module openat for portability"); 981 "use gnulib module fchownat for portability");
513# endif 982# endif
514#endif 983#endif
515 984
@@ -518,7 +987,7 @@ _GL_WARN_ON_USE (fchownat, "fchownat is not portable - "
518/* Synchronize changes to a file. 987/* Synchronize changes to a file.
519 Return 0 if successful, otherwise -1 and errno set. 988 Return 0 if successful, otherwise -1 and errno set.
520 See POSIX:2008 specification 989 See POSIX:2008 specification
521 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fdatasync.html>. */ 990 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/fdatasync.html>. */
522# if !@HAVE_FDATASYNC@ || !@HAVE_DECL_FDATASYNC@ 991# if !@HAVE_FDATASYNC@ || !@HAVE_DECL_FDATASYNC@
523_GL_FUNCDECL_SYS (fdatasync, int, (int fd)); 992_GL_FUNCDECL_SYS (fdatasync, int, (int fd));
524# endif 993# endif
@@ -537,7 +1006,7 @@ _GL_WARN_ON_USE (fdatasync, "fdatasync is unportable - "
537/* Synchronize changes, including metadata, to a file. 1006/* Synchronize changes, including metadata, to a file.
538 Return 0 if successful, otherwise -1 and errno set. 1007 Return 0 if successful, otherwise -1 and errno set.
539 See POSIX:2008 specification 1008 See POSIX:2008 specification
540 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html>. */ 1009 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html>. */
541# if !@HAVE_FSYNC@ 1010# if !@HAVE_FSYNC@
542_GL_FUNCDECL_SYS (fsync, int, (int fd)); 1011_GL_FUNCDECL_SYS (fsync, int, (int fd));
543# endif 1012# endif
@@ -556,7 +1025,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. 1025/* 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. 1026 Return 0 if successful, otherwise -1 and errno set.
558 See the POSIX:2008 specification 1027 See the POSIX:2008 specification
559 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html>. */ 1028 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html>. */
560# if @REPLACE_FTRUNCATE@ 1029# if @REPLACE_FTRUNCATE@
561# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1030# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
562# undef ftruncate 1031# undef ftruncate
@@ -586,7 +1055,7 @@ _GL_WARN_ON_USE (ftruncate, "ftruncate is unportable - "
586 Return BUF if successful, or NULL if the directory couldn't be determined 1055 Return BUF if successful, or NULL if the directory couldn't be determined
587 or SIZE was too small. 1056 or SIZE was too small.
588 See the POSIX:2008 specification 1057 See the POSIX:2008 specification
589 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html>. 1058 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html>.
590 Additionally, the gnulib module 'getcwd' guarantees the following GNU 1059 Additionally, the gnulib module 'getcwd' guarantees the following GNU
591 extension: If BUF is NULL, an array is allocated with 'malloc'; the array 1060 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 1061 is SIZE bytes long, unless SIZE == 0, in which case it is as big as
@@ -597,6 +1066,12 @@ _GL_WARN_ON_USE (ftruncate, "ftruncate is unportable - "
597# endif 1066# endif
598_GL_FUNCDECL_RPL (getcwd, char *, (char *buf, size_t size)); 1067_GL_FUNCDECL_RPL (getcwd, char *, (char *buf, size_t size));
599_GL_CXXALIAS_RPL (getcwd, char *, (char *buf, size_t size)); 1068_GL_CXXALIAS_RPL (getcwd, char *, (char *buf, size_t size));
1069# elif defined _WIN32 && !defined __CYGWIN__
1070# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1071# undef getcwd
1072# define getcwd _getcwd
1073# endif
1074_GL_CXXALIAS_MDA (getcwd, char *, (char *buf, size_t size));
600# else 1075# else
601/* Need to cast, because on mingw, the second parameter is 1076/* Need to cast, because on mingw, the second parameter is
602 int size. */ 1077 int size. */
@@ -609,6 +1084,22 @@ _GL_CXXALIASWARN (getcwd);
609_GL_WARN_ON_USE (getcwd, "getcwd is unportable - " 1084_GL_WARN_ON_USE (getcwd, "getcwd is unportable - "
610 "use gnulib module getcwd for portability"); 1085 "use gnulib module getcwd for portability");
611# endif 1086# endif
1087#elif @GNULIB_MDA_GETCWD@
1088/* On native Windows, map 'getcwd' to '_getcwd', so that -loldnames is not
1089 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1090 platforms by defining GNULIB_NAMESPACE::getcwd always. */
1091# if defined _WIN32 && !defined __CYGWIN__
1092# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1093# undef getcwd
1094# define getcwd _getcwd
1095# endif
1096/* Need to cast, because on mingw, the second parameter is either
1097 'int size' or 'size_t size'. */
1098_GL_CXXALIAS_MDA_CAST (getcwd, char *, (char *buf, size_t size));
1099# else
1100_GL_CXXALIAS_SYS_CAST (getcwd, char *, (char *buf, size_t size));
1101# endif
1102_GL_CXXALIASWARN (getcwd);
612#endif 1103#endif
613 1104
614 1105
@@ -651,10 +1142,21 @@ _GL_WARN_ON_USE (getdomainname, "getdomainname is unportable - "
651#if @GNULIB_GETDTABLESIZE@ 1142#if @GNULIB_GETDTABLESIZE@
652/* Return the maximum number of file descriptors in the current process. 1143/* Return the maximum number of file descriptors in the current process.
653 In POSIX, this is same as sysconf (_SC_OPEN_MAX). */ 1144 In POSIX, this is same as sysconf (_SC_OPEN_MAX). */
654# if !@HAVE_GETDTABLESIZE@ 1145# if @REPLACE_GETDTABLESIZE@
1146# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1147# undef getdtablesize
1148# define getdtablesize rpl_getdtablesize
1149# endif
1150_GL_FUNCDECL_RPL (getdtablesize, int, (void));
1151_GL_CXXALIAS_RPL (getdtablesize, int, (void));
1152# else
1153# if !@HAVE_GETDTABLESIZE@
655_GL_FUNCDECL_SYS (getdtablesize, int, (void)); 1154_GL_FUNCDECL_SYS (getdtablesize, int, (void));
1155# endif
1156/* Need to cast, because on AIX, the parameter list is
1157 (...). */
1158_GL_CXXALIAS_SYS_CAST (getdtablesize, int, (void));
656# endif 1159# endif
657_GL_CXXALIAS_SYS (getdtablesize, int, (void));
658_GL_CXXALIASWARN (getdtablesize); 1160_GL_CXXALIASWARN (getdtablesize);
659#elif defined GNULIB_POSIXCHECK 1161#elif defined GNULIB_POSIXCHECK
660# undef getdtablesize 1162# undef getdtablesize
@@ -665,6 +1167,22 @@ _GL_WARN_ON_USE (getdtablesize, "getdtablesize is unportable - "
665#endif 1167#endif
666 1168
667 1169
1170#if @GNULIB_GETENTROPY@
1171/* Fill a buffer with random bytes. */
1172# if !@HAVE_GETENTROPY@
1173_GL_FUNCDECL_SYS (getentropy, int, (void *buffer, size_t length));
1174# endif
1175_GL_CXXALIAS_SYS (getentropy, int, (void *buffer, size_t length));
1176_GL_CXXALIASWARN (getentropy);
1177#elif defined GNULIB_POSIXCHECK
1178# undef getentropy
1179# if HAVE_RAW_DECL_GETENTROPY
1180_GL_WARN_ON_USE (getentropy, "getentropy is unportable - "
1181 "use gnulib module getentropy for portability");
1182# endif
1183#endif
1184
1185
668#if @GNULIB_GETGROUPS@ 1186#if @GNULIB_GETGROUPS@
669/* Return the supplemental groups that the current process belongs to. 1187/* Return the supplemental groups that the current process belongs to.
670 It is unspecified whether the effective group id is in the list. 1188 It is unspecified whether the effective group id is in the list.
@@ -737,14 +1255,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, 1255/* Returns the user's login name, or NULL if it cannot be found. Upon error,
738 returns NULL with errno set. 1256 returns NULL with errno set.
739 1257
740 See <http://www.opengroup.org/susv3xsh/getlogin.html>. 1258 See <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getlogin.html>.
741 1259
742 Most programs don't need to use this function, because the information is 1260 Most programs don't need to use this function, because the information is
743 available through environment variables: 1261 available through environment variables:
744 ${LOGNAME-$USER} on Unix platforms, 1262 ${LOGNAME-$USER} on Unix platforms,
745 $USERNAME on native Windows platforms. 1263 $USERNAME on native Windows platforms.
746 */ 1264 */
747# if !@HAVE_GETLOGIN@ 1265# if !@HAVE_DECL_GETLOGIN@
748_GL_FUNCDECL_SYS (getlogin, char *, (void)); 1266_GL_FUNCDECL_SYS (getlogin, char *, (void));
749# endif 1267# endif
750_GL_CXXALIAS_SYS (getlogin, char *, (void)); 1268_GL_CXXALIAS_SYS (getlogin, char *, (void));
@@ -766,7 +1284,7 @@ _GL_WARN_ON_USE (getlogin, "getlogin is unportable - "
766 the case that the login name cannot be found but no specific error is 1284 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). 1285 provided (this case is hopefully rare but is left open by the POSIX spec).
768 1286
769 See <http://www.opengroup.org/susv3xsh/getlogin.html>. 1287 See <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getlogin.html>.
770 1288
771 Most programs don't need to use this function, because the information is 1289 Most programs don't need to use this function, because the information is
772 available through environment variables: 1290 available through environment variables:
@@ -807,6 +1325,11 @@ _GL_WARN_ON_USE (getlogin_r, "getlogin_r is unportable - "
807_GL_FUNCDECL_RPL (getpagesize, int, (void)); 1325_GL_FUNCDECL_RPL (getpagesize, int, (void));
808_GL_CXXALIAS_RPL (getpagesize, int, (void)); 1326_GL_CXXALIAS_RPL (getpagesize, int, (void));
809# else 1327# else
1328/* On HP-UX, getpagesize exists, but it is not declared in <unistd.h> even if
1329 the compiler options -D_HPUX_SOURCE -D_XOPEN_SOURCE=600 are used. */
1330# if defined __hpux
1331_GL_FUNCDECL_SYS (getpagesize, int, (void));
1332# endif
810# if !@HAVE_GETPAGESIZE@ 1333# if !@HAVE_GETPAGESIZE@
811# if !defined getpagesize 1334# if !defined getpagesize
812/* This is for POSIX systems. */ 1335/* This is for POSIX systems. */
@@ -881,6 +1404,53 @@ _GL_WARN_ON_USE (getpagesize, "getpagesize is unportable - "
881#endif 1404#endif
882 1405
883 1406
1407#if @GNULIB_GETPASS@
1408/* Function getpass() from module 'getpass':
1409 Read a password from /dev/tty or stdin.
1410 Function getpass() from module 'getpass-gnu':
1411 Read a password of arbitrary length from /dev/tty or stdin. */
1412# if @REPLACE_GETPASS@
1413# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1414# undef getpass
1415# define getpass rpl_getpass
1416# endif
1417_GL_FUNCDECL_RPL (getpass, char *, (const char *prompt)
1418 _GL_ARG_NONNULL ((1)));
1419_GL_CXXALIAS_RPL (getpass, char *, (const char *prompt));
1420# else
1421# if !@HAVE_GETPASS@
1422_GL_FUNCDECL_SYS (getpass, char *, (const char *prompt)
1423 _GL_ARG_NONNULL ((1)));
1424# endif
1425_GL_CXXALIAS_SYS (getpass, char *, (const char *prompt));
1426# endif
1427_GL_CXXALIASWARN (getpass);
1428#elif defined GNULIB_POSIXCHECK
1429# undef getpass
1430# if HAVE_RAW_DECL_GETPASS
1431_GL_WARN_ON_USE (getpass, "getpass is unportable - "
1432 "use gnulib module getpass or getpass-gnu for portability");
1433# endif
1434#endif
1435
1436
1437#if @GNULIB_MDA_GETPID@
1438/* On native Windows, map 'getpid' to '_getpid', so that -loldnames is not
1439 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1440 platforms by defining GNULIB_NAMESPACE::getpid always. */
1441# if defined _WIN32 && !defined __CYGWIN__
1442# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1443# undef getpid
1444# define getpid _getpid
1445# endif
1446_GL_CXXALIAS_MDA (getpid, int, (void));
1447# else
1448_GL_CXXALIAS_SYS (getpid, pid_t, (void));
1449# endif
1450_GL_CXXALIASWARN (getpid);
1451#endif
1452
1453
884#if @GNULIB_GETUSERSHELL@ 1454#if @GNULIB_GETUSERSHELL@
885/* Return the next valid login shell on the system, or NULL when the end of 1455/* Return the next valid login shell on the system, or NULL when the end of
886 the list has been reached. */ 1456 the list has been reached. */
@@ -951,8 +1521,15 @@ _GL_WARN_ON_USE (group_member, "group_member is unportable - "
951# undef isatty 1521# undef isatty
952# define isatty rpl_isatty 1522# define isatty rpl_isatty
953# endif 1523# endif
1524# define GNULIB_defined_isatty 1
954_GL_FUNCDECL_RPL (isatty, int, (int fd)); 1525_GL_FUNCDECL_RPL (isatty, int, (int fd));
955_GL_CXXALIAS_RPL (isatty, int, (int fd)); 1526_GL_CXXALIAS_RPL (isatty, int, (int fd));
1527# elif defined _WIN32 && !defined __CYGWIN__
1528# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1529# undef isatty
1530# define isatty _isatty
1531# endif
1532_GL_CXXALIAS_MDA (isatty, int, (int fd));
956# else 1533# else
957_GL_CXXALIAS_SYS (isatty, int, (int fd)); 1534_GL_CXXALIAS_SYS (isatty, int, (int fd));
958# endif 1535# endif
@@ -963,6 +1540,20 @@ _GL_CXXALIASWARN (isatty);
963_GL_WARN_ON_USE (isatty, "isatty has portability problems on native Windows - " 1540_GL_WARN_ON_USE (isatty, "isatty has portability problems on native Windows - "
964 "use gnulib module isatty for portability"); 1541 "use gnulib module isatty for portability");
965# endif 1542# endif
1543#elif @GNULIB_MDA_ISATTY@
1544/* On native Windows, map 'isatty' to '_isatty', so that -loldnames is not
1545 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1546 platforms by defining GNULIB_NAMESPACE::isatty always. */
1547# if defined _WIN32 && !defined __CYGWIN__
1548# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1549# undef isatty
1550# define isatty _isatty
1551# endif
1552_GL_CXXALIAS_MDA (isatty, int, (int fd));
1553# else
1554_GL_CXXALIAS_SYS (isatty, int, (int fd));
1555# endif
1556_GL_CXXALIASWARN (isatty);
966#endif 1557#endif
967 1558
968 1559
@@ -971,7 +1562,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. 1562 to GID (if GID is not -1). Do not follow symbolic links.
972 Return 0 if successful, otherwise -1 and errno set. 1563 Return 0 if successful, otherwise -1 and errno set.
973 See the POSIX:2008 specification 1564 See the POSIX:2008 specification
974 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/lchown.html>. */ 1565 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/lchown.html>. */
975# if @REPLACE_LCHOWN@ 1566# if @REPLACE_LCHOWN@
976# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1567# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
977# undef lchown 1568# undef lchown
@@ -1001,7 +1592,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. 1592/* Create a new hard link for an existing file.
1002 Return 0 if successful, otherwise -1 and errno set. 1593 Return 0 if successful, otherwise -1 and errno set.
1003 See POSIX:2008 specification 1594 See POSIX:2008 specification
1004 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html>. */ 1595 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html>. */
1005# if @REPLACE_LINK@ 1596# if @REPLACE_LINK@
1006# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1597# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1007# define link rpl_link 1598# define link rpl_link
@@ -1067,13 +1658,19 @@ _GL_WARN_ON_USE (linkat, "linkat is unportable - "
1067/* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END. 1658/* 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. 1659 Return the new offset if successful, otherwise -1 and errno set.
1069 See the POSIX:2008 specification 1660 See the POSIX:2008 specification
1070 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/lseek.html>. */ 1661 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/lseek.html>. */
1071# if @REPLACE_LSEEK@ 1662# if @REPLACE_LSEEK@
1072# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1663# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1073# define lseek rpl_lseek 1664# define lseek rpl_lseek
1074# endif 1665# endif
1075_GL_FUNCDECL_RPL (lseek, off_t, (int fd, off_t offset, int whence)); 1666_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)); 1667_GL_CXXALIAS_RPL (lseek, off_t, (int fd, off_t offset, int whence));
1668# elif defined _WIN32 && !defined __CYGWIN__
1669# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1670# undef lseek
1671# define lseek _lseek
1672# endif
1673_GL_CXXALIAS_MDA (lseek, off_t, (int fd, off_t offset, int whence));
1077# else 1674# else
1078_GL_CXXALIAS_SYS (lseek, off_t, (int fd, off_t offset, int whence)); 1675_GL_CXXALIAS_SYS (lseek, off_t, (int fd, off_t offset, int whence));
1079# endif 1676# endif
@@ -1084,6 +1681,20 @@ _GL_CXXALIASWARN (lseek);
1084_GL_WARN_ON_USE (lseek, "lseek does not fail with ESPIPE on pipes on some " 1681_GL_WARN_ON_USE (lseek, "lseek does not fail with ESPIPE on pipes on some "
1085 "systems - use gnulib module lseek for portability"); 1682 "systems - use gnulib module lseek for portability");
1086# endif 1683# endif
1684#elif @GNULIB_MDA_LSEEK@
1685/* On native Windows, map 'lseek' to '_lseek', so that -loldnames is not
1686 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1687 platforms by defining GNULIB_NAMESPACE::lseek always. */
1688# if defined _WIN32 && !defined __CYGWIN__
1689# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1690# undef lseek
1691# define lseek _lseek
1692# endif
1693_GL_CXXALIAS_MDA (lseek, long, (int fd, long offset, int whence));
1694# else
1695_GL_CXXALIAS_SYS (lseek, off_t, (int fd, off_t offset, int whence));
1696# endif
1697_GL_CXXALIASWARN (lseek);
1087#endif 1698#endif
1088 1699
1089 1700
@@ -1113,7 +1724,7 @@ _GL_WARN_ON_USE (pipe, "pipe is unportable - "
1113 Store the read-end as fd[0] and the write-end as fd[1]. 1724 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. 1725 Return 0 upon success, or -1 with errno set upon failure.
1115 See also the Linux man page at 1726 See also the Linux man page at
1116 <http://www.kernel.org/doc/man-pages/online/pages/man2/pipe2.2.html>. */ 1727 <https://www.kernel.org/doc/man-pages/online/pages/man2/pipe2.2.html>. */
1117# if @HAVE_PIPE2@ 1728# if @HAVE_PIPE2@
1118# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1729# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1119# define pipe2 rpl_pipe2 1730# define pipe2 rpl_pipe2
@@ -1139,7 +1750,7 @@ _GL_WARN_ON_USE (pipe2, "pipe2 is unportable - "
1139 Return the number of bytes placed into BUF if successful, otherwise 1750 Return the number of bytes placed into BUF if successful, otherwise
1140 set errno and return -1. 0 indicates EOF. 1751 set errno and return -1. 0 indicates EOF.
1141 See the POSIX:2008 specification 1752 See the POSIX:2008 specification
1142 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/pread.html>. */ 1753 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/pread.html>. */
1143# if @REPLACE_PREAD@ 1754# if @REPLACE_PREAD@
1144# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1755# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1145# undef pread 1756# undef pread
@@ -1174,7 +1785,7 @@ _GL_WARN_ON_USE (pread, "pread is unportable - "
1174 Return the number of bytes written if successful, otherwise 1785 Return the number of bytes written if successful, otherwise
1175 set errno and return -1. 0 indicates nothing written. See the 1786 set errno and return -1. 0 indicates nothing written. See the
1176 POSIX:2008 specification 1787 POSIX:2008 specification
1177 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/pwrite.html>. */ 1788 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/pwrite.html>. */
1178# if @REPLACE_PWRITE@ 1789# if @REPLACE_PWRITE@
1179# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1790# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1180# undef pwrite 1791# undef pwrite
@@ -1207,7 +1818,7 @@ _GL_WARN_ON_USE (pwrite, "pwrite is unportable - "
1207#if @GNULIB_READ@ 1818#if @GNULIB_READ@
1208/* Read up to COUNT bytes from file descriptor FD into the buffer starting 1819/* Read up to COUNT bytes from file descriptor FD into the buffer starting
1209 at BUF. See the POSIX:2008 specification 1820 at BUF. See the POSIX:2008 specification
1210 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html>. */ 1821 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html>. */
1211# if @REPLACE_READ@ 1822# if @REPLACE_READ@
1212# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1823# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1213# undef read 1824# undef read
@@ -1216,11 +1827,32 @@ _GL_WARN_ON_USE (pwrite, "pwrite is unportable - "
1216_GL_FUNCDECL_RPL (read, ssize_t, (int fd, void *buf, size_t count) 1827_GL_FUNCDECL_RPL (read, ssize_t, (int fd, void *buf, size_t count)
1217 _GL_ARG_NONNULL ((2))); 1828 _GL_ARG_NONNULL ((2)));
1218_GL_CXXALIAS_RPL (read, ssize_t, (int fd, void *buf, size_t count)); 1829_GL_CXXALIAS_RPL (read, ssize_t, (int fd, void *buf, size_t count));
1830# elif defined _WIN32 && !defined __CYGWIN__
1831# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1832# undef read
1833# define read _read
1834# endif
1835_GL_CXXALIAS_MDA (read, ssize_t, (int fd, void *buf, size_t count));
1836# else
1837_GL_CXXALIAS_SYS (read, ssize_t, (int fd, void *buf, size_t count));
1838# endif
1839_GL_CXXALIASWARN (read);
1840#elif @GNULIB_MDA_READ@
1841/* On native Windows, map 'read' to '_read', so that -loldnames is not
1842 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1843 platforms by defining GNULIB_NAMESPACE::read always. */
1844# if defined _WIN32 && !defined __CYGWIN__
1845# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1846# undef read
1847# define read _read
1848# endif
1849# ifdef __MINGW32__
1850_GL_CXXALIAS_MDA (read, int, (int fd, void *buf, unsigned int count));
1851# else
1852_GL_CXXALIAS_MDA (read, ssize_t, (int fd, void *buf, unsigned int count));
1853# endif
1219# else 1854# else
1220/* Need to cast, because on mingw, the third parameter is 1855_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 1856# endif
1225_GL_CXXALIASWARN (read); 1857_GL_CXXALIASWARN (read);
1226#endif 1858#endif
@@ -1231,24 +1863,28 @@ _GL_CXXALIASWARN (read);
1231 bytes of it into BUF. Return the number of bytes placed into BUF if 1863 bytes of it into BUF. Return the number of bytes placed into BUF if
1232 successful, otherwise -1 and errno set. 1864 successful, otherwise -1 and errno set.
1233 See the POSIX:2008 specification 1865 See the POSIX:2008 specification
1234 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html>. */ 1866 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html>. */
1235# if @REPLACE_READLINK@ 1867# if @REPLACE_READLINK@
1236# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 1868# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1237# define readlink rpl_readlink 1869# define readlink rpl_readlink
1238# endif 1870# endif
1239_GL_FUNCDECL_RPL (readlink, ssize_t, 1871_GL_FUNCDECL_RPL (readlink, ssize_t,
1240 (const char *file, char *buf, size_t bufsize) 1872 (const char *restrict file,
1873 char *restrict buf, size_t bufsize)
1241 _GL_ARG_NONNULL ((1, 2))); 1874 _GL_ARG_NONNULL ((1, 2)));
1242_GL_CXXALIAS_RPL (readlink, ssize_t, 1875_GL_CXXALIAS_RPL (readlink, ssize_t,
1243 (const char *file, char *buf, size_t bufsize)); 1876 (const char *restrict file,
1877 char *restrict buf, size_t bufsize));
1244# else 1878# else
1245# if !@HAVE_READLINK@ 1879# if !@HAVE_READLINK@
1246_GL_FUNCDECL_SYS (readlink, ssize_t, 1880_GL_FUNCDECL_SYS (readlink, ssize_t,
1247 (const char *file, char *buf, size_t bufsize) 1881 (const char *restrict file,
1882 char *restrict buf, size_t bufsize)
1248 _GL_ARG_NONNULL ((1, 2))); 1883 _GL_ARG_NONNULL ((1, 2)));
1249# endif 1884# endif
1250_GL_CXXALIAS_SYS (readlink, ssize_t, 1885_GL_CXXALIAS_SYS (readlink, ssize_t,
1251 (const char *file, char *buf, size_t bufsize)); 1886 (const char *restrict file,
1887 char *restrict buf, size_t bufsize));
1252# endif 1888# endif
1253_GL_CXXALIASWARN (readlink); 1889_GL_CXXALIASWARN (readlink);
1254#elif defined GNULIB_POSIXCHECK 1890#elif defined GNULIB_POSIXCHECK
@@ -1261,13 +1897,28 @@ _GL_WARN_ON_USE (readlink, "readlink is unportable - "
1261 1897
1262 1898
1263#if @GNULIB_READLINKAT@ 1899#if @GNULIB_READLINKAT@
1264# if !@HAVE_READLINKAT@ 1900# if @REPLACE_READLINKAT@
1901# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1902# define readlinkat rpl_readlinkat
1903# endif
1904_GL_FUNCDECL_RPL (readlinkat, ssize_t,
1905 (int fd, char const *restrict file,
1906 char *restrict buf, size_t len)
1907 _GL_ARG_NONNULL ((2, 3)));
1908_GL_CXXALIAS_RPL (readlinkat, ssize_t,
1909 (int fd, char const *restrict file,
1910 char *restrict buf, size_t len));
1911# else
1912# if !@HAVE_READLINKAT@
1265_GL_FUNCDECL_SYS (readlinkat, ssize_t, 1913_GL_FUNCDECL_SYS (readlinkat, ssize_t,
1266 (int fd, char const *file, char *buf, size_t len) 1914 (int fd, char const *restrict file,
1915 char *restrict buf, size_t len)
1267 _GL_ARG_NONNULL ((2, 3))); 1916 _GL_ARG_NONNULL ((2, 3)));
1268# endif 1917# endif
1269_GL_CXXALIAS_SYS (readlinkat, ssize_t, 1918_GL_CXXALIAS_SYS (readlinkat, ssize_t,
1270 (int fd, char const *file, char *buf, size_t len)); 1919 (int fd, char const *restrict file,
1920 char *restrict buf, size_t len));
1921# endif
1271_GL_CXXALIASWARN (readlinkat); 1922_GL_CXXALIASWARN (readlinkat);
1272#elif defined GNULIB_POSIXCHECK 1923#elif defined GNULIB_POSIXCHECK
1273# undef readlinkat 1924# undef readlinkat
@@ -1286,6 +1937,12 @@ _GL_WARN_ON_USE (readlinkat, "readlinkat is not portable - "
1286# endif 1937# endif
1287_GL_FUNCDECL_RPL (rmdir, int, (char const *name) _GL_ARG_NONNULL ((1))); 1938_GL_FUNCDECL_RPL (rmdir, int, (char const *name) _GL_ARG_NONNULL ((1)));
1288_GL_CXXALIAS_RPL (rmdir, int, (char const *name)); 1939_GL_CXXALIAS_RPL (rmdir, int, (char const *name));
1940# elif defined _WIN32 && !defined __CYGWIN__
1941# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1942# undef rmdir
1943# define rmdir _rmdir
1944# endif
1945_GL_CXXALIAS_MDA (rmdir, int, (char const *name));
1289# else 1946# else
1290_GL_CXXALIAS_SYS (rmdir, int, (char const *name)); 1947_GL_CXXALIAS_SYS (rmdir, int, (char const *name));
1291# endif 1948# endif
@@ -1296,6 +1953,20 @@ _GL_CXXALIASWARN (rmdir);
1296_GL_WARN_ON_USE (rmdir, "rmdir is unportable - " 1953_GL_WARN_ON_USE (rmdir, "rmdir is unportable - "
1297 "use gnulib module rmdir for portability"); 1954 "use gnulib module rmdir for portability");
1298# endif 1955# endif
1956#elif @GNULIB_MDA_RMDIR@
1957/* On native Windows, map 'rmdir' to '_rmdir', so that -loldnames is not
1958 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1959 platforms by defining GNULIB_NAMESPACE::rmdir always. */
1960# if defined _WIN32 && !defined __CYGWIN__
1961# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1962# undef rmdir
1963# define rmdir _rmdir
1964# endif
1965_GL_CXXALIAS_MDA (rmdir, int, (char const *name));
1966# else
1967_GL_CXXALIAS_SYS (rmdir, int, (char const *name));
1968# endif
1969_GL_CXXALIASWARN (rmdir);
1299#endif 1970#endif
1300 1971
1301 1972
@@ -1330,7 +2001,7 @@ _GL_WARN_ON_USE (sethostname, "sethostname is unportable - "
1330/* Pause the execution of the current thread for N seconds. 2001/* Pause the execution of the current thread for N seconds.
1331 Returns the number of seconds left to sleep. 2002 Returns the number of seconds left to sleep.
1332 See the POSIX:2008 specification 2003 See the POSIX:2008 specification
1333 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/sleep.html>. */ 2004 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/sleep.html>. */
1334# if @REPLACE_SLEEP@ 2005# if @REPLACE_SLEEP@
1335# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 2006# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1336# undef sleep 2007# undef sleep
@@ -1354,6 +2025,31 @@ _GL_WARN_ON_USE (sleep, "sleep is unportable - "
1354#endif 2025#endif
1355 2026
1356 2027
2028#if @GNULIB_MDA_SWAB@
2029/* On native Windows, map 'swab' to '_swab', so that -loldnames is not
2030 required. In C++ with GNULIB_NAMESPACE, avoid differences between
2031 platforms by defining GNULIB_NAMESPACE::swab always. */
2032# if defined _WIN32 && !defined __CYGWIN__
2033# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2034# undef swab
2035# define swab _swab
2036# endif
2037/* Need to cast, because in old mingw the arguments are
2038 (const char *from, char *to, size_t n). */
2039_GL_CXXALIAS_MDA_CAST (swab, void, (char *from, char *to, int n));
2040# else
2041# if defined __hpux /* HP-UX */
2042_GL_CXXALIAS_SYS (swab, void, (const char *from, char *to, int n));
2043# elif defined __sun && !defined _XPG4 /* Solaris */
2044_GL_CXXALIAS_SYS (swab, void, (const char *from, char *to, ssize_t n));
2045# else
2046_GL_CXXALIAS_SYS (swab, void, (const void *from, void *to, ssize_t n));
2047# endif
2048# endif
2049_GL_CXXALIASWARN (swab);
2050#endif
2051
2052
1357#if @GNULIB_SYMLINK@ 2053#if @GNULIB_SYMLINK@
1358# if @REPLACE_SYMLINK@ 2054# if @REPLACE_SYMLINK@
1359# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 2055# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -1381,13 +2077,25 @@ _GL_WARN_ON_USE (symlink, "symlink is not portable - "
1381 2077
1382 2078
1383#if @GNULIB_SYMLINKAT@ 2079#if @GNULIB_SYMLINKAT@
1384# if !@HAVE_SYMLINKAT@ 2080# if @REPLACE_SYMLINKAT@
2081# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2082# undef symlinkat
2083# define symlinkat rpl_symlinkat
2084# endif
2085_GL_FUNCDECL_RPL (symlinkat, int,
2086 (char const *contents, int fd, char const *file)
2087 _GL_ARG_NONNULL ((1, 3)));
2088_GL_CXXALIAS_RPL (symlinkat, int,
2089 (char const *contents, int fd, char const *file));
2090# else
2091# if !@HAVE_SYMLINKAT@
1385_GL_FUNCDECL_SYS (symlinkat, int, 2092_GL_FUNCDECL_SYS (symlinkat, int,
1386 (char const *contents, int fd, char const *file) 2093 (char const *contents, int fd, char const *file)
1387 _GL_ARG_NONNULL ((1, 3))); 2094 _GL_ARG_NONNULL ((1, 3)));
1388# endif 2095# endif
1389_GL_CXXALIAS_SYS (symlinkat, int, 2096_GL_CXXALIAS_SYS (symlinkat, int,
1390 (char const *contents, int fd, char const *file)); 2097 (char const *contents, int fd, char const *file));
2098# endif
1391_GL_CXXALIASWARN (symlinkat); 2099_GL_CXXALIASWARN (symlinkat);
1392#elif defined GNULIB_POSIXCHECK 2100#elif defined GNULIB_POSIXCHECK
1393# undef symlinkat 2101# undef symlinkat
@@ -1398,6 +2106,36 @@ _GL_WARN_ON_USE (symlinkat, "symlinkat is not portable - "
1398#endif 2106#endif
1399 2107
1400 2108
2109#if @GNULIB_TRUNCATE@
2110/* Change the size of the file designated by FILENAME to become equal to LENGTH.
2111 Return 0 if successful, otherwise -1 and errno set.
2112 See the POSIX:2008 specification
2113 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/truncate.html>. */
2114# if @REPLACE_TRUNCATE@
2115# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2116# undef truncate
2117# define truncate rpl_truncate
2118# endif
2119_GL_FUNCDECL_RPL (truncate, int, (const char *filename, off_t length)
2120 _GL_ARG_NONNULL ((1)));
2121_GL_CXXALIAS_RPL (truncate, int, (const char *filename, off_t length));
2122# else
2123# if !@HAVE_DECL_TRUNCATE@
2124_GL_FUNCDECL_SYS (truncate, int, (const char *filename, off_t length)
2125 _GL_ARG_NONNULL ((1)));
2126# endif
2127_GL_CXXALIAS_SYS (truncate, int, (const char *filename, off_t length));
2128# endif
2129_GL_CXXALIASWARN (truncate);
2130#elif defined GNULIB_POSIXCHECK
2131# undef truncate
2132# if HAVE_RAW_DECL_TRUNCATE
2133_GL_WARN_ON_USE (truncate, "truncate is unportable - "
2134 "use gnulib module truncate for portability");
2135# endif
2136#endif
2137
2138
1401#if @GNULIB_TTYNAME_R@ 2139#if @GNULIB_TTYNAME_R@
1402/* Store at most BUFLEN characters of the pathname of the terminal FD is 2140/* 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. */ 2141 open on in BUF. Return 0 on success, otherwise an error number. */
@@ -1436,6 +2174,12 @@ _GL_WARN_ON_USE (ttyname_r, "ttyname_r is not portable - "
1436# endif 2174# endif
1437_GL_FUNCDECL_RPL (unlink, int, (char const *file) _GL_ARG_NONNULL ((1))); 2175_GL_FUNCDECL_RPL (unlink, int, (char const *file) _GL_ARG_NONNULL ((1)));
1438_GL_CXXALIAS_RPL (unlink, int, (char const *file)); 2176_GL_CXXALIAS_RPL (unlink, int, (char const *file));
2177# elif defined _WIN32 && !defined __CYGWIN__
2178# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2179# undef unlink
2180# define unlink _unlink
2181# endif
2182_GL_CXXALIAS_MDA (unlink, int, (char const *file));
1439# else 2183# else
1440_GL_CXXALIAS_SYS (unlink, int, (char const *file)); 2184_GL_CXXALIAS_SYS (unlink, int, (char const *file));
1441# endif 2185# endif
@@ -1446,6 +2190,20 @@ _GL_CXXALIASWARN (unlink);
1446_GL_WARN_ON_USE (unlink, "unlink is not portable - " 2190_GL_WARN_ON_USE (unlink, "unlink is not portable - "
1447 "use gnulib module unlink for portability"); 2191 "use gnulib module unlink for portability");
1448# endif 2192# endif
2193#elif @GNULIB_MDA_UNLINK@
2194/* On native Windows, map 'unlink' to '_unlink', so that -loldnames is not
2195 required. In C++ with GNULIB_NAMESPACE, avoid differences between
2196 platforms by defining GNULIB_NAMESPACE::unlink always. */
2197# if defined _WIN32 && !defined __CYGWIN__
2198# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2199# undef unlink
2200# define unlink _unlink
2201# endif
2202_GL_CXXALIAS_MDA (unlink, int, (char const *file));
2203# else
2204_GL_CXXALIAS_SYS (unlink, int, (char const *file));
2205# endif
2206_GL_CXXALIASWARN (unlink);
1449#endif 2207#endif
1450 2208
1451 2209
@@ -1470,7 +2228,7 @@ _GL_CXXALIASWARN (unlinkat);
1470# undef unlinkat 2228# undef unlinkat
1471# if HAVE_RAW_DECL_UNLINKAT 2229# if HAVE_RAW_DECL_UNLINKAT
1472_GL_WARN_ON_USE (unlinkat, "unlinkat is not portable - " 2230_GL_WARN_ON_USE (unlinkat, "unlinkat is not portable - "
1473 "use gnulib module openat for portability"); 2231 "use gnulib module unlinkat for portability");
1474# endif 2232# endif
1475#endif 2233#endif
1476 2234
@@ -1479,7 +2237,7 @@ _GL_WARN_ON_USE (unlinkat, "unlinkat is not portable - "
1479/* Pause the execution of the current thread for N microseconds. 2237/* Pause the execution of the current thread for N microseconds.
1480 Returns 0 on completion, or -1 on range error. 2238 Returns 0 on completion, or -1 on range error.
1481 See the POSIX:2001 specification 2239 See the POSIX:2001 specification
1482 <http://www.opengroup.org/susv3xsh/usleep.html>. */ 2240 <https://pubs.opengroup.org/onlinepubs/009695399/functions/usleep.html>. */
1483# if @REPLACE_USLEEP@ 2241# if @REPLACE_USLEEP@
1484# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 2242# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1485# undef usleep 2243# undef usleep
@@ -1491,7 +2249,9 @@ _GL_CXXALIAS_RPL (usleep, int, (useconds_t n));
1491# if !@HAVE_USLEEP@ 2249# if !@HAVE_USLEEP@
1492_GL_FUNCDECL_SYS (usleep, int, (useconds_t n)); 2250_GL_FUNCDECL_SYS (usleep, int, (useconds_t n));
1493# endif 2251# endif
1494_GL_CXXALIAS_SYS (usleep, int, (useconds_t n)); 2252/* Need to cast, because on Haiku, the first parameter is
2253 unsigned int n. */
2254_GL_CXXALIAS_SYS_CAST (usleep, int, (useconds_t n));
1495# endif 2255# endif
1496_GL_CXXALIASWARN (usleep); 2256_GL_CXXALIASWARN (usleep);
1497#elif defined GNULIB_POSIXCHECK 2257#elif defined GNULIB_POSIXCHECK
@@ -1506,7 +2266,7 @@ _GL_WARN_ON_USE (usleep, "usleep is unportable - "
1506#if @GNULIB_WRITE@ 2266#if @GNULIB_WRITE@
1507/* Write up to COUNT bytes starting at BUF to file descriptor FD. 2267/* Write up to COUNT bytes starting at BUF to file descriptor FD.
1508 See the POSIX:2008 specification 2268 See the POSIX:2008 specification
1509 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html>. */ 2269 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html>. */
1510# if @REPLACE_WRITE@ 2270# if @REPLACE_WRITE@
1511# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 2271# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1512# undef write 2272# undef write
@@ -1515,11 +2275,32 @@ _GL_WARN_ON_USE (usleep, "usleep is unportable - "
1515_GL_FUNCDECL_RPL (write, ssize_t, (int fd, const void *buf, size_t count) 2275_GL_FUNCDECL_RPL (write, ssize_t, (int fd, const void *buf, size_t count)
1516 _GL_ARG_NONNULL ((2))); 2276 _GL_ARG_NONNULL ((2)));
1517_GL_CXXALIAS_RPL (write, ssize_t, (int fd, const void *buf, size_t count)); 2277_GL_CXXALIAS_RPL (write, ssize_t, (int fd, const void *buf, size_t count));
2278# elif defined _WIN32 && !defined __CYGWIN__
2279# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2280# undef write
2281# define write _write
2282# endif
2283_GL_CXXALIAS_MDA (write, ssize_t, (int fd, const void *buf, size_t count));
2284# else
2285_GL_CXXALIAS_SYS (write, ssize_t, (int fd, const void *buf, size_t count));
2286# endif
2287_GL_CXXALIASWARN (write);
2288#elif @GNULIB_MDA_WRITE@
2289/* On native Windows, map 'write' to '_write', so that -loldnames is not
2290 required. In C++ with GNULIB_NAMESPACE, avoid differences between
2291 platforms by defining GNULIB_NAMESPACE::write always. */
2292# if defined _WIN32 && !defined __CYGWIN__
2293# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2294# undef write
2295# define write _write
2296# endif
2297# ifdef __MINGW32__
2298_GL_CXXALIAS_MDA (write, int, (int fd, const void *buf, unsigned int count));
2299# else
2300_GL_CXXALIAS_MDA (write, ssize_t, (int fd, const void *buf, unsigned int count));
2301# endif
1518# else 2302# else
1519/* Need to cast, because on mingw, the third parameter is 2303_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 2304# endif
1524_GL_CXXALIASWARN (write); 2305_GL_CXXALIASWARN (write);
1525#endif 2306#endif
@@ -1527,4 +2308,5 @@ _GL_CXXALIASWARN (write);
1527_GL_INLINE_HEADER_END 2308_GL_INLINE_HEADER_END
1528 2309
1529#endif /* _@GUARD_PREFIX@_UNISTD_H */ 2310#endif /* _@GUARD_PREFIX@_UNISTD_H */
2311#endif /* _GL_INCLUDING_UNISTD_H */
1530#endif /* _@GUARD_PREFIX@_UNISTD_H */ 2312#endif /* _@GUARD_PREFIX@_UNISTD_H */
diff --git a/gl/unlocked-io.h b/gl/unlocked-io.h
new file mode 100644
index 0000000..ca184b3
--- /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-2021 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..b2e910e 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-2021 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..d9b669d 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-2021 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
@@ -87,6 +100,7 @@
87/* Checked size_t computations. */ 100/* Checked size_t computations. */
88#include "xsize.h" 101#include "xsize.h"
89 102
103#include "attribute.h"
90#include "verify.h" 104#include "verify.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
@@ -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
@@ -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
@@ -849,7 +935,9 @@ convert_to_decimal (mpn_t a, size_t extra_zeroes)
849 size_t a_len = a.nlimbs; 935 size_t a_len = a.nlimbs;
850 /* 0.03345 is slightly larger than log(2)/(9*log(10)). */ 936 /* 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); 937 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)); 938 /* We need extra_zeroes bytes for zeroes, followed by c_len bytes for the
939 digits of a, followed by 1 byte for the terminating NUL. */
940 char *c_ptr = (char *) malloc (xsum (xsum (extra_zeroes, c_len), 1));
853 if (c_ptr != NULL) 941 if (c_ptr != NULL)
854 { 942 {
855 char *d_ptr = c_ptr; 943 char *d_ptr = c_ptr;
@@ -1517,7 +1605,7 @@ is_borderline (const char *digits, size_t precision)
1517 1605
1518#endif 1606#endif
1519 1607
1520#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 1608#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF
1521 1609
1522/* Use a different function name, to make it possible that the 'wchar_t' 1610/* Use a different function name, to make it possible that the 'wchar_t'
1523 parametrization and the 'char' parametrization get compiled in the same 1611 parametrization and the 'char' parametrization get compiled in the same
@@ -1540,16 +1628,13 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion,
1540 switch (conversion) 1628 switch (conversion)
1541 { 1629 {
1542 case 'd': case 'i': case 'u': 1630 case 'd': case 'i': case 'u':
1543# if HAVE_LONG_LONG_INT
1544 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) 1631 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
1545 tmp_length = 1632 tmp_length =
1546 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT 1633 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
1547 * 0.30103 /* binary -> decimal */ 1634 * 0.30103 /* binary -> decimal */
1548 ) 1635 )
1549 + 1; /* turn floor into ceil */ 1636 + 1; /* turn floor into ceil */
1550 else 1637 else if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
1551# endif
1552 if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
1553 tmp_length = 1638 tmp_length =
1554 (unsigned int) (sizeof (unsigned long) * CHAR_BIT 1639 (unsigned int) (sizeof (unsigned long) * CHAR_BIT
1555 * 0.30103 /* binary -> decimal */ 1640 * 0.30103 /* binary -> decimal */
@@ -1570,16 +1655,13 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion,
1570 break; 1655 break;
1571 1656
1572 case 'o': 1657 case 'o':
1573# if HAVE_LONG_LONG_INT
1574 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) 1658 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
1575 tmp_length = 1659 tmp_length =
1576 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT 1660 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
1577 * 0.333334 /* binary -> octal */ 1661 * 0.333334 /* binary -> octal */
1578 ) 1662 )
1579 + 1; /* turn floor into ceil */ 1663 + 1; /* turn floor into ceil */
1580 else 1664 else if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
1581# endif
1582 if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
1583 tmp_length = 1665 tmp_length =
1584 (unsigned int) (sizeof (unsigned long) * CHAR_BIT 1666 (unsigned int) (sizeof (unsigned long) * CHAR_BIT
1585 * 0.333334 /* binary -> octal */ 1667 * 0.333334 /* binary -> octal */
@@ -1598,16 +1680,13 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion,
1598 break; 1680 break;
1599 1681
1600 case 'x': case 'X': 1682 case 'x': case 'X':
1601# if HAVE_LONG_LONG_INT
1602 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) 1683 if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
1603 tmp_length = 1684 tmp_length =
1604 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT 1685 (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
1605 * 0.25 /* binary -> hexadecimal */ 1686 * 0.25 /* binary -> hexadecimal */
1606 ) 1687 )
1607 + 1; /* turn floor into ceil */ 1688 + 1; /* turn floor into ceil */
1608 else 1689 else if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
1609# endif
1610 if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
1611 tmp_length = 1690 tmp_length =
1612 (unsigned int) (sizeof (unsigned long) * CHAR_BIT 1691 (unsigned int) (sizeof (unsigned long) * CHAR_BIT
1613 * 0.25 /* binary -> hexadecimal */ 1692 * 0.25 /* binary -> hexadecimal */
@@ -1673,7 +1752,13 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion,
1673 case 'c': 1752 case 'c':
1674# if HAVE_WINT_T && !WIDE_CHAR_VERSION 1753# if HAVE_WINT_T && !WIDE_CHAR_VERSION
1675 if (type == TYPE_WIDE_CHAR) 1754 if (type == TYPE_WIDE_CHAR)
1676 tmp_length = MB_CUR_MAX; 1755 {
1756 tmp_length = MB_CUR_MAX;
1757# if ENABLE_WCHAR_FALLBACK
1758 if (tmp_length < (sizeof (wchar_t) > 2 ? 10 : 6))
1759 tmp_length = (sizeof (wchar_t) > 2 ? 10 : 6);
1760# endif
1761 }
1677 else 1762 else
1678# endif 1763# endif
1679 tmp_length = 1; 1764 tmp_length = 1;
@@ -1780,6 +1865,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
1780 /* errno is already set. */ 1865 /* errno is already set. */
1781 return NULL; 1866 return NULL;
1782 1867
1868 /* Frees the memory allocated by this function. Preserves errno. */
1783#define CLEANUP() \ 1869#define CLEANUP() \
1784 if (d.dir != d.direct_alloc_dir) \ 1870 if (d.dir != d.direct_alloc_dir) \
1785 free (d.dir); \ 1871 free (d.dir); \
@@ -1844,7 +1930,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
1844 1930
1845 /* Ensures that allocated >= needed. Aborts through a jump to 1931 /* Ensures that allocated >= needed. Aborts through a jump to
1846 out_of_memory if needed is SIZE_MAX or otherwise too big. */ 1932 out_of_memory if needed is SIZE_MAX or otherwise too big. */
1847#define ENSURE_ALLOCATION(needed) \ 1933#define ENSURE_ALLOCATION_ELSE(needed, oom_statement) \
1848 if ((needed) > allocated) \ 1934 if ((needed) > allocated) \
1849 { \ 1935 { \
1850 size_t memory_size; \ 1936 size_t memory_size; \
@@ -1855,17 +1941,19 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
1855 allocated = (needed); \ 1941 allocated = (needed); \
1856 memory_size = xtimes (allocated, sizeof (DCHAR_T)); \ 1942 memory_size = xtimes (allocated, sizeof (DCHAR_T)); \
1857 if (size_overflow_p (memory_size)) \ 1943 if (size_overflow_p (memory_size)) \
1858 goto out_of_memory; \ 1944 oom_statement \
1859 if (result == resultbuf || result == NULL) \ 1945 if (result == resultbuf || result == NULL) \
1860 memory = (DCHAR_T *) malloc (memory_size); \ 1946 memory = (DCHAR_T *) malloc (memory_size); \
1861 else \ 1947 else \
1862 memory = (DCHAR_T *) realloc (result, memory_size); \ 1948 memory = (DCHAR_T *) realloc (result, memory_size); \
1863 if (memory == NULL) \ 1949 if (memory == NULL) \
1864 goto out_of_memory; \ 1950 oom_statement \
1865 if (result == resultbuf && length > 0) \ 1951 if (result == resultbuf && length > 0) \
1866 DCHAR_CPY (memory, result, length); \ 1952 DCHAR_CPY (memory, result, length); \
1867 result = memory; \ 1953 result = memory; \
1868 } 1954 }
1955#define ENSURE_ALLOCATION(needed) \
1956 ENSURE_ALLOCATION_ELSE((needed), goto out_of_memory; )
1869 1957
1870 for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++) 1958 for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++)
1871 { 1959 {
@@ -1886,7 +1974,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
1886 else 1974 else
1887 { 1975 {
1888 do 1976 do
1889 result[length++] = (unsigned char) *cp++; 1977 result[length++] = *cp++;
1890 while (--n > 0); 1978 while (--n > 0);
1891 } 1979 }
1892 } 1980 }
@@ -1926,11 +2014,9 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
1926 case TYPE_COUNT_LONGINT_POINTER: 2014 case TYPE_COUNT_LONGINT_POINTER:
1927 *a.arg[dp->arg_index].a.a_count_longint_pointer = length; 2015 *a.arg[dp->arg_index].a.a_count_longint_pointer = length;
1928 break; 2016 break;
1929#if HAVE_LONG_LONG_INT
1930 case TYPE_COUNT_LONGLONGINT_POINTER: 2017 case TYPE_COUNT_LONGLONGINT_POINTER:
1931 *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length; 2018 *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length;
1932 break; 2019 break;
1933#endif
1934 default: 2020 default:
1935 abort (); 2021 abort ();
1936 } 2022 }
@@ -1957,15 +2043,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
1957 if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) 2043 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
1958 abort (); 2044 abort ();
1959 arg = a.arg[dp->width_arg_index].a.a_int; 2045 arg = a.arg[dp->width_arg_index].a.a_int;
2046 width = arg;
1960 if (arg < 0) 2047 if (arg < 0)
1961 { 2048 {
1962 /* "A negative field width is taken as a '-' flag 2049 /* "A negative field width is taken as a '-' flag
1963 followed by a positive field width." */ 2050 followed by a positive field width." */
1964 flags |= FLAG_LEFT; 2051 flags |= FLAG_LEFT;
1965 width = (unsigned int) (-arg); 2052 width = -width;
1966 } 2053 }
1967 else
1968 width = arg;
1969 } 2054 }
1970 else 2055 else
1971 { 2056 {
@@ -2073,8 +2158,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2073 characters = 0; 2158 characters = 0;
2074 } 2159 }
2075 2160
2076 if (has_width && width > characters 2161 if (characters < width && !(dp->flags & FLAG_LEFT))
2077 && !(dp->flags & FLAG_LEFT))
2078 { 2162 {
2079 size_t n = width - characters; 2163 size_t n = width - characters;
2080 ENSURE_ALLOCATION (xsum (length, n)); 2164 ENSURE_ALLOCATION (xsum (length, n));
@@ -2108,18 +2192,17 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2108# endif 2192# endif
2109 if (converted == NULL) 2193 if (converted == NULL)
2110 { 2194 {
2111 int saved_errno = errno;
2112 if (!(result == resultbuf || result == NULL)) 2195 if (!(result == resultbuf || result == NULL))
2113 free (result); 2196 free (result);
2114 if (buf_malloced != NULL) 2197 if (buf_malloced != NULL)
2115 free (buf_malloced); 2198 free (buf_malloced);
2116 CLEANUP (); 2199 CLEANUP ();
2117 errno = saved_errno;
2118 return NULL; 2200 return NULL;
2119 } 2201 }
2120 if (converted != result + length) 2202 if (converted != result + length)
2121 { 2203 {
2122 ENSURE_ALLOCATION (xsum (length, converted_len)); 2204 ENSURE_ALLOCATION_ELSE (xsum (length, converted_len),
2205 { free (converted); goto out_of_memory; });
2123 DCHAR_CPY (result + length, converted, converted_len); 2206 DCHAR_CPY (result + length, converted, converted_len);
2124 free (converted); 2207 free (converted);
2125 } 2208 }
@@ -2127,8 +2210,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2127 } 2210 }
2128# endif 2211# endif
2129 2212
2130 if (has_width && width > characters 2213 if (characters < width && (dp->flags & FLAG_LEFT))
2131 && (dp->flags & FLAG_LEFT))
2132 { 2214 {
2133 size_t n = width - characters; 2215 size_t n = width - characters;
2134 ENSURE_ALLOCATION (xsum (length, n)); 2216 ENSURE_ALLOCATION (xsum (length, n));
@@ -2201,8 +2283,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2201 characters = 0; 2283 characters = 0;
2202 } 2284 }
2203 2285
2204 if (has_width && width > characters 2286 if (characters < width && !(dp->flags & FLAG_LEFT))
2205 && !(dp->flags & FLAG_LEFT))
2206 { 2287 {
2207 size_t n = width - characters; 2288 size_t n = width - characters;
2208 ENSURE_ALLOCATION (xsum (length, n)); 2289 ENSURE_ALLOCATION (xsum (length, n));
@@ -2236,18 +2317,17 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2236# endif 2317# endif
2237 if (converted == NULL) 2318 if (converted == NULL)
2238 { 2319 {
2239 int saved_errno = errno;
2240 if (!(result == resultbuf || result == NULL)) 2320 if (!(result == resultbuf || result == NULL))
2241 free (result); 2321 free (result);
2242 if (buf_malloced != NULL) 2322 if (buf_malloced != NULL)
2243 free (buf_malloced); 2323 free (buf_malloced);
2244 CLEANUP (); 2324 CLEANUP ();
2245 errno = saved_errno;
2246 return NULL; 2325 return NULL;
2247 } 2326 }
2248 if (converted != result + length) 2327 if (converted != result + length)
2249 { 2328 {
2250 ENSURE_ALLOCATION (xsum (length, converted_len)); 2329 ENSURE_ALLOCATION_ELSE (xsum (length, converted_len),
2330 { free (converted); goto out_of_memory; });
2251 DCHAR_CPY (result + length, converted, converted_len); 2331 DCHAR_CPY (result + length, converted, converted_len);
2252 free (converted); 2332 free (converted);
2253 } 2333 }
@@ -2255,8 +2335,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2255 } 2335 }
2256# endif 2336# endif
2257 2337
2258 if (has_width && width > characters 2338 if (characters < width && (dp->flags & FLAG_LEFT))
2259 && (dp->flags & FLAG_LEFT))
2260 { 2339 {
2261 size_t n = width - characters; 2340 size_t n = width - characters;
2262 ENSURE_ALLOCATION (xsum (length, n)); 2341 ENSURE_ALLOCATION (xsum (length, n));
@@ -2329,8 +2408,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2329 characters = 0; 2408 characters = 0;
2330 } 2409 }
2331 2410
2332 if (has_width && width > characters 2411 if (characters < width && !(dp->flags & FLAG_LEFT))
2333 && !(dp->flags & FLAG_LEFT))
2334 { 2412 {
2335 size_t n = width - characters; 2413 size_t n = width - characters;
2336 ENSURE_ALLOCATION (xsum (length, n)); 2414 ENSURE_ALLOCATION (xsum (length, n));
@@ -2364,18 +2442,17 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2364# endif 2442# endif
2365 if (converted == NULL) 2443 if (converted == NULL)
2366 { 2444 {
2367 int saved_errno = errno;
2368 if (!(result == resultbuf || result == NULL)) 2445 if (!(result == resultbuf || result == NULL))
2369 free (result); 2446 free (result);
2370 if (buf_malloced != NULL) 2447 if (buf_malloced != NULL)
2371 free (buf_malloced); 2448 free (buf_malloced);
2372 CLEANUP (); 2449 CLEANUP ();
2373 errno = saved_errno;
2374 return NULL; 2450 return NULL;
2375 } 2451 }
2376 if (converted != result + length) 2452 if (converted != result + length)
2377 { 2453 {
2378 ENSURE_ALLOCATION (xsum (length, converted_len)); 2454 ENSURE_ALLOCATION_ELSE (xsum (length, converted_len),
2455 { free (converted); goto out_of_memory; });
2379 DCHAR_CPY (result + length, converted, converted_len); 2456 DCHAR_CPY (result + length, converted, converted_len);
2380 free (converted); 2457 free (converted);
2381 } 2458 }
@@ -2383,8 +2460,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2383 } 2460 }
2384# endif 2461# endif
2385 2462
2386 if (has_width && width > characters 2463 if (characters < width && (dp->flags & FLAG_LEFT))
2387 && (dp->flags & FLAG_LEFT))
2388 { 2464 {
2389 size_t n = width - characters; 2465 size_t n = width - characters;
2390 ENSURE_ALLOCATION (xsum (length, n)); 2466 ENSURE_ALLOCATION (xsum (length, n));
@@ -2399,7 +2475,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2399 } 2475 }
2400 } 2476 }
2401#endif 2477#endif
2402#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && HAVE_WCHAR_T 2478#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' 2479 else if (dp->conversion == 's'
2404# if WIDE_CHAR_VERSION 2480# if WIDE_CHAR_VERSION
2405 && a.arg[dp->arg_index].type != TYPE_WIDE_STRING 2481 && a.arg[dp->arg_index].type != TYPE_WIDE_STRING
@@ -2435,15 +2511,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2435 if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) 2511 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
2436 abort (); 2512 abort ();
2437 arg = a.arg[dp->width_arg_index].a.a_int; 2513 arg = a.arg[dp->width_arg_index].a.a_int;
2514 width = arg;
2438 if (arg < 0) 2515 if (arg < 0)
2439 { 2516 {
2440 /* "A negative field width is taken as a '-' flag 2517 /* "A negative field width is taken as a '-' flag
2441 followed by a positive field width." */ 2518 followed by a positive field width." */
2442 flags |= FLAG_LEFT; 2519 flags |= FLAG_LEFT;
2443 width = (unsigned int) (-arg); 2520 width = -width;
2444 } 2521 }
2445 else
2446 width = arg;
2447 } 2522 }
2448 else 2523 else
2449 { 2524 {
@@ -2573,8 +2648,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2573 characters = 0; 2648 characters = 0;
2574 } 2649 }
2575 2650
2576 if (has_width && width > characters 2651 if (characters < width && !(dp->flags & FLAG_LEFT))
2577 && !(dp->flags & FLAG_LEFT))
2578 { 2652 {
2579 size_t n = width - characters; 2653 size_t n = width - characters;
2580 ENSURE_ALLOCATION (xsum (length, n)); 2654 ENSURE_ALLOCATION (xsum (length, n));
@@ -2635,8 +2709,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2635 } 2709 }
2636 } 2710 }
2637 2711
2638 if (has_width && width > characters 2712 if (characters < width && (dp->flags & FLAG_LEFT))
2639 && (dp->flags & FLAG_LEFT))
2640 { 2713 {
2641 size_t n = width - characters; 2714 size_t n = width - characters;
2642 ENSURE_ALLOCATION (xsum (length, n)); 2715 ENSURE_ALLOCATION (xsum (length, n));
@@ -2677,11 +2750,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2677 if (*arg_end == 0) 2750 if (*arg_end == 0)
2678 /* Found the terminating null wide character. */ 2751 /* Found the terminating null wide character. */
2679 break; 2752 break;
2680# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t 2753 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) 2754 if (count < 0)
2686 { 2755 {
2687 /* Cannot convert. */ 2756 /* Cannot convert. */
@@ -2693,7 +2762,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2693 errno = EILSEQ; 2762 errno = EILSEQ;
2694 return NULL; 2763 return NULL;
2695 } 2764 }
2696 if (precision < count) 2765 if (precision < (unsigned int) count)
2697 break; 2766 break;
2698 arg_end++; 2767 arg_end++;
2699 characters += count; 2768 characters += count;
@@ -2722,11 +2791,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2722 if (*arg_end == 0) 2791 if (*arg_end == 0)
2723 /* Found the terminating null wide character. */ 2792 /* Found the terminating null wide character. */
2724 break; 2793 break;
2725# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t 2794 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) 2795 if (count < 0)
2731 { 2796 {
2732 /* Cannot convert. */ 2797 /* Cannot convert. */
@@ -2771,11 +2836,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2771 2836
2772 if (*arg == 0) 2837 if (*arg == 0)
2773 abort (); 2838 abort ();
2774# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t 2839 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) 2840 if (count <= 0)
2780 /* Inconsistency. */ 2841 /* Inconsistency. */
2781 abort (); 2842 abort ();
@@ -2797,14 +2858,12 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2797 NULL, &tmpdst_len); 2858 NULL, &tmpdst_len);
2798 if (tmpdst == NULL) 2859 if (tmpdst == NULL)
2799 { 2860 {
2800 int saved_errno = errno;
2801 free (tmpsrc); 2861 free (tmpsrc);
2802 if (!(result == resultbuf || result == NULL)) 2862 if (!(result == resultbuf || result == NULL))
2803 free (result); 2863 free (result);
2804 if (buf_malloced != NULL) 2864 if (buf_malloced != NULL)
2805 free (buf_malloced); 2865 free (buf_malloced);
2806 CLEANUP (); 2866 CLEANUP ();
2807 errno = saved_errno;
2808 return NULL; 2867 return NULL;
2809 } 2868 }
2810 free (tmpsrc); 2869 free (tmpsrc);
@@ -2827,8 +2886,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2827 /* w doesn't matter. */ 2886 /* w doesn't matter. */
2828 w = 0; 2887 w = 0;
2829 2888
2830 if (has_width && width > w 2889 if (w < width && !(dp->flags & FLAG_LEFT))
2831 && !(dp->flags & FLAG_LEFT))
2832 { 2890 {
2833 size_t n = width - w; 2891 size_t n = width - w;
2834 ENSURE_ALLOCATION (xsum (length, n)); 2892 ENSURE_ALLOCATION (xsum (length, n));
@@ -2853,11 +2911,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2853 2911
2854 if (*arg == 0) 2912 if (*arg == 0)
2855 abort (); 2913 abort ();
2856# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t 2914 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) 2915 if (count <= 0)
2862 /* Inconsistency. */ 2916 /* Inconsistency. */
2863 abort (); 2917 abort ();
@@ -2882,11 +2936,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2882 2936
2883 if (*arg == 0) 2937 if (*arg == 0)
2884 abort (); 2938 abort ();
2885# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t 2939 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) 2940 if (count <= 0)
2891 { 2941 {
2892 /* Cannot convert. */ 2942 /* Cannot convert. */
@@ -2905,14 +2955,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2905 } 2955 }
2906 } 2956 }
2907# else 2957# else
2908 ENSURE_ALLOCATION (xsum (length, tmpdst_len)); 2958 ENSURE_ALLOCATION_ELSE (xsum (length, tmpdst_len),
2959 { free (tmpdst); goto out_of_memory; });
2909 DCHAR_CPY (result + length, tmpdst, tmpdst_len); 2960 DCHAR_CPY (result + length, tmpdst, tmpdst_len);
2910 free (tmpdst); 2961 free (tmpdst);
2911 length += tmpdst_len; 2962 length += tmpdst_len;
2912# endif 2963# endif
2913 2964
2914 if (has_width && width > w 2965 if (w < width && (dp->flags & FLAG_LEFT))
2915 && (dp->flags & FLAG_LEFT))
2916 { 2966 {
2917 size_t n = width - w; 2967 size_t n = width - w;
2918 ENSURE_ALLOCATION (xsum (length, n)); 2968 ENSURE_ALLOCATION (xsum (length, n));
@@ -2923,6 +2973,209 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2923# endif 2973# endif
2924 } 2974 }
2925#endif 2975#endif
2976#if ENABLE_WCHAR_FALLBACK && HAVE_WINT_T && !WIDE_CHAR_VERSION
2977 else if (dp->conversion == 'c'
2978 && a.arg[dp->arg_index].type == TYPE_WIDE_CHAR)
2979 {
2980 /* Implement the 'lc' directive ourselves, in order to provide
2981 the fallback that avoids EILSEQ. */
2982 int flags = dp->flags;
2983 int has_width;
2984 size_t width;
2985
2986 has_width = 0;
2987 width = 0;
2988 if (dp->width_start != dp->width_end)
2989 {
2990 if (dp->width_arg_index != ARG_NONE)
2991 {
2992 int arg;
2993
2994 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
2995 abort ();
2996 arg = a.arg[dp->width_arg_index].a.a_int;
2997 width = arg;
2998 if (arg < 0)
2999 {
3000 /* "A negative field width is taken as a '-' flag
3001 followed by a positive field width." */
3002 flags |= FLAG_LEFT;
3003 width = -width;
3004 }
3005 }
3006 else
3007 {
3008 const FCHAR_T *digitp = dp->width_start;
3009
3010 do
3011 width = xsum (xtimes (width, 10), *digitp++ - '0');
3012 while (digitp != dp->width_end);
3013 }
3014 has_width = 1;
3015 }
3016
3017 /* %lc in vasnprintf. See the specification of fprintf. */
3018 {
3019 wchar_t arg = (wchar_t) a.arg[dp->arg_index].a.a_wide_char;
3020 size_t characters;
3021# if !DCHAR_IS_TCHAR
3022 /* This code assumes that TCHAR_T is 'char'. */
3023 verify (sizeof (TCHAR_T) == 1);
3024 TCHAR_T tmpsrc[64]; /* Assume MB_CUR_MAX <= 64. */
3025 DCHAR_T *tmpdst;
3026 size_t tmpdst_len;
3027# endif
3028 size_t w;
3029
3030# if DCHAR_IS_TCHAR
3031 if (has_width)
3032# endif
3033 {
3034 /* Count the number of bytes. */
3035 characters = 0;
3036 if (arg != 0)
3037 {
3038 char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
3039 int count;
3040# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
3041 mbstate_t state;
3042 memset (&state, '\0', sizeof (mbstate_t));
3043# endif
3044
3045 count = local_wcrtomb (cbuf, arg, &state);
3046 if (count < 0)
3047 /* Inconsistency. */
3048 abort ();
3049 characters = count;
3050 }
3051 }
3052# if DCHAR_IS_TCHAR
3053 else
3054 {
3055 /* The number of bytes doesn't matter. */
3056 characters = 0;
3057 }
3058# endif
3059
3060# if !DCHAR_IS_TCHAR
3061 /* Convert the string into a piece of temporary memory. */
3062 if (characters > 0) /* implies arg != 0 */
3063 {
3064 char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
3065 int count;
3066# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
3067 mbstate_t state;
3068 memset (&state, '\0', sizeof (mbstate_t));
3069# endif
3070
3071 count = local_wcrtomb (cbuf, arg, &state);
3072 if (count <= 0)
3073 /* Inconsistency. */
3074 abort ();
3075 memcpy (tmpsrc, cbuf, count);
3076 }
3077
3078 /* Convert from TCHAR_T[] to DCHAR_T[]. */
3079 tmpdst =
3080 DCHAR_CONV_FROM_ENCODING (locale_charset (),
3081 iconveh_question_mark,
3082 tmpsrc, characters,
3083 NULL,
3084 NULL, &tmpdst_len);
3085 if (tmpdst == NULL)
3086 {
3087 if (!(result == resultbuf || result == NULL))
3088 free (result);
3089 if (buf_malloced != NULL)
3090 free (buf_malloced);
3091 CLEANUP ();
3092 return NULL;
3093 }
3094# endif
3095
3096 if (has_width)
3097 {
3098# if ENABLE_UNISTDIO
3099 /* Outside POSIX, it's preferable to compare the width
3100 against the number of _characters_ of the converted
3101 value. */
3102 w = DCHAR_MBSNLEN (result + length, characters);
3103# else
3104 /* The width is compared against the number of _bytes_
3105 of the converted value, says POSIX. */
3106 w = characters;
3107# endif
3108 }
3109 else
3110 /* w doesn't matter. */
3111 w = 0;
3112
3113 if (w < width && !(dp->flags & FLAG_LEFT))
3114 {
3115 size_t n = width - w;
3116 ENSURE_ALLOCATION (xsum (length, n));
3117 DCHAR_SET (result + length, ' ', n);
3118 length += n;
3119 }
3120
3121# if DCHAR_IS_TCHAR
3122 if (has_width)
3123 {
3124 /* We know the number of bytes in advance. */
3125 ENSURE_ALLOCATION (xsum (length, characters));
3126 if (characters > 0) /* implies arg != 0 */
3127 {
3128 int count;
3129# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
3130 mbstate_t state;
3131 memset (&state, '\0', sizeof (mbstate_t));
3132# endif
3133
3134 count = local_wcrtomb (result + length, arg, &state);
3135 if (count <= 0)
3136 /* Inconsistency. */
3137 abort ();
3138 length += count;
3139 }
3140 }
3141 else
3142 {
3143 if (arg != 0)
3144 {
3145 char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */
3146 int count;
3147# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t
3148 mbstate_t state;
3149 memset (&state, '\0', sizeof (mbstate_t));
3150# endif
3151
3152 count = local_wcrtomb (cbuf, arg, &state);
3153 if (count <= 0)
3154 /* Inconsistency. */
3155 abort ();
3156 ENSURE_ALLOCATION (xsum (length, count));
3157 memcpy (result + length, cbuf, count);
3158 length += count;
3159 }
3160 }
3161# else
3162 ENSURE_ALLOCATION_ELSE (xsum (length, tmpdst_len),
3163 { free (tmpdst); goto out_of_memory; });
3164 DCHAR_CPY (result + length, tmpdst, tmpdst_len);
3165 free (tmpdst);
3166 length += tmpdst_len;
3167# endif
3168
3169 if (w < width && (dp->flags & FLAG_LEFT))
3170 {
3171 size_t n = width - w;
3172 ENSURE_ALLOCATION (xsum (length, n));
3173 DCHAR_SET (result + length, ' ', n);
3174 length += n;
3175 }
3176 }
3177 }
3178#endif
2926#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL 3179#if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL
2927 else if ((dp->conversion == 'a' || dp->conversion == 'A') 3180 else if ((dp->conversion == 'a' || dp->conversion == 'A')
2928# if !(NEED_PRINTF_DIRECTIVE_A || (NEED_PRINTF_LONG_DOUBLE && NEED_PRINTF_DOUBLE)) 3181# if !(NEED_PRINTF_DIRECTIVE_A || (NEED_PRINTF_LONG_DOUBLE && NEED_PRINTF_DOUBLE))
@@ -2939,17 +3192,16 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2939 { 3192 {
2940 arg_type type = a.arg[dp->arg_index].type; 3193 arg_type type = a.arg[dp->arg_index].type;
2941 int flags = dp->flags; 3194 int flags = dp->flags;
2942 int has_width;
2943 size_t width; 3195 size_t width;
2944 int has_precision; 3196 int has_precision;
2945 size_t precision; 3197 size_t precision;
2946 size_t tmp_length; 3198 size_t tmp_length;
3199 size_t count;
2947 DCHAR_T tmpbuf[700]; 3200 DCHAR_T tmpbuf[700];
2948 DCHAR_T *tmp; 3201 DCHAR_T *tmp;
2949 DCHAR_T *pad_ptr; 3202 DCHAR_T *pad_ptr;
2950 DCHAR_T *p; 3203 DCHAR_T *p;
2951 3204
2952 has_width = 0;
2953 width = 0; 3205 width = 0;
2954 if (dp->width_start != dp->width_end) 3206 if (dp->width_start != dp->width_end)
2955 { 3207 {
@@ -2960,15 +3212,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2960 if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) 3212 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
2961 abort (); 3213 abort ();
2962 arg = a.arg[dp->width_arg_index].a.a_int; 3214 arg = a.arg[dp->width_arg_index].a.a_int;
3215 width = arg;
2963 if (arg < 0) 3216 if (arg < 0)
2964 { 3217 {
2965 /* "A negative field width is taken as a '-' flag 3218 /* "A negative field width is taken as a '-' flag
2966 followed by a positive field width." */ 3219 followed by a positive field width." */
2967 flags |= FLAG_LEFT; 3220 flags |= FLAG_LEFT;
2968 width = (unsigned int) (-arg); 3221 width = -width;
2969 } 3222 }
2970 else
2971 width = arg;
2972 } 3223 }
2973 else 3224 else
2974 { 3225 {
@@ -2978,7 +3229,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
2978 width = xsum (xtimes (width, 10), *digitp++ - '0'); 3229 width = xsum (xtimes (width, 10), *digitp++ - '0');
2979 while (digitp != dp->width_end); 3230 while (digitp != dp->width_end);
2980 } 3231 }
2981 has_width = 1;
2982 } 3232 }
2983 3233
2984 has_precision = 0; 3234 has_precision = 0;
@@ -3354,11 +3604,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
3354 abort (); 3604 abort ();
3355# endif 3605# endif
3356 } 3606 }
3607
3357 /* The generated string now extends from tmp to p, with the 3608 /* The generated string now extends from tmp to p, with the
3358 zero padding insertion point being at pad_ptr. */ 3609 zero padding insertion point being at pad_ptr. */
3359 if (has_width && p - tmp < width) 3610 count = p - tmp;
3611
3612 if (count < width)
3360 { 3613 {
3361 size_t pad = width - (p - tmp); 3614 size_t pad = width - count;
3362 DCHAR_T *end = p + pad; 3615 DCHAR_T *end = p + pad;
3363 3616
3364 if (flags & FLAG_LEFT) 3617 if (flags & FLAG_LEFT)
@@ -3391,28 +3644,26 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
3391 p = end; 3644 p = end;
3392 } 3645 }
3393 3646
3394 { 3647 count = p - tmp;
3395 size_t count = p - tmp;
3396 3648
3397 if (count >= tmp_length) 3649 if (count >= tmp_length)
3398 /* tmp_length was incorrectly calculated - fix the 3650 /* tmp_length was incorrectly calculated - fix the
3399 code above! */ 3651 code above! */
3400 abort (); 3652 abort ();
3401 3653
3402 /* Make room for the result. */ 3654 /* Make room for the result. */
3403 if (count >= allocated - length) 3655 if (count >= allocated - length)
3404 { 3656 {
3405 size_t n = xsum (length, count); 3657 size_t n = xsum (length, count);
3406 3658
3407 ENSURE_ALLOCATION (n); 3659 ENSURE_ALLOCATION (n);
3408 } 3660 }
3409 3661
3410 /* Append the result. */ 3662 /* Append the result. */
3411 memcpy (result + length, tmp, count * sizeof (DCHAR_T)); 3663 memcpy (result + length, tmp, count * sizeof (DCHAR_T));
3412 if (tmp != tmpbuf) 3664 if (tmp != tmpbuf)
3413 free (tmp); 3665 free (tmp);
3414 length += count; 3666 length += count;
3415 }
3416 } 3667 }
3417#endif 3668#endif
3418#if (NEED_PRINTF_INFINITE_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL 3669#if (NEED_PRINTF_INFINITE_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL
@@ -3446,8 +3697,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
3446 arg_type type = a.arg[dp->arg_index].type; 3697 arg_type type = a.arg[dp->arg_index].type;
3447# endif 3698# endif
3448 int flags = dp->flags; 3699 int flags = dp->flags;
3449 int has_width;
3450 size_t width; 3700 size_t width;
3701 size_t count;
3451 int has_precision; 3702 int has_precision;
3452 size_t precision; 3703 size_t precision;
3453 size_t tmp_length; 3704 size_t tmp_length;
@@ -3456,7 +3707,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
3456 DCHAR_T *pad_ptr; 3707 DCHAR_T *pad_ptr;
3457 DCHAR_T *p; 3708 DCHAR_T *p;
3458 3709
3459 has_width = 0;
3460 width = 0; 3710 width = 0;
3461 if (dp->width_start != dp->width_end) 3711 if (dp->width_start != dp->width_end)
3462 { 3712 {
@@ -3467,15 +3717,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
3467 if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) 3717 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
3468 abort (); 3718 abort ();
3469 arg = a.arg[dp->width_arg_index].a.a_int; 3719 arg = a.arg[dp->width_arg_index].a.a_int;
3720 width = arg;
3470 if (arg < 0) 3721 if (arg < 0)
3471 { 3722 {
3472 /* "A negative field width is taken as a '-' flag 3723 /* "A negative field width is taken as a '-' flag
3473 followed by a positive field width." */ 3724 followed by a positive field width." */
3474 flags |= FLAG_LEFT; 3725 flags |= FLAG_LEFT;
3475 width = (unsigned int) (-arg); 3726 width = -width;
3476 } 3727 }
3477 else
3478 width = arg;
3479 } 3728 }
3480 else 3729 else
3481 { 3730 {
@@ -3485,7 +3734,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
3485 width = xsum (xtimes (width, 10), *digitp++ - '0'); 3734 width = xsum (xtimes (width, 10), *digitp++ - '0');
3486 while (digitp != dp->width_end); 3735 while (digitp != dp->width_end);
3487 } 3736 }
3488 has_width = 1;
3489 } 3737 }
3490 3738
3491 has_precision = 0; 3739 has_precision = 0;
@@ -3925,9 +4173,9 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
3925 digits without trailing zeroes. */ 4173 digits without trailing zeroes. */
3926 if (exponent >= 0) 4174 if (exponent >= 0)
3927 { 4175 {
3928 size_t count = exponent + 1; 4176 size_t ecount = exponent + 1;
3929 /* Note: count <= precision = ndigits. */ 4177 /* Note: count <= precision = ndigits. */
3930 for (; count > 0; count--) 4178 for (; ecount > 0; ecount--)
3931 *p++ = digits[--ndigits]; 4179 *p++ = digits[--ndigits];
3932 if ((flags & FLAG_ALT) || ndigits > nzeroes) 4180 if ((flags & FLAG_ALT) || ndigits > nzeroes)
3933 { 4181 {
@@ -3941,10 +4189,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
3941 } 4189 }
3942 else 4190 else
3943 { 4191 {
3944 size_t count = -exponent - 1; 4192 size_t ecount = -exponent - 1;
3945 *p++ = '0'; 4193 *p++ = '0';
3946 *p++ = decimal_point_char (); 4194 *p++ = decimal_point_char ();
3947 for (; count > 0; count--) 4195 for (; ecount > 0; ecount--)
3948 *p++ = '0'; 4196 *p++ = '0';
3949 while (ndigits > nzeroes) 4197 while (ndigits > nzeroes)
3950 { 4198 {
@@ -4249,7 +4497,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4249 static const wchar_t decimal_format[] = 4497 static const wchar_t decimal_format[] =
4250 /* Produce the same number of exponent digits 4498 /* Produce the same number of exponent digits
4251 as the native printf implementation. */ 4499 as the native printf implementation. */
4252# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 4500# if defined _WIN32 && ! defined __CYGWIN__
4253 { '%', '+', '.', '3', 'd', '\0' }; 4501 { '%', '+', '.', '3', 'd', '\0' };
4254# else 4502# else
4255 { '%', '+', '.', '2', 'd', '\0' }; 4503 { '%', '+', '.', '2', 'd', '\0' };
@@ -4263,7 +4511,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4263 static const char decimal_format[] = 4511 static const char decimal_format[] =
4264 /* Produce the same number of exponent digits 4512 /* Produce the same number of exponent digits
4265 as the native printf implementation. */ 4513 as the native printf implementation. */
4266# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 4514# if defined _WIN32 && ! defined __CYGWIN__
4267 "%+.3d"; 4515 "%+.3d";
4268# else 4516# else
4269 "%+.2d"; 4517 "%+.2d";
@@ -4395,9 +4643,9 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4395 digits without trailing zeroes. */ 4643 digits without trailing zeroes. */
4396 if (exponent >= 0) 4644 if (exponent >= 0)
4397 { 4645 {
4398 size_t count = exponent + 1; 4646 size_t ecount = exponent + 1;
4399 /* Note: count <= precision = ndigits. */ 4647 /* Note: ecount <= precision = ndigits. */
4400 for (; count > 0; count--) 4648 for (; ecount > 0; ecount--)
4401 *p++ = digits[--ndigits]; 4649 *p++ = digits[--ndigits];
4402 if ((flags & FLAG_ALT) || ndigits > nzeroes) 4650 if ((flags & FLAG_ALT) || ndigits > nzeroes)
4403 { 4651 {
@@ -4411,10 +4659,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4411 } 4659 }
4412 else 4660 else
4413 { 4661 {
4414 size_t count = -exponent - 1; 4662 size_t ecount = -exponent - 1;
4415 *p++ = '0'; 4663 *p++ = '0';
4416 *p++ = decimal_point_char (); 4664 *p++ = decimal_point_char ();
4417 for (; count > 0; count--) 4665 for (; ecount > 0; ecount--)
4418 *p++ = '0'; 4666 *p++ = '0';
4419 while (ndigits > nzeroes) 4667 while (ndigits > nzeroes)
4420 { 4668 {
@@ -4442,7 +4690,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4442 static const wchar_t decimal_format[] = 4690 static const wchar_t decimal_format[] =
4443 /* Produce the same number of exponent digits 4691 /* Produce the same number of exponent digits
4444 as the native printf implementation. */ 4692 as the native printf implementation. */
4445# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 4693# if defined _WIN32 && ! defined __CYGWIN__
4446 { '%', '+', '.', '3', 'd', '\0' }; 4694 { '%', '+', '.', '3', 'd', '\0' };
4447# else 4695# else
4448 { '%', '+', '.', '2', 'd', '\0' }; 4696 { '%', '+', '.', '2', 'd', '\0' };
@@ -4456,7 +4704,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4456 static const char decimal_format[] = 4704 static const char decimal_format[] =
4457 /* Produce the same number of exponent digits 4705 /* Produce the same number of exponent digits
4458 as the native printf implementation. */ 4706 as the native printf implementation. */
4459# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 4707# if defined _WIN32 && ! defined __CYGWIN__
4460 "%+.3d"; 4708 "%+.3d";
4461# else 4709# else
4462 "%+.2d"; 4710 "%+.2d";
@@ -4514,7 +4762,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4514 *p++ = '+'; 4762 *p++ = '+';
4515 /* Produce the same number of exponent digits as 4763 /* Produce the same number of exponent digits as
4516 the native printf implementation. */ 4764 the native printf implementation. */
4517# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 4765# if defined _WIN32 && ! defined __CYGWIN__
4518 *p++ = '0'; 4766 *p++ = '0';
4519# endif 4767# endif
4520 *p++ = '0'; 4768 *p++ = '0';
@@ -4542,9 +4790,11 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4542 4790
4543 /* The generated string now extends from tmp to p, with the 4791 /* The generated string now extends from tmp to p, with the
4544 zero padding insertion point being at pad_ptr. */ 4792 zero padding insertion point being at pad_ptr. */
4545 if (has_width && p - tmp < width) 4793 count = p - tmp;
4794
4795 if (count < width)
4546 { 4796 {
4547 size_t pad = width - (p - tmp); 4797 size_t pad = width - count;
4548 DCHAR_T *end = p + pad; 4798 DCHAR_T *end = p + pad;
4549 4799
4550 if (flags & FLAG_LEFT) 4800 if (flags & FLAG_LEFT)
@@ -4577,39 +4827,39 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4577 p = end; 4827 p = end;
4578 } 4828 }
4579 4829
4580 { 4830 count = p - tmp;
4581 size_t count = p - tmp;
4582 4831
4583 if (count >= tmp_length) 4832 if (count >= tmp_length)
4584 /* tmp_length was incorrectly calculated - fix the 4833 /* tmp_length was incorrectly calculated - fix the
4585 code above! */ 4834 code above! */
4586 abort (); 4835 abort ();
4587 4836
4588 /* Make room for the result. */ 4837 /* Make room for the result. */
4589 if (count >= allocated - length) 4838 if (count >= allocated - length)
4590 { 4839 {
4591 size_t n = xsum (length, count); 4840 size_t n = xsum (length, count);
4592 4841
4593 ENSURE_ALLOCATION (n); 4842 ENSURE_ALLOCATION (n);
4594 } 4843 }
4595 4844
4596 /* Append the result. */ 4845 /* Append the result. */
4597 memcpy (result + length, tmp, count * sizeof (DCHAR_T)); 4846 memcpy (result + length, tmp, count * sizeof (DCHAR_T));
4598 if (tmp != tmpbuf) 4847 if (tmp != tmpbuf)
4599 free (tmp); 4848 free (tmp);
4600 length += count; 4849 length += count;
4601 }
4602 } 4850 }
4603#endif 4851#endif
4604 else 4852 else
4605 { 4853 {
4606 arg_type type = a.arg[dp->arg_index].type; 4854 arg_type type = a.arg[dp->arg_index].type;
4607 int flags = dp->flags; 4855 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 4856#if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
4609 int has_width; 4857 int has_width;
4858#endif
4859#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; 4860 size_t width;
4611#endif 4861#endif
4612#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || NEED_PRINTF_UNBOUNDED_PRECISION 4862#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION
4613 int has_precision; 4863 int has_precision;
4614 size_t precision; 4864 size_t precision;
4615#endif 4865#endif
@@ -4635,8 +4885,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4635 TCHAR_T *tmp; 4885 TCHAR_T *tmp;
4636#endif 4886#endif
4637 4887
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 4888#if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
4639 has_width = 0; 4889 has_width = 0;
4890#endif
4891#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; 4892 width = 0;
4641 if (dp->width_start != dp->width_end) 4893 if (dp->width_start != dp->width_end)
4642 { 4894 {
@@ -4647,15 +4899,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4647 if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) 4899 if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
4648 abort (); 4900 abort ();
4649 arg = a.arg[dp->width_arg_index].a.a_int; 4901 arg = a.arg[dp->width_arg_index].a.a_int;
4902 width = arg;
4650 if (arg < 0) 4903 if (arg < 0)
4651 { 4904 {
4652 /* "A negative field width is taken as a '-' flag 4905 /* "A negative field width is taken as a '-' flag
4653 followed by a positive field width." */ 4906 followed by a positive field width." */
4654 flags |= FLAG_LEFT; 4907 flags |= FLAG_LEFT;
4655 width = (unsigned int) (-arg); 4908 width = -width;
4656 } 4909 }
4657 else
4658 width = arg;
4659 } 4910 }
4660 else 4911 else
4661 { 4912 {
@@ -4665,11 +4916,13 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4665 width = xsum (xtimes (width, 10), *digitp++ - '0'); 4916 width = xsum (xtimes (width, 10), *digitp++ - '0');
4666 while (digitp != dp->width_end); 4917 while (digitp != dp->width_end);
4667 } 4918 }
4919#if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION
4668 has_width = 1; 4920 has_width = 1;
4921#endif
4669 } 4922 }
4670#endif 4923#endif
4671 4924
4672#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || NEED_PRINTF_UNBOUNDED_PRECISION 4925#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION
4673 has_precision = 0; 4926 has_precision = 0;
4674 precision = 6; 4927 precision = 6;
4675 if (dp->precision_start != dp->precision_end) 4928 if (dp->precision_start != dp->precision_end)
@@ -4805,7 +5058,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4805 { 5058 {
4806 const FCHAR_T *mp = dp->width_start; 5059 const FCHAR_T *mp = dp->width_start;
4807 do 5060 do
4808 *fbp++ = (unsigned char) *mp++; 5061 *fbp++ = *mp++;
4809 while (--n > 0); 5062 while (--n > 0);
4810 } 5063 }
4811 } 5064 }
@@ -4826,7 +5079,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4826 { 5079 {
4827 const FCHAR_T *mp = dp->precision_start; 5080 const FCHAR_T *mp = dp->precision_start;
4828 do 5081 do
4829 *fbp++ = (unsigned char) *mp++; 5082 *fbp++ = *mp++;
4830 while (--n > 0); 5083 while (--n > 0);
4831 } 5084 }
4832 } 5085 }
@@ -4834,19 +5087,17 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4834 5087
4835 switch (type) 5088 switch (type)
4836 { 5089 {
4837#if HAVE_LONG_LONG_INT
4838 case TYPE_LONGLONGINT: 5090 case TYPE_LONGLONGINT:
4839 case TYPE_ULONGLONGINT: 5091 case TYPE_ULONGLONGINT:
4840# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 5092#if defined _WIN32 && ! defined __CYGWIN__
4841 *fbp++ = 'I'; 5093 *fbp++ = 'I';
4842 *fbp++ = '6'; 5094 *fbp++ = '6';
4843 *fbp++ = '4'; 5095 *fbp++ = '4';
4844 break; 5096 break;
4845# else 5097#else
4846 *fbp++ = 'l'; 5098 *fbp++ = 'l';
4847 /*FALLTHROUGH*/
4848# endif
4849#endif 5099#endif
5100 FALLTHROUGH;
4850 case TYPE_LONGINT: 5101 case TYPE_LONGINT:
4851 case TYPE_ULONGINT: 5102 case TYPE_ULONGINT:
4852#if HAVE_WINT_T 5103#if HAVE_WINT_T
@@ -4870,20 +5121,32 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4870#endif 5121#endif
4871 *fbp = dp->conversion; 5122 *fbp = dp->conversion;
4872#if USE_SNPRINTF 5123#if USE_SNPRINTF
4873# if !(((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) && !defined __UCLIBC__) || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)) 5124# if ((HAVE_SNPRINTF_RETVAL_C99 && HAVE_SNPRINTF_TRUNCATION_C99) \
4874 fbp[1] = '%'; 5125 || ((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) \
4875 fbp[2] = 'n'; 5126 && !defined __UCLIBC__) \
4876 fbp[3] = '\0'; 5127 || (defined __APPLE__ && defined __MACH__) \
4877# else 5128 || defined __ANDROID__ \
4878 /* On glibc2 systems from glibc >= 2.3 - probably also older 5129 || (defined _WIN32 && ! defined __CYGWIN__))
4879 ones - we know that snprintf's return value conforms to 5130 /* On systems where we know that snprintf's return value
4880 ISO C 99: the tests gl_SNPRINTF_RETVAL_C99 and 5131 conforms to ISO C 99 (HAVE_SNPRINTF_RETVAL_C99) and that
4881 gl_SNPRINTF_TRUNCATION_C99 pass. 5132 snprintf always produces NUL-terminated strings
4882 Therefore we can avoid using %n in this situation. 5133 (HAVE_SNPRINTF_TRUNCATION_C99), it is possible to avoid
4883 On glibc2 systems from 2004-10-18 or newer, the use of %n 5134 using %n. And it is desirable to do so, because more and
4884 in format strings in writable memory may crash the program 5135 more platforms no longer support %n, for "security reasons".
4885 (if compiled with _FORTIFY_SOURCE=2), so we should avoid it 5136 In particular, the following platforms:
4886 in this situation. */ 5137 - On glibc2 systems from 2004-10-18 or newer, the use of
5138 %n in format strings in writable memory may crash the
5139 program (if compiled with _FORTIFY_SOURCE=2).
5140 - On Mac OS X 10.13 or newer, the use of %n in format
5141 strings in writable memory by default crashes the
5142 program.
5143 - On Android, starting on 2018-03-07, the use of %n in
5144 format strings produces a fatal error (see
5145 <https://android.googlesource.com/platform/bionic/+/41398d03b7e8e0dfb951660ae713e682e9fc0336>).
5146 On these platforms, HAVE_SNPRINTF_RETVAL_C99 and
5147 HAVE_SNPRINTF_TRUNCATION_C99 are 1. We have listed them
5148 explicitly in the condition above, in case of cross-
5149 compilation (just to be sure). */
4887 /* On native Windows systems (such as mingw), we can avoid using 5150 /* On native Windows systems (such as mingw), we can avoid using
4888 %n because: 5151 %n because:
4889 - Although the gl_SNPRINTF_TRUNCATION_C99 test fails, 5152 - Although the gl_SNPRINTF_TRUNCATION_C99 test fails,
@@ -4896,10 +5159,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
4896 On native Windows systems (such as mingw) where the OS is 5159 On native Windows systems (such as mingw) where the OS is
4897 Windows Vista, the use of %n in format strings by default 5160 Windows Vista, the use of %n in format strings by default
4898 crashes the program. See 5161 crashes the program. See
4899 <http://gcc.gnu.org/ml/gcc/2007-06/msg00122.html> and 5162 <https://gcc.gnu.org/ml/gcc/2007-06/msg00122.html> and
4900 <http://msdn2.microsoft.com/en-us/library/ms175782(VS.80).aspx> 5163 <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/set-printf-count-output>
4901 So we should avoid %n in this situation. */ 5164 So we should avoid %n in this situation. */
4902 fbp[1] = '\0'; 5165 fbp[1] = '\0';
5166# else /* AIX <= 5.1, HP-UX, IRIX, OSF/1, Solaris <= 9, BeOS */
5167 fbp[1] = '%';
5168 fbp[2] = 'n';
5169 fbp[3] = '\0';
4903# endif 5170# endif
4904#else 5171#else
4905 fbp[1] = '\0'; 5172 fbp[1] = '\0';
@@ -5043,7 +5310,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
5043 SNPRINTF_BUF (arg); 5310 SNPRINTF_BUF (arg);
5044 } 5311 }
5045 break; 5312 break;
5046#if HAVE_LONG_LONG_INT
5047 case TYPE_LONGLONGINT: 5313 case TYPE_LONGLONGINT:
5048 { 5314 {
5049 long long int arg = a.arg[dp->arg_index].a.a_longlongint; 5315 long long int arg = a.arg[dp->arg_index].a.a_longlongint;
@@ -5056,7 +5322,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
5056 SNPRINTF_BUF (arg); 5322 SNPRINTF_BUF (arg);
5057 } 5323 }
5058 break; 5324 break;
5059#endif
5060 case TYPE_DOUBLE: 5325 case TYPE_DOUBLE:
5061 { 5326 {
5062 double arg = a.arg[dp->arg_index].a.a_double; 5327 double arg = a.arg[dp->arg_index].a.a_double;
@@ -5116,7 +5381,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
5116 { 5381 {
5117 /* Verify that snprintf() has NUL-terminated its 5382 /* Verify that snprintf() has NUL-terminated its
5118 result. */ 5383 result. */
5119 if (count < maxlen 5384 if ((unsigned int) count < maxlen
5120 && ((TCHAR_T *) (result + length)) [count] != '\0') 5385 && ((TCHAR_T *) (result + length)) [count] != '\0')
5121 abort (); 5386 abort ();
5122 /* Portability hack. */ 5387 /* Portability hack. */
@@ -5139,7 +5404,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
5139 /* Look at the snprintf() return value. */ 5404 /* Look at the snprintf() return value. */
5140 if (retcount < 0) 5405 if (retcount < 0)
5141 { 5406 {
5142# if !HAVE_SNPRINTF_RETVAL_C99 5407# if !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF
5143 /* HP-UX 10.20 snprintf() is doubly deficient: 5408 /* HP-UX 10.20 snprintf() is doubly deficient:
5144 It doesn't understand the '%n' directive, 5409 It doesn't understand the '%n' directive,
5145 *and* it returns -1 (rather than the length 5410 *and* it returns -1 (rather than the length
@@ -5153,7 +5418,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
5153 size_t tmp_length = 5418 size_t tmp_length =
5154 MAX_ROOM_NEEDED (&a, dp->arg_index, 5419 MAX_ROOM_NEEDED (&a, dp->arg_index,
5155 dp->conversion, type, flags, 5420 dp->conversion, type, flags,
5156 has_width ? width : 0, 5421 width,
5157 has_precision, 5422 has_precision,
5158 precision, pad_ourselves); 5423 precision, pad_ourselves);
5159 5424
@@ -5188,21 +5453,22 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
5188 /* Attempt to handle failure. */ 5453 /* Attempt to handle failure. */
5189 if (count < 0) 5454 if (count < 0)
5190 { 5455 {
5191 /* SNPRINTF or sprintf failed. Save and use the errno 5456 /* SNPRINTF or sprintf failed. Use the errno that it
5192 that it has set, if any. */ 5457 has set, if any. */
5193 int saved_errno = errno; 5458 if (errno == 0)
5459 {
5460 if (dp->conversion == 'c' || dp->conversion == 's')
5461 errno = EILSEQ;
5462 else
5463 errno = EINVAL;
5464 }
5194 5465
5195 if (!(result == resultbuf || result == NULL)) 5466 if (!(result == resultbuf || result == NULL))
5196 free (result); 5467 free (result);
5197 if (buf_malloced != NULL) 5468 if (buf_malloced != NULL)
5198 free (buf_malloced); 5469 free (buf_malloced);
5199 CLEANUP (); 5470 CLEANUP ();
5200 errno = 5471
5201 (saved_errno != 0
5202 ? saved_errno
5203 : (dp->conversion == 'c' || dp->conversion == 's'
5204 ? EILSEQ
5205 : EINVAL));
5206 return NULL; 5472 return NULL;
5207 } 5473 }
5208 5474
@@ -5338,16 +5604,15 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
5338 NULL, &tmpdst_len); 5604 NULL, &tmpdst_len);
5339 if (tmpdst == NULL) 5605 if (tmpdst == NULL)
5340 { 5606 {
5341 int saved_errno = errno;
5342 if (!(result == resultbuf || result == NULL)) 5607 if (!(result == resultbuf || result == NULL))
5343 free (result); 5608 free (result);
5344 if (buf_malloced != NULL) 5609 if (buf_malloced != NULL)
5345 free (buf_malloced); 5610 free (buf_malloced);
5346 CLEANUP (); 5611 CLEANUP ();
5347 errno = saved_errno;
5348 return NULL; 5612 return NULL;
5349 } 5613 }
5350 ENSURE_ALLOCATION (xsum (length, tmpdst_len)); 5614 ENSURE_ALLOCATION_ELSE (xsum (length, tmpdst_len),
5615 { free (tmpdst); goto out_of_memory; });
5351 DCHAR_CPY (result + length, tmpdst, tmpdst_len); 5616 DCHAR_CPY (result + length, tmpdst, tmpdst_len);
5352 free (tmpdst); 5617 free (tmpdst);
5353 count = tmpdst_len; 5618 count = tmpdst_len;
@@ -5391,7 +5656,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
5391 tmpsrc += count; 5656 tmpsrc += count;
5392 tmpdst += count; 5657 tmpdst += count;
5393 for (n = count; n > 0; n--) 5658 for (n = count; n > 0; n--)
5394 *--tmpdst = (unsigned char) *--tmpsrc; 5659 *--tmpdst = *--tmpsrc;
5395 } 5660 }
5396 } 5661 }
5397#endif 5662#endif
diff --git a/gl/vasnprintf.h b/gl/vasnprintf.h
index 7658f50..9b02cdf 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-2021 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..fe8b14f 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-2021 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..a8ca59b 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-2021 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 C2x. 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 (201112L <= __STDC_VERSION__ \
37# define _GL_HAVE__STATIC_ASSERT 1 36 || (!defined __STRICT_ANSI__ \
38#endif 37 && (4 < __GNUC__ + (6 <= __GNUC_MINOR__) || 4 <= __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 (202000L <= __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,63 @@ 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 C2x 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 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)]
212#endif 218#endif
213 219
214/* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h. */ 220/* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h. */
215#ifdef _GL_STATIC_ASSERT_H 221#ifdef _GL_STATIC_ASSERT_H
216# if !defined _GL_HAVE__STATIC_ASSERT && !defined _Static_assert 222# if !defined _GL_HAVE__STATIC_ASSERT1 && !defined _Static_assert
217# define _Static_assert(R, DIAGNOSTIC) _GL_VERIFY (R, DIAGNOSTIC) 223# define _Static_assert(...) \
224 _GL_VERIFY (__VA_ARGS__, "static assertion failed", -)
218# endif 225# endif
219# if !defined _GL_HAVE_STATIC_ASSERT && !defined static_assert 226# if __cpp_static_assert < 201411 && !defined static_assert
220# define static_assert _Static_assert /* C11 requires this #define. */ 227# define static_assert _Static_assert /* C11 requires this #define. */
221# endif 228# endif
222#endif 229#endif
223 230
224/* @assert.h omit start@ */ 231/* @assert.h omit start@ */
225 232
233#if 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__))
234# define _GL_HAS_BUILTIN_TRAP 1
235#elif defined __has_builtin
236# define _GL_HAS_BUILTIN_TRAP __has_builtin (__builtin_trap)
237#else
238# define _GL_HAS_BUILTIN_TRAP 0
239#endif
240
241#if 4 < __GNUC__ + (5 <= __GNUC_MINOR__)
242# define _GL_HAS_BUILTIN_UNREACHABLE 1
243#elif defined __has_builtin
244# define _GL_HAS_BUILTIN_UNREACHABLE __has_builtin (__builtin_unreachable)
245#else
246# define _GL_HAS_BUILTIN_UNREACHABLE 0
247#endif
248
226/* Each of these macros verifies that its argument R is nonzero. To 249/* Each of these macros verifies that its argument R is nonzero. To
227 be portable, R should be an integer constant expression. Unlike 250 be portable, R should be an integer constant expression. Unlike
228 assert (R), there is no run-time overhead. 251 assert (R), there is no run-time overhead.
229 252
230 There are two macros, since no single macro can be used in all 253 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 254 contexts in C. verify_expr (R, E) is for scalar contexts, including
232 integer constant expression contexts. verify (R) is for declaration 255 integer constant expression contexts. verify (R) is for declaration
233 contexts, e.g., the top level. */ 256 contexts, e.g., the top level. */
234 257
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 258/* Verify requirement R at compile-time. Return the value of the
243 expression E. */ 259 expression E. */
244 260
@@ -246,9 +262,53 @@ template <int w>
246 (_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E)) 262 (_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E))
247 263
248/* Verify requirement R at compile-time, as a declaration without a 264/* Verify requirement R at compile-time, as a declaration without a
249 trailing ';'. */ 265 trailing ';'. verify (R) acts like static_assert (R) except that
266 it is portable to C11/C++14 and earlier, it can issue better
267 diagnostics, and its name is shorter and may be more convenient. */
250 268
251#define verify(R) _GL_VERIFY (R, "verify (" #R ")") 269#ifdef __PGI
270/* PGI barfs if R is long. */
271# define verify(R) _GL_VERIFY (R, "verify (...)", -)
272#else
273# define verify(R) _GL_VERIFY (R, "verify (" #R ")", -)
274#endif
275
276/* Assume that R always holds. Behavior is undefined if R is false,
277 fails to evaluate, or has side effects.
278
279 'assume (R)' is a directive from the programmer telling the
280 compiler that R is true so the compiler needn't generate code to
281 test R. This is why 'assume' is in verify.h: it's related to
282 static checking (in this case, static checking done by the
283 programmer), not dynamic checking.
284
285 'assume (R)' can affect compilation of all the code, not just code
286 that happens to be executed after the assume (R) is "executed".
287 For example, if the code mistakenly does 'assert (R); assume (R);'
288 the compiler is entitled to optimize away the 'assert (R)'.
289
290 Although assuming R can help a compiler generate better code or
291 diagnostics, performance can suffer if R uses hard-to-optimize
292 features such as function calls not inlined by the compiler.
293
294 Avoid Clang's __builtin_assume, as it breaks GNU Emacs master
295 as of 2020-08-23T21:09:49Z!eggert@cs.ucla.edu; see
296 <https://bugs.gnu.org/43152#71>. It's not known whether this breakage
297 is a Clang bug or an Emacs bug; play it safe for now. */
298
299#if _GL_HAS_BUILTIN_UNREACHABLE
300# define assume(R) ((R) ? (void) 0 : __builtin_unreachable ())
301#elif 1200 <= _MSC_VER
302# define assume(R) __assume (R)
303#elif (defined GCC_LINT || defined lint) && _GL_HAS_BUILTIN_TRAP
304 /* Doing it this way helps various packages when configured with
305 --enable-gcc-warnings, which compiles with -Dlint. It's nicer
306 when 'assume' silences warnings even with older GCCs. */
307# define assume(R) ((R) ? (void) 0 : __builtin_trap ())
308#else
309 /* Some tools grok NOTREACHED, e.g., Oracle Studio 12.6. */
310# define assume(R) ((R) ? (void) 0 : /*NOTREACHED*/ (void) 0)
311#endif
252 312
253/* @assert.h omit end@ */ 313/* @assert.h omit end@ */
254 314
diff --git a/gl/vsnprintf.c b/gl/vsnprintf.c
index 7d4dfbe..4a0a3dc 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-2021 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..635a1b2 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-2021 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/wchar.in.h b/gl/wchar.in.h
index b6e4362..20315dd 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-2021 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,43 @@
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# define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (free, 1)
103#endif
104
105/* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly
106 allocated memory. */
107/* Applies to: functions. */
108#ifndef _GL_ATTRIBUTE_MALLOC
109# if __GNUC__ >= 3 || defined __clang__
110# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
111# else
112# define _GL_ATTRIBUTE_MALLOC
113# endif
114#endif
115
86/* The __attribute__ feature is available in gcc versions 2.5 and later. 116/* The __attribute__ feature is available in gcc versions 2.5 and later.
87 The attribute __pure__ was added in gcc 2.96. */ 117 The attribute __pure__ was added in gcc 2.96. */
88#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) 118#ifndef _GL_ATTRIBUTE_PURE
89# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) 119# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__
90#else 120# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
91# define _GL_ATTRIBUTE_PURE /* empty */ 121# else
122# define _GL_ATTRIBUTE_PURE /* empty */
123# endif
92#endif 124#endif
93 125
94/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ 126/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
@@ -105,12 +137,16 @@
105# define WEOF -1 137# define WEOF -1
106# endif 138# endif
107#else 139#else
108/* MSVC defines wint_t as 'unsigned short' in <crtdefs.h>. 140/* 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 141 <stddef.h>. This is too small: ISO C 99 section 7.24.1.(2) says that
110 "unchanged by default argument promotions". Override it. */ 142 wint_t must be "unchanged by default argument promotions". Override it. */
111# if defined _MSC_VER 143# if @GNULIBHEADERS_OVERRIDE_WINT_T@
112# if !GNULIB_defined_wint_t 144# if !GNULIB_defined_wint_t
113# include <crtdefs.h> 145# if @HAVE_CRTDEFS_H@
146# include <crtdefs.h>
147# else
148# include <stddef.h>
149# endif
114typedef unsigned int rpl_wint_t; 150typedef unsigned int rpl_wint_t;
115# undef wint_t 151# undef wint_t
116# define wint_t rpl_wint_t 152# define wint_t rpl_wint_t
@@ -125,16 +161,29 @@ typedef unsigned int rpl_wint_t;
125 161
126/* Override mbstate_t if it is too small. 162/* Override mbstate_t if it is too small.
127 On IRIX 6.5, sizeof (mbstate_t) == 1, which is not sufficient for 163 On IRIX 6.5, sizeof (mbstate_t) == 1, which is not sufficient for
128 implementing mbrtowc for encodings like UTF-8. */ 164 implementing mbrtowc for encodings like UTF-8.
129#if !(@HAVE_MBSINIT@ && @HAVE_MBRTOWC@) || @REPLACE_MBSTATE_T@ 165 On AIX and MSVC, mbrtowc needs to be overridden, but mbstate_t exists and is
166 large enough and overriding it would cause problems in C++ mode. */
167#if !(((defined _WIN32 && !defined __CYGWIN__) || @HAVE_MBSINIT@) && @HAVE_MBRTOWC@) || @REPLACE_MBSTATE_T@
130# if !GNULIB_defined_mbstate_t 168# if !GNULIB_defined_mbstate_t
169# if !(defined _AIX || defined _MSC_VER)
131typedef int rpl_mbstate_t; 170typedef int rpl_mbstate_t;
132# undef mbstate_t 171# undef mbstate_t
133# define mbstate_t rpl_mbstate_t 172# define mbstate_t rpl_mbstate_t
173# endif
134# define GNULIB_defined_mbstate_t 1 174# define GNULIB_defined_mbstate_t 1
135# endif 175# endif
136#endif 176#endif
137 177
178/* Declare 'free' if needed for _GL_ATTRIBUTE_DEALLOC_FREE. */
179_GL_EXTERN_C void free (void *);
180#if @GNULIB_FREE_POSIX@
181# if (@REPLACE_FREE@ && !defined free \
182 && !(defined __cplusplus && defined GNULIB_NAMESPACE))
183# define free rpl_free
184_GL_EXTERN_C void free (void *);
185# endif
186#endif
138 187
139/* Convert a single-byte character to a wide character. */ 188/* Convert a single-byte character to a wide character. */
140#if @GNULIB_BTOWC@ 189#if @GNULIB_BTOWC@
@@ -149,9 +198,12 @@ _GL_CXXALIAS_RPL (btowc, wint_t, (int c));
149# if !@HAVE_BTOWC@ 198# if !@HAVE_BTOWC@
150_GL_FUNCDECL_SYS (btowc, wint_t, (int c) _GL_ATTRIBUTE_PURE); 199_GL_FUNCDECL_SYS (btowc, wint_t, (int c) _GL_ATTRIBUTE_PURE);
151# endif 200# endif
152_GL_CXXALIAS_SYS (btowc, wint_t, (int c)); 201/* Need to cast, because on mingw, the return type is 'unsigned short'. */
202_GL_CXXALIAS_SYS_CAST (btowc, wint_t, (int c));
153# endif 203# endif
204# if __GLIBC__ >= 2
154_GL_CXXALIASWARN (btowc); 205_GL_CXXALIASWARN (btowc);
206# endif
155#elif defined GNULIB_POSIXCHECK 207#elif defined GNULIB_POSIXCHECK
156# undef btowc 208# undef btowc
157# if HAVE_RAW_DECL_BTOWC 209# if HAVE_RAW_DECL_BTOWC
@@ -177,7 +229,9 @@ _GL_FUNCDECL_SYS (wctob, int, (wint_t wc) _GL_ATTRIBUTE_PURE);
177# endif 229# endif
178_GL_CXXALIAS_SYS (wctob, int, (wint_t wc)); 230_GL_CXXALIAS_SYS (wctob, int, (wint_t wc));
179# endif 231# endif
232# if __GLIBC__ >= 2
180_GL_CXXALIASWARN (wctob); 233_GL_CXXALIASWARN (wctob);
234# endif
181#elif defined GNULIB_POSIXCHECK 235#elif defined GNULIB_POSIXCHECK
182# undef wctob 236# undef wctob
183# if HAVE_RAW_DECL_WCTOB 237# if HAVE_RAW_DECL_WCTOB
@@ -202,7 +256,9 @@ _GL_FUNCDECL_SYS (mbsinit, int, (const mbstate_t *ps));
202# endif 256# endif
203_GL_CXXALIAS_SYS (mbsinit, int, (const mbstate_t *ps)); 257_GL_CXXALIAS_SYS (mbsinit, int, (const mbstate_t *ps));
204# endif 258# endif
259# if __GLIBC__ >= 2
205_GL_CXXALIASWARN (mbsinit); 260_GL_CXXALIASWARN (mbsinit);
261# endif
206#elif defined GNULIB_POSIXCHECK 262#elif defined GNULIB_POSIXCHECK
207# undef mbsinit 263# undef mbsinit
208# if HAVE_RAW_DECL_MBSINIT 264# if HAVE_RAW_DECL_MBSINIT
@@ -220,18 +276,24 @@ _GL_WARN_ON_USE (mbsinit, "mbsinit is unportable - "
220# define mbrtowc rpl_mbrtowc 276# define mbrtowc rpl_mbrtowc
221# endif 277# endif
222_GL_FUNCDECL_RPL (mbrtowc, size_t, 278_GL_FUNCDECL_RPL (mbrtowc, size_t,
223 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)); 279 (wchar_t *restrict pwc, const char *restrict s, size_t n,
280 mbstate_t *restrict ps));
224_GL_CXXALIAS_RPL (mbrtowc, size_t, 281_GL_CXXALIAS_RPL (mbrtowc, size_t,
225 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)); 282 (wchar_t *restrict pwc, const char *restrict s, size_t n,
283 mbstate_t *restrict ps));
226# else 284# else
227# if !@HAVE_MBRTOWC@ 285# if !@HAVE_MBRTOWC@
228_GL_FUNCDECL_SYS (mbrtowc, size_t, 286_GL_FUNCDECL_SYS (mbrtowc, size_t,
229 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)); 287 (wchar_t *restrict pwc, const char *restrict s, size_t n,
288 mbstate_t *restrict ps));
230# endif 289# endif
231_GL_CXXALIAS_SYS (mbrtowc, size_t, 290_GL_CXXALIAS_SYS (mbrtowc, size_t,
232 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)); 291 (wchar_t *restrict pwc, const char *restrict s, size_t n,
292 mbstate_t *restrict ps));
233# endif 293# endif
294# if __GLIBC__ >= 2
234_GL_CXXALIASWARN (mbrtowc); 295_GL_CXXALIASWARN (mbrtowc);
296# endif
235#elif defined GNULIB_POSIXCHECK 297#elif defined GNULIB_POSIXCHECK
236# undef mbrtowc 298# undef mbrtowc
237# if HAVE_RAW_DECL_MBRTOWC 299# if HAVE_RAW_DECL_MBRTOWC
@@ -248,15 +310,21 @@ _GL_WARN_ON_USE (mbrtowc, "mbrtowc is unportable - "
248# undef mbrlen 310# undef mbrlen
249# define mbrlen rpl_mbrlen 311# define mbrlen rpl_mbrlen
250# endif 312# endif
251_GL_FUNCDECL_RPL (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps)); 313_GL_FUNCDECL_RPL (mbrlen, size_t,
252_GL_CXXALIAS_RPL (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps)); 314 (const char *restrict s, size_t n, mbstate_t *restrict ps));
315_GL_CXXALIAS_RPL (mbrlen, size_t,
316 (const char *restrict s, size_t n, mbstate_t *restrict ps));
253# else 317# else
254# if !@HAVE_MBRLEN@ 318# if !@HAVE_MBRLEN@
255_GL_FUNCDECL_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps)); 319_GL_FUNCDECL_SYS (mbrlen, size_t,
320 (const char *restrict s, size_t n, mbstate_t *restrict ps));
256# endif 321# endif
257_GL_CXXALIAS_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps)); 322_GL_CXXALIAS_SYS (mbrlen, size_t,
323 (const char *restrict s, size_t n, mbstate_t *restrict ps));
258# endif 324# endif
325# if __GLIBC__ >= 2
259_GL_CXXALIASWARN (mbrlen); 326_GL_CXXALIASWARN (mbrlen);
327# endif
260#elif defined GNULIB_POSIXCHECK 328#elif defined GNULIB_POSIXCHECK
261# undef mbrlen 329# undef mbrlen
262# if HAVE_RAW_DECL_MBRLEN 330# if HAVE_RAW_DECL_MBRLEN
@@ -274,22 +342,30 @@ _GL_WARN_ON_USE (mbrlen, "mbrlen is unportable - "
274# define mbsrtowcs rpl_mbsrtowcs 342# define mbsrtowcs rpl_mbsrtowcs
275# endif 343# endif
276_GL_FUNCDECL_RPL (mbsrtowcs, size_t, 344_GL_FUNCDECL_RPL (mbsrtowcs, size_t,
277 (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps) 345 (wchar_t *restrict dest,
346 const char **restrict srcp, size_t len,
347 mbstate_t *restrict ps)
278 _GL_ARG_NONNULL ((2))); 348 _GL_ARG_NONNULL ((2)));
279_GL_CXXALIAS_RPL (mbsrtowcs, size_t, 349_GL_CXXALIAS_RPL (mbsrtowcs, size_t,
280 (wchar_t *dest, const char **srcp, size_t len, 350 (wchar_t *restrict dest,
281 mbstate_t *ps)); 351 const char **restrict srcp, size_t len,
352 mbstate_t *restrict ps));
282# else 353# else
283# if !@HAVE_MBSRTOWCS@ 354# if !@HAVE_MBSRTOWCS@
284_GL_FUNCDECL_SYS (mbsrtowcs, size_t, 355_GL_FUNCDECL_SYS (mbsrtowcs, size_t,
285 (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps) 356 (wchar_t *restrict dest,
357 const char **restrict srcp, size_t len,
358 mbstate_t *restrict ps)
286 _GL_ARG_NONNULL ((2))); 359 _GL_ARG_NONNULL ((2)));
287# endif 360# endif
288_GL_CXXALIAS_SYS (mbsrtowcs, size_t, 361_GL_CXXALIAS_SYS (mbsrtowcs, size_t,
289 (wchar_t *dest, const char **srcp, size_t len, 362 (wchar_t *restrict dest,
290 mbstate_t *ps)); 363 const char **restrict srcp, size_t len,
364 mbstate_t *restrict ps));
291# endif 365# endif
366# if __GLIBC__ >= 2
292_GL_CXXALIASWARN (mbsrtowcs); 367_GL_CXXALIASWARN (mbsrtowcs);
368# endif
293#elif defined GNULIB_POSIXCHECK 369#elif defined GNULIB_POSIXCHECK
294# undef mbsrtowcs 370# undef mbsrtowcs
295# if HAVE_RAW_DECL_MBSRTOWCS 371# if HAVE_RAW_DECL_MBSRTOWCS
@@ -307,22 +383,26 @@ _GL_WARN_ON_USE (mbsrtowcs, "mbsrtowcs is unportable - "
307# define mbsnrtowcs rpl_mbsnrtowcs 383# define mbsnrtowcs rpl_mbsnrtowcs
308# endif 384# endif
309_GL_FUNCDECL_RPL (mbsnrtowcs, size_t, 385_GL_FUNCDECL_RPL (mbsnrtowcs, size_t,
310 (wchar_t *dest, const char **srcp, size_t srclen, size_t len, 386 (wchar_t *restrict dest,
311 mbstate_t *ps) 387 const char **restrict srcp, size_t srclen, size_t len,
388 mbstate_t *restrict ps)
312 _GL_ARG_NONNULL ((2))); 389 _GL_ARG_NONNULL ((2)));
313_GL_CXXALIAS_RPL (mbsnrtowcs, size_t, 390_GL_CXXALIAS_RPL (mbsnrtowcs, size_t,
314 (wchar_t *dest, const char **srcp, size_t srclen, size_t len, 391 (wchar_t *restrict dest,
315 mbstate_t *ps)); 392 const char **restrict srcp, size_t srclen, size_t len,
393 mbstate_t *restrict ps));
316# else 394# else
317# if !@HAVE_MBSNRTOWCS@ 395# if !@HAVE_MBSNRTOWCS@
318_GL_FUNCDECL_SYS (mbsnrtowcs, size_t, 396_GL_FUNCDECL_SYS (mbsnrtowcs, size_t,
319 (wchar_t *dest, const char **srcp, size_t srclen, size_t len, 397 (wchar_t *restrict dest,
320 mbstate_t *ps) 398 const char **restrict srcp, size_t srclen, size_t len,
399 mbstate_t *restrict ps)
321 _GL_ARG_NONNULL ((2))); 400 _GL_ARG_NONNULL ((2)));
322# endif 401# endif
323_GL_CXXALIAS_SYS (mbsnrtowcs, size_t, 402_GL_CXXALIAS_SYS (mbsnrtowcs, size_t,
324 (wchar_t *dest, const char **srcp, size_t srclen, size_t len, 403 (wchar_t *restrict dest,
325 mbstate_t *ps)); 404 const char **restrict srcp, size_t srclen, size_t len,
405 mbstate_t *restrict ps));
326# endif 406# endif
327_GL_CXXALIASWARN (mbsnrtowcs); 407_GL_CXXALIASWARN (mbsnrtowcs);
328#elif defined GNULIB_POSIXCHECK 408#elif defined GNULIB_POSIXCHECK
@@ -341,15 +421,21 @@ _GL_WARN_ON_USE (mbsnrtowcs, "mbsnrtowcs is unportable - "
341# undef wcrtomb 421# undef wcrtomb
342# define wcrtomb rpl_wcrtomb 422# define wcrtomb rpl_wcrtomb
343# endif 423# endif
344_GL_FUNCDECL_RPL (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps)); 424_GL_FUNCDECL_RPL (wcrtomb, size_t,
345_GL_CXXALIAS_RPL (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps)); 425 (char *restrict s, wchar_t wc, mbstate_t *restrict ps));
426_GL_CXXALIAS_RPL (wcrtomb, size_t,
427 (char *restrict s, wchar_t wc, mbstate_t *restrict ps));
346# else 428# else
347# if !@HAVE_WCRTOMB@ 429# if !@HAVE_WCRTOMB@
348_GL_FUNCDECL_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps)); 430_GL_FUNCDECL_SYS (wcrtomb, size_t,
431 (char *restrict s, wchar_t wc, mbstate_t *restrict ps));
349# endif 432# endif
350_GL_CXXALIAS_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps)); 433_GL_CXXALIAS_SYS (wcrtomb, size_t,
434 (char *restrict s, wchar_t wc, mbstate_t *restrict ps));
351# endif 435# endif
436# if __GLIBC__ >= 2
352_GL_CXXALIASWARN (wcrtomb); 437_GL_CXXALIASWARN (wcrtomb);
438# endif
353#elif defined GNULIB_POSIXCHECK 439#elif defined GNULIB_POSIXCHECK
354# undef wcrtomb 440# undef wcrtomb
355# if HAVE_RAW_DECL_WCRTOMB 441# if HAVE_RAW_DECL_WCRTOMB
@@ -367,22 +453,30 @@ _GL_WARN_ON_USE (wcrtomb, "wcrtomb is unportable - "
367# define wcsrtombs rpl_wcsrtombs 453# define wcsrtombs rpl_wcsrtombs
368# endif 454# endif
369_GL_FUNCDECL_RPL (wcsrtombs, size_t, 455_GL_FUNCDECL_RPL (wcsrtombs, size_t,
370 (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps) 456 (char *restrict dest, const wchar_t **restrict srcp,
457 size_t len,
458 mbstate_t *restrict ps)
371 _GL_ARG_NONNULL ((2))); 459 _GL_ARG_NONNULL ((2)));
372_GL_CXXALIAS_RPL (wcsrtombs, size_t, 460_GL_CXXALIAS_RPL (wcsrtombs, size_t,
373 (char *dest, const wchar_t **srcp, size_t len, 461 (char *restrict dest, const wchar_t **restrict srcp,
374 mbstate_t *ps)); 462 size_t len,
463 mbstate_t *restrict ps));
375# else 464# else
376# if !@HAVE_WCSRTOMBS@ 465# if !@HAVE_WCSRTOMBS@
377_GL_FUNCDECL_SYS (wcsrtombs, size_t, 466_GL_FUNCDECL_SYS (wcsrtombs, size_t,
378 (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps) 467 (char *restrict dest, const wchar_t **restrict srcp,
468 size_t len,
469 mbstate_t *restrict ps)
379 _GL_ARG_NONNULL ((2))); 470 _GL_ARG_NONNULL ((2)));
380# endif 471# endif
381_GL_CXXALIAS_SYS (wcsrtombs, size_t, 472_GL_CXXALIAS_SYS (wcsrtombs, size_t,
382 (char *dest, const wchar_t **srcp, size_t len, 473 (char *restrict dest, const wchar_t **restrict srcp,
383 mbstate_t *ps)); 474 size_t len,
475 mbstate_t *restrict ps));
384# endif 476# endif
477# if __GLIBC__ >= 2
385_GL_CXXALIASWARN (wcsrtombs); 478_GL_CXXALIASWARN (wcsrtombs);
479# endif
386#elif defined GNULIB_POSIXCHECK 480#elif defined GNULIB_POSIXCHECK
387# undef wcsrtombs 481# undef wcsrtombs
388# if HAVE_RAW_DECL_WCSRTOMBS 482# if HAVE_RAW_DECL_WCSRTOMBS
@@ -400,24 +494,34 @@ _GL_WARN_ON_USE (wcsrtombs, "wcsrtombs is unportable - "
400# define wcsnrtombs rpl_wcsnrtombs 494# define wcsnrtombs rpl_wcsnrtombs
401# endif 495# endif
402_GL_FUNCDECL_RPL (wcsnrtombs, size_t, 496_GL_FUNCDECL_RPL (wcsnrtombs, size_t,
403 (char *dest, const wchar_t **srcp, size_t srclen, size_t len, 497 (char *restrict dest,
404 mbstate_t *ps) 498 const wchar_t **restrict srcp, size_t srclen,
499 size_t len,
500 mbstate_t *restrict ps)
405 _GL_ARG_NONNULL ((2))); 501 _GL_ARG_NONNULL ((2)));
406_GL_CXXALIAS_RPL (wcsnrtombs, size_t, 502_GL_CXXALIAS_RPL (wcsnrtombs, size_t,
407 (char *dest, const wchar_t **srcp, size_t srclen, size_t len, 503 (char *restrict dest,
408 mbstate_t *ps)); 504 const wchar_t **restrict srcp, size_t srclen,
505 size_t len,
506 mbstate_t *restrict ps));
409# else 507# else
410# if !@HAVE_WCSNRTOMBS@ 508# if !@HAVE_WCSNRTOMBS@ || (defined __cplusplus && defined __sun)
411_GL_FUNCDECL_SYS (wcsnrtombs, size_t, 509_GL_FUNCDECL_SYS (wcsnrtombs, size_t,
412 (char *dest, const wchar_t **srcp, size_t srclen, size_t len, 510 (char *restrict dest,
413 mbstate_t *ps) 511 const wchar_t **restrict srcp, size_t srclen,
512 size_t len,
513 mbstate_t *restrict ps)
414 _GL_ARG_NONNULL ((2))); 514 _GL_ARG_NONNULL ((2)));
415# endif 515# endif
416_GL_CXXALIAS_SYS (wcsnrtombs, size_t, 516_GL_CXXALIAS_SYS (wcsnrtombs, size_t,
417 (char *dest, const wchar_t **srcp, size_t srclen, size_t len, 517 (char *restrict dest,
418 mbstate_t *ps)); 518 const wchar_t **restrict srcp, size_t srclen,
519 size_t len,
520 mbstate_t *restrict ps));
419# endif 521# endif
522# if __GLIBC__ >= 2
420_GL_CXXALIASWARN (wcsnrtombs); 523_GL_CXXALIASWARN (wcsnrtombs);
524# endif
421#elif defined GNULIB_POSIXCHECK 525#elif defined GNULIB_POSIXCHECK
422# undef wcsnrtombs 526# undef wcsnrtombs
423# if HAVE_RAW_DECL_WCSNRTOMBS 527# if HAVE_RAW_DECL_WCSNRTOMBS
@@ -443,7 +547,9 @@ _GL_FUNCDECL_SYS (wcwidth, int, (wchar_t) _GL_ATTRIBUTE_PURE);
443# endif 547# endif
444_GL_CXXALIAS_SYS (wcwidth, int, (wchar_t)); 548_GL_CXXALIAS_SYS (wcwidth, int, (wchar_t));
445# endif 549# endif
550# if __GLIBC__ >= 2
446_GL_CXXALIASWARN (wcwidth); 551_GL_CXXALIASWARN (wcwidth);
552# endif
447#elif defined GNULIB_POSIXCHECK 553#elif defined GNULIB_POSIXCHECK
448# undef wcwidth 554# undef wcwidth
449# if HAVE_RAW_DECL_WCWIDTH 555# if HAVE_RAW_DECL_WCWIDTH
@@ -472,7 +578,7 @@ _GL_CXXALIAS_SYS_CAST2 (wmemchr,
472_GL_CXXALIASWARN1 (wmemchr, wchar_t *, (wchar_t *s, wchar_t c, size_t n)); 578_GL_CXXALIASWARN1 (wmemchr, wchar_t *, (wchar_t *s, wchar_t c, size_t n));
473_GL_CXXALIASWARN1 (wmemchr, const wchar_t *, 579_GL_CXXALIASWARN1 (wmemchr, const wchar_t *,
474 (const wchar_t *s, wchar_t c, size_t n)); 580 (const wchar_t *s, wchar_t c, size_t n));
475# else 581# elif __GLIBC__ >= 2
476_GL_CXXALIASWARN (wmemchr); 582_GL_CXXALIASWARN (wmemchr);
477# endif 583# endif
478#elif defined GNULIB_POSIXCHECK 584#elif defined GNULIB_POSIXCHECK
@@ -493,7 +599,9 @@ _GL_FUNCDECL_SYS (wmemcmp, int,
493# endif 599# endif
494_GL_CXXALIAS_SYS (wmemcmp, int, 600_GL_CXXALIAS_SYS (wmemcmp, int,
495 (const wchar_t *s1, const wchar_t *s2, size_t n)); 601 (const wchar_t *s1, const wchar_t *s2, size_t n));
602# if __GLIBC__ >= 2
496_GL_CXXALIASWARN (wmemcmp); 603_GL_CXXALIASWARN (wmemcmp);
604# endif
497#elif defined GNULIB_POSIXCHECK 605#elif defined GNULIB_POSIXCHECK
498# undef wmemcmp 606# undef wmemcmp
499# if HAVE_RAW_DECL_WMEMCMP 607# if HAVE_RAW_DECL_WMEMCMP
@@ -507,11 +615,15 @@ _GL_WARN_ON_USE (wmemcmp, "wmemcmp is unportable - "
507#if @GNULIB_WMEMCPY@ 615#if @GNULIB_WMEMCPY@
508# if !@HAVE_WMEMCPY@ 616# if !@HAVE_WMEMCPY@
509_GL_FUNCDECL_SYS (wmemcpy, wchar_t *, 617_GL_FUNCDECL_SYS (wmemcpy, wchar_t *,
510 (wchar_t *dest, const wchar_t *src, size_t n)); 618 (wchar_t *restrict dest,
619 const wchar_t *restrict src, size_t n));
511# endif 620# endif
512_GL_CXXALIAS_SYS (wmemcpy, wchar_t *, 621_GL_CXXALIAS_SYS (wmemcpy, wchar_t *,
513 (wchar_t *dest, const wchar_t *src, size_t n)); 622 (wchar_t *restrict dest,
623 const wchar_t *restrict src, size_t n));
624# if __GLIBC__ >= 2
514_GL_CXXALIASWARN (wmemcpy); 625_GL_CXXALIASWARN (wmemcpy);
626# endif
515#elif defined GNULIB_POSIXCHECK 627#elif defined GNULIB_POSIXCHECK
516# undef wmemcpy 628# undef wmemcpy
517# if HAVE_RAW_DECL_WMEMCPY 629# if HAVE_RAW_DECL_WMEMCPY
@@ -530,7 +642,9 @@ _GL_FUNCDECL_SYS (wmemmove, wchar_t *,
530# endif 642# endif
531_GL_CXXALIAS_SYS (wmemmove, wchar_t *, 643_GL_CXXALIAS_SYS (wmemmove, wchar_t *,
532 (wchar_t *dest, const wchar_t *src, size_t n)); 644 (wchar_t *dest, const wchar_t *src, size_t n));
645# if __GLIBC__ >= 2
533_GL_CXXALIASWARN (wmemmove); 646_GL_CXXALIASWARN (wmemmove);
647# endif
534#elif defined GNULIB_POSIXCHECK 648#elif defined GNULIB_POSIXCHECK
535# undef wmemmove 649# undef wmemmove
536# if HAVE_RAW_DECL_WMEMMOVE 650# if HAVE_RAW_DECL_WMEMMOVE
@@ -540,13 +654,38 @@ _GL_WARN_ON_USE (wmemmove, "wmemmove is unportable - "
540#endif 654#endif
541 655
542 656
657/* Copy N wide characters of SRC to DEST.
658 Return pointer to wide characters after the last written wide character. */
659#if @GNULIB_WMEMPCPY@
660# if !@HAVE_WMEMPCPY@
661_GL_FUNCDECL_SYS (wmempcpy, wchar_t *,
662 (wchar_t *restrict dest,
663 const wchar_t *restrict src, size_t n));
664# endif
665_GL_CXXALIAS_SYS (wmempcpy, wchar_t *,
666 (wchar_t *restrict dest,
667 const wchar_t *restrict src, size_t n));
668# if __GLIBC__ >= 2
669_GL_CXXALIASWARN (wmempcpy);
670# endif
671#elif defined GNULIB_POSIXCHECK
672# undef wmempcpy
673# if HAVE_RAW_DECL_WMEMPCPY
674_GL_WARN_ON_USE (wmempcpy, "wmempcpy is unportable - "
675 "use gnulib module wmempcpy for portability");
676# endif
677#endif
678
679
543/* Set N wide characters of S to C. */ 680/* Set N wide characters of S to C. */
544#if @GNULIB_WMEMSET@ 681#if @GNULIB_WMEMSET@
545# if !@HAVE_WMEMSET@ 682# if !@HAVE_WMEMSET@
546_GL_FUNCDECL_SYS (wmemset, wchar_t *, (wchar_t *s, wchar_t c, size_t n)); 683_GL_FUNCDECL_SYS (wmemset, wchar_t *, (wchar_t *s, wchar_t c, size_t n));
547# endif 684# endif
548_GL_CXXALIAS_SYS (wmemset, wchar_t *, (wchar_t *s, wchar_t c, size_t n)); 685_GL_CXXALIAS_SYS (wmemset, wchar_t *, (wchar_t *s, wchar_t c, size_t n));
686# if __GLIBC__ >= 2
549_GL_CXXALIASWARN (wmemset); 687_GL_CXXALIASWARN (wmemset);
688# endif
550#elif defined GNULIB_POSIXCHECK 689#elif defined GNULIB_POSIXCHECK
551# undef wmemset 690# undef wmemset
552# if HAVE_RAW_DECL_WMEMSET 691# if HAVE_RAW_DECL_WMEMSET
@@ -562,7 +701,9 @@ _GL_WARN_ON_USE (wmemset, "wmemset is unportable - "
562_GL_FUNCDECL_SYS (wcslen, size_t, (const wchar_t *s) _GL_ATTRIBUTE_PURE); 701_GL_FUNCDECL_SYS (wcslen, size_t, (const wchar_t *s) _GL_ATTRIBUTE_PURE);
563# endif 702# endif
564_GL_CXXALIAS_SYS (wcslen, size_t, (const wchar_t *s)); 703_GL_CXXALIAS_SYS (wcslen, size_t, (const wchar_t *s));
704# if __GLIBC__ >= 2
565_GL_CXXALIASWARN (wcslen); 705_GL_CXXALIASWARN (wcslen);
706# endif
566#elif defined GNULIB_POSIXCHECK 707#elif defined GNULIB_POSIXCHECK
567# undef wcslen 708# undef wcslen
568# if HAVE_RAW_DECL_WCSLEN 709# if HAVE_RAW_DECL_WCSLEN
@@ -592,10 +733,14 @@ _GL_WARN_ON_USE (wcsnlen, "wcsnlen is unportable - "
592/* Copy SRC to DEST. */ 733/* Copy SRC to DEST. */
593#if @GNULIB_WCSCPY@ 734#if @GNULIB_WCSCPY@
594# if !@HAVE_WCSCPY@ 735# if !@HAVE_WCSCPY@
595_GL_FUNCDECL_SYS (wcscpy, wchar_t *, (wchar_t *dest, const wchar_t *src)); 736_GL_FUNCDECL_SYS (wcscpy, wchar_t *,
737 (wchar_t *restrict dest, const wchar_t *restrict src));
596# endif 738# endif
597_GL_CXXALIAS_SYS (wcscpy, wchar_t *, (wchar_t *dest, const wchar_t *src)); 739_GL_CXXALIAS_SYS (wcscpy, wchar_t *,
740 (wchar_t *restrict dest, const wchar_t *restrict src));
741# if __GLIBC__ >= 2
598_GL_CXXALIASWARN (wcscpy); 742_GL_CXXALIASWARN (wcscpy);
743# endif
599#elif defined GNULIB_POSIXCHECK 744#elif defined GNULIB_POSIXCHECK
600# undef wcscpy 745# undef wcscpy
601# if HAVE_RAW_DECL_WCSCPY 746# if HAVE_RAW_DECL_WCSCPY
@@ -608,9 +753,11 @@ _GL_WARN_ON_USE (wcscpy, "wcscpy is unportable - "
608/* Copy SRC to DEST, returning the address of the terminating L'\0' in DEST. */ 753/* Copy SRC to DEST, returning the address of the terminating L'\0' in DEST. */
609#if @GNULIB_WCPCPY@ 754#if @GNULIB_WCPCPY@
610# if !@HAVE_WCPCPY@ 755# if !@HAVE_WCPCPY@
611_GL_FUNCDECL_SYS (wcpcpy, wchar_t *, (wchar_t *dest, const wchar_t *src)); 756_GL_FUNCDECL_SYS (wcpcpy, wchar_t *,
757 (wchar_t *restrict dest, const wchar_t *restrict src));
612# endif 758# endif
613_GL_CXXALIAS_SYS (wcpcpy, wchar_t *, (wchar_t *dest, const wchar_t *src)); 759_GL_CXXALIAS_SYS (wcpcpy, wchar_t *,
760 (wchar_t *restrict dest, const wchar_t *restrict src));
614_GL_CXXALIASWARN (wcpcpy); 761_GL_CXXALIASWARN (wcpcpy);
615#elif defined GNULIB_POSIXCHECK 762#elif defined GNULIB_POSIXCHECK
616# undef wcpcpy 763# undef wcpcpy
@@ -625,11 +772,15 @@ _GL_WARN_ON_USE (wcpcpy, "wcpcpy is unportable - "
625#if @GNULIB_WCSNCPY@ 772#if @GNULIB_WCSNCPY@
626# if !@HAVE_WCSNCPY@ 773# if !@HAVE_WCSNCPY@
627_GL_FUNCDECL_SYS (wcsncpy, wchar_t *, 774_GL_FUNCDECL_SYS (wcsncpy, wchar_t *,
628 (wchar_t *dest, const wchar_t *src, size_t n)); 775 (wchar_t *restrict dest,
776 const wchar_t *restrict src, size_t n));
629# endif 777# endif
630_GL_CXXALIAS_SYS (wcsncpy, wchar_t *, 778_GL_CXXALIAS_SYS (wcsncpy, wchar_t *,
631 (wchar_t *dest, const wchar_t *src, size_t n)); 779 (wchar_t *restrict dest,
780 const wchar_t *restrict src, size_t n));
781# if __GLIBC__ >= 2
632_GL_CXXALIASWARN (wcsncpy); 782_GL_CXXALIASWARN (wcsncpy);
783# endif
633#elif defined GNULIB_POSIXCHECK 784#elif defined GNULIB_POSIXCHECK
634# undef wcsncpy 785# undef wcsncpy
635# if HAVE_RAW_DECL_WCSNCPY 786# if HAVE_RAW_DECL_WCSNCPY
@@ -644,10 +795,12 @@ _GL_WARN_ON_USE (wcsncpy, "wcsncpy is unportable - "
644#if @GNULIB_WCPNCPY@ 795#if @GNULIB_WCPNCPY@
645# if !@HAVE_WCPNCPY@ 796# if !@HAVE_WCPNCPY@
646_GL_FUNCDECL_SYS (wcpncpy, wchar_t *, 797_GL_FUNCDECL_SYS (wcpncpy, wchar_t *,
647 (wchar_t *dest, const wchar_t *src, size_t n)); 798 (wchar_t *restrict dest,
799 const wchar_t *restrict src, size_t n));
648# endif 800# endif
649_GL_CXXALIAS_SYS (wcpncpy, wchar_t *, 801_GL_CXXALIAS_SYS (wcpncpy, wchar_t *,
650 (wchar_t *dest, const wchar_t *src, size_t n)); 802 (wchar_t *restrict dest,
803 const wchar_t *restrict src, size_t n));
651_GL_CXXALIASWARN (wcpncpy); 804_GL_CXXALIASWARN (wcpncpy);
652#elif defined GNULIB_POSIXCHECK 805#elif defined GNULIB_POSIXCHECK
653# undef wcpncpy 806# undef wcpncpy
@@ -661,10 +814,14 @@ _GL_WARN_ON_USE (wcpncpy, "wcpncpy is unportable - "
661/* Append SRC onto DEST. */ 814/* Append SRC onto DEST. */
662#if @GNULIB_WCSCAT@ 815#if @GNULIB_WCSCAT@
663# if !@HAVE_WCSCAT@ 816# if !@HAVE_WCSCAT@
664_GL_FUNCDECL_SYS (wcscat, wchar_t *, (wchar_t *dest, const wchar_t *src)); 817_GL_FUNCDECL_SYS (wcscat, wchar_t *,
818 (wchar_t *restrict dest, const wchar_t *restrict src));
665# endif 819# endif
666_GL_CXXALIAS_SYS (wcscat, wchar_t *, (wchar_t *dest, const wchar_t *src)); 820_GL_CXXALIAS_SYS (wcscat, wchar_t *,
821 (wchar_t *restrict dest, const wchar_t *restrict src));
822# if __GLIBC__ >= 2
667_GL_CXXALIASWARN (wcscat); 823_GL_CXXALIASWARN (wcscat);
824# endif
668#elif defined GNULIB_POSIXCHECK 825#elif defined GNULIB_POSIXCHECK
669# undef wcscat 826# undef wcscat
670# if HAVE_RAW_DECL_WCSCAT 827# if HAVE_RAW_DECL_WCSCAT
@@ -678,11 +835,15 @@ _GL_WARN_ON_USE (wcscat, "wcscat is unportable - "
678#if @GNULIB_WCSNCAT@ 835#if @GNULIB_WCSNCAT@
679# if !@HAVE_WCSNCAT@ 836# if !@HAVE_WCSNCAT@
680_GL_FUNCDECL_SYS (wcsncat, wchar_t *, 837_GL_FUNCDECL_SYS (wcsncat, wchar_t *,
681 (wchar_t *dest, const wchar_t *src, size_t n)); 838 (wchar_t *restrict dest, const wchar_t *restrict src,
839 size_t n));
682# endif 840# endif
683_GL_CXXALIAS_SYS (wcsncat, wchar_t *, 841_GL_CXXALIAS_SYS (wcsncat, wchar_t *,
684 (wchar_t *dest, const wchar_t *src, size_t n)); 842 (wchar_t *restrict dest, const wchar_t *restrict src,
843 size_t n));
844# if __GLIBC__ >= 2
685_GL_CXXALIASWARN (wcsncat); 845_GL_CXXALIASWARN (wcsncat);
846# endif
686#elif defined GNULIB_POSIXCHECK 847#elif defined GNULIB_POSIXCHECK
687# undef wcsncat 848# undef wcsncat
688# if HAVE_RAW_DECL_WCSNCAT 849# if HAVE_RAW_DECL_WCSNCAT
@@ -699,7 +860,9 @@ _GL_FUNCDECL_SYS (wcscmp, int, (const wchar_t *s1, const wchar_t *s2)
699 _GL_ATTRIBUTE_PURE); 860 _GL_ATTRIBUTE_PURE);
700# endif 861# endif
701_GL_CXXALIAS_SYS (wcscmp, int, (const wchar_t *s1, const wchar_t *s2)); 862_GL_CXXALIAS_SYS (wcscmp, int, (const wchar_t *s1, const wchar_t *s2));
863# if __GLIBC__ >= 2
702_GL_CXXALIASWARN (wcscmp); 864_GL_CXXALIASWARN (wcscmp);
865# endif
703#elif defined GNULIB_POSIXCHECK 866#elif defined GNULIB_POSIXCHECK
704# undef wcscmp 867# undef wcscmp
705# if HAVE_RAW_DECL_WCSCMP 868# if HAVE_RAW_DECL_WCSCMP
@@ -718,7 +881,9 @@ _GL_FUNCDECL_SYS (wcsncmp, int,
718# endif 881# endif
719_GL_CXXALIAS_SYS (wcsncmp, int, 882_GL_CXXALIAS_SYS (wcsncmp, int,
720 (const wchar_t *s1, const wchar_t *s2, size_t n)); 883 (const wchar_t *s1, const wchar_t *s2, size_t n));
884# if __GLIBC__ >= 2
721_GL_CXXALIASWARN (wcsncmp); 885_GL_CXXALIASWARN (wcsncmp);
886# endif
722#elif defined GNULIB_POSIXCHECK 887#elif defined GNULIB_POSIXCHECK
723# undef wcsncmp 888# undef wcsncmp
724# if HAVE_RAW_DECL_WCSNCMP 889# if HAVE_RAW_DECL_WCSNCMP
@@ -771,7 +936,9 @@ _GL_WARN_ON_USE (wcsncasecmp, "wcsncasecmp is unportable - "
771_GL_FUNCDECL_SYS (wcscoll, int, (const wchar_t *s1, const wchar_t *s2)); 936_GL_FUNCDECL_SYS (wcscoll, int, (const wchar_t *s1, const wchar_t *s2));
772# endif 937# endif
773_GL_CXXALIAS_SYS (wcscoll, int, (const wchar_t *s1, const wchar_t *s2)); 938_GL_CXXALIAS_SYS (wcscoll, int, (const wchar_t *s1, const wchar_t *s2));
939# if __GLIBC__ >= 2
774_GL_CXXALIASWARN (wcscoll); 940_GL_CXXALIASWARN (wcscoll);
941# endif
775#elif defined GNULIB_POSIXCHECK 942#elif defined GNULIB_POSIXCHECK
776# undef wcscoll 943# undef wcscoll
777# if HAVE_RAW_DECL_WCSCOLL 944# if HAVE_RAW_DECL_WCSCOLL
@@ -786,10 +953,14 @@ _GL_WARN_ON_USE (wcscoll, "wcscoll is unportable - "
786 original strings. */ 953 original strings. */
787#if @GNULIB_WCSXFRM@ 954#if @GNULIB_WCSXFRM@
788# if !@HAVE_WCSXFRM@ 955# if !@HAVE_WCSXFRM@
789_GL_FUNCDECL_SYS (wcsxfrm, size_t, (wchar_t *s1, const wchar_t *s2, size_t n)); 956_GL_FUNCDECL_SYS (wcsxfrm, size_t,
957 (wchar_t *restrict s1, const wchar_t *restrict s2, size_t n));
790# endif 958# endif
791_GL_CXXALIAS_SYS (wcsxfrm, size_t, (wchar_t *s1, const wchar_t *s2, size_t n)); 959_GL_CXXALIAS_SYS (wcsxfrm, size_t,
960 (wchar_t *restrict s1, const wchar_t *restrict s2, size_t n));
961# if __GLIBC__ >= 2
792_GL_CXXALIASWARN (wcsxfrm); 962_GL_CXXALIASWARN (wcsxfrm);
963# endif
793#elif defined GNULIB_POSIXCHECK 964#elif defined GNULIB_POSIXCHECK
794# undef wcsxfrm 965# undef wcsxfrm
795# if HAVE_RAW_DECL_WCSXFRM 966# if HAVE_RAW_DECL_WCSXFRM
@@ -801,16 +972,55 @@ _GL_WARN_ON_USE (wcsxfrm, "wcsxfrm is unportable - "
801 972
802/* Duplicate S, returning an identical malloc'd string. */ 973/* Duplicate S, returning an identical malloc'd string. */
803#if @GNULIB_WCSDUP@ 974#if @GNULIB_WCSDUP@
804# if !@HAVE_WCSDUP@ 975# if defined _WIN32 && !defined __CYGWIN__
805_GL_FUNCDECL_SYS (wcsdup, wchar_t *, (const wchar_t *s)); 976# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
806# endif 977# undef wcsdup
978# define wcsdup _wcsdup
979# endif
980_GL_CXXALIAS_MDA (wcsdup, wchar_t *, (const wchar_t *s));
981# else
982# if !@HAVE_WCSDUP@ || __GNUC__ >= 11
983_GL_FUNCDECL_SYS (wcsdup, wchar_t *,
984 (const wchar_t *s)
985 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
986# endif
807_GL_CXXALIAS_SYS (wcsdup, wchar_t *, (const wchar_t *s)); 987_GL_CXXALIAS_SYS (wcsdup, wchar_t *, (const wchar_t *s));
988# endif
808_GL_CXXALIASWARN (wcsdup); 989_GL_CXXALIASWARN (wcsdup);
809#elif defined GNULIB_POSIXCHECK 990#else
810# undef wcsdup 991# if __GNUC__ >= 11 && !defined wcsdup
811# if HAVE_RAW_DECL_WCSDUP 992/* For -Wmismatched-dealloc: Associate wcsdup with free or rpl_free. */
993_GL_FUNCDECL_SYS (wcsdup, wchar_t *,
994 (const wchar_t *s)
995 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
996# endif
997# if defined GNULIB_POSIXCHECK
998# undef wcsdup
999# if HAVE_RAW_DECL_WCSDUP
812_GL_WARN_ON_USE (wcsdup, "wcsdup is unportable - " 1000_GL_WARN_ON_USE (wcsdup, "wcsdup is unportable - "
813 "use gnulib module wcsdup for portability"); 1001 "use gnulib module wcsdup for portability");
1002# endif
1003# elif @GNULIB_MDA_WCSDUP@
1004/* On native Windows, map 'wcsdup' to '_wcsdup', so that -loldnames is not
1005 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1006 platforms by defining GNULIB_NAMESPACE::wcsdup always. */
1007# if defined _WIN32 && !defined __CYGWIN__
1008# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1009# undef wcsdup
1010# define wcsdup _wcsdup
1011# endif
1012_GL_CXXALIAS_MDA (wcsdup, wchar_t *, (const wchar_t *s));
1013# else
1014_GL_FUNCDECL_SYS (wcsdup, wchar_t *,
1015 (const wchar_t *s)
1016 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);
1017# if @HAVE_DECL_WCSDUP@
1018_GL_CXXALIAS_SYS (wcsdup, wchar_t *, (const wchar_t *s));
1019# endif
1020# endif
1021# if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_WCSDUP@
1022_GL_CXXALIASWARN (wcsdup);
1023# endif
814# endif 1024# endif
815#endif 1025#endif
816 1026
@@ -833,7 +1043,7 @@ _GL_CXXALIAS_SYS_CAST2 (wcschr,
833 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) 1043 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
834_GL_CXXALIASWARN1 (wcschr, wchar_t *, (wchar_t *wcs, wchar_t wc)); 1044_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)); 1045_GL_CXXALIASWARN1 (wcschr, const wchar_t *, (const wchar_t *wcs, wchar_t wc));
836# else 1046# elif __GLIBC__ >= 2
837_GL_CXXALIASWARN (wcschr); 1047_GL_CXXALIASWARN (wcschr);
838# endif 1048# endif
839#elif defined GNULIB_POSIXCHECK 1049#elif defined GNULIB_POSIXCHECK
@@ -863,7 +1073,7 @@ _GL_CXXALIAS_SYS_CAST2 (wcsrchr,
863 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) 1073 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
864_GL_CXXALIASWARN1 (wcsrchr, wchar_t *, (wchar_t *wcs, wchar_t wc)); 1074_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)); 1075_GL_CXXALIASWARN1 (wcsrchr, const wchar_t *, (const wchar_t *wcs, wchar_t wc));
866# else 1076# elif __GLIBC__ >= 2
867_GL_CXXALIASWARN (wcsrchr); 1077_GL_CXXALIASWARN (wcsrchr);
868# endif 1078# endif
869#elif defined GNULIB_POSIXCHECK 1079#elif defined GNULIB_POSIXCHECK
@@ -883,7 +1093,9 @@ _GL_FUNCDECL_SYS (wcscspn, size_t, (const wchar_t *wcs, const wchar_t *reject)
883 _GL_ATTRIBUTE_PURE); 1093 _GL_ATTRIBUTE_PURE);
884# endif 1094# endif
885_GL_CXXALIAS_SYS (wcscspn, size_t, (const wchar_t *wcs, const wchar_t *reject)); 1095_GL_CXXALIAS_SYS (wcscspn, size_t, (const wchar_t *wcs, const wchar_t *reject));
1096# if __GLIBC__ >= 2
886_GL_CXXALIASWARN (wcscspn); 1097_GL_CXXALIASWARN (wcscspn);
1098# endif
887#elif defined GNULIB_POSIXCHECK 1099#elif defined GNULIB_POSIXCHECK
888# undef wcscspn 1100# undef wcscspn
889# if HAVE_RAW_DECL_WCSCSPN 1101# if HAVE_RAW_DECL_WCSCSPN
@@ -901,7 +1113,9 @@ _GL_FUNCDECL_SYS (wcsspn, size_t, (const wchar_t *wcs, const wchar_t *accept)
901 _GL_ATTRIBUTE_PURE); 1113 _GL_ATTRIBUTE_PURE);
902# endif 1114# endif
903_GL_CXXALIAS_SYS (wcsspn, size_t, (const wchar_t *wcs, const wchar_t *accept)); 1115_GL_CXXALIAS_SYS (wcsspn, size_t, (const wchar_t *wcs, const wchar_t *accept));
1116# if __GLIBC__ >= 2
904_GL_CXXALIASWARN (wcsspn); 1117_GL_CXXALIASWARN (wcsspn);
1118# endif
905#elif defined GNULIB_POSIXCHECK 1119#elif defined GNULIB_POSIXCHECK
906# undef wcsspn 1120# undef wcsspn
907# if HAVE_RAW_DECL_WCSSPN 1121# if HAVE_RAW_DECL_WCSSPN
@@ -932,7 +1146,7 @@ _GL_CXXALIASWARN1 (wcspbrk, wchar_t *,
932 (wchar_t *wcs, const wchar_t *accept)); 1146 (wchar_t *wcs, const wchar_t *accept));
933_GL_CXXALIASWARN1 (wcspbrk, const wchar_t *, 1147_GL_CXXALIASWARN1 (wcspbrk, const wchar_t *,
934 (const wchar_t *wcs, const wchar_t *accept)); 1148 (const wchar_t *wcs, const wchar_t *accept));
935# else 1149# elif __GLIBC__ >= 2
936_GL_CXXALIASWARN (wcspbrk); 1150_GL_CXXALIASWARN (wcspbrk);
937# endif 1151# endif
938#elif defined GNULIB_POSIXCHECK 1152#elif defined GNULIB_POSIXCHECK
@@ -948,7 +1162,8 @@ _GL_WARN_ON_USE (wcspbrk, "wcspbrk is unportable - "
948#if @GNULIB_WCSSTR@ 1162#if @GNULIB_WCSSTR@
949# if !@HAVE_WCSSTR@ 1163# if !@HAVE_WCSSTR@
950_GL_FUNCDECL_SYS (wcsstr, wchar_t *, 1164_GL_FUNCDECL_SYS (wcsstr, wchar_t *,
951 (const wchar_t *haystack, const wchar_t *needle) 1165 (const wchar_t *restrict haystack,
1166 const wchar_t *restrict needle)
952 _GL_ATTRIBUTE_PURE); 1167 _GL_ATTRIBUTE_PURE);
953# endif 1168# endif
954 /* On some systems, this function is defined as an overloaded function: 1169 /* On some systems, this function is defined as an overloaded function:
@@ -957,15 +1172,19 @@ _GL_FUNCDECL_SYS (wcsstr, wchar_t *,
957 wchar_t * std::wcsstr (wchar_t *, const wchar_t *); 1172 wchar_t * std::wcsstr (wchar_t *, const wchar_t *);
958 } */ 1173 } */
959_GL_CXXALIAS_SYS_CAST2 (wcsstr, 1174_GL_CXXALIAS_SYS_CAST2 (wcsstr,
960 wchar_t *, (const wchar_t *, const wchar_t *), 1175 wchar_t *,
961 const wchar_t *, (const wchar_t *, const wchar_t *)); 1176 (const wchar_t *restrict, const wchar_t *restrict),
1177 const wchar_t *,
1178 (const wchar_t *restrict, const wchar_t *restrict));
962# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \ 1179# if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 10) && !defined __UCLIBC__) \
963 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) 1180 && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
964_GL_CXXALIASWARN1 (wcsstr, wchar_t *, 1181_GL_CXXALIASWARN1 (wcsstr, wchar_t *,
965 (wchar_t *haystack, const wchar_t *needle)); 1182 (wchar_t *restrict haystack,
1183 const wchar_t *restrict needle));
966_GL_CXXALIASWARN1 (wcsstr, const wchar_t *, 1184_GL_CXXALIASWARN1 (wcsstr, const wchar_t *,
967 (const wchar_t *haystack, const wchar_t *needle)); 1185 (const wchar_t *restrict haystack,
968# else 1186 const wchar_t *restrict needle));
1187# elif __GLIBC__ >= 2
969_GL_CXXALIASWARN (wcsstr); 1188_GL_CXXALIASWARN (wcsstr);
970# endif 1189# endif
971#elif defined GNULIB_POSIXCHECK 1190#elif defined GNULIB_POSIXCHECK
@@ -979,13 +1198,30 @@ _GL_WARN_ON_USE (wcsstr, "wcsstr is unportable - "
979 1198
980/* Divide WCS into tokens separated by characters in DELIM. */ 1199/* Divide WCS into tokens separated by characters in DELIM. */
981#if @GNULIB_WCSTOK@ 1200#if @GNULIB_WCSTOK@
982# if !@HAVE_WCSTOK@ 1201# if @REPLACE_WCSTOK@
1202# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1203# undef wcstok
1204# define wcstok rpl_wcstok
1205# endif
1206_GL_FUNCDECL_RPL (wcstok, wchar_t *,
1207 (wchar_t *restrict wcs, const wchar_t *restrict delim,
1208 wchar_t **restrict ptr));
1209_GL_CXXALIAS_RPL (wcstok, wchar_t *,
1210 (wchar_t *restrict wcs, const wchar_t *restrict delim,
1211 wchar_t **restrict ptr));
1212# else
1213# if !@HAVE_WCSTOK@
983_GL_FUNCDECL_SYS (wcstok, wchar_t *, 1214_GL_FUNCDECL_SYS (wcstok, wchar_t *,
984 (wchar_t *wcs, const wchar_t *delim, wchar_t **ptr)); 1215 (wchar_t *restrict wcs, const wchar_t *restrict delim,
985# endif 1216 wchar_t **restrict ptr));
1217# endif
986_GL_CXXALIAS_SYS (wcstok, wchar_t *, 1218_GL_CXXALIAS_SYS (wcstok, wchar_t *,
987 (wchar_t *wcs, const wchar_t *delim, wchar_t **ptr)); 1219 (wchar_t *restrict wcs, const wchar_t *restrict delim,
1220 wchar_t **restrict ptr));
1221# endif
1222# if __GLIBC__ >= 2
988_GL_CXXALIASWARN (wcstok); 1223_GL_CXXALIASWARN (wcstok);
1224# endif
989#elif defined GNULIB_POSIXCHECK 1225#elif defined GNULIB_POSIXCHECK
990# undef wcstok 1226# undef wcstok
991# if HAVE_RAW_DECL_WCSTOK 1227# if HAVE_RAW_DECL_WCSTOK
@@ -1013,7 +1249,9 @@ _GL_FUNCDECL_SYS (wcswidth, int, (const wchar_t *s, size_t n)
1013# endif 1249# endif
1014_GL_CXXALIAS_SYS (wcswidth, int, (const wchar_t *s, size_t n)); 1250_GL_CXXALIAS_SYS (wcswidth, int, (const wchar_t *s, size_t n));
1015# endif 1251# endif
1252# if __GLIBC__ >= 2
1016_GL_CXXALIASWARN (wcswidth); 1253_GL_CXXALIASWARN (wcswidth);
1254# endif
1017#elif defined GNULIB_POSIXCHECK 1255#elif defined GNULIB_POSIXCHECK
1018# undef wcswidth 1256# undef wcswidth
1019# if HAVE_RAW_DECL_WCSWIDTH 1257# if HAVE_RAW_DECL_WCSWIDTH
@@ -1023,6 +1261,48 @@ _GL_WARN_ON_USE (wcswidth, "wcswidth is unportable - "
1023#endif 1261#endif
1024 1262
1025 1263
1264/* Convert *TP to a date and time wide string. See
1265 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcsftime.html>. */
1266#if @GNULIB_WCSFTIME@
1267# if @REPLACE_WCSFTIME@
1268# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1269# undef wcsftime
1270# define wcsftime rpl_wcsftime
1271# endif
1272_GL_FUNCDECL_RPL (wcsftime, size_t,
1273 (wchar_t *restrict __buf, size_t __bufsize,
1274 const wchar_t *restrict __fmt,
1275 const struct tm *restrict __tp)
1276 _GL_ARG_NONNULL ((1, 3, 4)));
1277_GL_CXXALIAS_RPL (wcsftime, size_t,
1278 (wchar_t *restrict __buf, size_t __bufsize,
1279 const wchar_t *restrict __fmt,
1280 const struct tm *restrict __tp));
1281# else
1282# if !@HAVE_WCSFTIME@
1283_GL_FUNCDECL_SYS (wcsftime, size_t,
1284 (wchar_t *restrict __buf, size_t __bufsize,
1285 const wchar_t *restrict __fmt,
1286 const struct tm *restrict __tp)
1287 _GL_ARG_NONNULL ((1, 3, 4)));
1288# endif
1289_GL_CXXALIAS_SYS (wcsftime, size_t,
1290 (wchar_t *restrict __buf, size_t __bufsize,
1291 const wchar_t *restrict __fmt,
1292 const struct tm *restrict __tp));
1293# endif
1294# if __GLIBC__ >= 2
1295_GL_CXXALIASWARN (wcsftime);
1296# endif
1297#elif defined GNULIB_POSIXCHECK
1298# undef wcsftime
1299# if HAVE_RAW_DECL_WCSFTIME
1300_GL_WARN_ON_USE (wcsftime, "wcsftime is unportable - "
1301 "use gnulib module wcsftime for portability");
1302# endif
1303#endif
1304
1305
1026#endif /* _@GUARD_PREFIX@_WCHAR_H */ 1306#endif /* _@GUARD_PREFIX@_WCHAR_H */
1027#endif /* _@GUARD_PREFIX@_WCHAR_H */ 1307#endif /* _@GUARD_PREFIX@_WCHAR_H */
1028#endif 1308#endif
diff --git a/gl/wcrtomb.c b/gl/wcrtomb.c
index da42809..5c9fd79 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-2021 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..150221d 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-2021 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..652d811 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-2021 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..7999b23
--- /dev/null
+++ b/gl/windows-initguard.h
@@ -0,0 +1,35 @@
1/* Init guards, somewhat like spinlocks (native Windows implementation).
2 Copyright (C) 2005-2021 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..2edfeaa
--- /dev/null
+++ b/gl/windows-mutex.c
@@ -0,0 +1,95 @@
1/* Plain mutexes (native Windows implementation).
2 Copyright (C) 2005-2021 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..5ecf9f8
--- /dev/null
+++ b/gl/windows-mutex.h
@@ -0,0 +1,51 @@
1/* Plain mutexes (native Windows implementation).
2 Copyright (C) 2005-2021 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..8dcd37c
--- /dev/null
+++ b/gl/windows-once.c
@@ -0,0 +1,62 @@
1/* Once-only control (native Windows implementation).
2 Copyright (C) 2005-2021 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..58632f9
--- /dev/null
+++ b/gl/windows-once.h
@@ -0,0 +1,47 @@
1/* Once-only control (native Windows implementation).
2 Copyright (C) 2005-2021 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..cfc94b4
--- /dev/null
+++ b/gl/windows-recmutex.c
@@ -0,0 +1,127 @@
1/* Plain recursive mutexes (native Windows implementation).
2 Copyright (C) 2005-2021 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..174fe73
--- /dev/null
+++ b/gl/windows-recmutex.h
@@ -0,0 +1,57 @@
1/* Plain recursive mutexes (native Windows implementation).
2 Copyright (C) 2005-2021 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..d63936c
--- /dev/null
+++ b/gl/windows-rwlock.c
@@ -0,0 +1,377 @@
1/* Read-write locks (native Windows implementation).
2 Copyright (C) 2005-2021 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..280c9f2
--- /dev/null
+++ b/gl/windows-rwlock.h
@@ -0,0 +1,68 @@
1/* Read-write locks (native Windows implementation).
2 Copyright (C) 2005-2021 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..1bf0a9e 100644
--- a/gl/xalloc-die.c
+++ b/gl/xalloc-die.c
@@ -1,6 +1,6 @@
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-2021 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
@@ -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..4184f33 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-2021 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..7f2c3fb 100644
--- a/gl/xalloc.h
+++ b/gl/xalloc.h
@@ -1,6 +1,6 @@
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-2021 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
@@ -13,57 +13,94 @@
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>
23#include <stdint.h>
22 24
23#include "xalloc-oversized.h" 25#if GNULIB_XALLOC
26# include "idx.h"
27# include "intprops.h"
28#endif
24 29
30#ifndef _GL_INLINE_HEADER_BEGIN
31 #error "Please include config.h first."
32#endif
25_GL_INLINE_HEADER_BEGIN 33_GL_INLINE_HEADER_BEGIN
26#ifndef XALLOC_INLINE 34#ifndef XALLOC_INLINE
27# define XALLOC_INLINE _GL_INLINE 35# define XALLOC_INLINE _GL_INLINE
28#endif 36#endif
29 37
38
30#ifdef __cplusplus 39#ifdef __cplusplus
31extern "C" { 40extern "C" {
32#endif 41#endif
33 42
34 43
35#if __GNUC__ >= 3 44#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 45
47/* This function is always triggered when memory is exhausted. 46/* This function is always triggered when memory is exhausted.
48 It must be defined by the application, either explicitly 47 It must be defined by the application, either explicitly
49 or by using gnulib's xalloc-die module. This is the 48 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 49 function to call when one wants the program to die because of a
51 memory allocation failure. */ 50 memory allocation failure. */
52extern _Noreturn void xalloc_die (void); 51/*extern*/ _Noreturn void xalloc_die (void);
52
53#endif /* GNULIB_XALLOC_DIE */
54
55#if GNULIB_XALLOC
53 56
54void *xmalloc (size_t s) 57void *xmalloc (size_t s)
55 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1)); 58 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
59 _GL_ATTRIBUTE_ALLOC_SIZE ((1)) _GL_ATTRIBUTE_RETURNS_NONNULL;
60void *ximalloc (idx_t s)
61 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
62 _GL_ATTRIBUTE_ALLOC_SIZE ((1)) _GL_ATTRIBUTE_RETURNS_NONNULL;
63void *xinmalloc (idx_t n, idx_t s)
64 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
65 _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2)) _GL_ATTRIBUTE_RETURNS_NONNULL;
56void *xzalloc (size_t s) 66void *xzalloc (size_t s)
57 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1)); 67 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
68 _GL_ATTRIBUTE_ALLOC_SIZE ((1)) _GL_ATTRIBUTE_RETURNS_NONNULL;
69void *xizalloc (idx_t s)
70 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
71 _GL_ATTRIBUTE_ALLOC_SIZE ((1)) _GL_ATTRIBUTE_RETURNS_NONNULL;
58void *xcalloc (size_t n, size_t s) 72void *xcalloc (size_t n, size_t s)
59 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2)); 73 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
74 _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2)) _GL_ATTRIBUTE_RETURNS_NONNULL;
75void *xicalloc (idx_t n, idx_t s)
76 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
77 _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2)) _GL_ATTRIBUTE_RETURNS_NONNULL;
60void *xrealloc (void *p, size_t s) 78void *xrealloc (void *p, size_t s)
61 _GL_ATTRIBUTE_ALLOC_SIZE ((2)); 79 _GL_ATTRIBUTE_ALLOC_SIZE ((2));
62void *x2realloc (void *p, size_t *pn); 80void *xirealloc (void *p, idx_t s)
81 _GL_ATTRIBUTE_ALLOC_SIZE ((2)) _GL_ATTRIBUTE_RETURNS_NONNULL;
82void *xreallocarray (void *p, size_t n, size_t s)
83 _GL_ATTRIBUTE_ALLOC_SIZE ((2, 3));
84void *xireallocarray (void *p, idx_t n, idx_t s)
85 _GL_ATTRIBUTE_ALLOC_SIZE ((2, 3)) _GL_ATTRIBUTE_RETURNS_NONNULL;
86void *x2realloc (void *p, size_t *ps) /* superseded by xpalloc */
87 _GL_ATTRIBUTE_RETURNS_NONNULL;
88void *x2nrealloc (void *p, size_t *pn, size_t s) /* superseded by xpalloc */
89 _GL_ATTRIBUTE_RETURNS_NONNULL;
90void *xpalloc (void *pa, idx_t *pn, idx_t n_incr_min, ptrdiff_t n_max, idx_t s)
91 _GL_ATTRIBUTE_RETURNS_NONNULL;
63void *xmemdup (void const *p, size_t s) 92void *xmemdup (void const *p, size_t s)
64 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((2)); 93 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
94 _GL_ATTRIBUTE_ALLOC_SIZE ((2)) _GL_ATTRIBUTE_RETURNS_NONNULL;
95void *ximemdup (void const *p, idx_t s)
96 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
97 _GL_ATTRIBUTE_ALLOC_SIZE ((2)) _GL_ATTRIBUTE_RETURNS_NONNULL;
98char *ximemdup0 (void const *p, idx_t s)
99 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
100 _GL_ATTRIBUTE_RETURNS_NONNULL;
65char *xstrdup (char const *str) 101char *xstrdup (char const *str)
66 _GL_ATTRIBUTE_MALLOC; 102 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
103 _GL_ATTRIBUTE_RETURNS_NONNULL;
67 104
68/* In the following macros, T must be an elementary or structure/union or 105/* 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 106 typedef'ed type, or a pointer to such a type. To apply one of the
@@ -72,153 +109,60 @@ char *xstrdup (char const *str)
72 109
73/* Allocate an object of type T dynamically, with error checking. */ 110/* Allocate an object of type T dynamically, with error checking. */
74/* extern t *XMALLOC (typename t); */ 111/* extern t *XMALLOC (typename t); */
75#define XMALLOC(t) ((t *) xmalloc (sizeof (t))) 112# define XMALLOC(t) ((t *) xmalloc (sizeof (t)))
76 113
77/* Allocate memory for N elements of type T, with error checking. */ 114/* Allocate memory for N elements of type T, with error checking. */
78/* extern t *XNMALLOC (size_t n, typename t); */ 115/* extern t *XNMALLOC (size_t n, typename t); */
79#define XNMALLOC(n, t) \ 116# define XNMALLOC(n, t) \
80 ((t *) (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t)))) 117 ((t *) (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t))))
81 118
82/* Allocate an object of type T dynamically, with error checking, 119/* Allocate an object of type T dynamically, with error checking,
83 and zero it. */ 120 and zero it. */
84/* extern t *XZALLOC (typename t); */ 121/* extern t *XZALLOC (typename t); */
85#define XZALLOC(t) ((t *) xzalloc (sizeof (t))) 122# define XZALLOC(t) ((t *) xzalloc (sizeof (t)))
86 123
87/* Allocate memory for N elements of type T, with error checking, 124/* Allocate memory for N elements of type T, with error checking,
88 and zero it. */ 125 and zero it. */
89/* extern t *XCALLOC (size_t n, typename t); */ 126/* extern t *XCALLOC (size_t n, typename t); */
90#define XCALLOC(n, t) \ 127# define XCALLOC(n, t) \
91 ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t)))) 128 ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t))))
92 129
93 130
94/* Allocate an array of N objects, each with S bytes of memory, 131/* Allocate an array of N objects, each with S bytes of memory,
95 dynamically, with error checking. S must be nonzero. */ 132 dynamically, with error checking. S must be nonzero. */
96 133
97XALLOC_INLINE void *xnmalloc (size_t n, size_t s) 134void *xnmalloc (size_t n, size_t s)
98 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2)); 135 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
99XALLOC_INLINE void * 136 _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 137
138/* FIXME: Deprecate this in favor of xreallocarray? */
107/* Change the size of an allocated block of memory P to an array of N 139/* 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. */ 140 objects each of S bytes, with error checking. S must be nonzero. */
109 141
110XALLOC_INLINE void *xnrealloc (void *p, size_t n, size_t s) 142XALLOC_INLINE void *xnrealloc (void *p, size_t n, size_t s)
111 _GL_ATTRIBUTE_ALLOC_SIZE ((2, 3)); 143 _GL_ATTRIBUTE_ALLOC_SIZE ((2, 3));
112XALLOC_INLINE void * 144XALLOC_INLINE void *
113xnrealloc (void *p, size_t n, size_t s) 145xnrealloc (void *p, size_t n, size_t s)
114{ 146{
115 if (xalloc_oversized (n, s)) 147 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} 148}
208 149
209/* Return a pointer to a new buffer of N bytes. This is like xmalloc, 150/* Return a pointer to a new buffer of N bytes. This is like xmalloc,
210 except it returns char *. */ 151 except it returns char *. */
211 152
212XALLOC_INLINE char *xcharalloc (size_t n) 153char *xcharalloc (size_t n)
213 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1)); 154 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
214XALLOC_INLINE char * 155 _GL_ATTRIBUTE_ALLOC_SIZE ((1)) _GL_ATTRIBUTE_RETURNS_NONNULL;
215xcharalloc (size_t n) 156
216{ 157#endif /* GNULIB_XALLOC */
217 return XNMALLOC (n, char); 158
218}
219 159
220#ifdef __cplusplus 160#ifdef __cplusplus
221} 161}
162#endif
163
164
165#if GNULIB_XALLOC && defined __cplusplus
222 166
223/* C++ does not allow conversions from void * to other pointer types 167/* C++ does not allow conversions from void * to other pointer types
224 without a cast. Use templates to work around the problem when 168 without a cast. Use templates to work around the problem when
@@ -231,9 +175,16 @@ xrealloc (T *p, size_t s)
231} 175}
232 176
233template <typename T> inline T * 177template <typename T> inline T *
178xreallocarray (T *p, size_t n, size_t s)
179{
180 return (T *) xreallocarray ((void *) p, n, s);
181}
182
183/* FIXME: Deprecate this in favor of xreallocarray? */
184template <typename T> inline T *
234xnrealloc (T *p, size_t n, size_t s) 185xnrealloc (T *p, size_t n, size_t s)
235{ 186{
236 return (T *) xnrealloc ((void *) p, n, s); 187 return xreallocarray (p, n, s);
237} 188}
238 189
239template <typename T> inline T * 190template <typename T> inline T *
@@ -254,7 +205,9 @@ xmemdup (T const *p, size_t s)
254 return (T *) xmemdup ((void const *) p, s); 205 return (T *) xmemdup ((void const *) p, s);
255} 206}
256 207
257#endif 208#endif /* GNULIB_XALLOC && C++ */
209
258 210
211_GL_INLINE_HEADER_END
259 212
260#endif /* !XALLOC_H_ */ 213#endif /* !XALLOC_H_ */
diff --git a/gl/xmalloc.c b/gl/xmalloc.c
index 57e34b7..d5def0b 100644
--- a/gl/xmalloc.c
+++ b/gl/xmalloc.c
@@ -1,6 +1,6 @@
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-2021 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
@@ -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,255 @@
21 21
22#include "xalloc.h" 22#include "xalloc.h"
23 23
24#include "ialloc.h"
25#include "intprops.h"
26#include "minmax.h"
27
24#include <stdlib.h> 28#include <stdlib.h>
25#include <string.h> 29#include <string.h>
26 30
27/* 1 if calloc is known to be compatible with GNU calloc. This 31static void * _GL_ATTRIBUTE_PURE
28 matters if we are not also using the calloc module, which defines 32nonnull (void *p)
29 HAVE_CALLOC_GNU and supports the GNU API even on non-GNU platforms. */ 33{
30#if defined HAVE_CALLOC_GNU || (defined __GLIBC__ && !defined __UCLIBC__) 34 if (!p)
31enum { HAVE_GNU_CALLOC = 1 }; 35 xalloc_die ();
32#else 36 return p;
33enum { HAVE_GNU_CALLOC = 0 }; 37}
34#endif
35 38
36/* Allocate N bytes of memory dynamically, with error checking. */ 39/* Allocate S bytes of memory dynamically, with error checking. */
37 40
38void * 41void *
39xmalloc (size_t n) 42xmalloc (size_t s)
40{ 43{
41 void *p = malloc (n); 44 return nonnull (malloc (s));
42 if (!p && n != 0) 45}
43 xalloc_die (); 46
44 return p; 47void *
48ximalloc (idx_t s)
49{
50 return nonnull (imalloc (s));
45} 51}
46 52
47/* Change the size of an allocated block of memory P to N bytes, 53char *
54xcharalloc (size_t n)
55{
56 return XNMALLOC (n, char);
57}
58
59/* Change the size of an allocated block of memory P to S bytes,
48 with error checking. */ 60 with error checking. */
49 61
50void * 62void *
51xrealloc (void *p, size_t n) 63xrealloc (void *p, size_t s)
64{
65 void *r = realloc (p, s);
66 if (!r && (!p || s))
67 xalloc_die ();
68 return r;
69}
70
71void *
72xirealloc (void *p, idx_t s)
73{
74 return nonnull (irealloc (p, s));
75}
76
77/* Change the size of an allocated block of memory P to an array of N
78 objects each of S bytes, with error checking. */
79
80void *
81xreallocarray (void *p, size_t n, size_t s)
82{
83 void *r = reallocarray (p, n, s);
84 if (!r && (!p || (n && s)))
85 xalloc_die ();
86 return r;
87}
88
89void *
90xireallocarray (void *p, idx_t n, idx_t s)
91{
92 return nonnull (ireallocarray (p, n, s));
93}
94
95/* Allocate an array of N objects, each with S bytes of memory,
96 dynamically, with error checking. S must be nonzero. */
97
98void *
99xnmalloc (size_t n, size_t s)
100{
101 return xreallocarray (NULL, n, s);
102}
103
104void *
105xinmalloc (idx_t n, idx_t s)
106{
107 return xireallocarray (NULL, n, s);
108}
109
110/* If P is null, allocate a block of at least *PS bytes; otherwise,
111 reallocate P so that it contains more than *PS bytes. *PS must be
112 nonzero unless P is null. Set *PS to the new block's size, and
113 return the pointer to the new block. *PS is never set to zero, and
114 the returned pointer is never null. */
115
116void *
117x2realloc (void *p, size_t *ps)
118{
119 return x2nrealloc (p, ps, 1);
120}
121
122/* If P is null, allocate a block of at least *PN such objects;
123 otherwise, reallocate P so that it contains more than *PN objects
124 each of S bytes. S must be nonzero. Set *PN to the new number of
125 objects, and return the pointer to the new block. *PN is never set
126 to zero, and the returned pointer is never null.
127
128 Repeated reallocations are guaranteed to make progress, either by
129 allocating an initial block with a nonzero size, or by allocating a
130 larger block.
131
132 In the following implementation, nonzero sizes are increased by a
133 factor of approximately 1.5 so that repeated reallocations have
134 O(N) overall cost rather than O(N**2) cost, but the
135 specification for this function does not guarantee that rate.
136
137 Here is an example of use:
138
139 int *p = NULL;
140 size_t used = 0;
141 size_t allocated = 0;
142
143 void
144 append_int (int value)
145 {
146 if (used == allocated)
147 p = x2nrealloc (p, &allocated, sizeof *p);
148 p[used++] = value;
149 }
150
151 This causes x2nrealloc to allocate a block of some nonzero size the
152 first time it is called.
153
154 To have finer-grained control over the initial size, set *PN to a
155 nonzero value before calling this function with P == NULL. For
156 example:
157
158 int *p = NULL;
159 size_t used = 0;
160 size_t allocated = 0;
161 size_t allocated1 = 1000;
162
163 void
164 append_int (int value)
165 {
166 if (used == allocated)
167 {
168 p = x2nrealloc (p, &allocated1, sizeof *p);
169 allocated = allocated1;
170 }
171 p[used++] = value;
172 }
173
174 */
175
176void *
177x2nrealloc (void *p, size_t *pn, size_t s)
52{ 178{
53 if (!n && p) 179 size_t n = *pn;
180
181 if (! p)
54 { 182 {
55 /* The GNU and C99 realloc behaviors disagree here. Act like 183 if (! n)
56 GNU, even if the underlying realloc is C99. */ 184 {
57 free (p); 185 /* The approximate size to use for initial small allocation
58 return NULL; 186 requests, when the invoking code specifies an old size of
187 zero. This is the largest "small" request for the GNU C
188 library malloc. */
189 enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 };
190
191 n = DEFAULT_MXFAST / s;
192 n += !n;
193 }
194 }
195 else
196 {
197 /* Set N = floor (1.5 * N) + 1 to make progress even if N == 0. */
198 if (INT_ADD_WRAPV (n, (n >> 1) + 1, &n))
199 xalloc_die ();
59 } 200 }
60 201
61 p = realloc (p, n); 202 p = xreallocarray (p, n, s);
62 if (!p && n) 203 *pn = n;
63 xalloc_die ();
64 return p; 204 return p;
65} 205}
66 206
67/* If P is null, allocate a block of at least *PN bytes; otherwise, 207/* 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 208 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 209 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 210 items, but will not contain more than N_MAX items total.
71 the returned pointer is never null. */ 211 S is the size of each item, in bytes.
212
213 S and N_INCR_MIN must be positive. *PN must be
214 nonnegative. If N_MAX is -1, it is treated as if it were
215 infinity.
216
217 If PA is null, then allocate a new array instead of reallocating
218 the old one.
219
220 Thus, to grow an array A without saving its old contents, do
221 { free (A); A = xpalloc (NULL, &AITEMS, ...); }. */
72 222
73void * 223void *
74x2realloc (void *p, size_t *pn) 224xpalloc (void *pa, idx_t *pn, idx_t n_incr_min, ptrdiff_t n_max, idx_t s)
75{ 225{
76 return x2nrealloc (p, pn, 1); 226 idx_t n0 = *pn;
227
228 /* The approximate size to use for initial small allocation
229 requests. This is the largest "small" request for the GNU C
230 library malloc. */
231 enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 };
232
233 /* If the array is tiny, grow it to about (but no greater than)
234 DEFAULT_MXFAST bytes. Otherwise, grow it by about 50%.
235 Adjust the growth according to three constraints: N_INCR_MIN,
236 N_MAX, and what the C language can represent safely. */
237
238 idx_t n;
239 if (INT_ADD_WRAPV (n0, n0 >> 1, &n))
240 n = IDX_MAX;
241 if (0 <= n_max && n_max < n)
242 n = n_max;
243
244 /* NBYTES is of a type suitable for holding the count of bytes in an object.
245 This is typically idx_t, but it should be size_t on (theoretical?)
246 platforms where SIZE_MAX < IDX_MAX so xpalloc does not pass
247 values greater than SIZE_MAX to xrealloc. */
248#if IDX_MAX <= SIZE_MAX
249 idx_t nbytes;
250#else
251 size_t nbytes;
252#endif
253 idx_t adjusted_nbytes
254 = (INT_MULTIPLY_WRAPV (n, s, &nbytes)
255 ? MIN (IDX_MAX, SIZE_MAX)
256 : nbytes < DEFAULT_MXFAST ? DEFAULT_MXFAST : 0);
257 if (adjusted_nbytes)
258 {
259 n = adjusted_nbytes / s;
260 nbytes = adjusted_nbytes - adjusted_nbytes % s;
261 }
262
263 if (! pa)
264 *pn = 0;
265 if (n - n0 < n_incr_min
266 && (INT_ADD_WRAPV (n0, n_incr_min, &n)
267 || (0 <= n_max && n_max < n)
268 || INT_MULTIPLY_WRAPV (n, s, &nbytes)))
269 xalloc_die ();
270 pa = xrealloc (pa, nbytes);
271 *pn = n;
272 return pa;
77} 273}
78 274
79/* Allocate S bytes of zeroed memory dynamically, with error checking. 275/* Allocate S bytes of zeroed memory dynamically, with error checking.
@@ -83,7 +279,13 @@ x2realloc (void *p, size_t *pn)
83void * 279void *
84xzalloc (size_t s) 280xzalloc (size_t s)
85{ 281{
86 return memset (xmalloc (s), 0, s); 282 return xcalloc (s, 1);
283}
284
285void *
286xizalloc (idx_t s)
287{
288 return xicalloc (s, 1);
87} 289}
88 290
89/* Allocate zeroed memory for N elements of S bytes, with error 291/* Allocate zeroed memory for N elements of S bytes, with error
@@ -92,15 +294,13 @@ xzalloc (size_t s)
92void * 294void *
93xcalloc (size_t n, size_t s) 295xcalloc (size_t n, size_t s)
94{ 296{
95 void *p; 297 return nonnull (calloc (n, s));
96 /* Test for overflow, since some calloc implementations don't have 298}
97 proper overflow checks. But omit overflow and size-zero tests if 299
98 HAVE_GNU_CALLOC, since GNU calloc catches overflow and never 300void *
99 returns NULL if successful. */ 301xicalloc (idx_t n, idx_t s)
100 if ((! HAVE_GNU_CALLOC && xalloc_oversized (n, s)) 302{
101 || (! (p = calloc (n, s)) && (HAVE_GNU_CALLOC || n != 0))) 303 return nonnull (icalloc (n, s));
102 xalloc_die ();
103 return p;
104} 304}
105 305
106/* Clone an object P of size S, with error checking. There's no need 306/* Clone an object P of size S, with error checking. There's no need
@@ -113,6 +313,23 @@ xmemdup (void const *p, size_t s)
113 return memcpy (xmalloc (s), p, s); 313 return memcpy (xmalloc (s), p, s);
114} 314}
115 315
316void *
317ximemdup (void const *p, idx_t s)
318{
319 return memcpy (ximalloc (s), p, s);
320}
321
322/* Clone an object P of size S, with error checking. Append
323 a terminating NUL byte. */
324
325char *
326ximemdup0 (void const *p, idx_t s)
327{
328 char *result = ximalloc (s + 1);
329 result[s] = 0;
330 return memcpy (result, p, s);
331}
332
116/* Clone STRING. */ 333/* Clone STRING. */
117 334
118char * 335char *
diff --git a/gl/xsize.c b/gl/xsize.c
index 4b4914c..b3d73a2 100644
--- a/gl/xsize.c
+++ b/gl/xsize.c
@@ -1,3 +1,21 @@
1/* Checked size_t computations.
2
3 Copyright (C) 2012-2021 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..91fa877 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-2021 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);