Compare commits
10 Commits
65418e9b6b
...
master
Author | SHA1 | Date | |
---|---|---|---|
31280c8475 | |||
bc1456e464 | |||
d03e779a72 | |||
8d7bbe5417 | |||
e725f20b30 | |||
cefd122c19 | |||
494e3724ed | |||
5df2ddbd89 | |||
96246e8eb8 | |||
daafec68f5 |
62
README.md
62
README.md
@ -1,22 +1,56 @@
|
|||||||
# rm_
|
# rm_
|
||||||
代替rm命令防止错误删除文件
|
代替rm命令防止错误删除文件
|
||||||
基于coreutils-8.32 mv源代码
|
基于coreutils-9.1 mv源代码
|
||||||
|
|
||||||
# Build
|
# Build
|
||||||
git clone https://github.com/niuyuling/rm_.git
|
git clone https://git.aixiao.me/aixiao/rm_
|
||||||
cd rm_
|
cd rm_
|
||||||
apt-get build-dep coreutils
|
bash build.sh
|
||||||
bash build_mv.sh
|
|
||||||
|
|
||||||
# Help Information
|
# Help Information
|
||||||
root@niuyuling:/mnt/c/Users/niuyuling/Desktop/Arm-tool# rm_ busybox-1.31.1
|
root@NIUYULING:/mnt/c/Users/niuyuling/Desktop/rm_# ./rm_ --help
|
||||||
rm_
|
Usage: ./rm_ [OPTION]... [-T] SOURCE DEST
|
||||||
busybox-1.31.1
|
or: ./rm_ [OPTION]... SOURCE... DIRECTORY
|
||||||
/tmp/
|
or: ./rm_ [OPTION]... -t DIRECTORY SOURCE...
|
||||||
3
|
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
|
||||||
root@niuyuling:/mnt/c/Users/niuyuling/Desktop/Arm-tool#
|
|
||||||
|
|
||||||
#支持配置文件
|
Mandatory arguments to long options are mandatory for short options too.
|
||||||
root@NIUYULING:/mnt/c/Users/niuyuling/Desktop/rm_# cat /etc/rm_.conf
|
--backup[=CONTROL] make a backup of each existing destination file
|
||||||
/opt/
|
-b like --backup but does not accept an argument
|
||||||
root@NIUYULING:/mnt/c/Users/niuyuling/Desktop/rm_#
|
-f, --force do not prompt before overwriting
|
||||||
|
-i, --interactive prompt before overwrite
|
||||||
|
-n, --no-clobber do not overwrite an existing file
|
||||||
|
If you specify more than one of -i, -f, -n, only the final one takes effect.
|
||||||
|
--strip-trailing-slashes remove any trailing slashes from each SOURCE
|
||||||
|
argument
|
||||||
|
-S, --suffix=SUFFIX override the usual backup suffix
|
||||||
|
-t, --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY
|
||||||
|
-T, --no-target-directory treat DEST as a normal file
|
||||||
|
-u, --update move only when the SOURCE file is newer
|
||||||
|
than the destination file or when the
|
||||||
|
destination file is missing
|
||||||
|
-v, --verbose explain what is being done
|
||||||
|
-Z, --context set SELinux security context of destination
|
||||||
|
file to default type
|
||||||
|
--help display this help and exit
|
||||||
|
--version output version information and exit
|
||||||
|
|
||||||
|
Instead of rm command to prevent mistaken deletion of files
|
||||||
|
Author: aixiao@aixiao.me
|
||||||
|
|
||||||
|
代替rm命令,以防止错误删除文件
|
||||||
|
作者: aixiao@aixiao.me
|
||||||
|
|
||||||
|
The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
|
||||||
|
The version control method may be selected via the --backup option or through
|
||||||
|
the VERSION_CONTROL environment variable. Here are the values:
|
||||||
|
|
||||||
|
none, off never make backups (even if --backup is given)
|
||||||
|
numbered, t make numbered backups
|
||||||
|
existing, nil numbered if numbered backups exist, simple otherwise
|
||||||
|
simple, never always make simple backups
|
||||||
|
|
||||||
|
GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
|
||||||
|
Report any translation bugs to <https://translationproject.org/team/>
|
||||||
|
Full documentation <https://www.gnu.org/software/coreutils/mv>
|
||||||
|
or available locally via: info '(coreutils) mv invocation'
|
141
build.sh
Normal file
141
build.sh
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Build MV command
|
||||||
|
# Based on coreutils-9.1
|
||||||
|
# Test System: Debian GNU/Linux bookworm/sid (WSL)
|
||||||
|
#
|
||||||
|
|
||||||
|
init()
|
||||||
|
{
|
||||||
|
SHELL_FOLDER=$(dirname $(readlink -f "$0"));
|
||||||
|
CC=${CROSS_COMPILE}gcc
|
||||||
|
AR=${CROSS_COMPILE}ar
|
||||||
|
STRIP=${CROSS_COMPILE}strip
|
||||||
|
}
|
||||||
|
|
||||||
|
check_os()
|
||||||
|
{
|
||||||
|
if test -f /etc/debian_version ; then
|
||||||
|
OS=debian
|
||||||
|
OS_VER=$(cat /etc/debian_version)
|
||||||
|
echo -e SYSTEM: DEBIAN $(uname -m) ${OS_VER}\\nKERNEL: $(uname -sr)
|
||||||
|
apt-get build-dep coreutils
|
||||||
|
else
|
||||||
|
echo "Only supports Debian system build source code!";
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
build_lib()
|
||||||
|
{
|
||||||
|
S=(lib/copy-acl.c lib/set-acl.c lib/acl-errno-valid.c lib/acl-internal.c lib/get-permissions.c lib/set-permissions.c lib/alignalloc.c lib/allocator.c lib/areadlink.c lib/areadlink-with-size.c lib/areadlinkat.c lib/areadlinkat-with-size.c lib/argmatch.c lib/argv-iter.c lib/openat-proc.c lib/backupfile.c lib/backup-rename.c lib/backupfile.c lib/backup-find.c lib/base32.c lib/base64.c lib/basename-lgpl.c lib/binary-io.c lib/bitrotate.c lib/buffer-lcm.c lib/c-ctype.c lib/c-strcasecmp.c lib/c-strncasecmp.c lib/c-strtod.c lib/c-strtold.c lib/canon-host.c lib/canonicalize.c lib/careadlinkat.c lib/chdir-long.c lib/chmodat.c lib/chownat.c lib/cl-strtod.c lib/cl-strtold.c lib/cloexec.c lib/close-stream.c lib/closein.c lib/closeout.c lib/count-leading-zeros.c lib/af_alg.c lib/md5-stream.c lib/md5.c lib/sha1-stream.c lib/sha1.c lib/sha256-stream.c lib/sha256.c lib/sha512-stream.c lib/sha512.c lib/sm3-stream.c lib/sm3.c lib/cycle-check.c lib/di-set.c lib/opendir-safer.c lib/dirname.c lib/basename.c lib/dirname-lgpl.c lib/stripslash.c lib/dtoastr.c lib/dtotimespec.c lib/malloc/dynarray_at_failure.c lib/malloc/dynarray_emplace_enlarge.c lib/malloc/dynarray_finalize.c lib/malloc/dynarray_resize.c lib/malloc/dynarray_resize_clear.c lib/exclude.c lib/exitfail.c lib/fadvise.c lib/fchmodat.c lib/fclose.c lib/fcntl.c lib/creat-safer.c lib/open-safer.c lib/fd-hook.c lib/fd-reopen.c lib/fd-safer-flag.c lib/dup-safer-flag.c lib/fdutimensat.c lib/fflush.c lib/file-has-acl.c lib/file-set.c lib/file-type.c lib/filemode.c lib/filenamecat.c lib/filenamecat-lgpl.c lib/filevercmp.c lib/fopen-safer.c lib/fprintftime.c lib/fpurge.c lib/freadahead.c lib/freading.c lib/freadptr.c lib/freadseek.c lib/freopen-safer.c lib/fseek.c lib/fseeko.c lib/fseterr.c lib/fsusage.c lib/ftoastr.c lib/fts.c lib/full-read.c lib/full-write.c lib/gethrxtime.c lib/xtime.c lib/getndelim2.c lib/getprogname.c lib/gettime.c lib/gettime-res.c lib/getugroups.c lib/hard-locale.c lib/hash.c lib/hash-pjw.c lib/hash-triple.c lib/hash-triple-simple.c lib/heap.c lib/human.c lib/i-ring.c lib/ialloc.c lib/idcache.c lib/ino-map.c lib/imaxtostr.c lib/inttostr.c lib/offtostr.c lib/uinttostr.c lib/umaxtostr.c lib/isapipe.c lib/ldtoastr.c lib/linebuffer.c lib/localcharset.c lib/glthread/lock.c lib/long-options.c lib/malloca.c lib/math.c lib/mbchar.c lib/mbiter.c lib/mbrlen.c lib/mbrtowc.c lib/mbsalign.c lib/mbscasecmp.c lib/mbschr.c lib/mbslen.c lib/mbsstr.c lib/mbswidth.c lib/mbuiter.c lib/memcasecmp.c lib/memchr2.c lib/memcmp2.c lib/memcoll.c lib/mgetgroups.c lib/mkancesdirs.c lib/dirchownmod.c lib/mkdir-p.c lib/mknod.c lib/mkstemp.c lib/modechange.c lib/mountlist.c lib/mpsort.c lib/nanosleep.c lib/nproc.c lib/nstrftime.c lib/obstack.c lib/openat-die.c lib/openat-safer.c lib/opendirat.c lib/parse-datetime.c lib/physmem.c lib/pipe2.c lib/posixtm.c lib/posixver.c lib/printf-frexp.c lib/printf-frexpl.c lib/priv-set.c lib/progname.c lib/propername.c lib/qcopy-acl.c lib/qset-acl.c lib/quotearg.c lib/randint.c lib/randperm.c lib/randread.c lib/rand-isaac.c lib/read-file.c lib/readtokens.c lib/readtokens0.c lib/readutmp.c lib/regex.c lib/renameatu.c lib/root-dev-ino.c lib/safe-read.c lib/safe-write.c lib/same.c lib/save-cwd.c lib/savedir.c lib/savewd.c lib/malloc/scratch_buffer_dupfree.c lib/malloc/scratch_buffer_grow.c lib/malloc/scratch_buffer_grow_preserve.c lib/malloc/scratch_buffer_set_array_size.c lib/selinux-at.c lib/getfilecon.c lib/se-context.c lib/se-label.c lib/se-selinux.c lib/setlocale_null.c lib/settime.c lib/sig2str.c lib/sig-handler.c lib/sockets.c lib/stat-time.c lib/mkstemp-safer.c lib/striconv.c lib/strnlen1.c lib/strintcmp.c lib/strnumcmp.c lib/sys_socket.c lib/targetdir.c lib/tempname.c lib/glthread/threadlib.c lib/time_rz.c lib/timegm.c lib/timespec.c lib/glthread/tls.c lib/trim.c lib/u64.c lib/unicodeio.c lib/unistd.c lib/dup-safer.c lib/fd-safer.c lib/pipe-safer.c lib/unistr/u8-mbtoucr.c lib/unistr/u8-uctomb.c lib/unistr/u8-uctomb-aux.c lib/uniwidth/width.c lib/unlinkdir.c lib/userspec.c lib/utimecmp.c lib/utimens.c lib/verror.c lib/version-etc.c lib/version-etc-fsf.c lib/wctype-h.c lib/write-any-file.c lib/xalignalloc.c lib/xmalloc.c lib/xalloc-die.c lib/xbinary-io.c lib/xdectoimax.c lib/xdectoumax.c lib/xfts.c lib/xgetcwd.c lib/xgetgroups.c lib/xgethostname.c lib/xmemcoll.c lib/xnanosleep.c lib/xprintf.c lib/xreadlink.c lib/xsize.c lib/xstriconv.c lib/xstrtod.c lib/xstrtoimax.c lib/xstrtol.c lib/xstrtoul.c lib/xstrtol-error.c lib/xstrtold.c lib/xstrtoumax.c lib/xvasprintf.c lib/xasprintf.c lib/yesno.c lib/asnprintf.c lib/mktime.c lib/printf-args.c lib/printf-parse.c lib/vasnprintf.c)
|
||||||
|
O="lib/copy-acl.o lib/set-acl.o lib/acl-errno-valid.o lib/acl-internal.o lib/get-permissions.o lib/set-permissions.o lib/alignalloc.o lib/allocator.o lib/areadlink.o lib/areadlink-with-size.o lib/areadlinkat.o lib/areadlinkat-with-size.o lib/argmatch.o lib/argv-iter.o lib/openat-proc.o lib/backupfile.o lib/backup-rename.o lib/backupfile.o lib/backup-find.o lib/base32.o lib/base64.o lib/basename-lgpl.o lib/binary-io.o lib/bitrotate.o lib/buffer-lcm.o lib/c-ctype.o lib/c-strcasecmp.o lib/c-strncasecmp.o lib/c-strtod.o lib/c-strtold.o lib/canon-host.o lib/canonicalize.o lib/careadlinkat.o lib/chdir-long.o lib/chmodat.o lib/chownat.o lib/cl-strtod.o lib/cl-strtold.o lib/cloexec.o lib/close-stream.o lib/closein.o lib/closeout.o lib/count-leading-zeros.o lib/af_alg.o lib/md5-stream.o lib/md5.o lib/sha1-stream.o lib/sha1.o lib/sha256-stream.o lib/sha256.o lib/sha512-stream.o lib/sha512.o lib/sm3-stream.o lib/sm3.o lib/cycle-check.o lib/di-set.o lib/opendir-safer.o lib/dirname.o lib/basename.o lib/dirname-lgpl.o lib/stripslash.o lib/dtoastr.o lib/dtotimespec.o lib/malloc/dynarray_at_failure.o lib/malloc/dynarray_emplace_enlarge.o lib/malloc/dynarray_finalize.o lib/malloc/dynarray_resize.o lib/malloc/dynarray_resize_clear.o lib/exclude.o lib/exitfail.o lib/fadvise.o lib/fchmodat.o lib/fclose.o lib/fcntl.o lib/creat-safer.o lib/open-safer.o lib/fd-hook.o lib/fd-reopen.o lib/fd-safer-flag.o lib/dup-safer-flag.o lib/fdutimensat.o lib/fflush.o lib/file-has-acl.o lib/file-set.o lib/file-type.o lib/filemode.o lib/filenamecat.o lib/filenamecat-lgpl.o lib/filevercmp.o lib/fopen-safer.o lib/fprintftime.o lib/fpurge.o lib/freadahead.o lib/freading.o lib/freadptr.o lib/freadseek.o lib/freopen-safer.o lib/fseek.o lib/fseeko.o lib/fseterr.o lib/fsusage.o lib/ftoastr.o lib/fts.o lib/full-read.o lib/full-write.o lib/gethrxtime.o lib/xtime.o lib/getndelim2.o lib/getprogname.o lib/gettime.o lib/gettime-res.o lib/getugroups.o lib/hard-locale.o lib/hash.o lib/hash-pjw.o lib/hash-triple.o lib/hash-triple-simple.o lib/heap.o lib/human.o lib/i-ring.o lib/ialloc.o lib/idcache.o lib/ino-map.o lib/imaxtostr.o lib/inttostr.o lib/offtostr.o lib/uinttostr.o lib/umaxtostr.o lib/isapipe.o lib/ldtoastr.o lib/linebuffer.o lib/localcharset.o lib/glthread/lock.o lib/long-options.o lib/malloca.o lib/math.o lib/mbchar.o lib/mbiter.o lib/mbrlen.o lib/mbrtowc.o lib/mbsalign.o lib/mbscasecmp.o lib/mbschr.o lib/mbslen.o lib/mbsstr.o lib/mbswidth.o lib/mbuiter.o lib/memcasecmp.o lib/memchr2.o lib/memcmp2.o lib/memcoll.o lib/mgetgroups.o lib/mkancesdirs.o lib/dirchownmod.o lib/mkdir-p.o lib/mknod.o lib/mkstemp.o lib/modechange.o lib/mountlist.o lib/mpsort.o lib/nanosleep.o lib/nproc.o lib/nstrftime.o lib/obstack.o lib/openat-die.o lib/openat-safer.o lib/opendirat.o lib/parse-datetime.o lib/physmem.o lib/pipe2.o lib/posixtm.o lib/posixver.o lib/printf-frexp.o lib/printf-frexpl.o lib/priv-set.o lib/progname.o lib/propername.o lib/qcopy-acl.o lib/qset-acl.o lib/quotearg.o lib/randint.o lib/randperm.o lib/randread.o lib/rand-isaac.o lib/read-file.o lib/readtokens.o lib/readtokens0.o lib/readutmp.o lib/regex.o lib/renameatu.o lib/root-dev-ino.o lib/safe-read.o lib/safe-write.o lib/same.o lib/save-cwd.o lib/savedir.o lib/savewd.o lib/malloc/scratch_buffer_dupfree.o lib/malloc/scratch_buffer_grow.o lib/malloc/scratch_buffer_grow_preserve.o lib/malloc/scratch_buffer_set_array_size.o lib/selinux-at.o lib/getfilecon.o lib/se-context.o lib/se-label.o lib/se-selinux.o lib/setlocale_null.o lib/settime.o lib/sig2str.o lib/sig-handler.o lib/sockets.o lib/stat-time.o lib/mkstemp-safer.o lib/striconv.o lib/strnlen1.o lib/strintcmp.o lib/strnumcmp.o lib/sys_socket.o lib/targetdir.o lib/tempname.o lib/glthread/threadlib.o lib/time_rz.o lib/timegm.o lib/timespec.o lib/glthread/tls.o lib/trim.o lib/u64.o lib/unicodeio.o lib/unistd.o lib/dup-safer.o lib/fd-safer.o lib/pipe-safer.o lib/unistr/u8-mbtoucr.o lib/unistr/u8-uctomb.o lib/unistr/u8-uctomb-aux.o lib/uniwidth/width.o lib/unlinkdir.o lib/userspec.o lib/utimecmp.o lib/utimens.o lib/verror.o lib/version-etc.o lib/version-etc-fsf.o lib/wctype-h.o lib/write-any-file.o lib/xalignalloc.o lib/xmalloc.o lib/xalloc-die.o lib/xbinary-io.o lib/xdectoimax.o lib/xdectoumax.o lib/xfts.o lib/xgetcwd.o lib/xgetgroups.o lib/xgethostname.o lib/xmemcoll.o lib/xnanosleep.o lib/xprintf.o lib/xreadlink.o lib/xsize.o lib/xstriconv.o lib/xstrtod.o lib/xstrtoimax.o lib/xstrtol.o lib/xstrtoul.o lib/xstrtol-error.o lib/xstrtold.o lib/xstrtoumax.o lib/xvasprintf.o lib/xasprintf.o lib/yesno.o lib/asnprintf.o lib/mktime.o lib/printf-args.o lib/printf-parse.o lib/vasnprintf.o"
|
||||||
|
|
||||||
|
for i in ${S[@]}; do
|
||||||
|
echo $i
|
||||||
|
o=$(echo $i | sed 's/\.c/\.o/');
|
||||||
|
echo $o;
|
||||||
|
${CC} -I. -I./lib -Ilib -I./lib -g -O2 -c -o ${o} ${i}
|
||||||
|
done
|
||||||
|
|
||||||
|
${AR} cr lib/libcoreutils.a ${O};
|
||||||
|
}
|
||||||
|
|
||||||
|
build_mv()
|
||||||
|
{
|
||||||
|
|
||||||
|
${CC} -I. -I./lib -Ilib -I./lib -Isrc -I./src -g -O2 -c -o src/version.o src/version.c
|
||||||
|
${AR} cr src/libver.a src/version.o
|
||||||
|
|
||||||
|
${CC} -I. -I./lib -Ilib -I./lib -Isrc -I./src -g -O2 -c -o src/remove.o src/remove.c
|
||||||
|
${CC} -I. -I./lib -Ilib -I./lib -Isrc -I./src -g -O2 -c -o src/copy.o src/copy.c
|
||||||
|
${CC} -I. -I./lib -Ilib -I./lib -Isrc -I./src -g -O2 -c -o src/cp-hash.o src/cp-hash.c
|
||||||
|
${CC} -I. -I./lib -Ilib -I./lib -Isrc -I./src -g -O2 -c -o src/force-link.o src/force-link.c
|
||||||
|
${CC} -I. -I./lib -Ilib -I./lib -Isrc -I./src -g -O2 -c -o src/selinux.o src/selinux.c
|
||||||
|
${CC} -I. -I./lib -Ilib -I./lib -Isrc -I./src -g -O2 -c -o src/mv.o src/mv.c
|
||||||
|
|
||||||
|
|
||||||
|
${CC} -g -O2 -Wl,--as-needed -o src/mv src/mv.o src/remove.o src/copy.o src/cp-hash.o src/force-link.o src/selinux.o src/libver.a \
|
||||||
|
lib/libcoreutils.a lib/libcoreutils.a -lselinux -lacl -lattr -pthread -lpcre2-8 -ldl -static
|
||||||
|
|
||||||
|
mv src/mv ./rm_
|
||||||
|
$STRIP ./rm_
|
||||||
|
}
|
||||||
|
|
||||||
|
installbin_()
|
||||||
|
{
|
||||||
|
wget --no-check-certificate -O /bin/rm_ https://git.aixiao.me/attachments/aa26219b-868d-4eb4-a8e0-b1b04da7d964
|
||||||
|
chmod a+x /bin/rm_
|
||||||
|
}
|
||||||
|
|
||||||
|
install_() {
|
||||||
|
cp rm_ /bin/
|
||||||
|
}
|
||||||
|
|
||||||
|
uninstall_() {
|
||||||
|
rm /bin/rm_
|
||||||
|
}
|
||||||
|
|
||||||
|
help_() {
|
||||||
|
cat << EOF
|
||||||
|
Usage:
|
||||||
|
${0} [-x] [installbin|install|uninstall|build|clean].
|
||||||
|
parameter:
|
||||||
|
-x : print debug.
|
||||||
|
|
||||||
|
Option:
|
||||||
|
installbin : download bin.
|
||||||
|
install : install bin.
|
||||||
|
uninstall : uninstall bin.
|
||||||
|
build : build project.
|
||||||
|
clean : clean project.
|
||||||
|
|
||||||
|
EOF
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
while getopts :x arg; do
|
||||||
|
case ${arg} in
|
||||||
|
x)
|
||||||
|
debug=x;
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
help_;
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
done
|
||||||
|
shift $((OPTIND-1)); #参数移位
|
||||||
|
test "${debug}" = "x" && set -x;
|
||||||
|
|
||||||
|
init
|
||||||
|
case $1 in
|
||||||
|
"install")
|
||||||
|
install_;
|
||||||
|
;;
|
||||||
|
"uninstall")
|
||||||
|
uninstall_;
|
||||||
|
;;
|
||||||
|
"build")
|
||||||
|
check_os
|
||||||
|
build_lib;
|
||||||
|
build_mv;
|
||||||
|
;;
|
||||||
|
"clean")
|
||||||
|
rm `find . \( -name "*.a" -o -name "*.o" \) | xargs `
|
||||||
|
rm -rf rm_
|
||||||
|
exit 0;
|
||||||
|
;;
|
||||||
|
"installbin")
|
||||||
|
installbin_
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
help_;
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
by aixiao@aixiao.me
|
||||||
|
20220728
|
57
build_mv.sh
57
build_mv.sh
@ -1,57 +0,0 @@
|
|||||||
#!/bin/bsh
|
|
||||||
#
|
|
||||||
# Build MV command
|
|
||||||
# based on coreutils-8.32
|
|
||||||
#
|
|
||||||
|
|
||||||
function init() {
|
|
||||||
SHELL_FOLDER=$(dirname $(readlink -f "$0"));
|
|
||||||
set -x
|
|
||||||
}
|
|
||||||
|
|
||||||
function LIB() {
|
|
||||||
S=(copy-acl.c set-acl.c acl-errno-valid.c acl-internal.c get-permissions.c set-permissions.c allocator.c areadlink.c areadlink-with-size.c areadlinkat.c argmatch.c argv-iter.c openat-proc.c backupfile.c backup-rename.c backupfile.c backup-find.c base32.c base64.c binary-io.c bitrotate.c buffer-lcm.c c-ctype.c c-strcasecmp.c c-strncasecmp.c c-strtod.c c-strtold.c canon-host.c canonicalize.c careadlinkat.c chmodat.c chownat.c cl-strtod.c cl-strtold.c cloexec.c close-stream.c closein.c closeout.c count-leading-zeros.c af_alg.c md5.c sha1.c sha256.c sha512.c cycle-check.c di-set.c diacrit.c opendir-safer.c dirname.c basename.c dirname-lgpl.c basename-lgpl.c stripslash.c dtoastr.c dtotimespec.c exclude.c exitfail.c fadvise.c creat-safer.c open-safer.c fd-hook.c fd-reopen.c fd-safer-flag.c dup-safer-flag.c fdutimensat.c file-has-acl.c file-set.c file-type.c filemode.c filenamecat.c filenamecat-lgpl.c filevercmp.c fopen-safer.c fprintftime.c freading.c freadseek.c freopen-safer.c ftoastr.c full-read.c full-write.c gethrxtime.c xtime.c getndelim2.c getprogname.c gettime.c getugroups.c hard-locale.c hash.c hash-pjw.c hash-triple.c heap.c human.c i-ring.c idcache.c ino-map.c imaxtostr.c inttostr.c offtostr.c uinttostr.c umaxtostr.c ldtoastr.c linebuffer.c localcharset.c glthread/lock.c long-options.c malloca.c math.c mbchar.c mbiter.c mbsalign.c mbscasecmp.c mbschr.c mbslen.c mbsstr.c mbswidth.c mbuiter.c memcasecmp.c memchr2.c memcmp2.c memcoll.c mgetgroups.c mkancesdirs.c dirchownmod.c mkdir-p.c modechange.c mpsort.c nproc.c nstrftime.c openat-die.c openat-safer.c opendirat.c parse-datetime.c physmem.c pipe2.c posixtm.c posixver.c printf-frexp.c printf-frexpl.c priv-set.c progname.c propername.c qcopy-acl.c qset-acl.c quotearg.c randint.c randperm.c randread.c rand-isaac.c read-file.c readtokens.c readtokens0.c renameatu.c root-dev-ino.c safe-read.c safe-write.c same.c save-cwd.c savedir.c savewd.c selinux-at.c se-context.c se-selinux.c setlocale_null.c settime.c sig-handler.c sockets.c stat-time.c statat.c mkstemp-safer.c striconv.c strnlen1.c strintcmp.c strnumcmp.c sys_socket.c tempname.c glthread/threadlib.c timespec.c glthread/tls.c trim.c u64.c unicodeio.c unistd.c dup-safer.c fd-safer.c pipe-safer.c unistr/u8-mbtoucr.c unistr/u8-uctomb.c unistr/u8-uctomb-aux.c uniwidth/width.c unlinkdir.c userspec.c utimecmp.c utimens.c verror.c version-etc.c version-etc-fsf.c wctype-h.c write-any-file.c xmalloc.c xalloc-die.c xbinary-io.c xdectoimax.c xdectoumax.c xfts.c xgetcwd.c xgetgroups.c xgethostname.c xmemcoll.c xnanosleep.c xprintf.c xreadlink.c xsize.c xstriconv.c xstrndup.c xstrtod.c xstrtoimax.c xstrtol.c xstrtoul.c xstrtol-error.c xstrtold.c xstrtoumax.c xvasprintf.c xasprintf.c yesno.c asnprintf.c chdir-long.c fchmodat.c fclose.c fcntl.c fflush.c fpurge.c freadahead.c freadptr.c fseek.c fseeko.c fseterr.c fsusage.c fts.c getfilecon.c isapipe.c lchmod.c localtime-buffer.c mbrlen.c mbrtowc.c mknod.c mkstemp.c mktime.c mountlist.c nanosleep.c obstack.c printf-args.c printf-parse.c readutmp.c regex.c sig2str.c time_rz.c vasnprintf.c)
|
|
||||||
O="copy-acl.o set-acl.o acl-errno-valid.o acl-internal.o get-permissions.o set-permissions.o allocator.o areadlink.o areadlink-with-size.o areadlinkat.o argmatch.o argv-iter.o openat-proc.o backupfile.o backup-rename.o backupfile.o backup-find.o base32.o base64.o binary-io.o bitrotate.o buffer-lcm.o c-ctype.o c-strcasecmp.o c-strncasecmp.o c-strtod.o c-strtold.o canon-host.o canonicalize.o careadlinkat.o chmodat.o chownat.o cl-strtod.o cl-strtold.o cloexec.o close-stream.o closein.o closeout.o count-leading-zeros.o af_alg.o md5.o sha1.o sha256.o sha512.o cycle-check.o di-set.o diacrit.o opendir-safer.o dirname.o basename.o dirname-lgpl.o basename-lgpl.o stripslash.o dtoastr.o dtotimespec.o exclude.o exitfail.o fadvise.o creat-safer.o open-safer.o fd-hook.o fd-reopen.o fd-safer-flag.o dup-safer-flag.o fdutimensat.o file-has-acl.o file-set.o file-type.o filemode.o filenamecat.o filenamecat-lgpl.o filevercmp.o fopen-safer.o fprintftime.o freading.o freadseek.o freopen-safer.o ftoastr.o full-read.o full-write.o gethrxtime.o xtime.o getndelim2.o getprogname.o gettime.o getugroups.o hard-locale.o hash.o hash-pjw.o hash-triple.o heap.o human.o i-ring.o idcache.o ino-map.o imaxtostr.o inttostr.o offtostr.o uinttostr.o umaxtostr.o ldtoastr.o linebuffer.o localcharset.o glthread/lock.o long-options.o malloca.o math.o mbchar.o mbiter.o mbsalign.o mbscasecmp.o mbschr.o mbslen.o mbsstr.o mbswidth.o mbuiter.o memcasecmp.o memchr2.o memcmp2.o memcoll.o mgetgroups.o mkancesdirs.o dirchownmod.o mkdir-p.o modechange.o mpsort.o nproc.o nstrftime.o openat-die.o openat-safer.o opendirat.o parse-datetime.o physmem.o pipe2.o posixtm.o posixver.o printf-frexp.o printf-frexpl.o priv-set.o progname.o propername.o qcopy-acl.o qset-acl.o quotearg.o randint.o randperm.o randread.o rand-isaac.o read-file.o readtokens.o readtokens0.o renameatu.o root-dev-ino.o safe-read.o safe-write.o same.o save-cwd.o savedir.o savewd.o selinux-at.o se-context.o se-selinux.o setlocale_null.o settime.o sig-handler.o sockets.o stat-time.o statat.o mkstemp-safer.o striconv.o strnlen1.o strintcmp.o strnumcmp.o sys_socket.o tempname.o glthread/threadlib.o timespec.o glthread/tls.o trim.o u64.o unicodeio.o unistd.o dup-safer.o fd-safer.o pipe-safer.o unistr/u8-mbtoucr.o unistr/u8-uctomb.o unistr/u8-uctomb-aux.o uniwidth/width.o unlinkdir.o userspec.o utimecmp.o utimens.o verror.o version-etc.o version-etc-fsf.o wctype-h.o write-any-file.o xmalloc.o xalloc-die.o xbinary-io.o xdectoimax.o xdectoumax.o xfts.o xgetcwd.o xgetgroups.o xgethostname.o xmemcoll.o xnanosleep.o xprintf.o xreadlink.o xsize.o xstriconv.o xstrndup.o xstrtod.o xstrtoimax.o xstrtol.o xstrtoul.o xstrtol-error.o xstrtold.o xstrtoumax.o xvasprintf.o xasprintf.o yesno.o asnprintf.o chdir-long.o fchmodat.o fclose.o fcntl.o fflush.o fpurge.o freadahead.o freadptr.o fseek.o fseeko.o fseterr.o fsusage.o fts.o getfilecon.o isapipe.o lchmod.o localtime-buffer.o mbrlen.o mbrtowc.o mknod.o mkstemp.o mktime.o mountlist.o nanosleep.o obstack.o printf-args.o printf-parse.o readutmp.o regex.o sig2str.o time_rz.o vasnprintf.o"
|
|
||||||
|
|
||||||
for i in ${S[@]}; do
|
|
||||||
echo $i
|
|
||||||
o=$(echo $i | sed 's/\.c/\.o/');
|
|
||||||
echo $o;
|
|
||||||
gcc -I. -I./lib -Ilib -I./lib -g -O2 -c -o lib/${o} lib/${i}
|
|
||||||
done
|
|
||||||
|
|
||||||
cd ${SHELL_FOLDER}/lib;
|
|
||||||
ar cr libcoreutils.a ${O};
|
|
||||||
}
|
|
||||||
|
|
||||||
function MV() {
|
|
||||||
cd ${SHELL_FOLDER};
|
|
||||||
gcc -I./lib -c -o version.o version.c
|
|
||||||
ar cr libver.a version.o
|
|
||||||
gcc -I. -I./lib -g -O2 -c -o remove.o remove.c
|
|
||||||
gcc -I. -I./lib -g -O2 -c -o copy.o copy.c
|
|
||||||
gcc -I. -I./lib -g -O2 -c -o cp-hash.o cp-hash.c
|
|
||||||
gcc -I. -I./lib -g -O2 -c -o extent-scan.o extent-scan.c
|
|
||||||
gcc -I. -I./lib -g -O2 -c -o force-link.o force-link.c
|
|
||||||
gcc -I. -I./lib -g -O2 -c -o selinux.o selinux.c
|
|
||||||
gcc -I. -I./lib -g -O2 -c -o mv.o mv.c
|
|
||||||
|
|
||||||
gcc -g -O2 -Wl,--as-needed -o mv \
|
|
||||||
mv.o remove.o copy.o cp-hash.o extent-scan.o force-link.o selinux.o libver.a lib/libcoreutils.a lib/libcoreutils.a \
|
|
||||||
-lselinux -lacl -lattr -pthread -lpcre2-8 -ldl -static
|
|
||||||
|
|
||||||
mv ./mv rm_
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
init
|
|
||||||
|
|
||||||
if test "$@" = "clean"; then
|
|
||||||
rm `find . \( -name "*.a" -o -name "*.o" \) | xargs `
|
|
||||||
rm rm_
|
|
||||||
exit 0;
|
|
||||||
fi
|
|
||||||
|
|
||||||
LIB
|
|
||||||
MV
|
|
63
build_mv.txt
63
build_mv.txt
@ -1,63 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
# MV
|
|
||||||
gcc -I. -I./lib -Ilib -I./lib -Isrc -I./src -g -O2 -MT src/mv.o -MD -MP -MF src/.deps/mv.Tpo -c -o src/mv.o src/mv.c
|
|
||||||
gcc -g -O2 -Wl,--as-needed -o src/mv \
|
|
||||||
src/mv.o src/remove.o src/copy.o src/cp-hash.o src/extent-scan.o src/force-link.o src/selinux.o src/libver.a lib/libcoreutils.a lib/libcoreutils.a \
|
|
||||||
-lselinux -lacl -lattr -pthread -lpcre2-8 -ldl -static
|
|
||||||
|
|
||||||
|
|
||||||
# remove.o
|
|
||||||
gcc -I. -I./lib -Ilib -I./lib -Isrc -I./src -g -O2 -MT src/remove.o -MD -MP -MF src/.deps/remove.Tpo -c -o src/remove.o src/remove.c
|
|
||||||
|
|
||||||
# copy.o
|
|
||||||
gcc -I. -I./lib -Ilib -I./lib -Isrc -I./src -g -O2 -MT src/copy.o -MD -MP -MF src/.deps/copy.Tpo -c -o src/copy.o src/copy.c
|
|
||||||
|
|
||||||
# cp-hash.o
|
|
||||||
gcc -I. -I./lib -Ilib -I./lib -Isrc -I./src -g -O2 -MT src/cp-hash.o -MD -MP -MF src/.deps/cp-hash.Tpo -c -o src/cp-hash.o src/cp-hash.c
|
|
||||||
|
|
||||||
# extent-scan.o
|
|
||||||
gcc -I. -I./lib -Ilib -I./lib -Isrc -I./src -g -O2 -MT src/extent-scan.o -MD -MP -MF src/.deps/extent-scan.Tpo -c -o src/extent-scan.o src/extent-scan.c
|
|
||||||
|
|
||||||
# force-link.o
|
|
||||||
gcc -I. -I./lib -Ilib -I./lib -Isrc -I./src -g -O2 -MT src/force-link.o -MD -MP -MF src/.deps/force-link.Tpo -c -o src/force-link.o src/force-link.c
|
|
||||||
|
|
||||||
# selinux.o
|
|
||||||
gcc -I. -I./lib -Ilib -I./lib -Isrc -I./src -g -O2 -MT src/selinux.o -MD -MP -MF src/.deps/selinux.Tpo -c -o src/selinux.o src/selinux.c
|
|
||||||
|
|
||||||
# libver.a
|
|
||||||
ar cr src/libver.a src/version.o
|
|
||||||
|
|
||||||
# libcoreutils.a
|
|
||||||
ar cr lib/libcoreutils.a lib/copy-acl.o lib/set-acl.o lib/acl-errno-valid.o lib/acl-internal.o lib/get-permissions.o lib/set-permissions.o \
|
|
||||||
lib/allocator.o lib/areadlink.o lib/areadlink-with-size.o lib/areadlinkat.o lib/argmatch.o lib/argv-iter.o lib/openat-proc.o lib/backupfile.o \
|
|
||||||
lib/backup-rename.o lib/backupfile.o lib/backup-find.o lib/base32.o lib/base64.o lib/binary-io.o lib/bitrotate.o lib/buffer-lcm.o lib/c-ctype.o \
|
|
||||||
lib/c-strcasecmp.o lib/c-strncasecmp.o lib/c-strtod.o lib/c-strtold.o lib/canon-host.o lib/canonicalize.o lib/careadlinkat.o lib/chmodat.o lib/chownat.o \
|
|
||||||
lib/cl-strtod.o lib/cl-strtold.o lib/cloexec.o lib/close-stream.o lib/closein.o lib/closeout.o lib/count-leading-zeros.o lib/af_alg.o lib/md5.o lib/sha1.o \
|
|
||||||
lib/sha256.o lib/sha512.o lib/cycle-check.o lib/di-set.o lib/diacrit.o lib/opendir-safer.o lib/dirname.o lib/basename.o lib/dirname-lgpl.o lib/basename-lgpl.o \
|
|
||||||
lib/stripslash.o lib/dtoastr.o lib/dtotimespec.o lib/exclude.o lib/exitfail.o lib/fadvise.o lib/creat-safer.o lib/open-safer.o lib/fd-hook.o lib/fd-reopen.o \
|
|
||||||
lib/fd-safer-flag.o lib/dup-safer-flag.o lib/fdutimensat.o lib/file-has-acl.o lib/file-set.o lib/file-type.o lib/filemode.o lib/filenamecat.o lib/filenamecat-lgpl.o \
|
|
||||||
lib/filevercmp.o lib/fopen-safer.o lib/fprintftime.o lib/freading.o lib/freadseek.o lib/freopen-safer.o lib/ftoastr.o lib/full-read.o lib/full-write.o lib/gethrxtime.o \
|
|
||||||
lib/xtime.o lib/getndelim2.o lib/getprogname.o lib/gettime.o lib/getugroups.o lib/hard-locale.o lib/hash.o lib/hash-pjw.o lib/hash-triple.o lib/heap.o lib/human.o lib/i-ring.o \
|
|
||||||
lib/idcache.o lib/ino-map.o lib/imaxtostr.o lib/inttostr.o lib/offtostr.o lib/uinttostr.o lib/umaxtostr.o lib/ldtoastr.o lib/linebuffer.o lib/localcharset.o \
|
|
||||||
lib/glthread/lock.o lib/long-options.o lib/malloca.o lib/math.o lib/mbchar.o lib/mbiter.o lib/mbsalign.o lib/mbscasecmp.o lib/mbschr.o lib/mbslen.o lib/mbsstr.o \
|
|
||||||
lib/mbswidth.o lib/mbuiter.o lib/memcasecmp.o lib/memchr2.o lib/memcmp2.o lib/memcoll.o lib/mgetgroups.o lib/mkancesdirs.o lib/dirchownmod.o lib/mkdir-p.o lib/modechange.o \
|
|
||||||
lib/mpsort.o lib/nproc.o lib/nstrftime.o lib/openat-die.o lib/openat-safer.o lib/opendirat.o lib/parse-datetime.o lib/physmem.o lib/pipe2.o lib/posixtm.o lib/posixver.o \
|
|
||||||
lib/printf-frexp.o lib/printf-frexpl.o lib/priv-set.o lib/progname.o lib/propername.o lib/qcopy-acl.o lib/qset-acl.o lib/quotearg.o lib/randint.o lib/randperm.o \
|
|
||||||
lib/randread.o lib/rand-isaac.o lib/read-file.o lib/readtokens.o lib/readtokens0.o lib/renameatu.o lib/root-dev-ino.o lib/safe-read.o lib/safe-write.o lib/same.o \
|
|
||||||
lib/save-cwd.o lib/savedir.o lib/savewd.o lib/selinux-at.o lib/se-context.o lib/se-selinux.o lib/setlocale_null.o lib/settime.o lib/sig-handler.o lib/sockets.o \
|
|
||||||
lib/stat-time.o lib/statat.o lib/mkstemp-safer.o lib/striconv.o lib/strnlen1.o lib/strintcmp.o lib/strnumcmp.o lib/sys_socket.o lib/tempname.o lib/glthread/threadlib.o \
|
|
||||||
lib/timespec.o lib/glthread/tls.o lib/trim.o lib/u64.o lib/unicodeio.o lib/unistd.o lib/dup-safer.o lib/fd-safer.o lib/pipe-safer.o lib/unistr/u8-mbtoucr.o \
|
|
||||||
lib/unistr/u8-uctomb.o lib/unistr/u8-uctomb-aux.o lib/uniwidth/width.o lib/unlinkdir.o lib/userspec.o lib/utimecmp.o lib/utimens.o lib/verror.o lib/version-etc.o \
|
|
||||||
lib/version-etc-fsf.o lib/wctype-h.o lib/write-any-file.o lib/xmalloc.o lib/xalloc-die.o lib/xbinary-io.o lib/xdectoimax.o lib/xdectoumax.o lib/xfts.o lib/xgetcwd.o \
|
|
||||||
lib/xgetgroups.o lib/xgethostname.o lib/xmemcoll.o lib/xnanosleep.o lib/xprintf.o lib/xreadlink.o lib/xsize.o lib/xstriconv.o lib/xstrndup.o lib/xstrtod.o \
|
|
||||||
lib/xstrtoimax.o lib/xstrtol.o lib/xstrtoul.o lib/xstrtol-error.o lib/xstrtold.o lib/xstrtoumax.o lib/xvasprintf.o lib/xasprintf.o lib/yesno.o \
|
|
||||||
lib/asnprintf.o lib/chdir-long.o lib/fchmodat.o lib/fclose.o lib/fcntl.o lib/fflush.o lib/fpurge.o lib/freadahead.o lib/freadptr.o lib/fseek.o \
|
|
||||||
lib/fseeko.o lib/fseterr.o lib/fsusage.o lib/fts.o lib/getfilecon.o lib/isapipe.o lib/lchmod.o lib/localtime-buffer.o lib/mbrlen.o lib/mbrtowc.o \
|
|
||||||
lib/mknod.o lib/mkstemp.o lib/mktime.o lib/mountlist.o lib/nanosleep.o lib/obstack.o lib/printf-args.o lib/printf-parse.o lib/readutmp.o lib/regex.o \
|
|
||||||
lib/sig2str.o lib/time_rz.o lib/vasnprintf.o
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
103260
coreutils.txt
103260
coreutils.txt
File diff suppressed because it is too large
Load Diff
228
extent-scan.c
228
extent-scan.c
@ -1,228 +0,0 @@
|
|||||||
/* extent-scan.c -- core functions for scanning extents
|
|
||||||
Copyright (C) 2010-2020 Free Software Foundation, Inc.
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Written by Jie Liu (jeff.liu@oracle.com). */
|
|
||||||
|
|
||||||
#include <config.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/utsname.h>
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include "system.h"
|
|
||||||
#include "extent-scan.h"
|
|
||||||
#include "fiemap.h"
|
|
||||||
#include "xstrtol.h"
|
|
||||||
|
|
||||||
|
|
||||||
/* Work around Linux kernel issues on BTRFS and EXT4. */
|
|
||||||
static bool
|
|
||||||
extent_need_sync (void)
|
|
||||||
{
|
|
||||||
/* For now always return true, to be on the safe side.
|
|
||||||
If/when FIEMAP semantics are well defined (before SEEK_HOLE support
|
|
||||||
is usable) and kernels implementing them are in use, we may relax
|
|
||||||
this once again. */
|
|
||||||
return true;
|
|
||||||
|
|
||||||
#if FIEMAP_BEHAVIOR_IS_DEFINED_AND_USABLE
|
|
||||||
static int need_sync = -1;
|
|
||||||
|
|
||||||
if (need_sync == -1)
|
|
||||||
{
|
|
||||||
struct utsname name;
|
|
||||||
need_sync = 0; /* No workaround by default. */
|
|
||||||
|
|
||||||
# ifdef __linux__
|
|
||||||
if (uname (&name) != -1 && STRNCMP_LIT (name.release, "2.6.") == 0)
|
|
||||||
{
|
|
||||||
unsigned long val;
|
|
||||||
if (xstrtoul (name.release + 4, NULL, 10, &val, NULL) == LONGINT_OK)
|
|
||||||
{
|
|
||||||
if (val < 39)
|
|
||||||
need_sync = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
# endif
|
|
||||||
}
|
|
||||||
|
|
||||||
return need_sync;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Allocate space for struct extent_scan, initialize the entries if
|
|
||||||
necessary and return it as the input argument of extent_scan_read(). */
|
|
||||||
extern void
|
|
||||||
extent_scan_init (int src_fd, struct extent_scan *scan)
|
|
||||||
{
|
|
||||||
scan->fd = src_fd;
|
|
||||||
scan->ei_count = 0;
|
|
||||||
scan->ext_info = NULL;
|
|
||||||
scan->scan_start = 0;
|
|
||||||
scan->initial_scan_failed = false;
|
|
||||||
scan->hit_final_extent = false;
|
|
||||||
scan->fm_flags = extent_need_sync () ? FIEMAP_FLAG_SYNC : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __linux__
|
|
||||||
# ifndef FS_IOC_FIEMAP
|
|
||||||
# define FS_IOC_FIEMAP _IOWR ('f', 11, struct fiemap)
|
|
||||||
# endif
|
|
||||||
/* Call ioctl(2) with FS_IOC_FIEMAP (available in linux 2.6.27) to
|
|
||||||
obtain a map of file extents excluding holes. */
|
|
||||||
extern bool
|
|
||||||
extent_scan_read (struct extent_scan *scan)
|
|
||||||
{
|
|
||||||
unsigned int si = 0;
|
|
||||||
struct extent_info *last_ei = scan->ext_info;
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
union { struct fiemap f; char c[4096]; } fiemap_buf;
|
|
||||||
struct fiemap *fiemap = &fiemap_buf.f;
|
|
||||||
struct fiemap_extent *fm_extents = &fiemap->fm_extents[0];
|
|
||||||
enum { headersize = offsetof (struct fiemap, fm_extents) };
|
|
||||||
enum { count = (sizeof fiemap_buf - headersize) / sizeof *fm_extents };
|
|
||||||
verify (count > 1);
|
|
||||||
|
|
||||||
/* This is required at least to initialize fiemap->fm_start,
|
|
||||||
but also serves (in mid 2010) to appease valgrind, which
|
|
||||||
appears not to know the semantics of the FIEMAP ioctl. */
|
|
||||||
memset (&fiemap_buf, 0, sizeof fiemap_buf);
|
|
||||||
|
|
||||||
fiemap->fm_start = scan->scan_start;
|
|
||||||
fiemap->fm_flags = scan->fm_flags;
|
|
||||||
fiemap->fm_extent_count = count;
|
|
||||||
fiemap->fm_length = FIEMAP_MAX_OFFSET - scan->scan_start;
|
|
||||||
|
|
||||||
/* Fall back to the standard copy if call ioctl(2) failed for
|
|
||||||
the first time. */
|
|
||||||
if (ioctl (scan->fd, FS_IOC_FIEMAP, fiemap) < 0)
|
|
||||||
{
|
|
||||||
if (scan->scan_start == 0)
|
|
||||||
scan->initial_scan_failed = true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If 0 extents are returned, then no more scans are needed. */
|
|
||||||
if (fiemap->fm_mapped_extents == 0)
|
|
||||||
{
|
|
||||||
scan->hit_final_extent = true;
|
|
||||||
return scan->scan_start != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert (scan->ei_count <= SIZE_MAX - fiemap->fm_mapped_extents);
|
|
||||||
scan->ei_count += fiemap->fm_mapped_extents;
|
|
||||||
{
|
|
||||||
/* last_ei points into a buffer that may be freed via xnrealloc.
|
|
||||||
Record its offset and adjust after allocation. */
|
|
||||||
size_t prev_idx = last_ei - scan->ext_info;
|
|
||||||
scan->ext_info = xnrealloc (scan->ext_info, scan->ei_count,
|
|
||||||
sizeof (struct extent_info));
|
|
||||||
last_ei = scan->ext_info + prev_idx;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int i = 0;
|
|
||||||
for (i = 0; i < fiemap->fm_mapped_extents; i++)
|
|
||||||
{
|
|
||||||
assert (fm_extents[i].fe_logical
|
|
||||||
<= OFF_T_MAX - fm_extents[i].fe_length);
|
|
||||||
|
|
||||||
verify (sizeof last_ei->ext_flags >= sizeof fm_extents->fe_flags);
|
|
||||||
|
|
||||||
if (si && last_ei->ext_flags
|
|
||||||
== (fm_extents[i].fe_flags & ~FIEMAP_EXTENT_LAST)
|
|
||||||
&& (last_ei->ext_logical + last_ei->ext_length
|
|
||||||
== fm_extents[i].fe_logical))
|
|
||||||
{
|
|
||||||
/* Merge previous with last. */
|
|
||||||
last_ei->ext_length += fm_extents[i].fe_length;
|
|
||||||
/* Copy flags in case different. */
|
|
||||||
last_ei->ext_flags = fm_extents[i].fe_flags;
|
|
||||||
}
|
|
||||||
else if ((si == 0 && scan->scan_start > fm_extents[i].fe_logical)
|
|
||||||
|| (si && (last_ei->ext_logical + last_ei->ext_length
|
|
||||||
> fm_extents[i].fe_logical)))
|
|
||||||
{
|
|
||||||
/* BTRFS before 2.6.38 could return overlapping extents
|
|
||||||
for sparse files. We adjust the returned extents
|
|
||||||
rather than failing, as otherwise it would be inefficient
|
|
||||||
to detect this on the initial scan. */
|
|
||||||
uint64_t new_logical;
|
|
||||||
uint64_t length_adjust;
|
|
||||||
if (si == 0)
|
|
||||||
new_logical = scan->scan_start;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* We could return here if scan->scan_start == 0
|
|
||||||
but don't so as to minimize special cases. */
|
|
||||||
new_logical = last_ei->ext_logical + last_ei->ext_length;
|
|
||||||
}
|
|
||||||
length_adjust = new_logical - fm_extents[i].fe_logical;
|
|
||||||
/* If an extent is contained within the previous one, fail. */
|
|
||||||
if (length_adjust < fm_extents[i].fe_length)
|
|
||||||
{
|
|
||||||
if (scan->scan_start == 0)
|
|
||||||
scan->initial_scan_failed = true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
fm_extents[i].fe_logical = new_logical;
|
|
||||||
fm_extents[i].fe_length -= length_adjust;
|
|
||||||
/* Process the adjusted extent again. */
|
|
||||||
i--;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
last_ei = scan->ext_info + si;
|
|
||||||
last_ei->ext_logical = fm_extents[i].fe_logical;
|
|
||||||
last_ei->ext_length = fm_extents[i].fe_length;
|
|
||||||
last_ei->ext_flags = fm_extents[i].fe_flags;
|
|
||||||
si++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (last_ei->ext_flags & FIEMAP_EXTENT_LAST)
|
|
||||||
scan->hit_final_extent = true;
|
|
||||||
|
|
||||||
/* If we have enough extents, discard the last as it might
|
|
||||||
be merged with one from the next scan. */
|
|
||||||
if (si > count && !scan->hit_final_extent)
|
|
||||||
last_ei = scan->ext_info + --si - 1;
|
|
||||||
|
|
||||||
/* We don't bother reallocating any trailing slots. */
|
|
||||||
scan->ei_count = si;
|
|
||||||
|
|
||||||
if (scan->hit_final_extent)
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
scan->scan_start = last_ei->ext_logical + last_ei->ext_length;
|
|
||||||
|
|
||||||
if (si >= count)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
extern bool
|
|
||||||
extent_scan_read (struct extent_scan *scan _GL_UNUSED)
|
|
||||||
{
|
|
||||||
scan->initial_scan_failed = true;
|
|
||||||
errno = ENOTSUP;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
|
@ -1,73 +0,0 @@
|
|||||||
/* core functions for efficient reading sparse files
|
|
||||||
Copyright (C) 2010-2020 Free Software Foundation, Inc.
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Written by Jie Liu (jeff.liu@oracle.com). */
|
|
||||||
|
|
||||||
#ifndef EXTENT_SCAN_H
|
|
||||||
# define EXTENT_SCAN_H
|
|
||||||
|
|
||||||
/* Structure used to store information of each extent. */
|
|
||||||
struct extent_info
|
|
||||||
{
|
|
||||||
/* Logical offset of an extent. */
|
|
||||||
off_t ext_logical;
|
|
||||||
|
|
||||||
/* Extent length. */
|
|
||||||
off_t ext_length;
|
|
||||||
|
|
||||||
/* Extent flags, use it for FIEMAP only, or set it to zero. */
|
|
||||||
unsigned int ext_flags;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Structure used to reserve extent scan information per file. */
|
|
||||||
struct extent_scan
|
|
||||||
{
|
|
||||||
/* File descriptor of extent scan run against. */
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
/* Next scan start offset. */
|
|
||||||
off_t scan_start;
|
|
||||||
|
|
||||||
/* Flags to use for scan. */
|
|
||||||
unsigned int fm_flags;
|
|
||||||
|
|
||||||
/* How many extent info returned for a scan. */
|
|
||||||
size_t ei_count;
|
|
||||||
|
|
||||||
/* If true, fall back to a normal copy, either set by the
|
|
||||||
failure of ioctl(2) for FIEMAP or lseek(2) with SEEK_DATA. */
|
|
||||||
bool initial_scan_failed;
|
|
||||||
|
|
||||||
/* If true, the total extent scan per file has been finished. */
|
|
||||||
bool hit_final_extent;
|
|
||||||
|
|
||||||
/* Extent information: a malloc'd array of ei_count structs. */
|
|
||||||
struct extent_info *ext_info;
|
|
||||||
};
|
|
||||||
|
|
||||||
void extent_scan_init (int src_fd, struct extent_scan *scan);
|
|
||||||
|
|
||||||
bool extent_scan_read (struct extent_scan *scan);
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
extent_scan_free (struct extent_scan *scan)
|
|
||||||
{
|
|
||||||
free (scan->ext_info);
|
|
||||||
scan->ext_info = NULL;
|
|
||||||
scan->ei_count = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* EXTENT_SCAN_H */
|
|
102
fiemap.h
102
fiemap.h
@ -1,102 +0,0 @@
|
|||||||
/* FS_IOC_FIEMAP ioctl infrastructure.
|
|
||||||
Some portions copyright (C) 2007 Cluster File Systems, Inc
|
|
||||||
Authors: Mark Fasheh <mfasheh@suse.com>
|
|
||||||
Kalpak Shah <kalpak.shah@sun.com>
|
|
||||||
Andreas Dilger <adilger@sun.com>. */
|
|
||||||
|
|
||||||
/* Copy from kernel, modified to respect GNU code style by Jie Liu. */
|
|
||||||
|
|
||||||
#ifndef _LINUX_FIEMAP_H
|
|
||||||
# define _LINUX_FIEMAP_H
|
|
||||||
|
|
||||||
# include <stdint.h>
|
|
||||||
|
|
||||||
struct fiemap_extent
|
|
||||||
{
|
|
||||||
/* Logical offset in bytes for the start of the extent
|
|
||||||
from the beginning of the file. */
|
|
||||||
uint64_t fe_logical;
|
|
||||||
|
|
||||||
/* Physical offset in bytes for the start of the extent
|
|
||||||
from the beginning of the disk. */
|
|
||||||
uint64_t fe_physical;
|
|
||||||
|
|
||||||
/* Length in bytes for this extent. */
|
|
||||||
uint64_t fe_length;
|
|
||||||
|
|
||||||
uint64_t fe_reserved64[2];
|
|
||||||
|
|
||||||
/* FIEMAP_EXTENT_* flags for this extent. */
|
|
||||||
uint32_t fe_flags;
|
|
||||||
|
|
||||||
uint32_t fe_reserved[3];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct fiemap
|
|
||||||
{
|
|
||||||
/* Logical offset(inclusive) at which to start mapping(in). */
|
|
||||||
uint64_t fm_start;
|
|
||||||
|
|
||||||
/* Logical length of mapping which userspace wants(in). */
|
|
||||||
uint64_t fm_length;
|
|
||||||
|
|
||||||
/* FIEMAP_FLAG_* flags for request(in/out). */
|
|
||||||
uint32_t fm_flags;
|
|
||||||
|
|
||||||
/* Number of extents that were mapped(out). */
|
|
||||||
uint32_t fm_mapped_extents;
|
|
||||||
|
|
||||||
/* Size of fm_extents array(in). */
|
|
||||||
uint32_t fm_extent_count;
|
|
||||||
|
|
||||||
uint32_t fm_reserved;
|
|
||||||
|
|
||||||
/* Array of mapped extents(out). */
|
|
||||||
struct fiemap_extent fm_extents[FLEXIBLE_ARRAY_MEMBER];
|
|
||||||
};
|
|
||||||
|
|
||||||
/* The maximum offset can be mapped for a file. */
|
|
||||||
# define FIEMAP_MAX_OFFSET (~0ULL)
|
|
||||||
|
|
||||||
/* Sync file data before map. */
|
|
||||||
# define FIEMAP_FLAG_SYNC 0x00000001
|
|
||||||
|
|
||||||
/* Map extented attribute tree. */
|
|
||||||
# define FIEMAP_FLAG_XATTR 0x00000002
|
|
||||||
|
|
||||||
# define FIEMAP_FLAGS_COMPAT (FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR)
|
|
||||||
|
|
||||||
/* Last extent in file. */
|
|
||||||
# define FIEMAP_EXTENT_LAST 0x00000001
|
|
||||||
|
|
||||||
/* Data location unknown. */
|
|
||||||
# define FIEMAP_EXTENT_UNKNOWN 0x00000002
|
|
||||||
|
|
||||||
/* Location still pending, Sets EXTENT_UNKNOWN. */
|
|
||||||
# define FIEMAP_EXTENT_DELALLOC 0x00000004
|
|
||||||
|
|
||||||
/* Data cannot be read while fs is unmounted. */
|
|
||||||
# define FIEMAP_EXTENT_ENCODED 0x00000008
|
|
||||||
|
|
||||||
/* Data is encrypted by fs. Sets EXTENT_NO_BYPASS. */
|
|
||||||
# define FIEMAP_EXTENT_DATA_ENCRYPTED 0x00000080
|
|
||||||
|
|
||||||
/* Extent offsets may not be block aligned. */
|
|
||||||
# define FIEMAP_EXTENT_NOT_ALIGNED 0x00000100
|
|
||||||
|
|
||||||
/* Data mixed with metadata. Sets EXTENT_NOT_ALIGNED. */
|
|
||||||
# define FIEMAP_EXTENT_DATA_INLINE 0x00000200
|
|
||||||
|
|
||||||
/* Multiple files in block. Set EXTENT_NOT_ALIGNED. */
|
|
||||||
# define FIEMAP_EXTENT_DATA_TAIL 0x00000400
|
|
||||||
|
|
||||||
/* Space allocated, but not data (i.e., zero). */
|
|
||||||
# define FIEMAP_EXTENT_UNWRITTEN 0x00000800
|
|
||||||
|
|
||||||
/* File does not natively support extents. Result merged for efficiency. */
|
|
||||||
# define FIEMAP_EXTENT_MERGED 0x00001000
|
|
||||||
|
|
||||||
/* Space shared with other files. */
|
|
||||||
# define FIEMAP_EXTENT_SHARED 0x00002000
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,17 +1,17 @@
|
|||||||
/* A C macro for declaring that a function does not return.
|
/* A C macro for declaring that a function does not return.
|
||||||
Copyright (C) 2011-2020 Free Software Foundation, Inc.
|
Copyright (C) 2011-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it
|
This program is free software: you can redistribute it and/or modify it
|
||||||
under the terms of the GNU General Public License as published
|
under the terms of the GNU Lesser General Public License as published
|
||||||
by the Free Software Foundation; either version 3 of the License, or
|
by the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
General Public License for more details.
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#ifndef _Noreturn
|
#ifndef _Noreturn
|
||||||
@ -26,14 +26,16 @@
|
|||||||
AIX system header files and several gnulib header files use precisely
|
AIX system header files and several gnulib header files use precisely
|
||||||
this syntax with 'extern'. */
|
this syntax with 'extern'. */
|
||||||
# define _Noreturn [[noreturn]]
|
# define _Noreturn [[noreturn]]
|
||||||
# elif ((!defined __cplusplus || defined __clang__) \
|
# elif ((!defined __cplusplus || defined __clang__) \
|
||||||
&& (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
|
&& (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
|
||||||
|| 4 < __GNUC__ + (7 <= __GNUC_MINOR__) \
|
|| (!defined __STRICT_ANSI__ \
|
||||||
|| (defined __apple_build_version__ \
|
&& (4 < __GNUC__ + (7 <= __GNUC_MINOR__) \
|
||||||
? 6000000 <= __apple_build_version__ \
|
|| (defined __apple_build_version__ \
|
||||||
: 3 < __clang_major__ + (5 <= __clang_minor__))))
|
? 6000000 <= __apple_build_version__ \
|
||||||
|
: 3 < __clang_major__ + (5 <= __clang_minor__))))))
|
||||||
/* _Noreturn works as-is. */
|
/* _Noreturn works as-is. */
|
||||||
# elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__) || 0x5110 <= __SUNPRO_C
|
# elif (2 < __GNUC__ + (8 <= __GNUC_MINOR__) || defined __clang__ \
|
||||||
|
|| 0x5110 <= __SUNPRO_C)
|
||||||
# define _Noreturn __attribute__ ((__noreturn__))
|
# define _Noreturn __attribute__ ((__noreturn__))
|
||||||
# elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
|
# elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
|
||||||
# define _Noreturn __declspec (noreturn)
|
# define _Noreturn __declspec (noreturn)
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/* Test whether ACLs are well supported on this system.
|
/* Test whether ACLs are well supported on this system.
|
||||||
|
|
||||||
Copyright 2013-2020 Free Software Foundation, Inc.
|
Copyright 2013-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/* Test whether a file has a nontrivial ACL. -*- coding: utf-8 -*-
|
/* Test whether a file has a nontrivial ACL. -*- coding: utf-8 -*-
|
||||||
|
|
||||||
Copyright (C) 2002-2003, 2005-2020 Free Software Foundation, Inc.
|
Copyright (C) 2002-2003, 2005-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/* Internal implementation of access control lists. -*- coding: utf-8 -*-
|
/* Internal implementation of access control lists. -*- coding: utf-8 -*-
|
||||||
|
|
||||||
Copyright (C) 2002-2003, 2005-2020 Free Software Foundation, Inc.
|
Copyright (C) 2002-2003, 2005-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/* acl.c - access control lists
|
/* acl.c - access control lists
|
||||||
|
|
||||||
Copyright (C) 2002, 2008-2020 Free Software Foundation, Inc.
|
Copyright (C) 2002, 2008-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/* Return the number of entries in an ACL.
|
/* Return the number of entries in an ACL.
|
||||||
|
|
||||||
Copyright (C) 2002-2003, 2005-2020 Free Software Foundation, Inc.
|
Copyright (C) 2002-2003, 2005-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
|
18
lib/af_alg.c
18
lib/af_alg.c
@ -1,18 +1,18 @@
|
|||||||
/* af_alg.c - Compute message digests from file streams and buffers.
|
/* af_alg.c - Compute message digests from file streams and buffers.
|
||||||
Copyright (C) 2018-2020 Free Software Foundation, Inc.
|
Copyright (C) 2018-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify it
|
This file is free software: you can redistribute it and/or modify
|
||||||
under the terms of the GNU General Public License as published by the
|
it under the terms of the GNU Lesser General Public License as
|
||||||
Free Software Foundation; either version 3, or (at your option) any
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program; if not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
/* Written by Matteo Croce <mcroce@redhat.com>, 2018. */
|
/* Written by Matteo Croce <mcroce@redhat.com>, 2018. */
|
||||||
|
|
||||||
|
18
lib/af_alg.h
18
lib/af_alg.h
@ -1,18 +1,18 @@
|
|||||||
/* af_alg.h - Compute message digests from file streams and buffers.
|
/* af_alg.h - Compute message digests from file streams and buffers.
|
||||||
Copyright (C) 2018-2020 Free Software Foundation, Inc.
|
Copyright (C) 2018-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify it
|
This file is free software: you can redistribute it and/or modify
|
||||||
under the terms of the GNU General Public License as published by the
|
it under the terms of the GNU Lesser General Public License as
|
||||||
Free Software Foundation; either version 3, or (at your option) any
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program; if not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
/* Written by Matteo Croce <mcroce@redhat.com>, 2018.
|
/* Written by Matteo Croce <mcroce@redhat.com>, 2018.
|
||||||
Documentation by Bruno Haible <bruno@clisp.org>, 2018. */
|
Documentation by Bruno Haible <bruno@clisp.org>, 2018. */
|
||||||
|
121
lib/alignalloc.c
Normal file
121
lib/alignalloc.c
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
/* aligned memory allocation
|
||||||
|
|
||||||
|
Copyright 2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
/* Written by Paul Eggert. */
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#define ALIGNALLOC_INLINE _GL_EXTERN_INLINE
|
||||||
|
#include "alignalloc.h"
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdalign.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "intprops.h"
|
||||||
|
#include "verify.h"
|
||||||
|
|
||||||
|
#if !ALIGNALLOC_VIA_ALIGNED_ALLOC
|
||||||
|
# if HAVE_POSIX_MEMALIGN
|
||||||
|
|
||||||
|
/* posix_memalign requires the alignment to be a power-of-two multiple of
|
||||||
|
sizeof (void *), whereas alignalloc requires it to be a power of two.
|
||||||
|
To make it OK for the latter to call the former, check that
|
||||||
|
sizeof (void *) is a power of two, which is true on all known platforms.
|
||||||
|
This check is here rather than in alignalloc.h to save the compiler
|
||||||
|
the trouble of checking it each time alignalloc.h is included. */
|
||||||
|
verify (! (sizeof (void *) & (sizeof (void *) - 1)));
|
||||||
|
|
||||||
|
# else /* !HAVE_POSIX_MEMALIGN */
|
||||||
|
|
||||||
|
/* Return P aligned down to ALIGNMENT, which should be a power of two. */
|
||||||
|
|
||||||
|
static void *
|
||||||
|
align_down (void *p, idx_t alignment)
|
||||||
|
{
|
||||||
|
char *c = p;
|
||||||
|
return c - ((uintptr_t) p & (alignment - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If alignalloc returned R and the base of the originally-allocated
|
||||||
|
storage is less than R - UCHAR_MAX, return the address of a pointer
|
||||||
|
holding the base of the originally-allocated storage. */
|
||||||
|
|
||||||
|
static void **
|
||||||
|
address_of_pointer_to_malloced (unsigned char *r)
|
||||||
|
{
|
||||||
|
/* The pointer P is located at the highest address A such that A is
|
||||||
|
aligned for pointers, and A + sizeof P < R so that there is room
|
||||||
|
for a 0 byte at R - 1. This approach assumes UCHAR_MAX is large
|
||||||
|
enough so that there is room for P; although true on all
|
||||||
|
plausible platforms, check the assumption to be safe. */
|
||||||
|
verify (sizeof (void *) + alignof (void *) - 1 <= UCHAR_MAX);
|
||||||
|
|
||||||
|
return align_down (r - 1 - sizeof (void *), alignof (void *));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return an ALIGNMENT-aligned pointer to new storage of size SIZE,
|
||||||
|
or a null pointer (setting errno) if memory is exhausted.
|
||||||
|
ALIGNMENT must be a power of two.
|
||||||
|
If SIZE is zero, on success return a unique pointer each time.
|
||||||
|
To free storage later, call alignfree. */
|
||||||
|
|
||||||
|
void *
|
||||||
|
alignalloc (idx_t alignment, idx_t size)
|
||||||
|
{
|
||||||
|
/* malloc (ALIGNMENT + SIZE); if it succeeds, there must be at least
|
||||||
|
one byte available before the returned pointer. It's OK if
|
||||||
|
ALIGNMENT + SIZE fits in size_t but not idx_t. */
|
||||||
|
|
||||||
|
size_t malloc_size;
|
||||||
|
unsigned char *q;
|
||||||
|
if (INT_ADD_WRAPV (size, alignment, &malloc_size)
|
||||||
|
|| ! (q = malloc (malloc_size)))
|
||||||
|
{
|
||||||
|
errno = ENOMEM;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char *r = align_down (q + alignment, alignment);
|
||||||
|
idx_t offset = r - q;
|
||||||
|
|
||||||
|
if (offset <= UCHAR_MAX)
|
||||||
|
r[-1] = offset;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
r[-1] = 0;
|
||||||
|
*address_of_pointer_to_malloced (r) = q;
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Free storage allocated via alignalloc. Do nothing if PTR is null. */
|
||||||
|
|
||||||
|
void
|
||||||
|
alignfree (void *ptr)
|
||||||
|
{
|
||||||
|
if (ptr)
|
||||||
|
{
|
||||||
|
unsigned char *r = ptr;
|
||||||
|
unsigned char offset = r[-1];
|
||||||
|
void *q = offset ? r - offset : *address_of_pointer_to_malloced (r);
|
||||||
|
free (q);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# endif /* ! HAVE_POSIX_MEMALIGN */
|
||||||
|
#endif /* ! ALIGNALLOC_VIA_ALIGNED_ALLOC */
|
113
lib/alignalloc.h
Normal file
113
lib/alignalloc.h
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
/* aligned memory allocation
|
||||||
|
|
||||||
|
Copyright 2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
/* Written by Paul Eggert. */
|
||||||
|
|
||||||
|
#ifndef ALIGNALLOC_H_
|
||||||
|
#define ALIGNALLOC_H_
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "idx.h"
|
||||||
|
|
||||||
|
#ifndef _GL_INLINE_HEADER_BEGIN
|
||||||
|
#error "Please include config.h first."
|
||||||
|
#endif
|
||||||
|
_GL_INLINE_HEADER_BEGIN
|
||||||
|
#ifndef ALIGNALLOC_INLINE
|
||||||
|
# define ALIGNALLOC_INLINE _GL_INLINE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Whether aligned_alloc supports any power-of-two alignment,
|
||||||
|
returns a nonnull pointer for size-zero allocations,
|
||||||
|
and sets errno on failure. */
|
||||||
|
#if 2 < __GLIBC__ + (15 <= __GLIBC_MINOR__)
|
||||||
|
# define ALIGNALLOC_VIA_ALIGNED_ALLOC 1
|
||||||
|
#else
|
||||||
|
# define ALIGNALLOC_VIA_ALIGNED_ALLOC 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Work around AddressSanitizer bug.
|
||||||
|
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104262
|
||||||
|
https://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20220124/1001910.html
|
||||||
|
*/
|
||||||
|
#ifdef __SANITIZE_ADDRESS__
|
||||||
|
# undef ALIGNALLOC_VIA_ALIGNED_ALLOC
|
||||||
|
# define ALIGNALLOC_VIA_ALIGNED_ALLOC 0
|
||||||
|
#endif
|
||||||
|
#ifdef __has_feature
|
||||||
|
# if __has_feature (address_sanitizer)
|
||||||
|
# undef ALIGNALLOC_VIA_ALIGNED_ALLOC
|
||||||
|
# define ALIGNALLOC_VIA_ALIGNED_ALLOC 0
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ALIGNALLOC_VIA_ALIGNED_ALLOC || HAVE_POSIX_MEMALIGN
|
||||||
|
|
||||||
|
/* Free storage allocated via alignalloc. Do nothing if PTR is null. */
|
||||||
|
|
||||||
|
ALIGNALLOC_INLINE void
|
||||||
|
alignfree (void *ptr)
|
||||||
|
{
|
||||||
|
free (ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return an ALIGNMENT-aligned pointer to new storage of size SIZE,
|
||||||
|
or a null pointer (setting errno) if memory is exhausted.
|
||||||
|
ALIGNMENT must be a power of two.
|
||||||
|
If SIZE is zero, on success return a unique pointer each time.
|
||||||
|
To free storage later, call alignfree. */
|
||||||
|
|
||||||
|
ALIGNALLOC_INLINE
|
||||||
|
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((2))
|
||||||
|
/* _GL_ATTRIBUTE_DEALLOC (alignfree, 1) */
|
||||||
|
void *
|
||||||
|
alignalloc (idx_t alignment, idx_t size)
|
||||||
|
{
|
||||||
|
if ((size_t) -1 < alignment)
|
||||||
|
alignment = (size_t) -1;
|
||||||
|
if ((size_t) -1 < size)
|
||||||
|
size = (size_t) -1;
|
||||||
|
|
||||||
|
# if ALIGNALLOC_VIA_ALIGNED_ALLOC
|
||||||
|
return aligned_alloc (alignment, size);
|
||||||
|
# else
|
||||||
|
void *ptr = NULL;
|
||||||
|
if (alignment < sizeof (void *))
|
||||||
|
alignment = sizeof (void *);
|
||||||
|
errno = posix_memalign (&ptr, alignment, size | !size);
|
||||||
|
return ptr;
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#else /* ! (ALIGNALLOC_VIA_ALIGNED_ALLOC || HAVE_POSIX_MEMALIGN) */
|
||||||
|
|
||||||
|
void alignfree (void *);
|
||||||
|
void *alignalloc (idx_t, idx_t)
|
||||||
|
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((2))
|
||||||
|
_GL_ATTRIBUTE_DEALLOC (alignfree, 1);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Like alignalloc, but die instead of returning a null pointer. */
|
||||||
|
void *xalignalloc (idx_t, idx_t)
|
||||||
|
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((2))
|
||||||
|
_GL_ATTRIBUTE_RETURNS_NONNULL /* _GL_ATTRIBUTE_DEALLOC (alignfree, 1) */;
|
||||||
|
|
||||||
|
_GL_INLINE_HEADER_END
|
||||||
|
|
||||||
|
#endif /* !ALIGNALLOC_H_ */
|
@ -1,18 +1,18 @@
|
|||||||
/* Determine alignment of types.
|
/* Determine alignment of types.
|
||||||
Copyright (C) 2003-2004, 2006, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 2003-2004, 2006, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3, or (at your option)
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program; if not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#ifndef _ALIGNOF_H
|
#ifndef _ALIGNOF_H
|
||||||
#define _ALIGNOF_H
|
#define _ALIGNOF_H
|
||||||
@ -36,12 +36,14 @@
|
|||||||
/* alignof_type (TYPE)
|
/* alignof_type (TYPE)
|
||||||
Determine the good alignment of an object of the given type at compile time.
|
Determine the good alignment of an object of the given type at compile time.
|
||||||
Note that this is not necessarily the same as alignof_slot(type).
|
Note that this is not necessarily the same as alignof_slot(type).
|
||||||
For example, with GNU C on x86 platforms: alignof_type(double) = 8, but
|
For example, with GNU C on x86 platforms and with clang on Linux/x86:
|
||||||
|
alignof_type(long long) = 8, but alignof_slot(long long) = 4.
|
||||||
|
And alignof_type(double) = 8, but
|
||||||
- when -malign-double is not specified: alignof_slot(double) = 4,
|
- when -malign-double is not specified: alignof_slot(double) = 4,
|
||||||
- when -malign-double is specified: alignof_slot(double) = 8.
|
- when -malign-double is specified: alignof_slot(double) = 8.
|
||||||
Note: The result cannot be used as a value for an 'enum' constant,
|
Note: The result cannot be used as a value for an 'enum' constant,
|
||||||
due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc. */
|
due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc. */
|
||||||
#if defined __GNUC__ || defined __IBM__ALIGNOF__
|
#if defined __GNUC__ || defined __clang__ || defined __IBM__ALIGNOF__
|
||||||
# define alignof_type __alignof__
|
# define alignof_type __alignof__
|
||||||
#else
|
#else
|
||||||
# define alignof_type alignof_slot
|
# define alignof_type alignof_slot
|
||||||
|
290
lib/alloca.c
290
lib/alloca.c
@ -1,5 +1,7 @@
|
|||||||
/* alloca.c -- allocate automatically reclaimed memory
|
/* alloca.c -- allocate automatically reclaimed memory
|
||||||
(Mostly) portable public-domain implementation -- D A Gwyn
|
This file is in the public domain. */
|
||||||
|
|
||||||
|
/* (Mostly) portable implementation -- D A Gwyn
|
||||||
|
|
||||||
This implementation of the PWB library alloca function,
|
This implementation of the PWB library alloca function,
|
||||||
which is used to allocate space off the run-time stack so
|
which is used to allocate space off the run-time stack so
|
||||||
@ -39,8 +41,8 @@
|
|||||||
# define memory_full() abort ()
|
# define memory_full() abort ()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* If compiling with GCC 2, this file's not needed. */
|
/* If compiling with GCC or clang, this file is not needed. */
|
||||||
#if !defined (__GNUC__) || __GNUC__ < 2
|
#if !(defined __GNUC__ || defined __clang__)
|
||||||
|
|
||||||
/* If someone has defined alloca as a macro,
|
/* If someone has defined alloca as a macro,
|
||||||
there must be some other way alloca is supposed to work. */
|
there must be some other way alloca is supposed to work. */
|
||||||
@ -62,16 +64,6 @@ lose
|
|||||||
# endif /* static */
|
# endif /* static */
|
||||||
# endif /* emacs */
|
# endif /* emacs */
|
||||||
|
|
||||||
/* If your stack is a linked list of frames, you have to
|
|
||||||
provide an "address metric" ADDRESS_FUNCTION macro. */
|
|
||||||
|
|
||||||
# if defined (CRAY) && defined (CRAY_STACKSEG_END)
|
|
||||||
long i00afunc ();
|
|
||||||
# define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
|
|
||||||
# else
|
|
||||||
# define ADDRESS_FUNCTION(arg) &(arg)
|
|
||||||
# endif
|
|
||||||
|
|
||||||
/* Define STACK_DIRECTION if you know the direction of stack
|
/* Define STACK_DIRECTION if you know the direction of stack
|
||||||
growth for your system; otherwise it will be automatically
|
growth for your system; otherwise it will be automatically
|
||||||
deduced at run-time.
|
deduced at run-time.
|
||||||
@ -140,7 +132,7 @@ void *
|
|||||||
alloca (size_t size)
|
alloca (size_t size)
|
||||||
{
|
{
|
||||||
auto char probe; /* Probes stack depth: */
|
auto char probe; /* Probes stack depth: */
|
||||||
register char *depth = ADDRESS_FUNCTION (probe);
|
register char *depth = &probe;
|
||||||
|
|
||||||
# if STACK_DIRECTION == 0
|
# if STACK_DIRECTION == 0
|
||||||
if (STACK_DIR == 0) /* Unknown growth direction. */
|
if (STACK_DIR == 0) /* Unknown growth direction. */
|
||||||
@ -206,273 +198,5 @@ alloca (size_t size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# if defined (CRAY) && defined (CRAY_STACKSEG_END)
|
|
||||||
|
|
||||||
# ifdef DEBUG_I00AFUNC
|
|
||||||
# include <stdio.h>
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# ifndef CRAY_STACK
|
|
||||||
# define CRAY_STACK
|
|
||||||
# ifndef CRAY2
|
|
||||||
/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
|
|
||||||
struct stack_control_header
|
|
||||||
{
|
|
||||||
long shgrow:32; /* Number of times stack has grown. */
|
|
||||||
long shaseg:32; /* Size of increments to stack. */
|
|
||||||
long shhwm:32; /* High water mark of stack. */
|
|
||||||
long shsize:32; /* Current size of stack (all segments). */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* The stack segment linkage control information occurs at
|
|
||||||
the high-address end of a stack segment. (The stack
|
|
||||||
grows from low addresses to high addresses.) The initial
|
|
||||||
part of the stack segment linkage control information is
|
|
||||||
0200 (octal) words. This provides for register storage
|
|
||||||
for the routine which overflows the stack. */
|
|
||||||
|
|
||||||
struct stack_segment_linkage
|
|
||||||
{
|
|
||||||
long ss[0200]; /* 0200 overflow words. */
|
|
||||||
long sssize:32; /* Number of words in this segment. */
|
|
||||||
long ssbase:32; /* Offset to stack base. */
|
|
||||||
long:32;
|
|
||||||
long sspseg:32; /* Offset to linkage control of previous
|
|
||||||
segment of stack. */
|
|
||||||
long:32;
|
|
||||||
long sstcpt:32; /* Pointer to task common address block. */
|
|
||||||
long sscsnm; /* Private control structure number for
|
|
||||||
microtasking. */
|
|
||||||
long ssusr1; /* Reserved for user. */
|
|
||||||
long ssusr2; /* Reserved for user. */
|
|
||||||
long sstpid; /* Process ID for pid based multi-tasking. */
|
|
||||||
long ssgvup; /* Pointer to multitasking thread giveup. */
|
|
||||||
long sscray[7]; /* Reserved for Cray Research. */
|
|
||||||
long ssa0;
|
|
||||||
long ssa1;
|
|
||||||
long ssa2;
|
|
||||||
long ssa3;
|
|
||||||
long ssa4;
|
|
||||||
long ssa5;
|
|
||||||
long ssa6;
|
|
||||||
long ssa7;
|
|
||||||
long sss0;
|
|
||||||
long sss1;
|
|
||||||
long sss2;
|
|
||||||
long sss3;
|
|
||||||
long sss4;
|
|
||||||
long sss5;
|
|
||||||
long sss6;
|
|
||||||
long sss7;
|
|
||||||
};
|
|
||||||
|
|
||||||
# else /* CRAY2 */
|
|
||||||
/* The following structure defines the vector of words
|
|
||||||
returned by the STKSTAT library routine. */
|
|
||||||
struct stk_stat
|
|
||||||
{
|
|
||||||
long now; /* Current total stack size. */
|
|
||||||
long maxc; /* Amount of contiguous space which would
|
|
||||||
be required to satisfy the maximum
|
|
||||||
stack demand to date. */
|
|
||||||
long high_water; /* Stack high-water mark. */
|
|
||||||
long overflows; /* Number of stack overflow ($STKOFEN) calls. */
|
|
||||||
long hits; /* Number of internal buffer hits. */
|
|
||||||
long extends; /* Number of block extensions. */
|
|
||||||
long stko_mallocs; /* Block allocations by $STKOFEN. */
|
|
||||||
long underflows; /* Number of stack underflow calls ($STKRETN). */
|
|
||||||
long stko_free; /* Number of deallocations by $STKRETN. */
|
|
||||||
long stkm_free; /* Number of deallocations by $STKMRET. */
|
|
||||||
long segments; /* Current number of stack segments. */
|
|
||||||
long maxs; /* Maximum number of stack segments so far. */
|
|
||||||
long pad_size; /* Stack pad size. */
|
|
||||||
long current_address; /* Current stack segment address. */
|
|
||||||
long current_size; /* Current stack segment size. This
|
|
||||||
number is actually corrupted by STKSTAT to
|
|
||||||
include the fifteen word trailer area. */
|
|
||||||
long initial_address; /* Address of initial segment. */
|
|
||||||
long initial_size; /* Size of initial segment. */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* The following structure describes the data structure which trails
|
|
||||||
any stack segment. I think that the description in 'asdef' is
|
|
||||||
out of date. I only describe the parts that I am sure about. */
|
|
||||||
|
|
||||||
struct stk_trailer
|
|
||||||
{
|
|
||||||
long this_address; /* Address of this block. */
|
|
||||||
long this_size; /* Size of this block (does not include
|
|
||||||
this trailer). */
|
|
||||||
long unknown2;
|
|
||||||
long unknown3;
|
|
||||||
long link; /* Address of trailer block of previous
|
|
||||||
segment. */
|
|
||||||
long unknown5;
|
|
||||||
long unknown6;
|
|
||||||
long unknown7;
|
|
||||||
long unknown8;
|
|
||||||
long unknown9;
|
|
||||||
long unknown10;
|
|
||||||
long unknown11;
|
|
||||||
long unknown12;
|
|
||||||
long unknown13;
|
|
||||||
long unknown14;
|
|
||||||
};
|
|
||||||
|
|
||||||
# endif /* CRAY2 */
|
|
||||||
# endif /* not CRAY_STACK */
|
|
||||||
|
|
||||||
# ifdef CRAY2
|
|
||||||
/* Determine a "stack measure" for an arbitrary ADDRESS.
|
|
||||||
I doubt that "lint" will like this much. */
|
|
||||||
|
|
||||||
static long
|
|
||||||
i00afunc (long *address)
|
|
||||||
{
|
|
||||||
struct stk_stat status;
|
|
||||||
struct stk_trailer *trailer;
|
|
||||||
long *block, size;
|
|
||||||
long result = 0;
|
|
||||||
|
|
||||||
/* We want to iterate through all of the segments. The first
|
|
||||||
step is to get the stack status structure. We could do this
|
|
||||||
more quickly and more directly, perhaps, by referencing the
|
|
||||||
$LM00 common block, but I know that this works. */
|
|
||||||
|
|
||||||
STKSTAT (&status);
|
|
||||||
|
|
||||||
/* Set up the iteration. */
|
|
||||||
|
|
||||||
trailer = (struct stk_trailer *) (status.current_address
|
|
||||||
+ status.current_size
|
|
||||||
- 15);
|
|
||||||
|
|
||||||
/* There must be at least one stack segment. Therefore it is
|
|
||||||
a fatal error if "trailer" is null. */
|
|
||||||
|
|
||||||
if (trailer == NULL)
|
|
||||||
abort ();
|
|
||||||
|
|
||||||
/* Discard segments that do not contain our argument address. */
|
|
||||||
|
|
||||||
while (trailer != NULL)
|
|
||||||
{
|
|
||||||
block = (long *) trailer->this_address;
|
|
||||||
size = trailer->this_size;
|
|
||||||
if (block == NULL || size == 0)
|
|
||||||
abort ();
|
|
||||||
trailer = (struct stk_trailer *) trailer->link;
|
|
||||||
if ((block <= address) && (address < (block + size)))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set the result to the offset in this segment and add the sizes
|
|
||||||
of all predecessor segments. */
|
|
||||||
|
|
||||||
result = address - block;
|
|
||||||
|
|
||||||
if (trailer == NULL)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if (trailer->this_size <= 0)
|
|
||||||
abort ();
|
|
||||||
result += trailer->this_size;
|
|
||||||
trailer = (struct stk_trailer *) trailer->link;
|
|
||||||
}
|
|
||||||
while (trailer != NULL);
|
|
||||||
|
|
||||||
/* We are done. Note that if you present a bogus address (one
|
|
||||||
not in any segment), you will get a different number back, formed
|
|
||||||
from subtracting the address of the first block. This is probably
|
|
||||||
not what you want. */
|
|
||||||
|
|
||||||
return (result);
|
|
||||||
}
|
|
||||||
|
|
||||||
# else /* not CRAY2 */
|
|
||||||
/* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP.
|
|
||||||
Determine the number of the cell within the stack,
|
|
||||||
given the address of the cell. The purpose of this
|
|
||||||
routine is to linearize, in some sense, stack addresses
|
|
||||||
for alloca. */
|
|
||||||
|
|
||||||
static long
|
|
||||||
i00afunc (long address)
|
|
||||||
{
|
|
||||||
long stkl = 0;
|
|
||||||
|
|
||||||
long size, pseg, this_segment, stack;
|
|
||||||
long result = 0;
|
|
||||||
|
|
||||||
struct stack_segment_linkage *ssptr;
|
|
||||||
|
|
||||||
/* Register B67 contains the address of the end of the
|
|
||||||
current stack segment. If you (as a subprogram) store
|
|
||||||
your registers on the stack and find that you are past
|
|
||||||
the contents of B67, you have overflowed the segment.
|
|
||||||
|
|
||||||
B67 also points to the stack segment linkage control
|
|
||||||
area, which is what we are really interested in. */
|
|
||||||
|
|
||||||
stkl = CRAY_STACKSEG_END ();
|
|
||||||
ssptr = (struct stack_segment_linkage *) stkl;
|
|
||||||
|
|
||||||
/* If one subtracts 'size' from the end of the segment,
|
|
||||||
one has the address of the first word of the segment.
|
|
||||||
|
|
||||||
If this is not the first segment, 'pseg' will be
|
|
||||||
nonzero. */
|
|
||||||
|
|
||||||
pseg = ssptr->sspseg;
|
|
||||||
size = ssptr->sssize;
|
|
||||||
|
|
||||||
this_segment = stkl - size;
|
|
||||||
|
|
||||||
/* It is possible that calling this routine itself caused
|
|
||||||
a stack overflow. Discard stack segments which do not
|
|
||||||
contain the target address. */
|
|
||||||
|
|
||||||
while (!(this_segment <= address && address <= stkl))
|
|
||||||
{
|
|
||||||
# ifdef DEBUG_I00AFUNC
|
|
||||||
fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
|
|
||||||
# endif
|
|
||||||
if (pseg == 0)
|
|
||||||
break;
|
|
||||||
stkl = stkl - pseg;
|
|
||||||
ssptr = (struct stack_segment_linkage *) stkl;
|
|
||||||
size = ssptr->sssize;
|
|
||||||
pseg = ssptr->sspseg;
|
|
||||||
this_segment = stkl - size;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = address - this_segment;
|
|
||||||
|
|
||||||
/* If you subtract pseg from the current end of the stack,
|
|
||||||
you get the address of the previous stack segment's end.
|
|
||||||
This seems a little convoluted to me, but I'll bet you save
|
|
||||||
a cycle somewhere. */
|
|
||||||
|
|
||||||
while (pseg != 0)
|
|
||||||
{
|
|
||||||
# ifdef DEBUG_I00AFUNC
|
|
||||||
fprintf (stderr, "%011o %011o\n", pseg, size);
|
|
||||||
# endif
|
|
||||||
stkl = stkl - pseg;
|
|
||||||
ssptr = (struct stack_segment_linkage *) stkl;
|
|
||||||
size = ssptr->sssize;
|
|
||||||
pseg = ssptr->sspseg;
|
|
||||||
result += size;
|
|
||||||
}
|
|
||||||
return (result);
|
|
||||||
}
|
|
||||||
|
|
||||||
# endif /* not CRAY2 */
|
|
||||||
# endif /* CRAY */
|
|
||||||
|
|
||||||
# endif /* no alloca */
|
# endif /* no alloca */
|
||||||
#endif /* not GCC 2 */
|
#endif /* not GCC || clang */
|
||||||
|
39
lib/alloca.h
39
lib/alloca.h
@ -1,23 +1,21 @@
|
|||||||
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
|
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
|
||||||
/* Memory allocation on the stack.
|
/* Memory allocation on the stack.
|
||||||
|
|
||||||
Copyright (C) 1995, 1999, 2001-2004, 2006-2020 Free Software Foundation,
|
Copyright (C) 1995, 1999, 2001-2004, 2006-2022 Free Software Foundation,
|
||||||
Inc.
|
Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify it
|
This file is free software: you can redistribute it and/or modify
|
||||||
under the terms of the GNU General Public License as published
|
it under the terms of the GNU Lesser General Public License as
|
||||||
by the Free Software Foundation; either version 3, or (at your option)
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
License along with this program; if not, see
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
<https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H
|
/* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H
|
||||||
means there is a real alloca function. */
|
means there is a real alloca function. */
|
||||||
@ -36,13 +34,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef alloca
|
#ifndef alloca
|
||||||
# ifdef __GNUC__
|
/* Some version of mingw have an <alloca.h> that causes trouble when
|
||||||
/* Some version of mingw have an <alloca.h> that causes trouble when
|
included after 'alloca' gets defined as a macro. As a workaround,
|
||||||
included after 'alloca' gets defined as a macro. As a workaround, include
|
include this <alloca.h> first and define 'alloca' as a macro afterwards
|
||||||
this <alloca.h> first and define 'alloca' as a macro afterwards. */
|
if needed. */
|
||||||
# if (defined _WIN32 && ! defined __CYGWIN__) && 1
|
# if defined __GNUC__ && (defined _WIN32 && ! defined __CYGWIN__) && 1
|
||||||
# include_next <alloca.h>
|
# include_next <alloca.h>
|
||||||
# endif
|
# endif
|
||||||
|
#endif
|
||||||
|
#ifndef alloca
|
||||||
|
# if defined __GNUC__ || (__clang_major__ >= 4)
|
||||||
# define alloca __builtin_alloca
|
# define alloca __builtin_alloca
|
||||||
# elif defined _AIX
|
# elif defined _AIX
|
||||||
# define alloca __alloca
|
# define alloca __alloca
|
||||||
|
@ -1,22 +1,20 @@
|
|||||||
/* Memory allocation on the stack.
|
/* Memory allocation on the stack.
|
||||||
|
|
||||||
Copyright (C) 1995, 1999, 2001-2004, 2006-2020 Free Software Foundation,
|
Copyright (C) 1995, 1999, 2001-2004, 2006-2022 Free Software Foundation,
|
||||||
Inc.
|
Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify it
|
This file is free software: you can redistribute it and/or modify
|
||||||
under the terms of the GNU General Public License as published
|
it under the terms of the GNU Lesser General Public License as
|
||||||
by the Free Software Foundation; either version 3, or (at your option)
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
License along with this program; if not, see
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
<https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H
|
/* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H
|
||||||
means there is a real alloca function. */
|
means there is a real alloca function. */
|
||||||
@ -35,13 +33,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef alloca
|
#ifndef alloca
|
||||||
# ifdef __GNUC__
|
/* Some version of mingw have an <alloca.h> that causes trouble when
|
||||||
/* Some version of mingw have an <alloca.h> that causes trouble when
|
included after 'alloca' gets defined as a macro. As a workaround,
|
||||||
included after 'alloca' gets defined as a macro. As a workaround, include
|
include this <alloca.h> first and define 'alloca' as a macro afterwards
|
||||||
this <alloca.h> first and define 'alloca' as a macro afterwards. */
|
if needed. */
|
||||||
# if (defined _WIN32 && ! defined __CYGWIN__) && @HAVE_ALLOCA_H@
|
# if defined __GNUC__ && (defined _WIN32 && ! defined __CYGWIN__) && @HAVE_ALLOCA_H@
|
||||||
# include_next <alloca.h>
|
# include_next <alloca.h>
|
||||||
# endif
|
# endif
|
||||||
|
#endif
|
||||||
|
#ifndef alloca
|
||||||
|
# if defined __GNUC__ || (__clang_major__ >= 4)
|
||||||
# define alloca __builtin_alloca
|
# define alloca __builtin_alloca
|
||||||
# elif defined _AIX
|
# elif defined _AIX
|
||||||
# define alloca __alloca
|
# define alloca __alloca
|
||||||
|
@ -1,3 +1,20 @@
|
|||||||
|
/* Memory allocators such as malloc+free.
|
||||||
|
|
||||||
|
Copyright (C) 2011-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This file is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as
|
||||||
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This file is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#define _GL_USE_STDLIB_ALLOC 1
|
#define _GL_USE_STDLIB_ALLOC 1
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include "allocator.h"
|
#include "allocator.h"
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
/* Memory allocators such as malloc+free.
|
/* Memory allocators such as malloc+free.
|
||||||
|
|
||||||
Copyright (C) 2011-2020 Free Software Foundation, Inc.
|
Copyright (C) 2011-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
(at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
/* Written by Paul Eggert. */
|
/* Written by Paul Eggert. */
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
/* anytostr.c -- convert integers to printable strings
|
/* anytostr.c -- convert integers to printable strings
|
||||||
|
|
||||||
Copyright (C) 2001, 2006, 2008-2020 Free Software Foundation, Inc.
|
Copyright (C) 2001, 2006, 2008-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
(at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
/* Written by Paul Eggert */
|
/* Written by Paul Eggert */
|
||||||
@ -32,7 +32,7 @@
|
|||||||
INT_BUFSIZE_BOUND (INTTYPE) bytes long. Return the address of the
|
INT_BUFSIZE_BOUND (INTTYPE) bytes long. Return the address of the
|
||||||
printable string, which need not start at BUF. */
|
printable string, which need not start at BUF. */
|
||||||
|
|
||||||
char * __attribute_warn_unused_result__
|
_GL_ATTRIBUTE_NODISCARD char *
|
||||||
anytostr (inttype i, char *buf)
|
anytostr (inttype i, char *buf)
|
||||||
{
|
{
|
||||||
char *p = buf + INT_STRLEN_BOUND (inttype);
|
char *p = buf + INT_STRLEN_BOUND (inttype);
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
/* readlink wrapper to return the link name in malloc'd storage.
|
/* readlink wrapper to return the link name in malloc'd storage.
|
||||||
Unlike xreadlink and xreadlink_with_size, don't ever call exit.
|
Unlike xreadlink and xreadlink_with_size, don't ever call exit.
|
||||||
|
|
||||||
Copyright (C) 2001, 2003-2007, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 2001, 2003-2007, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
(at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
/* Written by Jim Meyering <jim@meyering.net> */
|
/* Written by Jim Meyering <jim@meyering.net> */
|
||||||
@ -79,19 +79,18 @@ areadlink_with_size (char const *file, size_t size)
|
|||||||
{
|
{
|
||||||
buf = buffer = malloc (buf_size);
|
buf = buffer = malloc (buf_size);
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
return NULL;
|
{
|
||||||
|
errno = ENOMEM;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
r = readlink (file, buf, buf_size);
|
r = readlink (file, buf, buf_size);
|
||||||
link_length = r;
|
link_length = r;
|
||||||
|
|
||||||
/* On AIX 5L v5.3 and HP-UX 11i v2 04/09, readlink returns -1
|
if (r < 0)
|
||||||
with errno == ERANGE if the buffer is too small. */
|
|
||||||
if (r < 0 && errno != ERANGE)
|
|
||||||
{
|
{
|
||||||
int saved_errno = errno;
|
|
||||||
free (buffer);
|
free (buffer);
|
||||||
errno = saved_errno;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
/* areadlink.c -- readlink wrapper to return the link name in malloc'd storage
|
/* areadlink.c -- readlink wrapper to return the link name in malloc'd storage
|
||||||
Unlike xreadlink and xreadlink_with_size, don't ever call exit.
|
Unlike xreadlink and xreadlink_with_size, don't ever call exit.
|
||||||
|
|
||||||
Copyright (C) 2001, 2003-2007, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 2001, 2003-2007, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
(at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
/* Written by Jim Meyering <jim@meyering.net>
|
/* Written by Jim Meyering <jim@meyering.net>
|
||||||
|
@ -1,33 +1,37 @@
|
|||||||
/* Read symbolic links without size limitation.
|
/* Read symbolic links without size limitation.
|
||||||
|
|
||||||
Copyright (C) 2001, 2003-2004, 2007, 2009-2020 Free Software Foundation,
|
Copyright (C) 2001, 2003-2004, 2007, 2009-2022 Free Software Foundation,
|
||||||
Inc.
|
Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
(at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
/* Written by Jim Meyering <jim@meyering.net> */
|
/* Written by Jim Meyering <jim@meyering.net> */
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
extern char *areadlink (char const *filename);
|
extern char *areadlink (char const *filename)
|
||||||
extern char *areadlink_with_size (char const *filename, size_t size_hint);
|
_GL_ATTRIBUTE_DEALLOC_FREE;
|
||||||
|
extern char *areadlink_with_size (char const *filename, size_t size_hint)
|
||||||
|
_GL_ATTRIBUTE_DEALLOC_FREE;
|
||||||
|
|
||||||
#if GNULIB_AREADLINKAT
|
#if GNULIB_AREADLINKAT
|
||||||
extern char *areadlinkat (int fd, char const *filename);
|
extern char *areadlinkat (int fd, char const *filename)
|
||||||
|
_GL_ATTRIBUTE_DEALLOC_FREE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if GNULIB_AREADLINKAT_WITH_SIZE
|
#if GNULIB_AREADLINKAT_WITH_SIZE
|
||||||
extern char *areadlinkat_with_size (int fd, char const *filename,
|
extern char *areadlinkat_with_size (int fd, char const *filename,
|
||||||
size_t size_hint);
|
size_t size_hint)
|
||||||
|
_GL_ATTRIBUTE_DEALLOC_FREE;
|
||||||
#endif
|
#endif
|
||||||
|
154
lib/areadlinkat-with-size.c
Normal file
154
lib/areadlinkat-with-size.c
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
/* readlinkat wrapper to return the link name in malloc'd storage.
|
||||||
|
Unlike xreadlinkat, only call exit on failure to change directory.
|
||||||
|
|
||||||
|
Copyright (C) 2001, 2003-2007, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
/* Written by Jim Meyering <jim@meyering.net>
|
||||||
|
and Eric Blake <ebb9@byu.net>. */
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#include "areadlink.h"
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#if HAVE_READLINKAT
|
||||||
|
|
||||||
|
# ifndef SSIZE_MAX
|
||||||
|
# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
|
||||||
|
# endif
|
||||||
|
|
||||||
|
/* SYMLINK_MAX is used only for an initial memory-allocation sanity
|
||||||
|
check, so it's OK to guess too small on hosts where there is no
|
||||||
|
arbitrary limit to symbolic link length. */
|
||||||
|
# ifndef SYMLINK_MAX
|
||||||
|
# define SYMLINK_MAX 1024
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# define MAXSIZE (SIZE_MAX < SSIZE_MAX ? SIZE_MAX : SSIZE_MAX)
|
||||||
|
|
||||||
|
/* Call readlinkat to get the symbolic link value of FILE, relative to FD.
|
||||||
|
SIZE is a hint as to how long the link is expected to be;
|
||||||
|
typically it is taken from st_size. It need not be correct.
|
||||||
|
Return a pointer to that NUL-terminated string in malloc'd storage.
|
||||||
|
If readlinkat fails, malloc fails, or if the link value is longer
|
||||||
|
than SSIZE_MAX, return NULL (caller may use errno to diagnose).
|
||||||
|
However, failure to change directory during readlinkat will issue
|
||||||
|
a diagnostic and exit. */
|
||||||
|
|
||||||
|
char *
|
||||||
|
areadlinkat_with_size (int fd, char const *file, size_t size)
|
||||||
|
{
|
||||||
|
/* Some buggy file systems report garbage in st_size. Defend
|
||||||
|
against them by ignoring outlandish st_size values in the initial
|
||||||
|
memory allocation. */
|
||||||
|
size_t symlink_max = SYMLINK_MAX;
|
||||||
|
size_t INITIAL_LIMIT_BOUND = 8 * 1024;
|
||||||
|
size_t initial_limit = (symlink_max < INITIAL_LIMIT_BOUND
|
||||||
|
? symlink_max + 1
|
||||||
|
: INITIAL_LIMIT_BOUND);
|
||||||
|
|
||||||
|
enum { stackbuf_size = 128 };
|
||||||
|
|
||||||
|
/* The initial buffer size for the link value. */
|
||||||
|
size_t buf_size = (size == 0 ? stackbuf_size
|
||||||
|
: size < initial_limit ? size + 1 : initial_limit);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
ssize_t r;
|
||||||
|
size_t link_length;
|
||||||
|
char stackbuf[stackbuf_size];
|
||||||
|
char *buf = stackbuf;
|
||||||
|
char *buffer = NULL;
|
||||||
|
|
||||||
|
if (! (size == 0 && buf_size == stackbuf_size))
|
||||||
|
{
|
||||||
|
buf = buffer = malloc (buf_size);
|
||||||
|
if (!buffer)
|
||||||
|
/* We can assume errno == ENOMEM here, since all platforms that have
|
||||||
|
readlinkat() have a POSIX compliant malloc(). */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = readlinkat (fd, file, buf, buf_size);
|
||||||
|
link_length = r;
|
||||||
|
|
||||||
|
if (r < 0)
|
||||||
|
{
|
||||||
|
free (buffer);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (link_length < buf_size)
|
||||||
|
{
|
||||||
|
buf[link_length] = 0;
|
||||||
|
if (!buffer)
|
||||||
|
{
|
||||||
|
buffer = malloc (link_length + 1);
|
||||||
|
if (buffer)
|
||||||
|
return memcpy (buffer, buf, link_length + 1);
|
||||||
|
}
|
||||||
|
else if (link_length + 1 < buf_size)
|
||||||
|
{
|
||||||
|
/* Shrink BUFFER before returning it. */
|
||||||
|
char *shrinked_buffer = realloc (buffer, link_length + 1);
|
||||||
|
if (shrinked_buffer != NULL)
|
||||||
|
buffer = shrinked_buffer;
|
||||||
|
}
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
free (buffer);
|
||||||
|
if (buf_size <= MAXSIZE / 2)
|
||||||
|
buf_size *= 2;
|
||||||
|
else if (buf_size < MAXSIZE)
|
||||||
|
buf_size = MAXSIZE;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
errno = ENOMEM;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else /* !HAVE_READLINKAT */
|
||||||
|
|
||||||
|
|
||||||
|
/* It is more efficient to change directories only once and call
|
||||||
|
areadlink_with_size, rather than repeatedly call the replacement
|
||||||
|
readlinkat. */
|
||||||
|
|
||||||
|
# define AT_FUNC_NAME areadlinkat_with_size
|
||||||
|
# define AT_FUNC_F1 areadlink_with_size
|
||||||
|
# define AT_FUNC_POST_FILE_PARAM_DECLS , size_t size
|
||||||
|
# define AT_FUNC_POST_FILE_ARGS , size
|
||||||
|
# define AT_FUNC_RESULT char *
|
||||||
|
# define AT_FUNC_FAIL NULL
|
||||||
|
# include "at-func.c"
|
||||||
|
# undef AT_FUNC_NAME
|
||||||
|
# undef AT_FUNC_F1
|
||||||
|
# undef AT_FUNC_POST_FILE_PARAM_DECLS
|
||||||
|
# undef AT_FUNC_POST_FILE_ARGS
|
||||||
|
# undef AT_FUNC_RESULT
|
||||||
|
# undef AT_FUNC_FAIL
|
||||||
|
|
||||||
|
#endif /* !HAVE_READLINKAT */
|
@ -1,11 +1,11 @@
|
|||||||
/* areadlinkat.c -- readlinkat wrapper to return malloc'd link name
|
/* areadlinkat.c -- readlinkat wrapper to return malloc'd link name
|
||||||
Unlike xreadlinkat, only call exit on failure to change directory.
|
Unlike xreadlinkat, only call exit on failure to change directory.
|
||||||
|
|
||||||
Copyright (C) 2001, 2003-2007, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 2001, 2003-2007, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
/* A C macro for declaring that specific arguments must not be NULL.
|
/* A C macro for declaring that specific arguments must not be NULL.
|
||||||
Copyright (C) 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it
|
This program is free software: you can redistribute it and/or modify it
|
||||||
under the terms of the GNU General Public License as published
|
under the terms of the GNU Lesser General Public License as published
|
||||||
by the Free Software Foundation; either version 3 of the License, or
|
by the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
General Public License for more details.
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
|
/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
|
||||||
that the values passed as arguments n, ..., m must be non-NULL pointers.
|
that the values passed as arguments n, ..., m must be non-NULL pointers.
|
||||||
n = 1 stands for the first argument, n = 2 for the second argument etc. */
|
n = 1 stands for the first argument, n = 2 for the second argument etc. */
|
||||||
#ifndef _GL_ARG_NONNULL
|
#ifndef _GL_ARG_NONNULL
|
||||||
# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
|
# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || defined __clang__
|
||||||
# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
|
# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
|
||||||
# else
|
# else
|
||||||
# define _GL_ARG_NONNULL(params)
|
# define _GL_ARG_NONNULL(params)
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
/* argmatch.c -- find a match for a string in an array
|
/* argmatch.c -- find a match for a string in an array
|
||||||
|
|
||||||
Copyright (C) 1990, 1998-1999, 2001-2007, 2009-2020 Free Software
|
Copyright (C) 1990, 1998-1999, 2001-2007, 2009-2022 Free Software
|
||||||
Foundation, Inc.
|
Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
@ -62,7 +62,7 @@ __argmatch_die (void)
|
|||||||
ARGMATCH_DIE;
|
ARGMATCH_DIE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Used by XARGMATCH and XARGCASEMATCH. See description in argmatch.h.
|
/* Used by XARGMATCH. See description in argmatch.h.
|
||||||
Default to __argmatch_die, but allow caller to change this at run-time. */
|
Default to __argmatch_die, but allow caller to change this at run-time. */
|
||||||
argmatch_exit_fn argmatch_die = __argmatch_die;
|
argmatch_exit_fn argmatch_die = __argmatch_die;
|
||||||
|
|
||||||
@ -120,6 +120,21 @@ argmatch (const char *arg, const char *const *arglist,
|
|||||||
return matchind;
|
return matchind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ptrdiff_t
|
||||||
|
argmatch_exact (const char *arg, const char *const *arglist)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
/* Test elements for exact match. */
|
||||||
|
for (i = 0; arglist[i]; i++)
|
||||||
|
{
|
||||||
|
if (!strcmp (arglist[i], arg))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Error reporting for argmatch.
|
/* Error reporting for argmatch.
|
||||||
CONTEXT is a description of the type of entity that was being matched.
|
CONTEXT is a description of the type of entity that was being matched.
|
||||||
VALUE is the invalid value that was given.
|
VALUE is the invalid value that was given.
|
||||||
@ -174,9 +189,16 @@ ptrdiff_t
|
|||||||
__xargmatch_internal (const char *context,
|
__xargmatch_internal (const char *context,
|
||||||
const char *arg, const char *const *arglist,
|
const char *arg, const char *const *arglist,
|
||||||
const void *vallist, size_t valsize,
|
const void *vallist, size_t valsize,
|
||||||
argmatch_exit_fn exit_fn)
|
argmatch_exit_fn exit_fn,
|
||||||
|
bool allow_abbreviation)
|
||||||
{
|
{
|
||||||
ptrdiff_t res = argmatch (arg, arglist, vallist, valsize);
|
ptrdiff_t res;
|
||||||
|
|
||||||
|
if (allow_abbreviation)
|
||||||
|
res = argmatch (arg, arglist, vallist, valsize);
|
||||||
|
else
|
||||||
|
res = argmatch_exact (arg, arglist);
|
||||||
|
|
||||||
if (res >= 0)
|
if (res >= 0)
|
||||||
/* Success. */
|
/* Success. */
|
||||||
return res;
|
return res;
|
||||||
@ -266,7 +288,7 @@ main (int argc, const char *const *argv)
|
|||||||
backup_args, backup_vals);
|
backup_args, backup_vals);
|
||||||
|
|
||||||
printf ("The version control is '%s'\n",
|
printf ("The version control is '%s'\n",
|
||||||
ARGMATCH_TO_ARGUMENT (backup_type, backup_args, backup_vals));
|
ARGMATCH_TO_ARGUMENT (&backup_type, backup_args, backup_vals));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
/* argmatch.h -- definitions and prototypes for argmatch.c
|
/* argmatch.h -- definitions and prototypes for argmatch.c
|
||||||
|
|
||||||
Copyright (C) 1990, 1998-1999, 2001-2002, 2004-2005, 2009-2020 Free Software
|
Copyright (C) 1990, 1998-1999, 2001-2002, 2004-2005, 2009-2022 Free Software
|
||||||
Foundation, Inc.
|
Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
@ -52,9 +52,15 @@ extern "C" {
|
|||||||
ptrdiff_t argmatch (char const *arg, char const *const *arglist,
|
ptrdiff_t argmatch (char const *arg, char const *const *arglist,
|
||||||
void const *vallist, size_t valsize) _GL_ATTRIBUTE_PURE;
|
void const *vallist, size_t valsize) _GL_ATTRIBUTE_PURE;
|
||||||
|
|
||||||
|
ptrdiff_t argmatch_exact (char const *arg, char const *const *arglist)
|
||||||
|
_GL_ATTRIBUTE_PURE;
|
||||||
|
|
||||||
# define ARGMATCH(Arg, Arglist, Vallist) \
|
# define ARGMATCH(Arg, Arglist, Vallist) \
|
||||||
argmatch (Arg, Arglist, (void const *) (Vallist), sizeof *(Vallist))
|
argmatch (Arg, Arglist, (void const *) (Vallist), sizeof *(Vallist))
|
||||||
|
|
||||||
|
# define ARGMATCH_EXACT(Arg, Arglist) \
|
||||||
|
argmatch_exact (Arg, Arglist)
|
||||||
|
|
||||||
/* xargmatch calls this function when it fails. This function should not
|
/* xargmatch calls this function when it fails. This function should not
|
||||||
return. By default, this is a function that calls ARGMATCH_DIE which
|
return. By default, this is a function that calls ARGMATCH_DIE which
|
||||||
in turn defaults to 'exit (exit_failure)'. */
|
in turn defaults to 'exit (exit_failure)'. */
|
||||||
@ -83,13 +89,14 @@ void argmatch_valid (char const *const *arglist,
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Same as argmatch, but upon failure, report an explanation of the
|
/* Like argmatch/argmatch_exact, but upon failure, report an explanation
|
||||||
failure, and exit using the function EXIT_FN. */
|
of the failure, and exit using the function EXIT_FN. */
|
||||||
|
|
||||||
ptrdiff_t __xargmatch_internal (char const *context,
|
ptrdiff_t __xargmatch_internal (char const *context,
|
||||||
char const *arg, char const *const *arglist,
|
char const *arg, char const *const *arglist,
|
||||||
void const *vallist, size_t valsize,
|
void const *vallist, size_t valsize,
|
||||||
argmatch_exit_fn exit_fn);
|
argmatch_exit_fn exit_fn,
|
||||||
|
bool allow_abbreviation);
|
||||||
|
|
||||||
/* Programmer friendly interface to __xargmatch_internal. */
|
/* Programmer friendly interface to __xargmatch_internal. */
|
||||||
|
|
||||||
@ -97,7 +104,15 @@ ptrdiff_t __xargmatch_internal (char const *context,
|
|||||||
((Vallist) [__xargmatch_internal (Context, Arg, Arglist, \
|
((Vallist) [__xargmatch_internal (Context, Arg, Arglist, \
|
||||||
(void const *) (Vallist), \
|
(void const *) (Vallist), \
|
||||||
sizeof *(Vallist), \
|
sizeof *(Vallist), \
|
||||||
argmatch_die)])
|
argmatch_die, \
|
||||||
|
true)])
|
||||||
|
|
||||||
|
# define XARGMATCH_EXACT(Context, Arg, Arglist, Vallist) \
|
||||||
|
((Vallist) [__xargmatch_internal (Context, Arg, Arglist, \
|
||||||
|
(void const *) (Vallist), \
|
||||||
|
sizeof *(Vallist), \
|
||||||
|
argmatch_die, \
|
||||||
|
false)])
|
||||||
|
|
||||||
/* Convert a value into a corresponding argument. */
|
/* Convert a value into a corresponding argument. */
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* Iterate over arguments from argv or --files0-from=FILE
|
/* Iterate over arguments from argv or --files0-from=FILE
|
||||||
Copyright (C) 2008-2020 Free Software Foundation, Inc.
|
Copyright (C) 2008-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* Iterate over arguments from argv or --files0-from=FILE
|
/* Iterate over arguments from argv or --files0-from=FILE
|
||||||
Copyright (C) 2008-2020 Free Software Foundation, Inc.
|
Copyright (C) 2008-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@ -30,13 +30,14 @@ enum argv_iter_err
|
|||||||
AI_ERR_READ
|
AI_ERR_READ
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void argv_iter_free (struct argv_iterator *)
|
||||||
|
_GL_ARG_NONNULL ((1));
|
||||||
|
|
||||||
struct argv_iterator *argv_iter_init_argv (char **argv)
|
struct argv_iterator *argv_iter_init_argv (char **argv)
|
||||||
_GL_ARG_NONNULL ((1));
|
_GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_DEALLOC (argv_iter_free, 1);
|
||||||
struct argv_iterator *argv_iter_init_stream (FILE *fp)
|
struct argv_iterator *argv_iter_init_stream (FILE *fp)
|
||||||
_GL_ARG_NONNULL ((1));
|
_GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_DEALLOC (argv_iter_free, 1);
|
||||||
char *argv_iter (struct argv_iterator *, enum argv_iter_err *)
|
char *argv_iter (struct argv_iterator *, enum argv_iter_err *)
|
||||||
_GL_ARG_NONNULL ((1, 2));
|
_GL_ARG_NONNULL ((1, 2));
|
||||||
size_t argv_iter_n_args (struct argv_iterator const *)
|
size_t argv_iter_n_args (struct argv_iterator const *)
|
||||||
_GL_ATTRIBUTE_PURE _GL_ARG_NONNULL ((1));
|
_GL_ATTRIBUTE_PURE _GL_ARG_NONNULL ((1));
|
||||||
void argv_iter_free (struct argv_iterator *)
|
|
||||||
_GL_ARG_NONNULL ((1));
|
|
||||||
|
122
lib/arpa/inet.h
122
lib/arpa/inet.h
@ -1,20 +1,20 @@
|
|||||||
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
|
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
|
||||||
/* A GNU-like <arpa/inet.h>.
|
/* A GNU-like <arpa/inet.h>.
|
||||||
|
|
||||||
Copyright (C) 2005-2006, 2008-2020 Free Software Foundation, Inc.
|
Copyright (C) 2005-2006, 2008-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3, or (at your option)
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program; if not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#ifndef _GL_ARPA_INET_H
|
#ifndef _GL_ARPA_INET_H
|
||||||
|
|
||||||
@ -58,19 +58,19 @@
|
|||||||
|
|
||||||
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
|
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
|
||||||
/* C++ compatible function declaration macros.
|
/* C++ compatible function declaration macros.
|
||||||
Copyright (C) 2010-2020 Free Software Foundation, Inc.
|
Copyright (C) 2010-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it
|
This program is free software: you can redistribute it and/or modify it
|
||||||
under the terms of the GNU General Public License as published
|
under the terms of the GNU Lesser General Public License as published
|
||||||
by the Free Software Foundation; either version 3 of the License, or
|
by the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
General Public License for more details.
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#ifndef _GL_CXXDEFS_H
|
#ifndef _GL_CXXDEFS_H
|
||||||
@ -205,6 +205,16 @@
|
|||||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* _GL_CXXALIAS_MDA (func, rettype, parameters);
|
||||||
|
is to be used when func is a Microsoft deprecated alias, on native Windows.
|
||||||
|
It declares a C++ alias called GNULIB_NAMESPACE::func
|
||||||
|
that redirects to _func, if GNULIB_NAMESPACE is defined.
|
||||||
|
Example:
|
||||||
|
_GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...));
|
||||||
|
*/
|
||||||
|
#define _GL_CXXALIAS_MDA(func,rettype,parameters) \
|
||||||
|
_GL_CXXALIAS_RPL_1 (func, _##func, rettype, parameters)
|
||||||
|
|
||||||
/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
|
/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
|
||||||
is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
|
is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
|
||||||
except that the C function rpl_func may have a slightly different
|
except that the C function rpl_func may have a slightly different
|
||||||
@ -230,6 +240,14 @@
|
|||||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* _GL_CXXALIAS_MDA_CAST (func, rettype, parameters);
|
||||||
|
is like _GL_CXXALIAS_MDA (func, rettype, parameters);
|
||||||
|
except that the C function func may have a slightly different declaration.
|
||||||
|
A cast is used to silence the "invalid conversion" error that would
|
||||||
|
otherwise occur. */
|
||||||
|
#define _GL_CXXALIAS_MDA_CAST(func,rettype,parameters) \
|
||||||
|
_GL_CXXALIAS_RPL_CAST_1 (func, _##func, rettype, parameters)
|
||||||
|
|
||||||
/* _GL_CXXALIAS_SYS (func, rettype, parameters);
|
/* _GL_CXXALIAS_SYS (func, rettype, parameters);
|
||||||
declares a C++ alias called GNULIB_NAMESPACE::func
|
declares a C++ alias called GNULIB_NAMESPACE::func
|
||||||
that redirects to the system provided function func, if GNULIB_NAMESPACE
|
that redirects to the system provided function func, if GNULIB_NAMESPACE
|
||||||
@ -327,7 +345,7 @@
|
|||||||
_GL_CXXALIASWARN_2 (func, namespace)
|
_GL_CXXALIASWARN_2 (func, namespace)
|
||||||
/* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
|
/* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
|
||||||
we enable the warning only when not optimizing. */
|
we enable the warning only when not optimizing. */
|
||||||
# if !__OPTIMIZE__
|
# if !(defined __GNUC__ && !defined __clang__ && __OPTIMIZE__)
|
||||||
# define _GL_CXXALIASWARN_2(func,namespace) \
|
# define _GL_CXXALIASWARN_2(func,namespace) \
|
||||||
_GL_WARN_ON_USE (func, \
|
_GL_WARN_ON_USE (func, \
|
||||||
"The symbol ::" #func " refers to the system function. " \
|
"The symbol ::" #func " refers to the system function. " \
|
||||||
@ -355,9 +373,9 @@
|
|||||||
_GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
|
_GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
|
||||||
/* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
|
/* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
|
||||||
we enable the warning only when not optimizing. */
|
we enable the warning only when not optimizing. */
|
||||||
# if !__OPTIMIZE__
|
# if !(defined __GNUC__ && !defined __clang__ && __OPTIMIZE__)
|
||||||
# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
|
# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
|
||||||
_GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
|
_GL_WARN_ON_USE_CXX (func, rettype, rettype, parameters_and_attributes, \
|
||||||
"The symbol ::" #func " refers to the system function. " \
|
"The symbol ::" #func " refers to the system function. " \
|
||||||
"Use " #namespace "::" #func " instead.")
|
"Use " #namespace "::" #func " instead.")
|
||||||
# else
|
# else
|
||||||
@ -373,26 +391,26 @@
|
|||||||
|
|
||||||
/* The definition of _GL_ARG_NONNULL is copied here. */
|
/* The definition of _GL_ARG_NONNULL is copied here. */
|
||||||
/* A C macro for declaring that specific arguments must not be NULL.
|
/* A C macro for declaring that specific arguments must not be NULL.
|
||||||
Copyright (C) 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it
|
This program is free software: you can redistribute it and/or modify it
|
||||||
under the terms of the GNU General Public License as published
|
under the terms of the GNU Lesser General Public License as published
|
||||||
by the Free Software Foundation; either version 3 of the License, or
|
by the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
General Public License for more details.
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
|
/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools
|
||||||
that the values passed as arguments n, ..., m must be non-NULL pointers.
|
that the values passed as arguments n, ..., m must be non-NULL pointers.
|
||||||
n = 1 stands for the first argument, n = 2 for the second argument etc. */
|
n = 1 stands for the first argument, n = 2 for the second argument etc. */
|
||||||
#ifndef _GL_ARG_NONNULL
|
#ifndef _GL_ARG_NONNULL
|
||||||
# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3
|
# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || defined __clang__
|
||||||
# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
|
# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params))
|
||||||
# else
|
# else
|
||||||
# define _GL_ARG_NONNULL(params)
|
# define _GL_ARG_NONNULL(params)
|
||||||
@ -401,19 +419,19 @@
|
|||||||
|
|
||||||
/* The definition of _GL_WARN_ON_USE is copied here. */
|
/* The definition of _GL_WARN_ON_USE is copied here. */
|
||||||
/* A C macro for emitting warnings if a function is used.
|
/* A C macro for emitting warnings if a function is used.
|
||||||
Copyright (C) 2010-2020 Free Software Foundation, Inc.
|
Copyright (C) 2010-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it
|
This program is free software: you can redistribute it and/or modify it
|
||||||
under the terms of the GNU General Public License as published
|
under the terms of the GNU Lesser General Public License as published
|
||||||
by the Free Software Foundation; either version 3 of the License, or
|
by the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
General Public License for more details.
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
/* _GL_WARN_ON_USE (function, "literal string") issues a declaration
|
/* _GL_WARN_ON_USE (function, "literal string") issues a declaration
|
||||||
@ -486,13 +504,20 @@
|
|||||||
# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
|
# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
|
||||||
/* A compiler attribute is available in gcc versions 4.3.0 and later. */
|
/* A compiler attribute is available in gcc versions 4.3.0 and later. */
|
||||||
# define _GL_WARN_ON_USE(function, message) \
|
# define _GL_WARN_ON_USE(function, message) \
|
||||||
extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
|
_GL_WARN_EXTERN_C __typeof__ (function) function __attribute__ ((__warning__ (message)))
|
||||||
# define _GL_WARN_ON_USE_ATTRIBUTE(message) \
|
# define _GL_WARN_ON_USE_ATTRIBUTE(message) \
|
||||||
__attribute__ ((__warning__ (message)))
|
__attribute__ ((__warning__ (message)))
|
||||||
|
# elif __clang_major__ >= 4
|
||||||
|
/* Another compiler attribute is available in clang. */
|
||||||
|
# define _GL_WARN_ON_USE(function, message) \
|
||||||
|
_GL_WARN_EXTERN_C __typeof__ (function) function \
|
||||||
|
__attribute__ ((__diagnose_if__ (1, message, "warning")))
|
||||||
|
# define _GL_WARN_ON_USE_ATTRIBUTE(message) \
|
||||||
|
__attribute__ ((__diagnose_if__ (1, message, "warning")))
|
||||||
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
||||||
/* Verify the existence of the function. */
|
/* Verify the existence of the function. */
|
||||||
# define _GL_WARN_ON_USE(function, message) \
|
# define _GL_WARN_ON_USE(function, message) \
|
||||||
extern __typeof__ (function) function
|
_GL_WARN_EXTERN_C __typeof__ (function) function
|
||||||
# define _GL_WARN_ON_USE_ATTRIBUTE(message)
|
# define _GL_WARN_ON_USE_ATTRIBUTE(message)
|
||||||
# else /* Unsupported. */
|
# else /* Unsupported. */
|
||||||
# define _GL_WARN_ON_USE(function, message) \
|
# define _GL_WARN_ON_USE(function, message) \
|
||||||
@ -501,24 +526,35 @@ _GL_WARN_EXTERN_C int _gl_warn_on_use
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
|
/* _GL_WARN_ON_USE_CXX (function, rettype_gcc, rettype_clang, parameters_and_attributes, "message")
|
||||||
is like _GL_WARN_ON_USE (function, "string"), except that the function is
|
is like _GL_WARN_ON_USE (function, "message"), except that in C++ mode the
|
||||||
declared with the given prototype, consisting of return type, parameters,
|
function is declared with the given prototype, consisting of return type,
|
||||||
and attributes.
|
parameters, and attributes.
|
||||||
This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
|
This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
|
||||||
not work in this case. */
|
not work in this case. */
|
||||||
#ifndef _GL_WARN_ON_USE_CXX
|
#ifndef _GL_WARN_ON_USE_CXX
|
||||||
# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
|
# if !defined __cplusplus
|
||||||
# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
|
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||||
extern rettype function parameters_and_attributes \
|
_GL_WARN_ON_USE (function, msg)
|
||||||
__attribute__ ((__warning__ (msg)))
|
# else
|
||||||
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
|
||||||
|
/* A compiler attribute is available in gcc versions 4.3.0 and later. */
|
||||||
|
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||||
|
extern rettype_gcc function parameters_and_attributes \
|
||||||
|
__attribute__ ((__warning__ (msg)))
|
||||||
|
# elif __clang_major__ >= 4
|
||||||
|
/* Another compiler attribute is available in clang. */
|
||||||
|
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||||
|
extern rettype_clang function parameters_and_attributes \
|
||||||
|
__attribute__ ((__diagnose_if__ (1, msg, "warning")))
|
||||||
|
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
|
||||||
/* Verify the existence of the function. */
|
/* Verify the existence of the function. */
|
||||||
# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
|
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||||
extern rettype function parameters_and_attributes
|
extern rettype_gcc function parameters_and_attributes
|
||||||
# else /* Unsupported. */
|
# else /* Unsupported. */
|
||||||
# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
|
# define _GL_WARN_ON_USE_CXX(function,rettype_gcc,rettype_clang,parameters_and_attributes,msg) \
|
||||||
_GL_WARN_EXTERN_C int _gl_warn_on_use
|
_GL_WARN_EXTERN_C int _gl_warn_on_use
|
||||||
|
# endif
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
/* A GNU-like <arpa/inet.h>.
|
/* A GNU-like <arpa/inet.h>.
|
||||||
|
|
||||||
Copyright (C) 2005-2006, 2008-2020 Free Software Foundation, Inc.
|
Copyright (C) 2005-2006, 2008-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3, or (at your option)
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program; if not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#ifndef _@GUARD_PREFIX@_ARPA_INET_H
|
#ifndef _@GUARD_PREFIX@_ARPA_INET_H
|
||||||
|
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
/* Formatted output to strings.
|
/* Formatted output to strings.
|
||||||
Copyright (C) 1999, 2002, 2006, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 1999, 2002, 2006, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3, or (at your option)
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
with this program; if not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
/* Formatted output to strings.
|
/* Formatted output to strings.
|
||||||
Copyright (C) 1999, 2002, 2006-2007, 2009-2020 Free Software Foundation,
|
Copyright (C) 1999, 2002, 2006-2007, 2009-2022 Free Software Foundation,
|
||||||
Inc.
|
Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3, or (at your option)
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
with this program; if not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
|
40
lib/assure.h
40
lib/assure.h
@ -1,18 +1,18 @@
|
|||||||
/* Run-time assert-like macros.
|
/* Run-time assert-like macros.
|
||||||
|
|
||||||
Copyright (C) 2014-2020 Free Software Foundation, Inc.
|
Copyright (C) 2014-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
(at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
/* Written by Paul Eggert. */
|
/* Written by Paul Eggert. */
|
||||||
@ -21,12 +21,32 @@
|
|||||||
#define _GL_ASSURE_H
|
#define _GL_ASSURE_H
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include "verify.h"
|
||||||
|
|
||||||
|
/* Evaluate an assertion E that is guaranteed to be true.
|
||||||
|
If NDEBUG is not defined, abort the program if E is false.
|
||||||
|
If NDEBUG is defined, the compiler can assume E and behavior is
|
||||||
|
undefined if E is false, fails to evaluate, or has side effects.
|
||||||
|
|
||||||
|
Unlike standard 'assert', this macro evaluates E even when NDEBUG
|
||||||
|
is defined, so as to catch typos, avoid some GCC warnings, and
|
||||||
|
improve performance when E is simple enough.
|
||||||
|
|
||||||
|
Also see the documentation for 'assume' in verify.h. */
|
||||||
|
|
||||||
|
#ifdef NDEBUG
|
||||||
|
# define affirm(E) assume (E)
|
||||||
|
#else
|
||||||
|
# define affirm(E) assert (E)
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Check E's value at runtime, and report an error and abort if not.
|
/* Check E's value at runtime, and report an error and abort if not.
|
||||||
However, do nothing if NDEBUG is defined.
|
However, do nothing if NDEBUG is defined.
|
||||||
|
|
||||||
Unlike standard 'assert', this macro always compiles E even when NDEBUG
|
Unlike standard 'assert', this macro compiles E even when NDEBUG
|
||||||
is defined, so as to catch typos and avoid some GCC warnings. */
|
is defined, so as to catch typos and avoid some GCC warnings.
|
||||||
|
Unlike 'affirm', it is OK for E to use hard-to-optimize features,
|
||||||
|
since E is not executed if NDEBUG is defined. */
|
||||||
|
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
# define assure(E) ((void) (0 && (E)))
|
# define assure(E) ((void) (0 && (E)))
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
/* Define at-style functions like fstatat, unlinkat, fchownat, etc.
|
/* Define at-style functions like fstatat, unlinkat, fchownat, etc.
|
||||||
Copyright (C) 2006, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 2006, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
/* written by Jim Meyering */
|
/* written by Jim Meyering */
|
||||||
|
|
||||||
#include "dosname.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */
|
#include "filename.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */
|
||||||
|
|
||||||
#ifdef GNULIB_SUPPORT_ONLY_AT_FDCWD
|
#ifdef GNULIB_SUPPORT_ONLY_AT_FDCWD
|
||||||
# include <errno.h>
|
# include <errno.h>
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
/* Define 2-FD at-style functions like linkat or renameat.
|
/* Define 2-FD at-style functions like linkat or renameat.
|
||||||
Copyright (C) 2006, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 2006, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
@ -25,7 +25,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "dosname.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */
|
#include "filename.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */
|
||||||
#include "filenamecat.h"
|
#include "filenamecat.h"
|
||||||
#include "openat.h"
|
#include "openat.h"
|
||||||
#include "same-inode.h"
|
#include "same-inode.h"
|
||||||
|
226
lib/attribute.h
Normal file
226
lib/attribute.h
Normal file
@ -0,0 +1,226 @@
|
|||||||
|
/* ATTRIBUTE_* macros for using attributes in GCC and similar compilers
|
||||||
|
|
||||||
|
Copyright 2020-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This file is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as
|
||||||
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This file is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
/* Written by Paul Eggert. */
|
||||||
|
|
||||||
|
/* Provide public ATTRIBUTE_* names for the private _GL_ATTRIBUTE_*
|
||||||
|
macros used within Gnulib. */
|
||||||
|
|
||||||
|
/* These attributes can be placed in two ways:
|
||||||
|
- At the start of a declaration (i.e. even before storage-class
|
||||||
|
specifiers!); then they apply to all entities that are declared
|
||||||
|
by the declaration.
|
||||||
|
- Immediately after the name of an entity being declared by the
|
||||||
|
declaration; then they apply to that entity only. */
|
||||||
|
|
||||||
|
#ifndef _GL_ATTRIBUTE_H
|
||||||
|
#define _GL_ATTRIBUTE_H
|
||||||
|
|
||||||
|
|
||||||
|
/* This file defines two types of attributes:
|
||||||
|
* C2x standard attributes. These have macro names that do not begin with
|
||||||
|
'ATTRIBUTE_'.
|
||||||
|
* Selected GCC attributes; see:
|
||||||
|
https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html
|
||||||
|
https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
|
||||||
|
https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html
|
||||||
|
These names begin with 'ATTRIBUTE_' to avoid name clashes. */
|
||||||
|
|
||||||
|
|
||||||
|
/* =============== Attributes for specific kinds of functions =============== */
|
||||||
|
|
||||||
|
/* Attributes for functions that should not be used. */
|
||||||
|
|
||||||
|
/* Warn if the entity is used. */
|
||||||
|
/* Applies to:
|
||||||
|
- function, variable,
|
||||||
|
- struct, union, struct/union member,
|
||||||
|
- enumeration, enumeration item,
|
||||||
|
- typedef,
|
||||||
|
in C++ also: namespace, class, template specialization. */
|
||||||
|
#define DEPRECATED _GL_ATTRIBUTE_DEPRECATED
|
||||||
|
|
||||||
|
/* If a function call is not optimized way, warn with MSG. */
|
||||||
|
/* Applies to: functions. */
|
||||||
|
#define ATTRIBUTE_WARNING(msg) _GL_ATTRIBUTE_WARNING (msg)
|
||||||
|
|
||||||
|
/* If a function call is not optimized way, report an error with MSG. */
|
||||||
|
/* Applies to: functions. */
|
||||||
|
#define ATTRIBUTE_ERROR(msg) _GL_ATTRIBUTE_ERROR (msg)
|
||||||
|
|
||||||
|
|
||||||
|
/* Attributes for memory-allocating functions. */
|
||||||
|
|
||||||
|
/* The function returns a pointer to freshly allocated memory. */
|
||||||
|
/* Applies to: functions. */
|
||||||
|
#define ATTRIBUTE_MALLOC _GL_ATTRIBUTE_MALLOC
|
||||||
|
|
||||||
|
/* ATTRIBUTE_ALLOC_SIZE ((N)) - The Nth argument of the function
|
||||||
|
is the size of the returned memory block.
|
||||||
|
ATTRIBUTE_ALLOC_SIZE ((M, N)) - Multiply the Mth and Nth arguments
|
||||||
|
to determine the size of the returned memory block. */
|
||||||
|
/* Applies to: function, pointer to function, function types. */
|
||||||
|
#define ATTRIBUTE_ALLOC_SIZE(args) _GL_ATTRIBUTE_ALLOC_SIZE (args)
|
||||||
|
|
||||||
|
/* ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
|
||||||
|
that can be freed by passing them as the Ith argument to the
|
||||||
|
function F.
|
||||||
|
ATTRIBUTE_DEALLOC_FREE declares that the function returns pointers that
|
||||||
|
can be freed via 'free'; it can be used only after declaring 'free'. */
|
||||||
|
/* Applies to: functions. Cannot be used on inline functions. */
|
||||||
|
#define ATTRIBUTE_DEALLOC(f, i) _GL_ATTRIBUTE_DEALLOC(f, i)
|
||||||
|
#define ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC_FREE
|
||||||
|
|
||||||
|
/* Attributes for variadic functions. */
|
||||||
|
|
||||||
|
/* The variadic function expects a trailing NULL argument.
|
||||||
|
ATTRIBUTE_SENTINEL () - The last argument is NULL (requires C99).
|
||||||
|
ATTRIBUTE_SENTINEL ((N)) - The (N+1)st argument from the end is NULL. */
|
||||||
|
/* Applies to: functions. */
|
||||||
|
#define ATTRIBUTE_SENTINEL(pos) _GL_ATTRIBUTE_SENTINEL (pos)
|
||||||
|
|
||||||
|
|
||||||
|
/* ================== Attributes for compiler diagnostics ================== */
|
||||||
|
|
||||||
|
/* Attributes that help the compiler diagnose programmer mistakes.
|
||||||
|
Some of them may also help for some compiler optimizations. */
|
||||||
|
|
||||||
|
/* ATTRIBUTE_FORMAT ((ARCHETYPE, STRING-INDEX, FIRST-TO-CHECK)) -
|
||||||
|
The STRING-INDEXth function argument is a format string of style
|
||||||
|
ARCHETYPE, which is one of:
|
||||||
|
printf, gnu_printf
|
||||||
|
scanf, gnu_scanf,
|
||||||
|
strftime, gnu_strftime,
|
||||||
|
strfmon,
|
||||||
|
or the same thing prefixed and suffixed with '__'.
|
||||||
|
If FIRST-TO-CHECK is not 0, arguments starting at FIRST-TO_CHECK
|
||||||
|
are suitable for the format string. */
|
||||||
|
/* Applies to: functions. */
|
||||||
|
#define ATTRIBUTE_FORMAT(spec) _GL_ATTRIBUTE_FORMAT (spec)
|
||||||
|
|
||||||
|
/* ATTRIBUTE_NONNULL ((N1, N2,...)) - Arguments N1, N2,... must not be NULL.
|
||||||
|
ATTRIBUTE_NONNULL () - All pointer arguments must not be null. */
|
||||||
|
/* Applies to: functions. */
|
||||||
|
#define ATTRIBUTE_NONNULL(args) _GL_ATTRIBUTE_NONNULL (args)
|
||||||
|
|
||||||
|
/* The function's return value is a non-NULL pointer. */
|
||||||
|
/* Applies to: functions. */
|
||||||
|
#define ATTRIBUTE_RETURNS_NONNULL _GL_ATTRIBUTE_RETURNS_NONNULL
|
||||||
|
|
||||||
|
/* Warn if the caller does not use the return value,
|
||||||
|
unless the caller uses something like ignore_value. */
|
||||||
|
/* Applies to: function, enumeration, class. */
|
||||||
|
#define NODISCARD _GL_ATTRIBUTE_NODISCARD
|
||||||
|
|
||||||
|
|
||||||
|
/* Attributes that disable false alarms when the compiler diagnoses
|
||||||
|
programmer "mistakes". */
|
||||||
|
|
||||||
|
/* Do not warn if the entity is not used. */
|
||||||
|
/* Applies to:
|
||||||
|
- function, variable,
|
||||||
|
- struct, union, struct/union member,
|
||||||
|
- enumeration, enumeration item,
|
||||||
|
- typedef,
|
||||||
|
in C++ also: class. */
|
||||||
|
#define MAYBE_UNUSED _GL_ATTRIBUTE_MAYBE_UNUSED
|
||||||
|
|
||||||
|
/* The contents of a character array is not meant to be NUL-terminated. */
|
||||||
|
/* Applies to: struct/union members and variables that are arrays of element
|
||||||
|
type '[[un]signed] char'. */
|
||||||
|
#define ATTRIBUTE_NONSTRING _GL_ATTRIBUTE_NONSTRING
|
||||||
|
|
||||||
|
/* Do not warn if control flow falls through to the immediately
|
||||||
|
following 'case' or 'default' label. */
|
||||||
|
/* Applies to: Empty statement (;), inside a 'switch' statement. */
|
||||||
|
#define FALLTHROUGH _GL_ATTRIBUTE_FALLTHROUGH
|
||||||
|
|
||||||
|
|
||||||
|
/* ================== Attributes for debugging information ================== */
|
||||||
|
|
||||||
|
/* Attributes regarding debugging information emitted by the compiler. */
|
||||||
|
|
||||||
|
/* Omit the function from stack traces when debugging. */
|
||||||
|
/* Applies to: function. */
|
||||||
|
#define ATTRIBUTE_ARTIFICIAL _GL_ATTRIBUTE_ARTIFICIAL
|
||||||
|
|
||||||
|
/* Make the entity visible to debuggers etc., even with '-fwhole-program'. */
|
||||||
|
/* Applies to: functions, variables. */
|
||||||
|
#define ATTRIBUTE_EXTERNALLY_VISIBLE _GL_ATTRIBUTE_EXTERNALLY_VISIBLE
|
||||||
|
|
||||||
|
|
||||||
|
/* ========== Attributes that mainly direct compiler optimizations ========== */
|
||||||
|
|
||||||
|
/* The function does not throw exceptions. */
|
||||||
|
/* Applies to: functions. */
|
||||||
|
#define ATTRIBUTE_NOTHROW _GL_ATTRIBUTE_NOTHROW
|
||||||
|
|
||||||
|
/* Do not inline the function. */
|
||||||
|
/* Applies to: functions. */
|
||||||
|
#define ATTRIBUTE_NOINLINE _GL_ATTRIBUTE_NOINLINE
|
||||||
|
|
||||||
|
/* Always inline the function, and report an error if the compiler
|
||||||
|
cannot inline. */
|
||||||
|
/* Applies to: function. */
|
||||||
|
#define ATTRIBUTE_ALWAYS_INLINE _GL_ATTRIBUTE_ALWAYS_INLINE
|
||||||
|
|
||||||
|
/* It is OK for a compiler to omit duplicate calls with the same arguments.
|
||||||
|
This attribute is safe for a function that neither depends on
|
||||||
|
nor affects observable state, and always returns exactly once -
|
||||||
|
e.g., does not loop forever, and does not call longjmp.
|
||||||
|
(This attribute is stricter than ATTRIBUTE_PURE.) */
|
||||||
|
/* Applies to: functions. */
|
||||||
|
#define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST
|
||||||
|
|
||||||
|
/* It is OK for a compiler to omit duplicate calls with the same
|
||||||
|
arguments if observable state is not changed between calls.
|
||||||
|
This attribute is safe for a function that does not affect
|
||||||
|
observable state, and always returns exactly once.
|
||||||
|
(This attribute is looser than ATTRIBUTE_CONST.) */
|
||||||
|
/* Applies to: functions. */
|
||||||
|
#define ATTRIBUTE_PURE _GL_ATTRIBUTE_PURE
|
||||||
|
|
||||||
|
/* The function is rarely executed. */
|
||||||
|
/* Applies to: functions. */
|
||||||
|
#define ATTRIBUTE_COLD _GL_ATTRIBUTE_COLD
|
||||||
|
|
||||||
|
/* If called from some other compilation unit, the function executes
|
||||||
|
code from that unit only by return or by exception handling,
|
||||||
|
letting the compiler optimize that unit more aggressively. */
|
||||||
|
/* Applies to: functions. */
|
||||||
|
#define ATTRIBUTE_LEAF _GL_ATTRIBUTE_LEAF
|
||||||
|
|
||||||
|
/* For struct members: The member has the smallest possible alignment.
|
||||||
|
For struct, union, class: All members have the smallest possible alignment,
|
||||||
|
minimizing the memory required. */
|
||||||
|
/* Applies to: struct members, struct, union,
|
||||||
|
in C++ also: class. */
|
||||||
|
#define ATTRIBUTE_PACKED _GL_ATTRIBUTE_PACKED
|
||||||
|
|
||||||
|
|
||||||
|
/* ================ Attributes that make invalid code valid ================ */
|
||||||
|
|
||||||
|
/* Attributes that prevent fatal compiler optimizations for code that is not
|
||||||
|
fully ISO C compliant. */
|
||||||
|
|
||||||
|
/* Pointers to the type may point to the same storage as pointers to
|
||||||
|
other types, thus disabling strict aliasing optimization. */
|
||||||
|
/* Applies to: types. */
|
||||||
|
#define ATTRIBUTE_MAY_ALIAS _GL_ATTRIBUTE_MAY_ALIAS
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _GL_ATTRIBUTE_H */
|
@ -1,10 +1,10 @@
|
|||||||
/* backupfile.c -- make Emacs style backup file names
|
/* backupfile.c -- make Emacs style backup file names
|
||||||
|
|
||||||
Copyright 2017-2020 Free Software Foundation, Inc.
|
Copyright 2017-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
|
@ -1,3 +1,23 @@
|
|||||||
|
/* Backup files.
|
||||||
|
|
||||||
|
Copyright (C) 2017-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This file is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License,
|
||||||
|
or (at your option) any later version.
|
||||||
|
|
||||||
|
This file is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include "backupfile.h"
|
#include "backupfile.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
extern char *backupfile_internal (int, char const *, enum backup_type, bool);
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
extern char *backupfile_internal (int, char const *, enum backup_type, bool)
|
||||||
|
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/* Rename a file to a backup name, Emacs style.
|
/* Rename a file to a backup name, Emacs style.
|
||||||
|
|
||||||
Copyright 2017-2020 Free Software Foundation, Inc.
|
Copyright 2017-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
|
116
lib/backupfile.c
116
lib/backupfile.c
@ -1,10 +1,10 @@
|
|||||||
/* backupfile.c -- make Emacs style backup file names
|
/* backupfile.c -- make Emacs style backup file names
|
||||||
|
|
||||||
Copyright (C) 1990-2006, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 1990-2006, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
@ -22,11 +22,7 @@
|
|||||||
|
|
||||||
#include "backup-internal.h"
|
#include "backup-internal.h"
|
||||||
|
|
||||||
#include "dirname.h"
|
#include <dirent.h>
|
||||||
#include "opendirat.h"
|
|
||||||
#include "renameatu.h"
|
|
||||||
#include "xalloc-oversized.h"
|
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@ -35,13 +31,12 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#ifndef FALLTHROUGH
|
#include "attribute.h"
|
||||||
# if __GNUC__ < 7
|
#include "basename-lgpl.h"
|
||||||
# define FALLTHROUGH ((void) 0)
|
#include "ialloc.h"
|
||||||
# else
|
#include "intprops.h"
|
||||||
# define FALLTHROUGH __attribute__ ((__fallthrough__))
|
#include "opendirat.h"
|
||||||
# endif
|
#include "renameatu.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _D_EXACT_NAMLEN
|
#ifndef _D_EXACT_NAMLEN
|
||||||
# define _D_EXACT_NAMLEN(dp) strlen ((dp)->d_name)
|
# define _D_EXACT_NAMLEN(dp) strlen ((dp)->d_name)
|
||||||
@ -49,6 +44,7 @@
|
|||||||
|
|
||||||
#if ! (HAVE_PATHCONF && defined _PC_NAME_MAX)
|
#if ! (HAVE_PATHCONF && defined _PC_NAME_MAX)
|
||||||
# define pathconf(file, option) (errno = -1)
|
# define pathconf(file, option) (errno = -1)
|
||||||
|
# define fpathconf(fd, option) (errno = -1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _POSIX_NAME_MAX
|
#ifndef _POSIX_NAME_MAX
|
||||||
@ -95,19 +91,20 @@ set_simple_backup_suffix (char const *s)
|
|||||||
/* If FILE (which was of length FILELEN before an extension was
|
/* If FILE (which was of length FILELEN before an extension was
|
||||||
appended to it) is too long, replace the extension with the single
|
appended to it) is too long, replace the extension with the single
|
||||||
char E. If the result is still too long, remove the char just
|
char E. If the result is still too long, remove the char just
|
||||||
before E.
|
before E. Return true if the extension was OK already, false
|
||||||
|
if it needed replacement.
|
||||||
|
|
||||||
If DIR_FD is nonnegative, it is a file descriptor for FILE's parent.
|
If DIR_FD is nonnegative, it is a file descriptor for FILE's parent.
|
||||||
*NAME_MAX is either 0, or the cached result of a previous call for
|
*BASE_MAX is either 0, or the cached result of a previous call for
|
||||||
FILE's parent's _PC_NAME_MAX. */
|
FILE's parent's _PC_NAME_MAX. */
|
||||||
|
|
||||||
static void
|
static bool
|
||||||
check_extension (char *file, size_t filelen, char e,
|
check_extension (char *file, idx_t filelen, char e,
|
||||||
int dir_fd, size_t *base_max)
|
int dir_fd, idx_t *base_max)
|
||||||
{
|
{
|
||||||
char *base = last_component (file);
|
char *base = last_component (file);
|
||||||
size_t baselen = base_len (base);
|
idx_t baselen = base_len (base);
|
||||||
size_t baselen_max = HAVE_LONG_FILE_NAMES ? 255 : NAME_MAX_MINIMUM;
|
idx_t baselen_max = HAVE_LONG_FILE_NAMES ? 255 : NAME_MAX_MINIMUM;
|
||||||
|
|
||||||
if (HAVE_DOS_FILE_NAMES || NAME_MAX_MINIMUM < baselen)
|
if (HAVE_DOS_FILE_NAMES || NAME_MAX_MINIMUM < baselen)
|
||||||
{
|
{
|
||||||
@ -157,13 +154,16 @@ check_extension (char *file, size_t filelen, char e,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (baselen_max < baselen)
|
if (baselen <= baselen_max)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
baselen = file + filelen - base;
|
baselen = file + filelen - base;
|
||||||
if (baselen_max <= baselen)
|
if (baselen_max <= baselen)
|
||||||
baselen = baselen_max - 1;
|
baselen = baselen_max - 1;
|
||||||
base[baselen] = e;
|
base[baselen] = e;
|
||||||
base[baselen + 1] = '\0';
|
base[baselen + 1] = '\0';
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,9 +191,11 @@ enum numbered_backup_result
|
|||||||
Store into *BUFFER the next backup name for the named file,
|
Store into *BUFFER the next backup name for the named file,
|
||||||
with a version number greater than all the
|
with a version number greater than all the
|
||||||
existing numbered backups. Reallocate *BUFFER as necessary; its
|
existing numbered backups. Reallocate *BUFFER as necessary; its
|
||||||
initial allocated size is BUFFER_SIZE, which must be at least 4
|
initial allocated size is BUFFER_SIZE, which must be at least 5
|
||||||
bytes longer than the file name to make room for the initially
|
bytes longer than the file name to make room for the initially
|
||||||
appended ".~1". FILELEN is the length of the original file name.
|
appended ".~1~". FILELEN is the length of the original file name.
|
||||||
|
(The original file name is not necessarily null-terminated;
|
||||||
|
FILELEN does not count trailing slashes after a non-slash.)
|
||||||
BASE_OFFSET is the offset of the basename in *BUFFER.
|
BASE_OFFSET is the offset of the basename in *BUFFER.
|
||||||
The returned value indicates what kind of backup was found. If an
|
The returned value indicates what kind of backup was found. If an
|
||||||
I/O or other read error occurs, use the highest backup number that
|
I/O or other read error occurs, use the highest backup number that
|
||||||
@ -204,16 +206,14 @@ enum numbered_backup_result
|
|||||||
and its file descriptor into *PNEW_FD without closing the stream. */
|
and its file descriptor into *PNEW_FD without closing the stream. */
|
||||||
|
|
||||||
static enum numbered_backup_result
|
static enum numbered_backup_result
|
||||||
numbered_backup (int dir_fd, char **buffer, size_t buffer_size, size_t filelen,
|
numbered_backup (int dir_fd, char **buffer, idx_t buffer_size, idx_t filelen,
|
||||||
ptrdiff_t base_offset, DIR **dirpp, int *pnew_fd)
|
idx_t base_offset, DIR **dirpp, int *pnew_fd)
|
||||||
{
|
{
|
||||||
enum numbered_backup_result result = BACKUP_IS_NEW;
|
enum numbered_backup_result result = BACKUP_IS_NEW;
|
||||||
DIR *dirp = *dirpp;
|
DIR *dirp = *dirpp;
|
||||||
struct dirent *dp;
|
|
||||||
char *buf = *buffer;
|
char *buf = *buffer;
|
||||||
size_t versionlenmax = 1;
|
idx_t versionlenmax = 1;
|
||||||
char *base = buf + base_offset;
|
idx_t baselen = filelen - base_offset;
|
||||||
size_t baselen = base_len (base);
|
|
||||||
|
|
||||||
if (dirp)
|
if (dirp)
|
||||||
rewinddir (dirp);
|
rewinddir (dirp);
|
||||||
@ -222,6 +222,7 @@ numbered_backup (int dir_fd, char **buffer, size_t buffer_size, size_t filelen,
|
|||||||
/* Temporarily modify the buffer into its parent directory name,
|
/* Temporarily modify the buffer into its parent directory name,
|
||||||
open the directory, and then restore the buffer. */
|
open the directory, and then restore the buffer. */
|
||||||
char tmp[sizeof "."];
|
char tmp[sizeof "."];
|
||||||
|
char *base = buf + base_offset;
|
||||||
memcpy (tmp, base, sizeof ".");
|
memcpy (tmp, base, sizeof ".");
|
||||||
strcpy (base, ".");
|
strcpy (base, ".");
|
||||||
dirp = opendirat (dir_fd, buf, 0, pnew_fd);
|
dirp = opendirat (dir_fd, buf, 0, pnew_fd);
|
||||||
@ -234,20 +235,15 @@ numbered_backup (int dir_fd, char **buffer, size_t buffer_size, size_t filelen,
|
|||||||
*dirpp = dirp;
|
*dirpp = dirp;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((dp = readdir (dirp)) != NULL)
|
for (struct dirent *dp; (dp = readdir (dirp)) != NULL; )
|
||||||
{
|
{
|
||||||
char const *p;
|
|
||||||
char *q;
|
|
||||||
bool all_9s;
|
|
||||||
size_t versionlen;
|
|
||||||
|
|
||||||
if (_D_EXACT_NAMLEN (dp) < baselen + 4)
|
if (_D_EXACT_NAMLEN (dp) < baselen + 4)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (memcmp (buf + base_offset, dp->d_name, baselen + 2) != 0)
|
if (memcmp (buf + base_offset, dp->d_name, baselen + 2) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
p = dp->d_name + baselen + 2;
|
char const *p = dp->d_name + baselen + 2;
|
||||||
|
|
||||||
/* Check whether this file has a version number and if so,
|
/* Check whether this file has a version number and if so,
|
||||||
whether it is larger. Use string operations rather than
|
whether it is larger. Use string operations rather than
|
||||||
@ -255,7 +251,8 @@ numbered_backup (int dir_fd, char **buffer, size_t buffer_size, size_t filelen,
|
|||||||
|
|
||||||
if (! ('1' <= *p && *p <= '9'))
|
if (! ('1' <= *p && *p <= '9'))
|
||||||
continue;
|
continue;
|
||||||
all_9s = (*p == '9');
|
bool all_9s = (*p == '9');
|
||||||
|
idx_t versionlen;
|
||||||
for (versionlen = 1; ISDIGIT (p[versionlen]); versionlen++)
|
for (versionlen = 1; ISDIGIT (p[versionlen]); versionlen++)
|
||||||
all_9s &= (p[versionlen] == '9');
|
all_9s &= (p[versionlen] == '9');
|
||||||
|
|
||||||
@ -271,12 +268,13 @@ numbered_backup (int dir_fd, char **buffer, size_t buffer_size, size_t filelen,
|
|||||||
|
|
||||||
versionlenmax = all_9s + versionlen;
|
versionlenmax = all_9s + versionlen;
|
||||||
result = (all_9s ? BACKUP_IS_LONGER : BACKUP_IS_SAME_LENGTH);
|
result = (all_9s ? BACKUP_IS_LONGER : BACKUP_IS_SAME_LENGTH);
|
||||||
size_t new_buffer_size = filelen + 2 + versionlenmax + 2;
|
idx_t new_buffer_size = filelen + 2 + versionlenmax + 2;
|
||||||
if (buffer_size < new_buffer_size)
|
if (buffer_size < new_buffer_size)
|
||||||
{
|
{
|
||||||
if (! xalloc_oversized (new_buffer_size, 2))
|
idx_t grown;
|
||||||
new_buffer_size *= 2;
|
if (! INT_ADD_WRAPV (new_buffer_size, new_buffer_size >> 1, &grown))
|
||||||
char *new_buf = realloc (buf, new_buffer_size);
|
new_buffer_size = grown;
|
||||||
|
char *new_buf = irealloc (buf, new_buffer_size);
|
||||||
if (!new_buf)
|
if (!new_buf)
|
||||||
{
|
{
|
||||||
*buffer = buf;
|
*buffer = buf;
|
||||||
@ -285,7 +283,7 @@ numbered_backup (int dir_fd, char **buffer, size_t buffer_size, size_t filelen,
|
|||||||
buf = new_buf;
|
buf = new_buf;
|
||||||
buffer_size = new_buffer_size;
|
buffer_size = new_buffer_size;
|
||||||
}
|
}
|
||||||
q = buf + filelen;
|
char *q = buf + filelen;
|
||||||
*q++ = '.';
|
*q++ = '.';
|
||||||
*q++ = '~';
|
*q++ = '~';
|
||||||
*q = '0';
|
*q = '0';
|
||||||
@ -314,31 +312,32 @@ char *
|
|||||||
backupfile_internal (int dir_fd, char const *file,
|
backupfile_internal (int dir_fd, char const *file,
|
||||||
enum backup_type backup_type, bool rename)
|
enum backup_type backup_type, bool rename)
|
||||||
{
|
{
|
||||||
ptrdiff_t base_offset = last_component (file) - file;
|
idx_t base_offset = last_component (file) - file;
|
||||||
size_t filelen = base_offset + strlen (file + base_offset);
|
idx_t filelen = base_offset + base_len (file + base_offset);
|
||||||
|
|
||||||
if (! simple_backup_suffix)
|
if (! simple_backup_suffix)
|
||||||
set_simple_backup_suffix (NULL);
|
set_simple_backup_suffix (NULL);
|
||||||
|
|
||||||
/* Allow room for simple or ".~N~" backups. The guess must be at
|
/* Allow room for simple or ".~N~" backups. The guess must be at
|
||||||
least sizeof ".~1~", but otherwise will be adjusted as needed. */
|
least sizeof ".~1~", but otherwise will be adjusted as needed. */
|
||||||
size_t simple_backup_suffix_size = strlen (simple_backup_suffix) + 1;
|
idx_t simple_backup_suffix_size = strlen (simple_backup_suffix) + 1;
|
||||||
size_t backup_suffix_size_guess = simple_backup_suffix_size;
|
idx_t backup_suffix_size_guess = simple_backup_suffix_size;
|
||||||
enum { GUESS = sizeof ".~12345~" };
|
enum { GUESS = sizeof ".~12345~" };
|
||||||
if (backup_suffix_size_guess < GUESS)
|
if (backup_suffix_size_guess < GUESS)
|
||||||
backup_suffix_size_guess = GUESS;
|
backup_suffix_size_guess = GUESS;
|
||||||
|
|
||||||
ssize_t ssize = filelen + backup_suffix_size_guess + 1;
|
idx_t ssize = filelen + backup_suffix_size_guess + 1;
|
||||||
char *s = malloc (ssize);
|
char *s = imalloc (ssize);
|
||||||
if (!s)
|
if (!s)
|
||||||
return s;
|
return s;
|
||||||
|
|
||||||
DIR *dirp = NULL;
|
DIR *dirp = NULL;
|
||||||
int sdir = -1;
|
int sdir = AT_FDCWD;
|
||||||
size_t base_max = 0;
|
idx_t base_max = 0;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
memcpy (s, file, filelen + 1);
|
bool extended = true;
|
||||||
|
memcpy (s, file, filelen);
|
||||||
|
|
||||||
if (backup_type == simple_backups)
|
if (backup_type == simple_backups)
|
||||||
memcpy (s + filelen, simple_backup_suffix, simple_backup_suffix_size);
|
memcpy (s + filelen, simple_backup_suffix, simple_backup_suffix_size);
|
||||||
@ -358,7 +357,7 @@ backupfile_internal (int dir_fd, char const *file,
|
|||||||
}
|
}
|
||||||
FALLTHROUGH;
|
FALLTHROUGH;
|
||||||
case BACKUP_IS_LONGER:
|
case BACKUP_IS_LONGER:
|
||||||
check_extension (s, filelen, '~', sdir, &base_max);
|
extended = check_extension (s, filelen, '~', sdir, &base_max);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BACKUP_NOMEM:
|
case BACKUP_NOMEM:
|
||||||
@ -372,16 +371,13 @@ backupfile_internal (int dir_fd, char const *file,
|
|||||||
if (! rename)
|
if (! rename)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (sdir < 0)
|
int olddirfd = sdir < 0 ? dir_fd : sdir;
|
||||||
{
|
idx_t offset = sdir < 0 ? 0 : base_offset;
|
||||||
sdir = AT_FDCWD;
|
|
||||||
base_offset = 0;
|
|
||||||
}
|
|
||||||
unsigned flags = backup_type == simple_backups ? 0 : RENAME_NOREPLACE;
|
unsigned flags = backup_type == simple_backups ? 0 : RENAME_NOREPLACE;
|
||||||
if (renameatu (AT_FDCWD, file, sdir, s + base_offset, flags) == 0)
|
if (renameatu (olddirfd, file + offset, sdir, s + offset, flags) == 0)
|
||||||
break;
|
break;
|
||||||
int e = errno;
|
int e = errno;
|
||||||
if (e != EEXIST)
|
if (! (e == EEXIST && extended))
|
||||||
{
|
{
|
||||||
if (dirp)
|
if (dirp)
|
||||||
closedir (dirp);
|
closedir (dirp);
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
/* backupfile.h -- declarations for making Emacs style backup file names
|
/* backupfile.h -- declarations for making Emacs style backup file names
|
||||||
|
|
||||||
Copyright (C) 1990-1992, 1997-1999, 2003-2004, 2009-2020 Free Software
|
Copyright (C) 1990-1992, 1997-1999, 2003-2004, 2009-2022 Free Software
|
||||||
Foundation, Inc.
|
Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
@ -19,8 +19,11 @@
|
|||||||
#ifndef BACKUPFILE_H_
|
#ifndef BACKUPFILE_H_
|
||||||
#define BACKUPFILE_H_
|
#define BACKUPFILE_H_
|
||||||
|
|
||||||
|
/* Get AT_FDCWD, as a convenience for users of this file. */
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -49,8 +52,11 @@ enum backup_type
|
|||||||
extern char const *simple_backup_suffix;
|
extern char const *simple_backup_suffix;
|
||||||
|
|
||||||
void set_simple_backup_suffix (char const *);
|
void set_simple_backup_suffix (char const *);
|
||||||
char *backup_file_rename (int, char const *, enum backup_type);
|
char *backup_file_rename (int, char const *, enum backup_type)
|
||||||
char *find_backup_file_name (int, char const *, enum backup_type);
|
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
|
||||||
|
char *find_backup_file_name (int, char const *, enum backup_type)
|
||||||
|
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
|
||||||
|
_GL_ATTRIBUTE_RETURNS_NONNULL;
|
||||||
enum backup_type get_version (char const *context, char const *arg);
|
enum backup_type get_version (char const *context, char const *arg);
|
||||||
enum backup_type xget_version (char const *context, char const *arg);
|
enum backup_type xget_version (char const *context, char const *arg);
|
||||||
|
|
||||||
|
77
lib/base32.c
77
lib/base32.c
@ -1,18 +1,18 @@
|
|||||||
/* base32.c -- Encode binary data using printable characters.
|
/* base32.c -- Encode binary data using printable characters.
|
||||||
Copyright (C) 1999-2001, 2004-2006, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 1999-2001, 2004-2006, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3, or (at your option)
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program; if not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
/* Adapted from Simon Josefsson's base64 code by Gijs van Tulder.
|
/* Adapted from Simon Josefsson's base64 code by Gijs van Tulder.
|
||||||
*
|
*
|
||||||
@ -28,7 +28,7 @@
|
|||||||
* FAIL: memory allocation error
|
* FAIL: memory allocation error
|
||||||
* OK: data in OUT/OUTLEN
|
* OK: data in OUT/OUTLEN
|
||||||
*
|
*
|
||||||
* size_t outlen = base32_encode_alloc (in, inlen, &out);
|
* idx_t outlen = base32_encode_alloc (in, inlen, &out);
|
||||||
* if (out == NULL && outlen == 0 && inlen != 0)
|
* if (out == NULL && outlen == 0 && inlen != 0)
|
||||||
* FAIL: input too long
|
* FAIL: input too long
|
||||||
* if (out == NULL)
|
* if (out == NULL)
|
||||||
@ -42,15 +42,17 @@
|
|||||||
/* Get prototype. */
|
/* Get prototype. */
|
||||||
#include "base32.h"
|
#include "base32.h"
|
||||||
|
|
||||||
/* Get malloc. */
|
/* Get imalloc. */
|
||||||
#include <stdlib.h>
|
#include <ialloc.h>
|
||||||
|
|
||||||
|
#include <intprops.h>
|
||||||
|
|
||||||
/* Get UCHAR_MAX. */
|
/* Get UCHAR_MAX. */
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* C89 compliant way to cast 'char' to 'unsigned char'. */
|
/* Convert 'char' to 'unsigned char' without casting. */
|
||||||
static unsigned char
|
static unsigned char
|
||||||
to_uchar (char ch)
|
to_uchar (char ch)
|
||||||
{
|
{
|
||||||
@ -62,8 +64,8 @@ to_uchar (char ch)
|
|||||||
possible. If OUTLEN is larger than BASE32_LENGTH(INLEN), also zero
|
possible. If OUTLEN is larger than BASE32_LENGTH(INLEN), also zero
|
||||||
terminate the output buffer. */
|
terminate the output buffer. */
|
||||||
void
|
void
|
||||||
base32_encode (const char *restrict in, size_t inlen,
|
base32_encode (const char *restrict in, idx_t inlen,
|
||||||
char *restrict out, size_t outlen)
|
char *restrict out, idx_t outlen)
|
||||||
{
|
{
|
||||||
static const char b32str[32] =
|
static const char b32str[32] =
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
||||||
@ -136,24 +138,21 @@ base32_encode (const char *restrict in, size_t inlen,
|
|||||||
memory allocation failed, OUT is set to NULL, and the return value
|
memory allocation failed, OUT is set to NULL, and the return value
|
||||||
indicates length of the requested memory block, i.e.,
|
indicates length of the requested memory block, i.e.,
|
||||||
BASE32_LENGTH(inlen) + 1. */
|
BASE32_LENGTH(inlen) + 1. */
|
||||||
size_t
|
idx_t
|
||||||
base32_encode_alloc (const char *in, size_t inlen, char **out)
|
base32_encode_alloc (const char *in, idx_t inlen, char **out)
|
||||||
{
|
{
|
||||||
size_t outlen = 1 + BASE32_LENGTH (inlen);
|
|
||||||
|
|
||||||
/* Check for overflow in outlen computation.
|
/* Check for overflow in outlen computation.
|
||||||
*
|
Treat negative INLEN as overflow, for better compatibility with
|
||||||
* If there is no overflow, outlen >= inlen.
|
pre-2021-08-27 API, which used size_t. */
|
||||||
*
|
idx_t in_over_5 = inlen / 5 + (inlen % 5 != 0), outlen;
|
||||||
* TODO Is this a sufficient check? (See the notes in base64.c.)
|
if (! INT_MULTIPLY_OK (in_over_5, 8, &outlen) || inlen < 0)
|
||||||
*/
|
|
||||||
if (inlen > outlen)
|
|
||||||
{
|
{
|
||||||
*out = NULL;
|
*out = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
outlen++;
|
||||||
|
|
||||||
*out = malloc (outlen);
|
*out = imalloc (outlen);
|
||||||
if (!*out)
|
if (!*out)
|
||||||
return outlen;
|
return outlen;
|
||||||
|
|
||||||
@ -305,7 +304,7 @@ base32_decode_ctx_init (struct base32_decode_context *ctx)
|
|||||||
static char *
|
static char *
|
||||||
get_8 (struct base32_decode_context *ctx,
|
get_8 (struct base32_decode_context *ctx,
|
||||||
char const *restrict *in, char const *restrict in_end,
|
char const *restrict *in, char const *restrict in_end,
|
||||||
size_t *n_non_newline)
|
idx_t *n_non_newline)
|
||||||
{
|
{
|
||||||
if (ctx->i == 8)
|
if (ctx->i == 8)
|
||||||
ctx->i = 0;
|
ctx->i = 0;
|
||||||
@ -357,14 +356,14 @@ get_8 (struct base32_decode_context *ctx,
|
|||||||
*OUT to point to the byte after the last one written, and decrement
|
*OUT to point to the byte after the last one written, and decrement
|
||||||
*OUTLEN to reflect the number of bytes remaining in *OUT. */
|
*OUTLEN to reflect the number of bytes remaining in *OUT. */
|
||||||
static bool
|
static bool
|
||||||
decode_8 (char const *restrict in, size_t inlen,
|
decode_8 (char const *restrict in, idx_t inlen,
|
||||||
char *restrict *outp, size_t *outleft)
|
char *restrict *outp, idx_t *outleft)
|
||||||
{
|
{
|
||||||
char *out = *outp;
|
char *out = *outp;
|
||||||
if (inlen < 8)
|
if (inlen < 8)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!isbase32 (in[0]) || !isbase32 (in[1]) )
|
if (!isbase32 (in[0]) || !isbase32 (in[1]))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (*outleft)
|
if (*outleft)
|
||||||
@ -468,10 +467,10 @@ decode_8 (char const *restrict in, size_t inlen,
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
base32_decode_ctx (struct base32_decode_context *ctx,
|
base32_decode_ctx (struct base32_decode_context *ctx,
|
||||||
const char *restrict in, size_t inlen,
|
const char *restrict in, idx_t inlen,
|
||||||
char *restrict out, size_t *outlen)
|
char *restrict out, idx_t *outlen)
|
||||||
{
|
{
|
||||||
size_t outleft = *outlen;
|
idx_t outleft = *outlen;
|
||||||
bool ignore_newlines = ctx != NULL;
|
bool ignore_newlines = ctx != NULL;
|
||||||
bool flush_ctx = false;
|
bool flush_ctx = false;
|
||||||
unsigned int ctx_i = 0;
|
unsigned int ctx_i = 0;
|
||||||
@ -485,7 +484,7 @@ base32_decode_ctx (struct base32_decode_context *ctx,
|
|||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
size_t outleft_save = outleft;
|
idx_t outleft_save = outleft;
|
||||||
if (ctx_i == 0 && !flush_ctx)
|
if (ctx_i == 0 && !flush_ctx)
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
@ -559,17 +558,17 @@ base32_decode_ctx (struct base32_decode_context *ctx,
|
|||||||
undefined. */
|
undefined. */
|
||||||
bool
|
bool
|
||||||
base32_decode_alloc_ctx (struct base32_decode_context *ctx,
|
base32_decode_alloc_ctx (struct base32_decode_context *ctx,
|
||||||
const char *in, size_t inlen, char **out,
|
const char *in, idx_t inlen, char **out,
|
||||||
size_t *outlen)
|
idx_t *outlen)
|
||||||
{
|
{
|
||||||
/* This may allocate a few bytes too many, depending on input,
|
/* This may allocate a few bytes too many, depending on input,
|
||||||
but it's not worth the extra CPU time to compute the exact size.
|
but it's not worth the extra CPU time to compute the exact size.
|
||||||
The exact size is 5 * inlen / 8, minus one or more bytes if the
|
The exact size is 5 * inlen / 8, minus one or more bytes if the
|
||||||
input is padded with one or more "=".
|
input is padded with one or more "=".
|
||||||
Dividing before multiplying avoids the possibility of overflow. */
|
Shifting before multiplying avoids the possibility of overflow. */
|
||||||
size_t needlen = 5 * (inlen / 8) + 5;
|
idx_t needlen = 5 * ((inlen >> 3) + 1);
|
||||||
|
|
||||||
*out = malloc (needlen);
|
*out = imalloc (needlen);
|
||||||
if (!*out)
|
if (!*out)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
38
lib/base32.h
38
lib/base32.h
@ -1,25 +1,25 @@
|
|||||||
/* base32.h -- Encode binary data using printable characters.
|
/* base32.h -- Encode binary data using printable characters.
|
||||||
Copyright (C) 2004-2006, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 2004-2006, 2009-2022 Free Software Foundation, Inc.
|
||||||
Adapted from Simon Josefsson's base64 code by Gijs van Tulder.
|
Adapted from Simon Josefsson's base64 code by Gijs van Tulder.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3, or (at your option)
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program; if not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#ifndef BASE32_H
|
#ifndef BASE32_H
|
||||||
# define BASE32_H
|
# define BASE32_H
|
||||||
|
|
||||||
/* Get size_t. */
|
/* Get idx_t. */
|
||||||
# include <stddef.h>
|
# include <idx.h>
|
||||||
|
|
||||||
/* Get bool. */
|
/* Get bool. */
|
||||||
# include <stdbool.h>
|
# include <stdbool.h>
|
||||||
@ -30,26 +30,26 @@
|
|||||||
|
|
||||||
struct base32_decode_context
|
struct base32_decode_context
|
||||||
{
|
{
|
||||||
unsigned int i;
|
int i;
|
||||||
char buf[8];
|
char buf[8];
|
||||||
};
|
};
|
||||||
|
|
||||||
extern bool isbase32 (char ch) _GL_ATTRIBUTE_CONST;
|
extern bool isbase32 (char ch) _GL_ATTRIBUTE_CONST;
|
||||||
|
|
||||||
extern void base32_encode (const char *restrict in, size_t inlen,
|
extern void base32_encode (const char *restrict in, idx_t inlen,
|
||||||
char *restrict out, size_t outlen);
|
char *restrict out, idx_t outlen);
|
||||||
|
|
||||||
extern size_t base32_encode_alloc (const char *in, size_t inlen, char **out);
|
extern idx_t base32_encode_alloc (const char *in, idx_t inlen, char **out);
|
||||||
|
|
||||||
extern void base32_decode_ctx_init (struct base32_decode_context *ctx);
|
extern void base32_decode_ctx_init (struct base32_decode_context *ctx);
|
||||||
|
|
||||||
extern bool base32_decode_ctx (struct base32_decode_context *ctx,
|
extern bool base32_decode_ctx (struct base32_decode_context *ctx,
|
||||||
const char *restrict in, size_t inlen,
|
const char *restrict in, idx_t inlen,
|
||||||
char *restrict out, size_t *outlen);
|
char *restrict out, idx_t *outlen);
|
||||||
|
|
||||||
extern bool base32_decode_alloc_ctx (struct base32_decode_context *ctx,
|
extern bool base32_decode_alloc_ctx (struct base32_decode_context *ctx,
|
||||||
const char *in, size_t inlen,
|
const char *in, idx_t inlen,
|
||||||
char **out, size_t *outlen);
|
char **out, idx_t *outlen);
|
||||||
|
|
||||||
#define base32_decode(in, inlen, out, outlen) \
|
#define base32_decode(in, inlen, out, outlen) \
|
||||||
base32_decode_ctx (NULL, in, inlen, out, outlen)
|
base32_decode_ctx (NULL, in, inlen, out, outlen)
|
||||||
|
85
lib/base64.c
85
lib/base64.c
@ -1,18 +1,18 @@
|
|||||||
/* base64.c -- Encode binary data using printable characters.
|
/* base64.c -- Encode binary data using printable characters.
|
||||||
Copyright (C) 1999-2001, 2004-2006, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 1999-2001, 2004-2006, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3, or (at your option)
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program; if not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
/* Written by Simon Josefsson. Partially adapted from GNU MailUtils
|
/* Written by Simon Josefsson. Partially adapted from GNU MailUtils
|
||||||
* (mailbox/filter_trans.c, as of 2004-11-28). Improved by review
|
* (mailbox/filter_trans.c, as of 2004-11-28). Improved by review
|
||||||
@ -30,7 +30,7 @@
|
|||||||
* FAIL: memory allocation error
|
* FAIL: memory allocation error
|
||||||
* OK: data in OUT/OUTLEN
|
* OK: data in OUT/OUTLEN
|
||||||
*
|
*
|
||||||
* size_t outlen = base64_encode_alloc (in, inlen, &out);
|
* idx_t outlen = base64_encode_alloc (in, inlen, &out);
|
||||||
* if (out == NULL && outlen == 0 && inlen != 0)
|
* if (out == NULL && outlen == 0 && inlen != 0)
|
||||||
* FAIL: input too long
|
* FAIL: input too long
|
||||||
* if (out == NULL)
|
* if (out == NULL)
|
||||||
@ -44,15 +44,17 @@
|
|||||||
/* Get prototype. */
|
/* Get prototype. */
|
||||||
#include "base64.h"
|
#include "base64.h"
|
||||||
|
|
||||||
/* Get malloc. */
|
/* Get imalloc. */
|
||||||
#include <stdlib.h>
|
#include <ialloc.h>
|
||||||
|
|
||||||
|
#include <intprops.h>
|
||||||
|
|
||||||
/* Get UCHAR_MAX. */
|
/* Get UCHAR_MAX. */
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* C89 compliant way to cast 'char' to 'unsigned char'. */
|
/* Convert 'char' to 'unsigned char' without casting. */
|
||||||
static unsigned char
|
static unsigned char
|
||||||
to_uchar (char ch)
|
to_uchar (char ch)
|
||||||
{
|
{
|
||||||
@ -66,7 +68,7 @@ static const char b64c[64] =
|
|||||||
to be of length >= BASE64_LENGTH(INLEN), and INLEN needs to be
|
to be of length >= BASE64_LENGTH(INLEN), and INLEN needs to be
|
||||||
a multiple of 3. */
|
a multiple of 3. */
|
||||||
static void
|
static void
|
||||||
base64_encode_fast (const char *restrict in, size_t inlen, char *restrict out)
|
base64_encode_fast (const char *restrict in, idx_t inlen, char *restrict out)
|
||||||
{
|
{
|
||||||
while (inlen)
|
while (inlen)
|
||||||
{
|
{
|
||||||
@ -85,8 +87,8 @@ base64_encode_fast (const char *restrict in, size_t inlen, char *restrict out)
|
|||||||
possible. If OUTLEN is larger than BASE64_LENGTH(INLEN), also zero
|
possible. If OUTLEN is larger than BASE64_LENGTH(INLEN), also zero
|
||||||
terminate the output buffer. */
|
terminate the output buffer. */
|
||||||
void
|
void
|
||||||
base64_encode (const char *restrict in, size_t inlen,
|
base64_encode (const char *restrict in, idx_t inlen,
|
||||||
char *restrict out, size_t outlen)
|
char *restrict out, idx_t outlen)
|
||||||
{
|
{
|
||||||
/* Note this outlen constraint can be enforced at compile time.
|
/* Note this outlen constraint can be enforced at compile time.
|
||||||
I.E. that the output buffer is exactly large enough to hold
|
I.E. that the output buffer is exactly large enough to hold
|
||||||
@ -95,7 +97,7 @@ base64_encode (const char *restrict in, size_t inlen,
|
|||||||
at the end of input. However the common case when reading
|
at the end of input. However the common case when reading
|
||||||
large inputs is to have both constraints satisfied, so we depend
|
large inputs is to have both constraints satisfied, so we depend
|
||||||
on both in base_encode_fast(). */
|
on both in base_encode_fast(). */
|
||||||
if (outlen % 4 == 0 && inlen == outlen / 4 * 3)
|
if (outlen % 4 == 0 && inlen == (outlen >> 2) * 3)
|
||||||
{
|
{
|
||||||
base64_encode_fast (in, inlen, out);
|
base64_encode_fast (in, inlen, out);
|
||||||
return;
|
return;
|
||||||
@ -141,30 +143,21 @@ base64_encode (const char *restrict in, size_t inlen,
|
|||||||
memory allocation failed, OUT is set to NULL, and the return value
|
memory allocation failed, OUT is set to NULL, and the return value
|
||||||
indicates length of the requested memory block, i.e.,
|
indicates length of the requested memory block, i.e.,
|
||||||
BASE64_LENGTH(inlen) + 1. */
|
BASE64_LENGTH(inlen) + 1. */
|
||||||
size_t
|
idx_t
|
||||||
base64_encode_alloc (const char *in, size_t inlen, char **out)
|
base64_encode_alloc (const char *in, idx_t inlen, char **out)
|
||||||
{
|
{
|
||||||
size_t outlen = 1 + BASE64_LENGTH (inlen);
|
|
||||||
|
|
||||||
/* Check for overflow in outlen computation.
|
/* Check for overflow in outlen computation.
|
||||||
*
|
Treat negative INLEN as overflow, for better compatibility with
|
||||||
* If there is no overflow, outlen >= inlen.
|
pre-2021-08-27 API, which used size_t. */
|
||||||
*
|
idx_t in_over_3 = inlen / 3 + (inlen % 3 != 0), outlen;
|
||||||
* If the operation (inlen + 2) overflows then it yields at most +1, so
|
if (! INT_MULTIPLY_OK (in_over_3, 4, &outlen) || inlen < 0)
|
||||||
* outlen is 0.
|
|
||||||
*
|
|
||||||
* If the multiplication overflows, we lose at least half of the
|
|
||||||
* correct value, so the result is < ((inlen + 2) / 3) * 2, which is
|
|
||||||
* less than (inlen + 2) * 0.66667, which is less than inlen as soon as
|
|
||||||
* (inlen > 4).
|
|
||||||
*/
|
|
||||||
if (inlen > outlen)
|
|
||||||
{
|
{
|
||||||
*out = NULL;
|
*out = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
outlen++;
|
||||||
|
|
||||||
*out = malloc (outlen);
|
*out = imalloc (outlen);
|
||||||
if (!*out)
|
if (!*out)
|
||||||
return outlen;
|
return outlen;
|
||||||
|
|
||||||
@ -348,7 +341,7 @@ base64_decode_ctx_init (struct base64_decode_context *ctx)
|
|||||||
static char *
|
static char *
|
||||||
get_4 (struct base64_decode_context *ctx,
|
get_4 (struct base64_decode_context *ctx,
|
||||||
char const *restrict *in, char const *restrict in_end,
|
char const *restrict *in, char const *restrict in_end,
|
||||||
size_t *n_non_newline)
|
idx_t *n_non_newline)
|
||||||
{
|
{
|
||||||
if (ctx->i == 4)
|
if (ctx->i == 4)
|
||||||
ctx->i = 0;
|
ctx->i = 0;
|
||||||
@ -400,8 +393,8 @@ get_4 (struct base64_decode_context *ctx,
|
|||||||
*OUT to point to the byte after the last one written, and decrement
|
*OUT to point to the byte after the last one written, and decrement
|
||||||
*OUTLEN to reflect the number of bytes remaining in *OUT. */
|
*OUTLEN to reflect the number of bytes remaining in *OUT. */
|
||||||
static bool
|
static bool
|
||||||
decode_4 (char const *restrict in, size_t inlen,
|
decode_4 (char const *restrict in, idx_t inlen,
|
||||||
char *restrict *outp, size_t *outleft)
|
char *restrict *outp, idx_t *outleft)
|
||||||
{
|
{
|
||||||
char *out = *outp;
|
char *out = *outp;
|
||||||
if (inlen < 2)
|
if (inlen < 2)
|
||||||
@ -486,10 +479,10 @@ decode_4 (char const *restrict in, size_t inlen,
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
base64_decode_ctx (struct base64_decode_context *ctx,
|
base64_decode_ctx (struct base64_decode_context *ctx,
|
||||||
const char *restrict in, size_t inlen,
|
const char *restrict in, idx_t inlen,
|
||||||
char *restrict out, size_t *outlen)
|
char *restrict out, idx_t *outlen)
|
||||||
{
|
{
|
||||||
size_t outleft = *outlen;
|
idx_t outleft = *outlen;
|
||||||
bool ignore_newlines = ctx != NULL;
|
bool ignore_newlines = ctx != NULL;
|
||||||
bool flush_ctx = false;
|
bool flush_ctx = false;
|
||||||
unsigned int ctx_i = 0;
|
unsigned int ctx_i = 0;
|
||||||
@ -503,7 +496,7 @@ base64_decode_ctx (struct base64_decode_context *ctx,
|
|||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
size_t outleft_save = outleft;
|
idx_t outleft_save = outleft;
|
||||||
if (ctx_i == 0 && !flush_ctx)
|
if (ctx_i == 0 && !flush_ctx)
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
@ -577,17 +570,17 @@ base64_decode_ctx (struct base64_decode_context *ctx,
|
|||||||
undefined. */
|
undefined. */
|
||||||
bool
|
bool
|
||||||
base64_decode_alloc_ctx (struct base64_decode_context *ctx,
|
base64_decode_alloc_ctx (struct base64_decode_context *ctx,
|
||||||
const char *in, size_t inlen, char **out,
|
const char *in, idx_t inlen, char **out,
|
||||||
size_t *outlen)
|
idx_t *outlen)
|
||||||
{
|
{
|
||||||
/* This may allocate a few bytes too many, depending on input,
|
/* This may allocate a few bytes too many, depending on input,
|
||||||
but it's not worth the extra CPU time to compute the exact size.
|
but it's not worth the extra CPU time to compute the exact size.
|
||||||
The exact size is 3 * (inlen + (ctx ? ctx->i : 0)) / 4, minus 1 if the
|
The exact size is 3 * (inlen + (ctx ? ctx->i : 0)) / 4, minus 1 if the
|
||||||
input ends with "=" and minus another 1 if the input ends with "==".
|
input ends with "=" and minus another 1 if the input ends with "==".
|
||||||
Dividing before multiplying avoids the possibility of overflow. */
|
Shifting before multiplying avoids the possibility of overflow. */
|
||||||
size_t needlen = 3 * (inlen / 4) + 3;
|
idx_t needlen = 3 * ((inlen >> 2) + 1);
|
||||||
|
|
||||||
*out = malloc (needlen);
|
*out = imalloc (needlen);
|
||||||
if (!*out)
|
if (!*out)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
38
lib/base64.h
38
lib/base64.h
@ -1,25 +1,25 @@
|
|||||||
/* base64.h -- Encode binary data using printable characters.
|
/* base64.h -- Encode binary data using printable characters.
|
||||||
Copyright (C) 2004-2006, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 2004-2006, 2009-2022 Free Software Foundation, Inc.
|
||||||
Written by Simon Josefsson.
|
Written by Simon Josefsson.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3, or (at your option)
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program; if not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#ifndef BASE64_H
|
#ifndef BASE64_H
|
||||||
# define BASE64_H
|
# define BASE64_H
|
||||||
|
|
||||||
/* Get size_t. */
|
/* Get idx_t. */
|
||||||
# include <stddef.h>
|
# include <idx.h>
|
||||||
|
|
||||||
/* Get bool. */
|
/* Get bool. */
|
||||||
# include <stdbool.h>
|
# include <stdbool.h>
|
||||||
@ -34,26 +34,26 @@ extern "C" {
|
|||||||
|
|
||||||
struct base64_decode_context
|
struct base64_decode_context
|
||||||
{
|
{
|
||||||
unsigned int i;
|
int i;
|
||||||
char buf[4];
|
char buf[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
extern bool isbase64 (char ch) _GL_ATTRIBUTE_CONST;
|
extern bool isbase64 (char ch) _GL_ATTRIBUTE_CONST;
|
||||||
|
|
||||||
extern void base64_encode (const char *restrict in, size_t inlen,
|
extern void base64_encode (const char *restrict in, idx_t inlen,
|
||||||
char *restrict out, size_t outlen);
|
char *restrict out, idx_t outlen);
|
||||||
|
|
||||||
extern size_t base64_encode_alloc (const char *in, size_t inlen, char **out);
|
extern idx_t base64_encode_alloc (const char *in, idx_t inlen, char **out);
|
||||||
|
|
||||||
extern void base64_decode_ctx_init (struct base64_decode_context *ctx);
|
extern void base64_decode_ctx_init (struct base64_decode_context *ctx);
|
||||||
|
|
||||||
extern bool base64_decode_ctx (struct base64_decode_context *ctx,
|
extern bool base64_decode_ctx (struct base64_decode_context *ctx,
|
||||||
const char *restrict in, size_t inlen,
|
const char *restrict in, idx_t inlen,
|
||||||
char *restrict out, size_t *outlen);
|
char *restrict out, idx_t *outlen);
|
||||||
|
|
||||||
extern bool base64_decode_alloc_ctx (struct base64_decode_context *ctx,
|
extern bool base64_decode_alloc_ctx (struct base64_decode_context *ctx,
|
||||||
const char *in, size_t inlen,
|
const char *in, idx_t inlen,
|
||||||
char **out, size_t *outlen);
|
char **out, idx_t *outlen);
|
||||||
|
|
||||||
#define base64_decode(in, inlen, out, outlen) \
|
#define base64_decode(in, inlen, out, outlen) \
|
||||||
base64_decode_ctx (NULL, in, inlen, out, outlen)
|
base64_decode_ctx (NULL, in, inlen, out, outlen)
|
||||||
|
@ -1,37 +1,37 @@
|
|||||||
/* basename.c -- return the last element in a file name
|
/* basename.c -- return the last element in a file name
|
||||||
|
|
||||||
Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2020 Free Software
|
Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2022 Free Software
|
||||||
Foundation, Inc.
|
Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
(at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include "dirname.h"
|
/* Specification. */
|
||||||
|
#include "basename-lgpl.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* Return the address of the last file name component of NAME. If
|
#include "filename.h"
|
||||||
NAME has no relative file name components because it is a file
|
|
||||||
system root, return the empty string. */
|
|
||||||
|
|
||||||
char *
|
char *
|
||||||
last_component (char const *name)
|
last_component (char const *name)
|
||||||
{
|
{
|
||||||
char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);
|
char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);
|
||||||
char const *p;
|
char const *p;
|
||||||
bool saw_slash = false;
|
bool last_was_slash = false;
|
||||||
|
|
||||||
while (ISSLASH (*base))
|
while (ISSLASH (*base))
|
||||||
base++;
|
base++;
|
||||||
@ -39,21 +39,17 @@ last_component (char const *name)
|
|||||||
for (p = base; *p; p++)
|
for (p = base; *p; p++)
|
||||||
{
|
{
|
||||||
if (ISSLASH (*p))
|
if (ISSLASH (*p))
|
||||||
saw_slash = true;
|
last_was_slash = true;
|
||||||
else if (saw_slash)
|
else if (last_was_slash)
|
||||||
{
|
{
|
||||||
base = p;
|
base = p;
|
||||||
saw_slash = false;
|
last_was_slash = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (char *) base;
|
return (char *) base;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the length of the basename NAME. Typically NAME is the
|
|
||||||
value returned by base_name or last_component. Act like strlen
|
|
||||||
(NAME), except omit all trailing slashes. */
|
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
base_len (char const *name)
|
base_len (char const *name)
|
||||||
{
|
{
|
||||||
|
78
lib/basename-lgpl.h
Normal file
78
lib/basename-lgpl.h
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/* Extract the last component (base name) of a file name.
|
||||||
|
|
||||||
|
Copyright (C) 1998, 2001, 2003-2006, 2009-2022 Free Software Foundation,
|
||||||
|
Inc.
|
||||||
|
|
||||||
|
This file is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as
|
||||||
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This file is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#ifndef _BASENAME_LGPL_H
|
||||||
|
#define _BASENAME_LGPL_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
|
||||||
|
# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Return the address of the last file name component of FILENAME.
|
||||||
|
If FILENAME has some trailing slash(es), they are considered to be
|
||||||
|
part of the last component.
|
||||||
|
If FILENAME has no relative file name components because it is a file
|
||||||
|
system root, return the empty string.
|
||||||
|
Examples:
|
||||||
|
FILENAME RESULT
|
||||||
|
"foo.c" "foo.c"
|
||||||
|
"foo/bar.c" "bar.c"
|
||||||
|
"/foo/bar.c" "bar.c"
|
||||||
|
"foo/bar/" "bar/"
|
||||||
|
"foo/bar//" "bar//"
|
||||||
|
"/" ""
|
||||||
|
"//" ""
|
||||||
|
"" ""
|
||||||
|
The return value is a tail of the given FILENAME; do NOT free() it! */
|
||||||
|
|
||||||
|
/* This function was traditionally called 'basename', but we avoid this
|
||||||
|
function name because
|
||||||
|
* Various platforms have different functions in their libc.
|
||||||
|
In particular, the glibc basename(), defined in <string.h>, does
|
||||||
|
not consider trailing slashes to be part of the component:
|
||||||
|
FILENAME RESULT
|
||||||
|
"foo/bar/" ""
|
||||||
|
"foo/bar//" ""
|
||||||
|
* The 'basename' command eliminates trailing slashes and for a root
|
||||||
|
produces a non-empty result:
|
||||||
|
FILENAME RESULT
|
||||||
|
"foo/bar/" "bar"
|
||||||
|
"foo/bar//" "bar"
|
||||||
|
"/" "/"
|
||||||
|
"//" "/"
|
||||||
|
*/
|
||||||
|
extern char *last_component (char const *filename) _GL_ATTRIBUTE_PURE;
|
||||||
|
|
||||||
|
/* Return the length of the basename FILENAME.
|
||||||
|
Typically FILENAME is the value returned by base_name or last_component.
|
||||||
|
Act like strlen (FILENAME), except omit all trailing slashes. */
|
||||||
|
extern size_t base_len (char const *filename) _GL_ATTRIBUTE_PURE;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _BASENAME_LGPL_H */
|
@ -1,11 +1,11 @@
|
|||||||
/* basename.c -- return the last element in a file name
|
/* basename.c -- return the last element in a file name
|
||||||
|
|
||||||
Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2020 Free Software
|
Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2022 Free Software
|
||||||
Foundation, Inc.
|
Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
@ -22,37 +22,43 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "xalloc.h"
|
#include "xalloc.h"
|
||||||
#include "xstrndup.h"
|
|
||||||
|
|
||||||
char *
|
char *
|
||||||
base_name (char const *name)
|
base_name (char const *name)
|
||||||
{
|
{
|
||||||
char const *base = last_component (name);
|
char const *base = last_component (name);
|
||||||
size_t length;
|
idx_t length;
|
||||||
|
int dotslash_len;
|
||||||
/* If there is no last component, then name is a file system root or the
|
if (*base)
|
||||||
empty string. */
|
{
|
||||||
if (! *base)
|
length = base_len (base);
|
||||||
return xstrndup (name, base_len (name));
|
|
||||||
|
/* Collapse a sequence of trailing slashes into one. */
|
||||||
/* Collapse a sequence of trailing slashes into one. */
|
length += ISSLASH (base[length]);
|
||||||
length = base_len (base);
|
|
||||||
if (ISSLASH (base[length]))
|
/* On systems with drive letters, "a/b:c" must return "./b:c" rather
|
||||||
length++;
|
than "b:c" to avoid confusion with a drive letter. On systems
|
||||||
|
with pure POSIX semantics, this is not an issue. */
|
||||||
/* On systems with drive letters, "a/b:c" must return "./b:c" rather
|
dotslash_len = FILE_SYSTEM_PREFIX_LEN (base) != 0 ? 2 : 0;
|
||||||
than "b:c" to avoid confusion with a drive letter. On systems
|
}
|
||||||
with pure POSIX semantics, this is not an issue. */
|
else
|
||||||
if (FILE_SYSTEM_PREFIX_LEN (base))
|
{
|
||||||
|
/* There is no last component, so NAME is a file system root or
|
||||||
|
the empty string. */
|
||||||
|
base = name;
|
||||||
|
length = base_len (base);
|
||||||
|
dotslash_len = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *p = ximalloc (dotslash_len + length + 1);
|
||||||
|
if (dotslash_len)
|
||||||
{
|
{
|
||||||
char *p = xmalloc (length + 3);
|
|
||||||
p[0] = '.';
|
p[0] = '.';
|
||||||
p[1] = '/';
|
p[1] = '/';
|
||||||
memcpy (p + 2, base, length);
|
|
||||||
p[length + 2] = '\0';
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Finally, copy the basename. */
|
/* Finally, copy the basename. */
|
||||||
return xstrndup (base, length);
|
memcpy (p + dotslash_len, base, length);
|
||||||
|
p[dotslash_len + length] = '\0';
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/* Binary mode I/O.
|
/* Binary mode I/O.
|
||||||
Copyright 2017-2020 Free Software Foundation, Inc.
|
Copyright 2017-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
(at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/* Binary mode I/O.
|
/* Binary mode I/O.
|
||||||
Copyright (C) 2001, 2003, 2005, 2008-2020 Free Software Foundation, Inc.
|
Copyright (C) 2001, 2003, 2005, 2008-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
(at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#ifndef _BINARY_H
|
#ifndef _BINARY_H
|
||||||
@ -47,7 +47,7 @@ _GL_INLINE_HEADER_BEGIN
|
|||||||
/* Use a function rather than a macro, to avoid gcc warnings
|
/* Use a function rather than a macro, to avoid gcc warnings
|
||||||
"warning: statement with no effect". */
|
"warning: statement with no effect". */
|
||||||
BINARY_IO_INLINE int
|
BINARY_IO_INLINE int
|
||||||
__gl_setmode (int fd _GL_UNUSED, int mode _GL_UNUSED)
|
__gl_setmode (_GL_UNUSED int fd, _GL_UNUSED int mode)
|
||||||
{
|
{
|
||||||
return O_BINARY;
|
return O_BINARY;
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ __gl_setmode (int fd _GL_UNUSED, int mode _GL_UNUSED)
|
|||||||
/* Set FD's mode to MODE, which should be either O_TEXT or O_BINARY.
|
/* Set FD's mode to MODE, which should be either O_TEXT or O_BINARY.
|
||||||
Return the old mode if successful, -1 (setting errno) on failure.
|
Return the old mode if successful, -1 (setting errno) on failure.
|
||||||
Ordinarily this function would be called 'setmode', since that is
|
Ordinarily this function would be called 'setmode', since that is
|
||||||
its name on MS-Windows, but it is called 'set_binary_mode' here
|
its old name on MS-Windows, but it is called 'set_binary_mode' here
|
||||||
to avoid colliding with a BSD function of another name. */
|
to avoid colliding with a BSD function of another name. */
|
||||||
|
|
||||||
#if defined __DJGPP__ || defined __EMX__
|
#if defined __DJGPP__ || defined __EMX__
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/* Rotate bits in integers.
|
||||||
|
|
||||||
|
Copyright (C) 2012-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This file is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as
|
||||||
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This file is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#define BITROTATE_INLINE _GL_EXTERN_INLINE
|
#define BITROTATE_INLINE _GL_EXTERN_INLINE
|
||||||
#include "bitrotate.h"
|
#include "bitrotate.h"
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/* bitrotate.h - Rotate bits in integers
|
/* bitrotate.h - Rotate bits in integers
|
||||||
Copyright (C) 2008-2020 Free Software Foundation, Inc.
|
Copyright (C) 2008-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
(at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
/* Written by Simon Josefsson <simon@josefsson.org>, 2008. */
|
/* Written by Simon Josefsson <simon@josefsson.org>, 2008. */
|
||||||
|
16
lib/btowc.c
16
lib/btowc.c
@ -1,18 +1,18 @@
|
|||||||
/* Convert unibyte character to wide character.
|
/* Convert unibyte character to wide character.
|
||||||
Copyright (C) 2008, 2010-2020 Free Software Foundation, Inc.
|
Copyright (C) 2008, 2010-2022 Free Software Foundation, Inc.
|
||||||
Written by Bruno Haible <bruno@clisp.org>, 2008.
|
Written by Bruno Haible <bruno@clisp.org>, 2008.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
(at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* buffer-lcm.c - compute a good buffer size for dealing with two files
|
/* buffer-lcm.c - compute a good buffer size for dealing with two files
|
||||||
|
|
||||||
Copyright (C) 2002-2020 Free Software Foundation, Inc.
|
Copyright (C) 2002-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
/* byteswap.h - Byte swapping
|
/* byteswap.h - Byte swapping
|
||||||
Copyright (C) 2005, 2007, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 2005, 2007, 2009-2022 Free Software Foundation, Inc.
|
||||||
Written by Oskar Liljeblad <oskar@osk.mine.nu>, 2005.
|
Written by Oskar Liljeblad <oskar@osk.mine.nu>, 2005.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
(at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#ifndef _GL_BYTESWAP_H
|
#ifndef _GL_BYTESWAP_H
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/* C++ compatible function declaration macros.
|
/* C++ compatible function declaration macros.
|
||||||
Copyright (C) 2010-2020 Free Software Foundation, Inc.
|
Copyright (C) 2010-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it
|
This program is free software: you can redistribute it and/or modify it
|
||||||
under the terms of the GNU General Public License as published
|
under the terms of the GNU Lesser General Public License as published
|
||||||
by the Free Software Foundation; either version 3 of the License, or
|
by the Free Software Foundation; either version 2 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
General Public License for more details.
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#ifndef _GL_CXXDEFS_H
|
#ifndef _GL_CXXDEFS_H
|
||||||
@ -146,6 +146,16 @@
|
|||||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* _GL_CXXALIAS_MDA (func, rettype, parameters);
|
||||||
|
is to be used when func is a Microsoft deprecated alias, on native Windows.
|
||||||
|
It declares a C++ alias called GNULIB_NAMESPACE::func
|
||||||
|
that redirects to _func, if GNULIB_NAMESPACE is defined.
|
||||||
|
Example:
|
||||||
|
_GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...));
|
||||||
|
*/
|
||||||
|
#define _GL_CXXALIAS_MDA(func,rettype,parameters) \
|
||||||
|
_GL_CXXALIAS_RPL_1 (func, _##func, rettype, parameters)
|
||||||
|
|
||||||
/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
|
/* _GL_CXXALIAS_RPL_CAST_1 (func, rpl_func, rettype, parameters);
|
||||||
is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
|
is like _GL_CXXALIAS_RPL_1 (func, rpl_func, rettype, parameters);
|
||||||
except that the C function rpl_func may have a slightly different
|
except that the C function rpl_func may have a slightly different
|
||||||
@ -171,6 +181,14 @@
|
|||||||
_GL_EXTERN_C int _gl_cxxalias_dummy
|
_GL_EXTERN_C int _gl_cxxalias_dummy
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* _GL_CXXALIAS_MDA_CAST (func, rettype, parameters);
|
||||||
|
is like _GL_CXXALIAS_MDA (func, rettype, parameters);
|
||||||
|
except that the C function func may have a slightly different declaration.
|
||||||
|
A cast is used to silence the "invalid conversion" error that would
|
||||||
|
otherwise occur. */
|
||||||
|
#define _GL_CXXALIAS_MDA_CAST(func,rettype,parameters) \
|
||||||
|
_GL_CXXALIAS_RPL_CAST_1 (func, _##func, rettype, parameters)
|
||||||
|
|
||||||
/* _GL_CXXALIAS_SYS (func, rettype, parameters);
|
/* _GL_CXXALIAS_SYS (func, rettype, parameters);
|
||||||
declares a C++ alias called GNULIB_NAMESPACE::func
|
declares a C++ alias called GNULIB_NAMESPACE::func
|
||||||
that redirects to the system provided function func, if GNULIB_NAMESPACE
|
that redirects to the system provided function func, if GNULIB_NAMESPACE
|
||||||
@ -268,7 +286,7 @@
|
|||||||
_GL_CXXALIASWARN_2 (func, namespace)
|
_GL_CXXALIASWARN_2 (func, namespace)
|
||||||
/* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
|
/* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
|
||||||
we enable the warning only when not optimizing. */
|
we enable the warning only when not optimizing. */
|
||||||
# if !__OPTIMIZE__
|
# if !(defined __GNUC__ && !defined __clang__ && __OPTIMIZE__)
|
||||||
# define _GL_CXXALIASWARN_2(func,namespace) \
|
# define _GL_CXXALIASWARN_2(func,namespace) \
|
||||||
_GL_WARN_ON_USE (func, \
|
_GL_WARN_ON_USE (func, \
|
||||||
"The symbol ::" #func " refers to the system function. " \
|
"The symbol ::" #func " refers to the system function. " \
|
||||||
@ -296,9 +314,9 @@
|
|||||||
_GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
|
_GL_CXXALIASWARN1_2 (func, rettype, parameters_and_attributes, namespace)
|
||||||
/* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
|
/* To work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43881>,
|
||||||
we enable the warning only when not optimizing. */
|
we enable the warning only when not optimizing. */
|
||||||
# if !__OPTIMIZE__
|
# if !(defined __GNUC__ && !defined __clang__ && __OPTIMIZE__)
|
||||||
# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
|
# define _GL_CXXALIASWARN1_2(func,rettype,parameters_and_attributes,namespace) \
|
||||||
_GL_WARN_ON_USE_CXX (func, rettype, parameters_and_attributes, \
|
_GL_WARN_ON_USE_CXX (func, rettype, rettype, parameters_and_attributes, \
|
||||||
"The symbol ::" #func " refers to the system function. " \
|
"The symbol ::" #func " refers to the system function. " \
|
||||||
"Use " #namespace "::" #func " instead.")
|
"Use " #namespace "::" #func " instead.")
|
||||||
# else
|
# else
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/* Character handling in C locale.
|
||||||
|
|
||||||
|
Copyright (C) 2003-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This file is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as
|
||||||
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This file is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#define C_CTYPE_INLINE _GL_EXTERN_INLINE
|
#define C_CTYPE_INLINE _GL_EXTERN_INLINE
|
||||||
#include "c-ctype.h"
|
#include "c-ctype.h"
|
||||||
|
@ -5,20 +5,20 @@
|
|||||||
<ctype.h> functions' behaviour depends on the current locale set via
|
<ctype.h> functions' behaviour depends on the current locale set via
|
||||||
setlocale.
|
setlocale.
|
||||||
|
|
||||||
Copyright (C) 2000-2003, 2006, 2008-2020 Free Software Foundation, Inc.
|
Copyright (C) 2000-2003, 2006, 2008-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
(at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program; if not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#ifndef C_CTYPE_H
|
#ifndef C_CTYPE_H
|
||||||
#define C_CTYPE_H
|
#define C_CTYPE_H
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
/* Case-insensitive string comparison functions in C locale.
|
/* Case-insensitive string comparison functions in C locale.
|
||||||
Copyright (C) 1995-1996, 2001, 2003, 2005, 2009-2020 Free Software
|
Copyright (C) 1995-1996, 2001, 2003, 2005, 2009-2022 Free Software
|
||||||
Foundation, Inc.
|
Foundation, Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3, or (at your option)
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program; if not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#ifndef C_STRCASE_H
|
#ifndef C_STRCASE_H
|
||||||
#define C_STRCASE_H
|
#define C_STRCASE_H
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
/* c-strcasecmp.c -- case insensitive string comparator in C locale
|
/* c-strcasecmp.c -- case insensitive string comparator in C locale
|
||||||
Copyright (C) 1998-1999, 2005-2006, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 1998-1999, 2005-2006, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3, or (at your option)
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program; if not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
@ -52,5 +52,5 @@ c_strcasecmp (const char *s1, const char *s2)
|
|||||||
/* On machines where 'char' and 'int' are types of the same size, the
|
/* On machines where 'char' and 'int' are types of the same size, the
|
||||||
difference of two 'unsigned char' values - including the sign bit -
|
difference of two 'unsigned char' values - including the sign bit -
|
||||||
doesn't fit in an 'int'. */
|
doesn't fit in an 'int'. */
|
||||||
return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
|
return _GL_CMP (c1, c2);
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/* Optimized case-insensitive string comparison in C locale.
|
/* Optimized case-insensitive string comparison in C locale.
|
||||||
Copyright (C) 2001-2002, 2007, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 2001-2002, 2007, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify it
|
This file is free software: you can redistribute it and/or modify
|
||||||
under the terms of the GNU General Public License as published
|
it under the terms of the GNU Lesser General Public License as
|
||||||
by the Free Software Foundation; either version 3 of the License, or
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
(at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
/* Written by Bruno Haible <bruno@clisp.org>. */
|
/* Written by Bruno Haible <bruno@clisp.org>. */
|
||||||
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
/* Help GCC to generate good code for string comparisons with
|
/* Help GCC to generate good code for string comparisons with
|
||||||
immediate strings. */
|
immediate strings. */
|
||||||
#if defined (__GNUC__) && defined (__OPTIMIZE__)
|
#if (defined __GNUC__ || defined __clang__) && defined __OPTIMIZE__
|
||||||
|
|
||||||
/* Case insensitive comparison of ASCII characters. */
|
/* Case insensitive comparison of ASCII characters. */
|
||||||
# if C_CTYPE_ASCII
|
# if C_CTYPE_ASCII
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
/* c-strncasecmp.c -- case insensitive string comparator in C locale
|
/* c-strncasecmp.c -- case insensitive string comparator in C locale
|
||||||
Copyright (C) 1998-1999, 2005-2006, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 1998-1999, 2005-2006, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3, or (at your option)
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program; if not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
@ -52,5 +52,5 @@ c_strncasecmp (const char *s1, const char *s2, size_t n)
|
|||||||
/* On machines where 'char' and 'int' are types of the same size, the
|
/* On machines where 'char' and 'int' are types of the same size, the
|
||||||
difference of two 'unsigned char' values - including the sign bit -
|
difference of two 'unsigned char' values - including the sign bit -
|
||||||
doesn't fit in an 'int'. */
|
doesn't fit in an 'int'. */
|
||||||
return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
|
return _GL_CMP (c1, c2);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/* Convert string to double, using the C locale.
|
/* Convert string to double, using the C locale.
|
||||||
|
|
||||||
Copyright (C) 2003-2004, 2006, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 2003-2004, 2006, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/* Convert string to double, using the C locale. -*- coding: utf-8 -*-
|
/* Convert string to double, using the C locale. -*- coding: utf-8 -*-
|
||||||
|
|
||||||
Copyright (C) 2003-2004, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 2003-2004, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
|
@ -1,2 +1,19 @@
|
|||||||
|
/* Convert string to 'long double' in C locale.
|
||||||
|
|
||||||
|
Copyright (C) 2004-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This file is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License,
|
||||||
|
or (at your option) any later version.
|
||||||
|
|
||||||
|
This file is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#define LONG 1
|
#define LONG 1
|
||||||
#include "c-strtod.c"
|
#include "c-strtod.c"
|
||||||
|
60
lib/calloc.c
60
lib/calloc.c
@ -1,70 +1,52 @@
|
|||||||
/* calloc() function that is glibc compatible.
|
/* calloc() function that is glibc compatible.
|
||||||
This wrapper function is required at least on Tru64 UNIX 5.1 and mingw.
|
This wrapper function is required at least on Tru64 UNIX 5.1 and mingw.
|
||||||
Copyright (C) 2004-2007, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 2004-2007, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
(at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
/* written by Jim Meyering and Bruno Haible */
|
/* written by Jim Meyering and Bruno Haible */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
/* Only the AC_FUNC_CALLOC macro defines 'calloc' already in config.h. */
|
|
||||||
#ifdef calloc
|
|
||||||
# define NEED_CALLOC_GNU 1
|
|
||||||
# undef calloc
|
|
||||||
/* Whereas the gnulib module 'calloc-gnu' defines HAVE_CALLOC_GNU. */
|
|
||||||
#elif GNULIB_CALLOC_GNU && !HAVE_CALLOC_GNU
|
|
||||||
# define NEED_CALLOC_GNU 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Specification. */
|
/* Specification. */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include "xalloc-oversized.h"
|
||||||
|
|
||||||
/* Call the system's calloc below. */
|
/* Call the system's calloc below. */
|
||||||
#undef calloc
|
#undef calloc
|
||||||
|
|
||||||
/* Allocate and zero-fill an NxS-byte block of memory from the heap.
|
/* Allocate and zero-fill an NxS-byte block of memory from the heap,
|
||||||
If N or S is zero, allocate and zero-fill a 1-byte block. */
|
even if N or S is zero. */
|
||||||
|
|
||||||
void *
|
void *
|
||||||
rpl_calloc (size_t n, size_t s)
|
rpl_calloc (size_t n, size_t s)
|
||||||
{
|
{
|
||||||
void *result;
|
|
||||||
|
|
||||||
#if NEED_CALLOC_GNU
|
|
||||||
if (n == 0 || s == 0)
|
if (n == 0 || s == 0)
|
||||||
{
|
n = s = 1;
|
||||||
n = 1;
|
|
||||||
s = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Defend against buggy calloc implementations that mishandle
|
|
||||||
size_t overflow. */
|
|
||||||
size_t bytes = n * s;
|
|
||||||
if (bytes / s != n)
|
|
||||||
{
|
|
||||||
errno = ENOMEM;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
result = calloc (n, s);
|
if (xalloc_oversized (n, s))
|
||||||
|
{
|
||||||
|
errno = ENOMEM;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#if !HAVE_CALLOC_POSIX
|
void *result = calloc (n, s);
|
||||||
|
|
||||||
|
#if !HAVE_MALLOC_POSIX
|
||||||
if (result == NULL)
|
if (result == NULL)
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
/* Host name canonicalization
|
/* Host name canonicalization
|
||||||
|
|
||||||
Copyright (C) 2005-2020 Free Software Foundation, Inc.
|
Copyright (C) 2005-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
Written by Derek Price <derek@ximbiot.com>.
|
Written by Derek Price <derek@ximbiot.com>.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3, or (at your option)
|
published by the Free Software Foundation, either version 3 of the
|
||||||
any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -1,27 +1,31 @@
|
|||||||
/* Host name canonicalization
|
/* Host name canonicalization
|
||||||
|
|
||||||
Copyright (C) 2005, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 2005, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
Written by Derek Price <derek@ximbiot.com>
|
Written by Derek Price <derek@ximbiot.com>
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3, or (at your option)
|
published by the Free Software Foundation, either version 3 of the
|
||||||
any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#ifndef CANON_HOST_H
|
#ifndef CANON_HOST_H
|
||||||
# define CANON_HOST_H 1
|
# define CANON_HOST_H 1
|
||||||
|
|
||||||
char *canon_host (char const *host) _GL_ATTRIBUTE_MALLOC;
|
# include <stdlib.h>
|
||||||
char *canon_host_r (char const *host, int *cherror) _GL_ATTRIBUTE_MALLOC;
|
|
||||||
|
char *canon_host (char const *host)
|
||||||
|
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
|
||||||
|
char *canon_host_r (char const *host, int *cherror)
|
||||||
|
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
|
||||||
|
|
||||||
const char *ch_strerror (void);
|
const char *ch_strerror (void);
|
||||||
# define ch_strerror_r(cherror) gai_strerror (cherror);
|
# define ch_strerror_r(cherror) gai_strerror (cherror);
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
/* Return the canonical absolute name of a given file.
|
/* Return the canonical absolute name of a given file.
|
||||||
Copyright (C) 1996-2020 Free Software Foundation, Inc.
|
Copyright (C) 1996-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
@ -19,29 +19,31 @@
|
|||||||
#include "canonicalize.h"
|
#include "canonicalize.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <fcntl.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "areadlink.h"
|
#include <filename.h>
|
||||||
|
#include <idx.h>
|
||||||
|
#include <intprops.h>
|
||||||
|
#include <scratch_buffer.h>
|
||||||
|
|
||||||
|
#include "attribute.h"
|
||||||
#include "file-set.h"
|
#include "file-set.h"
|
||||||
#include "hash-triple.h"
|
#include "hash-triple.h"
|
||||||
#include "pathmax.h"
|
|
||||||
#include "xalloc.h"
|
#include "xalloc.h"
|
||||||
#include "xgetcwd.h"
|
|
||||||
#include "dosname.h"
|
|
||||||
|
|
||||||
#define MULTIPLE_BITS_SET(i) (((i) & ((i) - 1)) != 0)
|
/* Suppress bogus GCC -Wmaybe-uninitialized warnings. */
|
||||||
|
#if defined GCC_LINT || defined lint
|
||||||
/* In this file, we cannot handle file names longer than PATH_MAX.
|
# define IF_LINT(Code) Code
|
||||||
On systems with no file name length limit, use a fallback. */
|
#else
|
||||||
#ifndef PATH_MAX
|
# define IF_LINT(Code) /* empty */
|
||||||
# define PATH_MAX 8192
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
|
#ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
|
||||||
# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0
|
# define DOUBLE_SLASH_IS_DISTINCT_ROOT false
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ISSLASH ('\\')
|
#if ISSLASH ('\\')
|
||||||
@ -50,6 +52,73 @@
|
|||||||
# define SLASHES "/"
|
# define SLASHES "/"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Return true if FILE's existence can be shown, false (setting errno)
|
||||||
|
otherwise. Follow symbolic links. */
|
||||||
|
static bool
|
||||||
|
file_accessible (char const *file)
|
||||||
|
{
|
||||||
|
# if HAVE_FACCESSAT
|
||||||
|
return faccessat (AT_FDCWD, file, F_OK, AT_EACCESS) == 0;
|
||||||
|
# else
|
||||||
|
struct stat st;
|
||||||
|
return stat (file, &st) == 0 || errno == EOVERFLOW;
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* True if concatenating END as a suffix to a file name means that the
|
||||||
|
code needs to check that the file name is that of a searchable
|
||||||
|
directory, since the canonicalize_filename_mode_stk code won't
|
||||||
|
check this later anyway when it checks an ordinary file name
|
||||||
|
component within END. END must either be empty, or start with a
|
||||||
|
slash. */
|
||||||
|
|
||||||
|
static bool _GL_ATTRIBUTE_PURE
|
||||||
|
suffix_requires_dir_check (char const *end)
|
||||||
|
{
|
||||||
|
/* If END does not start with a slash, the suffix is OK. */
|
||||||
|
while (ISSLASH (*end))
|
||||||
|
{
|
||||||
|
/* Two or more slashes act like a single slash. */
|
||||||
|
do
|
||||||
|
end++;
|
||||||
|
while (ISSLASH (*end));
|
||||||
|
|
||||||
|
switch (*end++)
|
||||||
|
{
|
||||||
|
default: return false; /* An ordinary file name component is OK. */
|
||||||
|
case '\0': return true; /* Trailing "/" is trouble. */
|
||||||
|
case '.': break; /* Possibly "." or "..". */
|
||||||
|
}
|
||||||
|
/* Trailing "/.", or "/.." even if not trailing, is trouble. */
|
||||||
|
if (!*end || (*end == '.' && (!end[1] || ISSLASH (end[1]))))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Append this to a file name to test whether it is a searchable directory.
|
||||||
|
On POSIX platforms "/" suffices, but "/./" is sometimes needed on
|
||||||
|
macOS 10.13 <https://bugs.gnu.org/30350>, and should also work on
|
||||||
|
platforms like AIX 7.2 that need at least "/.". */
|
||||||
|
|
||||||
|
#ifdef LSTAT_FOLLOWS_SLASHED_SYMLINK
|
||||||
|
static char const dir_suffix[] = "/";
|
||||||
|
#else
|
||||||
|
static char const dir_suffix[] = "/./";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Return true if DIR is a searchable dir, false (setting errno) otherwise.
|
||||||
|
DIREND points to the NUL byte at the end of the DIR string.
|
||||||
|
Store garbage into DIREND[0 .. strlen (dir_suffix)]. */
|
||||||
|
|
||||||
|
static bool
|
||||||
|
dir_check (char *dir, char *dirend)
|
||||||
|
{
|
||||||
|
strcpy (dirend, dir_suffix);
|
||||||
|
return file_accessible (dir);
|
||||||
|
}
|
||||||
|
|
||||||
#if !((HAVE_CANONICALIZE_FILE_NAME && FUNC_REALPATH_WORKS) \
|
#if !((HAVE_CANONICALIZE_FILE_NAME && FUNC_REALPATH_WORKS) \
|
||||||
|| GNULIB_CANONICALIZE_LGPL)
|
|| GNULIB_CANONICALIZE_LGPL)
|
||||||
/* Return the canonical absolute name of file NAME. A canonical name
|
/* Return the canonical absolute name of file NAME. A canonical name
|
||||||
@ -64,6 +133,12 @@ canonicalize_file_name (const char *name)
|
|||||||
}
|
}
|
||||||
#endif /* !HAVE_CANONICALIZE_FILE_NAME */
|
#endif /* !HAVE_CANONICALIZE_FILE_NAME */
|
||||||
|
|
||||||
|
static bool
|
||||||
|
multiple_bits_set (canonicalize_mode_t i)
|
||||||
|
{
|
||||||
|
return (i & (i - 1)) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Return true if we've already seen the triple, <FILENAME, dev, ino>.
|
/* Return true if we've already seen the triple, <FILENAME, dev, ino>.
|
||||||
If *HT is not initialized, initialize it. */
|
If *HT is not initialized, initialize it. */
|
||||||
static bool
|
static bool
|
||||||
@ -71,7 +146,7 @@ seen_triple (Hash_table **ht, char const *filename, struct stat const *st)
|
|||||||
{
|
{
|
||||||
if (*ht == NULL)
|
if (*ht == NULL)
|
||||||
{
|
{
|
||||||
size_t initial_capacity = 7;
|
idx_t initial_capacity = 7;
|
||||||
*ht = hash_initialize (initial_capacity,
|
*ht = hash_initialize (initial_capacity,
|
||||||
NULL,
|
NULL,
|
||||||
triple_hash,
|
triple_hash,
|
||||||
@ -88,30 +163,38 @@ seen_triple (Hash_table **ht, char const *filename, struct stat const *st)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the canonical absolute name of file NAME, while treating
|
|
||||||
missing elements according to CAN_MODE. A canonical name
|
|
||||||
does not contain any ".", ".." components nor any repeated file name
|
|
||||||
separators ('/') or, depending on other CAN_MODE flags, symlinks.
|
|
||||||
Whether components must exist or not depends on canonicalize mode.
|
|
||||||
The result is malloc'd. */
|
|
||||||
|
|
||||||
char *
|
/* Act like canonicalize_filename_mode (see below), with an additional argument
|
||||||
canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)
|
rname_buf that can be used as temporary storage.
|
||||||
|
|
||||||
|
If GCC_LINT is defined, do not inline this function with GCC 10.1
|
||||||
|
and later, to avoid creating a pointer to the stack that GCC
|
||||||
|
-Wreturn-local-addr incorrectly complains about. See:
|
||||||
|
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644
|
||||||
|
Although the noinline attribute can hurt performance a bit, no better way
|
||||||
|
to pacify GCC is known; even an explicit #pragma does not pacify GCC.
|
||||||
|
When the GCC bug is fixed this workaround should be limited to the
|
||||||
|
broken GCC versions. */
|
||||||
|
#if _GL_GNUC_PREREQ (10, 1)
|
||||||
|
# if defined GCC_LINT || defined lint
|
||||||
|
__attribute__ ((__noinline__))
|
||||||
|
# elif __OPTIMIZE__ && !__NO_INLINE__
|
||||||
|
# define GCC_BOGUS_WRETURN_LOCAL_ADDR
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
static char *
|
||||||
|
canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
|
||||||
|
struct scratch_buffer *rname_buf)
|
||||||
{
|
{
|
||||||
char *rname, *dest, *extra_buf = NULL;
|
char *dest;
|
||||||
char const *start;
|
char const *start;
|
||||||
char const *end;
|
char const *end;
|
||||||
char const *rname_limit;
|
|
||||||
size_t extra_len = 0;
|
|
||||||
Hash_table *ht = NULL;
|
Hash_table *ht = NULL;
|
||||||
int saved_errno;
|
bool logical = (can_mode & CAN_NOLINKS) != 0;
|
||||||
int can_flags = can_mode & ~CAN_MODE_MASK;
|
int num_links = 0;
|
||||||
bool logical = can_flags & CAN_NOLINKS;
|
|
||||||
size_t prefix_len;
|
|
||||||
|
|
||||||
can_mode &= CAN_MODE_MASK;
|
canonicalize_mode_t can_exist = can_mode & CAN_MODE_MASK;
|
||||||
|
if (multiple_bits_set (can_exist))
|
||||||
if (MULTIPLE_BITS_SET (can_mode))
|
|
||||||
{
|
{
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -129,45 +212,76 @@ canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct scratch_buffer extra_buffer, link_buffer;
|
||||||
|
scratch_buffer_init (&extra_buffer);
|
||||||
|
scratch_buffer_init (&link_buffer);
|
||||||
|
scratch_buffer_init (rname_buf);
|
||||||
|
char *rname_on_stack = rname_buf->data;
|
||||||
|
char *rname = rname_on_stack;
|
||||||
|
bool end_in_extra_buffer = false;
|
||||||
|
bool failed = true;
|
||||||
|
|
||||||
/* This is always zero for Posix hosts, but can be 2 for MS-Windows
|
/* This is always zero for Posix hosts, but can be 2 for MS-Windows
|
||||||
and MS-DOS X:/foo/bar file names. */
|
and MS-DOS X:/foo/bar file names. */
|
||||||
prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
|
idx_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
|
||||||
|
|
||||||
if (!IS_ABSOLUTE_FILE_NAME (name))
|
if (!IS_ABSOLUTE_FILE_NAME (name))
|
||||||
{
|
{
|
||||||
rname = xgetcwd ();
|
while (!getcwd (rname, rname_buf->length))
|
||||||
if (!rname)
|
|
||||||
return NULL;
|
|
||||||
dest = strchr (rname, '\0');
|
|
||||||
if (dest - rname < PATH_MAX)
|
|
||||||
{
|
{
|
||||||
char *p = xrealloc (rname, PATH_MAX);
|
switch (errno)
|
||||||
dest = p + (dest - rname);
|
{
|
||||||
rname = p;
|
case ERANGE:
|
||||||
rname_limit = rname + PATH_MAX;
|
if (scratch_buffer_grow (rname_buf))
|
||||||
}
|
break;
|
||||||
else
|
FALLTHROUGH;
|
||||||
{
|
case ENOMEM:
|
||||||
rname_limit = dest;
|
xalloc_die ();
|
||||||
|
|
||||||
|
default:
|
||||||
|
dest = rname;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
rname = rname_buf->data;
|
||||||
}
|
}
|
||||||
|
dest = rawmemchr (rname, '\0');
|
||||||
start = name;
|
start = name;
|
||||||
prefix_len = FILE_SYSTEM_PREFIX_LEN (rname);
|
prefix_len = FILE_SYSTEM_PREFIX_LEN (rname);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rname = xmalloc (PATH_MAX);
|
dest = mempcpy (rname, name, prefix_len);
|
||||||
rname_limit = rname + PATH_MAX;
|
|
||||||
dest = rname;
|
|
||||||
if (prefix_len)
|
|
||||||
{
|
|
||||||
memcpy (rname, name, prefix_len);
|
|
||||||
dest += prefix_len;
|
|
||||||
}
|
|
||||||
*dest++ = '/';
|
*dest++ = '/';
|
||||||
if (DOUBLE_SLASH_IS_DISTINCT_ROOT)
|
if (DOUBLE_SLASH_IS_DISTINCT_ROOT)
|
||||||
{
|
{
|
||||||
if (ISSLASH (name[1]) && !ISSLASH (name[2]) && !prefix_len)
|
if (prefix_len == 0 /* implies ISSLASH (name[0]) */
|
||||||
*dest++ = '/';
|
&& ISSLASH (name[1]) && !ISSLASH (name[2]))
|
||||||
|
{
|
||||||
|
*dest++ = '/';
|
||||||
|
#if defined _WIN32 && !defined __CYGWIN__
|
||||||
|
/* For UNC file names '\\server\path\to\file', extend the prefix
|
||||||
|
to include the server: '\\server\'. */
|
||||||
|
{
|
||||||
|
idx_t i;
|
||||||
|
for (i = 2; name[i] != '\0' && !ISSLASH (name[i]); )
|
||||||
|
i++;
|
||||||
|
if (name[i] != '\0' /* implies ISSLASH (name[i]) */
|
||||||
|
&& i + 1 < rname_buf->length)
|
||||||
|
{
|
||||||
|
prefix_len = i;
|
||||||
|
memcpy (dest, name + 2, i - 2 + 1);
|
||||||
|
dest += i - 2 + 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Either name = '\\server'; this is an invalid file name.
|
||||||
|
Or name = '\\server\...' and server is more than
|
||||||
|
rname_buf->length - 4 bytes long. In either
|
||||||
|
case, stop the UNC processing. */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
*dest = '\0';
|
*dest = '\0';
|
||||||
}
|
}
|
||||||
start = name + prefix_len;
|
start = name + prefix_len;
|
||||||
@ -183,120 +297,119 @@ canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)
|
|||||||
for (end = start; *end && !ISSLASH (*end); ++end)
|
for (end = start; *end && !ISSLASH (*end); ++end)
|
||||||
/* Nothing. */;
|
/* Nothing. */;
|
||||||
|
|
||||||
if (end - start == 0)
|
/* Length of this file name component; it can be zero if a file
|
||||||
|
name ends in '/'. */
|
||||||
|
idx_t startlen = end - start;
|
||||||
|
|
||||||
|
if (startlen == 0)
|
||||||
break;
|
break;
|
||||||
else if (end - start == 1 && start[0] == '.')
|
else if (startlen == 1 && start[0] == '.')
|
||||||
/* nothing */;
|
/* nothing */;
|
||||||
else if (end - start == 2 && start[0] == '.' && start[1] == '.')
|
else if (startlen == 2 && start[0] == '.' && start[1] == '.')
|
||||||
{
|
{
|
||||||
/* Back up to previous component, ignore if at root already. */
|
/* Back up to previous component, ignore if at root already. */
|
||||||
if (dest > rname + prefix_len + 1)
|
if (dest > rname + prefix_len + 1)
|
||||||
for (--dest; dest > rname && !ISSLASH (dest[-1]); --dest)
|
for (--dest; dest > rname && !ISSLASH (dest[-1]); --dest)
|
||||||
continue;
|
continue;
|
||||||
if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rname + 1
|
if (DOUBLE_SLASH_IS_DISTINCT_ROOT
|
||||||
&& !prefix_len && ISSLASH (*dest) && !ISSLASH (dest[1]))
|
&& dest == rname + 1 && !prefix_len
|
||||||
|
&& ISSLASH (*dest) && !ISSLASH (dest[1]))
|
||||||
dest++;
|
dest++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
struct stat st;
|
|
||||||
|
|
||||||
if (!ISSLASH (dest[-1]))
|
if (!ISSLASH (dest[-1]))
|
||||||
*dest++ = '/';
|
*dest++ = '/';
|
||||||
|
|
||||||
if (dest + (end - start) >= rname_limit)
|
while (rname + rname_buf->length - dest
|
||||||
|
< startlen + sizeof dir_suffix)
|
||||||
{
|
{
|
||||||
ptrdiff_t dest_offset = dest - rname;
|
idx_t dest_offset = dest - rname;
|
||||||
size_t new_size = rname_limit - rname;
|
if (!scratch_buffer_grow_preserve (rname_buf))
|
||||||
|
xalloc_die ();
|
||||||
if (end - start + 1 > PATH_MAX)
|
rname = rname_buf->data;
|
||||||
new_size += end - start + 1;
|
|
||||||
else
|
|
||||||
new_size += PATH_MAX;
|
|
||||||
rname = xrealloc (rname, new_size);
|
|
||||||
rname_limit = rname + new_size;
|
|
||||||
|
|
||||||
dest = rname + dest_offset;
|
dest = rname + dest_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
dest = memcpy (dest, start, end - start);
|
dest = mempcpy (dest, start, startlen);
|
||||||
dest += end - start;
|
|
||||||
*dest = '\0';
|
*dest = '\0';
|
||||||
|
|
||||||
if (logical && (can_mode == CAN_MISSING))
|
char *buf;
|
||||||
|
ssize_t n = -1;
|
||||||
|
if (!logical)
|
||||||
{
|
{
|
||||||
/* Avoid the stat in this case as it's inconsequential.
|
while (true)
|
||||||
i.e. we're neither resolving symlinks or testing
|
|
||||||
component existence. */
|
|
||||||
st.st_mode = 0;
|
|
||||||
}
|
|
||||||
else if ((logical ? stat (rname, &st) : lstat (rname, &st)) != 0)
|
|
||||||
{
|
|
||||||
/* FIXME: If errno == EOVERFLOW here, the entry exists. */
|
|
||||||
saved_errno = errno;
|
|
||||||
if (can_mode == CAN_EXISTING)
|
|
||||||
goto error;
|
|
||||||
if (can_mode == CAN_ALL_BUT_LAST)
|
|
||||||
{
|
{
|
||||||
if (end[strspn (end, SLASHES)] || saved_errno != ENOENT)
|
buf = link_buffer.data;
|
||||||
|
idx_t bufsize = link_buffer.length;
|
||||||
|
n = readlink (rname, buf, bufsize - 1);
|
||||||
|
if (n < bufsize - 1)
|
||||||
|
break;
|
||||||
|
if (!scratch_buffer_grow (&link_buffer))
|
||||||
|
xalloc_die ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (0 <= n)
|
||||||
|
{
|
||||||
|
/* A physical traversal and RNAME is a symbolic link. */
|
||||||
|
|
||||||
|
if (num_links < 20)
|
||||||
|
num_links++;
|
||||||
|
else if (*start)
|
||||||
|
{
|
||||||
|
/* Enough symlinks have been seen that it is time to
|
||||||
|
worry about being in a symlink cycle.
|
||||||
|
Get the device and inode of the parent directory, as
|
||||||
|
pre-2017 POSIX says this info is not reliable for
|
||||||
|
symlinks. */
|
||||||
|
struct stat st;
|
||||||
|
dest[- startlen] = '\0';
|
||||||
|
if (stat (*rname ? rname : ".", &st) != 0)
|
||||||
goto error;
|
goto error;
|
||||||
continue;
|
dest[- startlen] = *start;
|
||||||
|
|
||||||
|
/* Detect loops. We cannot use the cycle-check module here,
|
||||||
|
since it's possible to encounter the same parent
|
||||||
|
directory more than once in a given traversal. However,
|
||||||
|
encountering the same (parentdir, START) pair twice does
|
||||||
|
indicate a loop. */
|
||||||
|
if (seen_triple (&ht, start, &st))
|
||||||
|
{
|
||||||
|
if (can_exist == CAN_MISSING)
|
||||||
|
continue;
|
||||||
|
errno = ELOOP;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
st.st_mode = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (S_ISLNK (st.st_mode))
|
buf[n] = '\0';
|
||||||
{
|
|
||||||
char *buf;
|
|
||||||
size_t n, len;
|
|
||||||
|
|
||||||
/* Detect loops. We cannot use the cycle-check module here,
|
char *extra_buf = extra_buffer.data;
|
||||||
since it's actually possible to encounter the same symlink
|
idx_t end_idx IF_LINT (= 0);
|
||||||
more than once in a given traversal. However, encountering
|
if (end_in_extra_buffer)
|
||||||
the same symlink,NAME pair twice does indicate a loop. */
|
end_idx = end - extra_buf;
|
||||||
if (seen_triple (&ht, name, &st))
|
size_t len = strlen (end);
|
||||||
|
if (INT_ADD_OVERFLOW (len, n))
|
||||||
|
xalloc_die ();
|
||||||
|
while (extra_buffer.length <= len + n)
|
||||||
{
|
{
|
||||||
if (can_mode == CAN_MISSING)
|
if (!scratch_buffer_grow_preserve (&extra_buffer))
|
||||||
continue;
|
xalloc_die ();
|
||||||
saved_errno = ELOOP;
|
extra_buf = extra_buffer.data;
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf = areadlink_with_size (rname, st.st_size);
|
|
||||||
if (!buf)
|
|
||||||
{
|
|
||||||
if (can_mode == CAN_MISSING && errno != ENOMEM)
|
|
||||||
continue;
|
|
||||||
saved_errno = errno;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
n = strlen (buf);
|
|
||||||
len = strlen (end);
|
|
||||||
|
|
||||||
if (!extra_len)
|
|
||||||
{
|
|
||||||
extra_len =
|
|
||||||
((n + len + 1) > PATH_MAX) ? (n + len + 1) : PATH_MAX;
|
|
||||||
extra_buf = xmalloc (extra_len);
|
|
||||||
}
|
|
||||||
else if ((n + len + 1) > extra_len)
|
|
||||||
{
|
|
||||||
extra_len = n + len + 1;
|
|
||||||
extra_buf = xrealloc (extra_buf, extra_len);
|
|
||||||
}
|
}
|
||||||
|
if (end_in_extra_buffer)
|
||||||
|
end = extra_buf + end_idx;
|
||||||
|
|
||||||
/* Careful here, end may be a pointer into extra_buf... */
|
/* Careful here, end may be a pointer into extra_buf... */
|
||||||
memmove (&extra_buf[n], end, len + 1);
|
memmove (&extra_buf[n], end, len + 1);
|
||||||
name = end = memcpy (extra_buf, buf, n);
|
name = end = memcpy (extra_buf, buf, n);
|
||||||
|
end_in_extra_buffer = true;
|
||||||
|
|
||||||
if (IS_ABSOLUTE_FILE_NAME (buf))
|
if (IS_ABSOLUTE_FILE_NAME (buf))
|
||||||
{
|
{
|
||||||
size_t pfxlen = FILE_SYSTEM_PREFIX_LEN (buf);
|
idx_t pfxlen = FILE_SYSTEM_PREFIX_LEN (buf);
|
||||||
|
|
||||||
if (pfxlen)
|
dest = mempcpy (rname, buf, pfxlen);
|
||||||
memcpy (rname, buf, pfxlen);
|
|
||||||
dest = rname + pfxlen;
|
|
||||||
*dest++ = '/'; /* It's an absolute symlink */
|
*dest++ = '/'; /* It's an absolute symlink */
|
||||||
if (DOUBLE_SLASH_IS_DISTINCT_ROOT)
|
if (DOUBLE_SLASH_IS_DISTINCT_ROOT)
|
||||||
{
|
{
|
||||||
@ -318,17 +431,17 @@ canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)
|
|||||||
&& ISSLASH (*dest) && !ISSLASH (dest[1]) && !prefix_len)
|
&& ISSLASH (*dest) && !ISSLASH (dest[1]) && !prefix_len)
|
||||||
dest++;
|
dest++;
|
||||||
}
|
}
|
||||||
|
|
||||||
free (buf);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!S_ISDIR (st.st_mode) && *end && (can_mode != CAN_MISSING))
|
|
||||||
{
|
|
||||||
saved_errno = ENOTDIR;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else if (! (can_exist == CAN_MISSING
|
||||||
|
|| (suffix_requires_dir_check (end)
|
||||||
|
? dir_check (rname, dest)
|
||||||
|
: !logical
|
||||||
|
? errno == EINVAL
|
||||||
|
: *end || file_accessible (rname))
|
||||||
|
|| (can_exist == CAN_ALL_BUT_LAST
|
||||||
|
&& errno == ENOENT
|
||||||
|
&& !end[strspn (end, SLASHES)])))
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dest > rname + prefix_len + 1 && ISSLASH (dest[-1]))
|
if (dest > rname + prefix_len + 1 && ISSLASH (dest[-1]))
|
||||||
@ -336,20 +449,41 @@ canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)
|
|||||||
if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rname + 1 && !prefix_len
|
if (DOUBLE_SLASH_IS_DISTINCT_ROOT && dest == rname + 1 && !prefix_len
|
||||||
&& ISSLASH (*dest) && !ISSLASH (dest[1]))
|
&& ISSLASH (*dest) && !ISSLASH (dest[1]))
|
||||||
dest++;
|
dest++;
|
||||||
*dest = '\0';
|
failed = false;
|
||||||
if (rname_limit != dest + 1)
|
|
||||||
rname = xrealloc (rname, dest - rname + 1);
|
|
||||||
|
|
||||||
free (extra_buf);
|
|
||||||
if (ht)
|
|
||||||
hash_free (ht);
|
|
||||||
return rname;
|
|
||||||
|
|
||||||
error:
|
error:
|
||||||
free (extra_buf);
|
|
||||||
free (rname);
|
|
||||||
if (ht)
|
if (ht)
|
||||||
hash_free (ht);
|
hash_free (ht);
|
||||||
errno = saved_errno;
|
scratch_buffer_free (&extra_buffer);
|
||||||
return NULL;
|
scratch_buffer_free (&link_buffer);
|
||||||
|
|
||||||
|
if (failed)
|
||||||
|
{
|
||||||
|
scratch_buffer_free (rname_buf);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*dest++ = '\0';
|
||||||
|
char *result = scratch_buffer_dupfree (rname_buf, dest - rname);
|
||||||
|
if (!result)
|
||||||
|
xalloc_die ();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return the canonical absolute name of file NAME, while treating
|
||||||
|
missing elements according to CAN_MODE. A canonical name
|
||||||
|
does not contain any ".", ".." components nor any repeated file name
|
||||||
|
separators ('/') or, depending on other CAN_MODE flags, symlinks.
|
||||||
|
Whether components must exist or not depends on canonicalize mode.
|
||||||
|
The result is malloc'd. */
|
||||||
|
|
||||||
|
char *
|
||||||
|
canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode)
|
||||||
|
{
|
||||||
|
#ifdef GCC_BOGUS_WRETURN_LOCAL_ADDR
|
||||||
|
#warning "GCC might issue a bogus -Wreturn-local-addr warning here."
|
||||||
|
#warning "See <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644>."
|
||||||
|
#endif
|
||||||
|
struct scratch_buffer rname_buffer;
|
||||||
|
return canonicalize_filename_mode_stk (name, can_mode, &rname_buffer);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
/* Return the canonical absolute name of a given file.
|
/* Return the canonical absolute name of a given file.
|
||||||
Copyright (C) 1996-2007, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 1996-2007, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
@ -46,8 +46,10 @@ typedef enum canonicalize_mode_t canonicalize_mode_t;
|
|||||||
does not contain any `.', `..' components nor any repeated file name
|
does not contain any `.', `..' components nor any repeated file name
|
||||||
separators ('/') or, depending on other CAN_MODE flags, symlinks.
|
separators ('/') or, depending on other CAN_MODE flags, symlinks.
|
||||||
Whether components must exist or not depends on canonicalize mode.
|
Whether components must exist or not depends on canonicalize mode.
|
||||||
The result is malloc'd. */
|
The result is malloc'd.
|
||||||
char *canonicalize_filename_mode (const char *, canonicalize_mode_t);
|
Upon failure, return NULL with errno set. */
|
||||||
|
char *canonicalize_filename_mode (const char *, canonicalize_mode_t)
|
||||||
|
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
/* Read symbolic links into a buffer without size limitation, relative to fd.
|
/* Read symbolic links into a buffer without size limitation, relative to fd.
|
||||||
|
|
||||||
Copyright (C) 2001, 2003-2004, 2007, 2009-2020 Free Software Foundation,
|
Copyright (C) 2001, 2003-2004, 2007, 2009-2022 Free Software Foundation,
|
||||||
Inc.
|
Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
(at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
/* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */
|
/* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */
|
||||||
@ -22,6 +22,9 @@
|
|||||||
|
|
||||||
#include "careadlinkat.h"
|
#include "careadlinkat.h"
|
||||||
|
|
||||||
|
#include "idx.h"
|
||||||
|
#include "minmax.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -38,6 +41,107 @@
|
|||||||
|
|
||||||
#include "allocator.h"
|
#include "allocator.h"
|
||||||
|
|
||||||
|
enum { STACK_BUF_SIZE = 1024 };
|
||||||
|
|
||||||
|
/* Act like careadlinkat (see below), with an additional argument
|
||||||
|
STACK_BUF that can be used as temporary storage.
|
||||||
|
|
||||||
|
If GCC_LINT is defined, do not inline this function with GCC 10.1
|
||||||
|
and later, to avoid creating a pointer to the stack that GCC
|
||||||
|
-Wreturn-local-addr incorrectly complains about. See:
|
||||||
|
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644
|
||||||
|
Although the noinline attribute can hurt performance a bit, no better way
|
||||||
|
to pacify GCC is known; even an explicit #pragma does not pacify GCC.
|
||||||
|
When the GCC bug is fixed this workaround should be limited to the
|
||||||
|
broken GCC versions. */
|
||||||
|
#if _GL_GNUC_PREREQ (10, 1)
|
||||||
|
# if defined GCC_LINT || defined lint
|
||||||
|
__attribute__ ((__noinline__))
|
||||||
|
# elif __OPTIMIZE__ && !__NO_INLINE__
|
||||||
|
# define GCC_BOGUS_WRETURN_LOCAL_ADDR
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
static char *
|
||||||
|
readlink_stk (int fd, char const *filename,
|
||||||
|
char *buffer, size_t buffer_size,
|
||||||
|
struct allocator const *alloc,
|
||||||
|
ssize_t (*preadlinkat) (int, char const *, char *, size_t),
|
||||||
|
char stack_buf[STACK_BUF_SIZE])
|
||||||
|
{
|
||||||
|
if (! alloc)
|
||||||
|
alloc = &stdlib_allocator;
|
||||||
|
|
||||||
|
if (!buffer)
|
||||||
|
{
|
||||||
|
buffer = stack_buf;
|
||||||
|
buffer_size = STACK_BUF_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *buf = buffer;
|
||||||
|
idx_t buf_size_max = MIN (IDX_MAX, MIN (SSIZE_MAX, SIZE_MAX));
|
||||||
|
idx_t buf_size = MIN (buffer_size, buf_size_max);
|
||||||
|
|
||||||
|
while (buf)
|
||||||
|
{
|
||||||
|
/* Attempt to read the link into the current buffer. */
|
||||||
|
idx_t link_length = preadlinkat (fd, filename, buf, buf_size);
|
||||||
|
if (link_length < 0)
|
||||||
|
{
|
||||||
|
if (buf != buffer)
|
||||||
|
{
|
||||||
|
int readlinkat_errno = errno;
|
||||||
|
alloc->free (buf);
|
||||||
|
errno = readlinkat_errno;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
idx_t link_size = link_length;
|
||||||
|
|
||||||
|
if (link_size < buf_size)
|
||||||
|
{
|
||||||
|
buf[link_size++] = '\0';
|
||||||
|
|
||||||
|
if (buf == stack_buf)
|
||||||
|
{
|
||||||
|
char *b = alloc->allocate (link_size);
|
||||||
|
buf_size = link_size;
|
||||||
|
if (! b)
|
||||||
|
break;
|
||||||
|
return memcpy (b, buf, link_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (link_size < buf_size && buf != buffer && alloc->reallocate)
|
||||||
|
{
|
||||||
|
/* Shrink BUF before returning it. */
|
||||||
|
char *b = alloc->reallocate (buf, link_size);
|
||||||
|
if (b)
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buf != buffer)
|
||||||
|
alloc->free (buf);
|
||||||
|
|
||||||
|
if (buf_size_max / 2 <= buf_size)
|
||||||
|
{
|
||||||
|
errno = ENAMETOOLONG;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf_size = 2 * buf_size + 1;
|
||||||
|
buf = alloc->allocate (buf_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (alloc->die)
|
||||||
|
alloc->die (buf_size);
|
||||||
|
errno = ENOMEM;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Assuming the current directory is FD, get the symbolic link value
|
/* Assuming the current directory is FD, get the symbolic link value
|
||||||
of FILENAME as a null-terminated string and put it into a buffer.
|
of FILENAME as a null-terminated string and put it into a buffer.
|
||||||
If FD is AT_FDCWD, FILENAME is interpreted relative to the current
|
If FD is AT_FDCWD, FILENAME is interpreted relative to the current
|
||||||
@ -66,95 +170,15 @@ careadlinkat (int fd, char const *filename,
|
|||||||
struct allocator const *alloc,
|
struct allocator const *alloc,
|
||||||
ssize_t (*preadlinkat) (int, char const *, char *, size_t))
|
ssize_t (*preadlinkat) (int, char const *, char *, size_t))
|
||||||
{
|
{
|
||||||
char *buf;
|
/* Allocate the initial buffer on the stack. This way, in the
|
||||||
size_t buf_size;
|
common case of a symlink of small size, we get away with a
|
||||||
size_t buf_size_max =
|
single small malloc instead of a big malloc followed by a
|
||||||
SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
|
shrinking realloc. */
|
||||||
char stack_buf[1024];
|
#ifdef GCC_BOGUS_WRETURN_LOCAL_ADDR
|
||||||
|
#warning "GCC might issue a bogus -Wreturn-local-addr warning here."
|
||||||
if (! alloc)
|
#warning "See <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644>."
|
||||||
alloc = &stdlib_allocator;
|
#endif
|
||||||
|
char stack_buf[STACK_BUF_SIZE];
|
||||||
if (! buffer_size)
|
return readlink_stk (fd, filename, buffer, buffer_size, alloc,
|
||||||
{
|
preadlinkat, stack_buf);
|
||||||
/* Allocate the initial buffer on the stack. This way, in the
|
|
||||||
common case of a symlink of small size, we get away with a
|
|
||||||
single small malloc() instead of a big malloc() followed by a
|
|
||||||
shrinking realloc(). */
|
|
||||||
buffer = stack_buf;
|
|
||||||
buffer_size = sizeof stack_buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf = buffer;
|
|
||||||
buf_size = buffer_size;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
/* Attempt to read the link into the current buffer. */
|
|
||||||
ssize_t link_length = preadlinkat (fd, filename, buf, buf_size);
|
|
||||||
size_t link_size;
|
|
||||||
if (link_length < 0)
|
|
||||||
{
|
|
||||||
/* On AIX 5L v5.3 and HP-UX 11i v2 04/09, readlink returns -1
|
|
||||||
with errno == ERANGE if the buffer is too small. */
|
|
||||||
int readlinkat_errno = errno;
|
|
||||||
if (readlinkat_errno != ERANGE)
|
|
||||||
{
|
|
||||||
if (buf != buffer)
|
|
||||||
{
|
|
||||||
alloc->free (buf);
|
|
||||||
errno = readlinkat_errno;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
link_size = link_length;
|
|
||||||
|
|
||||||
if (link_size < buf_size)
|
|
||||||
{
|
|
||||||
buf[link_size++] = '\0';
|
|
||||||
|
|
||||||
if (buf == stack_buf)
|
|
||||||
{
|
|
||||||
char *b = (char *) alloc->allocate (link_size);
|
|
||||||
buf_size = link_size;
|
|
||||||
if (! b)
|
|
||||||
break;
|
|
||||||
memcpy (b, buf, link_size);
|
|
||||||
buf = b;
|
|
||||||
}
|
|
||||||
else if (link_size < buf_size && buf != buffer && alloc->reallocate)
|
|
||||||
{
|
|
||||||
/* Shrink BUF before returning it. */
|
|
||||||
char *b = (char *) alloc->reallocate (buf, link_size);
|
|
||||||
if (b)
|
|
||||||
buf = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buf != buffer)
|
|
||||||
alloc->free (buf);
|
|
||||||
|
|
||||||
if (buf_size <= buf_size_max / 2)
|
|
||||||
buf_size *= 2;
|
|
||||||
else if (buf_size < buf_size_max)
|
|
||||||
buf_size = buf_size_max;
|
|
||||||
else if (buf_size_max < SIZE_MAX)
|
|
||||||
{
|
|
||||||
errno = ENAMETOOLONG;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
buf = (char *) alloc->allocate (buf_size);
|
|
||||||
}
|
|
||||||
while (buf);
|
|
||||||
|
|
||||||
if (alloc->die)
|
|
||||||
alloc->die (buf_size);
|
|
||||||
errno = ENOMEM;
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
/* Read symbolic links into a buffer without size limitation, relative to fd.
|
/* Read symbolic links into a buffer without size limitation, relative to fd.
|
||||||
|
|
||||||
Copyright (C) 2011-2020 Free Software Foundation, Inc.
|
Copyright (C) 2011-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
(at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
/* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */
|
/* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */
|
||||||
|
341
lib/cdefs.h
341
lib/cdefs.h
@ -1,17 +1,18 @@
|
|||||||
/* Copyright (C) 1992-2020 Free Software Foundation, Inc.
|
/* Copyright (C) 1992-2022 Free Software Foundation, Inc.
|
||||||
|
Copyright The GNU Toolchain Authors.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
The GNU C Library is free software; you can redistribute it and/or
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
License as published by the Free Software Foundation; either
|
License as published by the Free Software Foundation; either
|
||||||
version 3 of the License, or (at your option) any later version.
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
The GNU C Library is distributed in the hope that it will be useful,
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
General Public License for more details.
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public
|
You should have received a copy of the GNU Lesser General Public
|
||||||
License along with the GNU C Library; if not, see
|
License along with the GNU C Library; if not, see
|
||||||
<https://www.gnu.org/licenses/>. */
|
<https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
@ -25,7 +26,7 @@
|
|||||||
|
|
||||||
/* The GNU libc does not support any K&R compilers or the traditional mode
|
/* The GNU libc does not support any K&R compilers or the traditional mode
|
||||||
of ISO C compilers anymore. Check for some of the combinations not
|
of ISO C compilers anymore. Check for some of the combinations not
|
||||||
anymore supported. */
|
supported anymore. */
|
||||||
#if defined __GNUC__ && !defined __STDC__
|
#if defined __GNUC__ && !defined __STDC__
|
||||||
# error "You need a ISO C conforming compiler to use the glibc headers"
|
# error "You need a ISO C conforming compiler to use the glibc headers"
|
||||||
#endif
|
#endif
|
||||||
@ -34,7 +35,31 @@
|
|||||||
#undef __P
|
#undef __P
|
||||||
#undef __PMT
|
#undef __PMT
|
||||||
|
|
||||||
#ifdef __GNUC__
|
/* Compilers that lack __has_attribute may object to
|
||||||
|
#if defined __has_attribute && __has_attribute (...)
|
||||||
|
even though they do not need to evaluate the right-hand side of the &&.
|
||||||
|
Similarly for __has_builtin, etc. */
|
||||||
|
#if (defined __has_attribute \
|
||||||
|
&& (!defined __clang_minor__ \
|
||||||
|
|| (defined __apple_build_version__ \
|
||||||
|
? 6000000 <= __apple_build_version__ \
|
||||||
|
: 3 < __clang_major__ + (5 <= __clang_minor__))))
|
||||||
|
# define __glibc_has_attribute(attr) __has_attribute (attr)
|
||||||
|
#else
|
||||||
|
# define __glibc_has_attribute(attr) 0
|
||||||
|
#endif
|
||||||
|
#ifdef __has_builtin
|
||||||
|
# define __glibc_has_builtin(name) __has_builtin (name)
|
||||||
|
#else
|
||||||
|
# define __glibc_has_builtin(name) 0
|
||||||
|
#endif
|
||||||
|
#ifdef __has_extension
|
||||||
|
# define __glibc_has_extension(ext) __has_extension (ext)
|
||||||
|
#else
|
||||||
|
# define __glibc_has_extension(ext) 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined __GNUC__ || defined __clang__
|
||||||
|
|
||||||
/* All functions, except those with callbacks or those that
|
/* All functions, except those with callbacks or those that
|
||||||
synchronize memory, are leaf functions. */
|
synchronize memory, are leaf functions. */
|
||||||
@ -47,21 +72,26 @@
|
|||||||
# endif
|
# endif
|
||||||
|
|
||||||
/* GCC can always grok prototypes. For C++ programs we add throw()
|
/* GCC can always grok prototypes. For C++ programs we add throw()
|
||||||
to help it optimize the function calls. But this works only with
|
to help it optimize the function calls. But this only works with
|
||||||
gcc 2.8.x and egcs. For gcc 3.2 and up we even mark C functions
|
gcc 2.8.x and egcs. For gcc 3.4 and up we even mark C functions
|
||||||
as non-throwing using a function attribute since programs can use
|
as non-throwing using a function attribute since programs can use
|
||||||
the -fexceptions options for C code as well. */
|
the -fexceptions options for C code as well. */
|
||||||
# if !defined __cplusplus && __GNUC_PREREQ (3, 3)
|
# if !defined __cplusplus \
|
||||||
|
&& (__GNUC_PREREQ (3, 4) || __glibc_has_attribute (__nothrow__))
|
||||||
# define __THROW __attribute__ ((__nothrow__ __LEAF))
|
# define __THROW __attribute__ ((__nothrow__ __LEAF))
|
||||||
# define __THROWNL __attribute__ ((__nothrow__))
|
# define __THROWNL __attribute__ ((__nothrow__))
|
||||||
# define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct
|
# define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct
|
||||||
# define __NTHNL(fct) __attribute__ ((__nothrow__)) fct
|
# define __NTHNL(fct) __attribute__ ((__nothrow__)) fct
|
||||||
# else
|
# else
|
||||||
# if defined __cplusplus && __GNUC_PREREQ (2,8)
|
# if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major >= 4)
|
||||||
# define __THROW throw ()
|
# if __cplusplus >= 201103L
|
||||||
# define __THROWNL throw ()
|
# define __THROW noexcept (true)
|
||||||
# define __NTH(fct) __LEAF_ATTR fct throw ()
|
# else
|
||||||
# define __NTHNL(fct) fct throw ()
|
# define __THROW throw ()
|
||||||
|
# endif
|
||||||
|
# define __THROWNL __THROW
|
||||||
|
# define __NTH(fct) __LEAF_ATTR fct __THROW
|
||||||
|
# define __NTHNL(fct) fct __THROW
|
||||||
# else
|
# else
|
||||||
# define __THROW
|
# define __THROW
|
||||||
# define __THROWNL
|
# define __THROWNL
|
||||||
@ -70,7 +100,7 @@
|
|||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
#else /* Not GCC. */
|
#else /* Not GCC or clang. */
|
||||||
|
|
||||||
# if (defined __cplusplus \
|
# if (defined __cplusplus \
|
||||||
|| (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
|
|| (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
|
||||||
@ -83,16 +113,7 @@
|
|||||||
# define __THROWNL
|
# define __THROWNL
|
||||||
# define __NTH(fct) fct
|
# define __NTH(fct) fct
|
||||||
|
|
||||||
#endif /* GCC. */
|
#endif /* GCC || clang. */
|
||||||
|
|
||||||
/* Compilers that are not clang may object to
|
|
||||||
#if defined __clang__ && __has_extension(...)
|
|
||||||
even though they do not need to evaluate the right-hand side of the &&. */
|
|
||||||
#if defined __clang__ && defined __has_extension
|
|
||||||
# define __glibc_clang_has_extension(ext) __has_extension (ext)
|
|
||||||
#else
|
|
||||||
# define __glibc_clang_has_extension(ext) 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* These two macros are not used in glibc anymore. They are kept here
|
/* These two macros are not used in glibc anymore. They are kept here
|
||||||
only because some other projects expect the macros to be defined. */
|
only because some other projects expect the macros to be defined. */
|
||||||
@ -123,14 +144,68 @@
|
|||||||
#define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1)
|
#define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1)
|
||||||
#define __bos0(ptr) __builtin_object_size (ptr, 0)
|
#define __bos0(ptr) __builtin_object_size (ptr, 0)
|
||||||
|
|
||||||
|
/* Use __builtin_dynamic_object_size at _FORTIFY_SOURCE=3 when available. */
|
||||||
|
#if __USE_FORTIFY_LEVEL == 3 && (__glibc_clang_prereq (9, 0) \
|
||||||
|
|| __GNUC_PREREQ (12, 0))
|
||||||
|
# define __glibc_objsize0(__o) __builtin_dynamic_object_size (__o, 0)
|
||||||
|
# define __glibc_objsize(__o) __builtin_dynamic_object_size (__o, 1)
|
||||||
|
#else
|
||||||
|
# define __glibc_objsize0(__o) __bos0 (__o)
|
||||||
|
# define __glibc_objsize(__o) __bos (__o)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Compile time conditions to choose between the regular, _chk and _chk_warn
|
||||||
|
variants. These conditions should get evaluated to constant and optimized
|
||||||
|
away. */
|
||||||
|
|
||||||
|
#define __glibc_safe_len_cond(__l, __s, __osz) ((__l) <= (__osz) / (__s))
|
||||||
|
#define __glibc_unsigned_or_positive(__l) \
|
||||||
|
((__typeof (__l)) 0 < (__typeof (__l)) -1 \
|
||||||
|
|| (__builtin_constant_p (__l) && (__l) > 0))
|
||||||
|
|
||||||
|
/* Length is known to be safe at compile time if the __L * __S <= __OBJSZ
|
||||||
|
condition can be folded to a constant and if it is true. The -1 check is
|
||||||
|
redundant because since it implies that __glibc_safe_len_cond is true. */
|
||||||
|
#define __glibc_safe_or_unknown_len(__l, __s, __osz) \
|
||||||
|
(__glibc_unsigned_or_positive (__l) \
|
||||||
|
&& __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \
|
||||||
|
__s, __osz)) \
|
||||||
|
&& __glibc_safe_len_cond ((__SIZE_TYPE__) (__l), __s, __osz))
|
||||||
|
|
||||||
|
/* Conversely, we know at compile time that the length is unsafe if the
|
||||||
|
__L * __S <= __OBJSZ condition can be folded to a constant and if it is
|
||||||
|
false. */
|
||||||
|
#define __glibc_unsafe_len(__l, __s, __osz) \
|
||||||
|
(__glibc_unsigned_or_positive (__l) \
|
||||||
|
&& __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \
|
||||||
|
__s, __osz)) \
|
||||||
|
&& !__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), __s, __osz))
|
||||||
|
|
||||||
|
/* Fortify function f. __f_alias, __f_chk and __f_chk_warn must be
|
||||||
|
declared. */
|
||||||
|
|
||||||
|
#define __glibc_fortify(f, __l, __s, __osz, ...) \
|
||||||
|
(__glibc_safe_or_unknown_len (__l, __s, __osz) \
|
||||||
|
? __ ## f ## _alias (__VA_ARGS__) \
|
||||||
|
: (__glibc_unsafe_len (__l, __s, __osz) \
|
||||||
|
? __ ## f ## _chk_warn (__VA_ARGS__, __osz) \
|
||||||
|
: __ ## f ## _chk (__VA_ARGS__, __osz))) \
|
||||||
|
|
||||||
|
/* Fortify function f, where object size argument passed to f is the number of
|
||||||
|
elements and not total size. */
|
||||||
|
|
||||||
|
#define __glibc_fortify_n(f, __l, __s, __osz, ...) \
|
||||||
|
(__glibc_safe_or_unknown_len (__l, __s, __osz) \
|
||||||
|
? __ ## f ## _alias (__VA_ARGS__) \
|
||||||
|
: (__glibc_unsafe_len (__l, __s, __osz) \
|
||||||
|
? __ ## f ## _chk_warn (__VA_ARGS__, (__osz) / (__s)) \
|
||||||
|
: __ ## f ## _chk (__VA_ARGS__, (__osz) / (__s)))) \
|
||||||
|
|
||||||
#if __GNUC_PREREQ (4,3)
|
#if __GNUC_PREREQ (4,3)
|
||||||
# define __warndecl(name, msg) \
|
|
||||||
extern void name (void) __attribute__((__warning__ (msg)))
|
|
||||||
# define __warnattr(msg) __attribute__((__warning__ (msg)))
|
# define __warnattr(msg) __attribute__((__warning__ (msg)))
|
||||||
# define __errordecl(name, msg) \
|
# define __errordecl(name, msg) \
|
||||||
extern void name (void) __attribute__((__error__ (msg)))
|
extern void name (void) __attribute__((__error__ (msg)))
|
||||||
#else
|
#else
|
||||||
# define __warndecl(name, msg) extern void name (void)
|
|
||||||
# define __warnattr(msg)
|
# define __warnattr(msg)
|
||||||
# define __errordecl(name, msg) extern void name (void)
|
# define __errordecl(name, msg) extern void name (void)
|
||||||
#endif
|
#endif
|
||||||
@ -142,8 +217,8 @@
|
|||||||
#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L && !defined __HP_cc
|
#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L && !defined __HP_cc
|
||||||
# define __flexarr []
|
# define __flexarr []
|
||||||
# define __glibc_c99_flexarr_available 1
|
# define __glibc_c99_flexarr_available 1
|
||||||
#elif __GNUC_PREREQ (2,97)
|
#elif __GNUC_PREREQ (2,97) || defined __clang__
|
||||||
/* GCC 2.97 supports C99 flexible array members as an extension,
|
/* GCC 2.97 and clang support C99 flexible array members as an extension,
|
||||||
even when in C89 mode or compiling C++ (any version). */
|
even when in C89 mode or compiling C++ (any version). */
|
||||||
# define __flexarr []
|
# define __flexarr []
|
||||||
# define __glibc_c99_flexarr_available 1
|
# define __glibc_c99_flexarr_available 1
|
||||||
@ -169,7 +244,7 @@
|
|||||||
Example:
|
Example:
|
||||||
int __REDIRECT(setpgrp, (__pid_t pid, __pid_t pgrp), setpgid); */
|
int __REDIRECT(setpgrp, (__pid_t pid, __pid_t pgrp), setpgid); */
|
||||||
|
|
||||||
#if defined __GNUC__ && __GNUC__ >= 2
|
#if (defined __GNUC__ && __GNUC__ >= 2) || (__clang_major__ >= 4)
|
||||||
|
|
||||||
# define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))
|
# define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))
|
||||||
# ifdef __cplusplus
|
# ifdef __cplusplus
|
||||||
@ -194,17 +269,17 @@
|
|||||||
*/
|
*/
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* GCC has various useful declarations that can be made with the
|
/* GCC and clang have various useful declarations that can be made with
|
||||||
`__attribute__' syntax. All of the ways we use this do fine if
|
the '__attribute__' syntax. All of the ways we use this do fine if
|
||||||
they are omitted for compilers that don't understand it. */
|
they are omitted for compilers that don't understand it. */
|
||||||
#if !defined __GNUC__ || __GNUC__ < 2
|
#if !(defined __GNUC__ || defined __clang__)
|
||||||
# define __attribute__(xyz) /* Ignore */
|
# define __attribute__(xyz) /* Ignore */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* At some point during the gcc 2.96 development the `malloc' attribute
|
/* At some point during the gcc 2.96 development the `malloc' attribute
|
||||||
for functions was introduced. We don't want to use it unconditionally
|
for functions was introduced. We don't want to use it unconditionally
|
||||||
(although this would be possible) since it generates warnings. */
|
(although this would be possible) since it generates warnings. */
|
||||||
#if __GNUC_PREREQ (2,96)
|
#if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__malloc__)
|
||||||
# define __attribute_malloc__ __attribute__ ((__malloc__))
|
# define __attribute_malloc__ __attribute__ ((__malloc__))
|
||||||
#else
|
#else
|
||||||
# define __attribute_malloc__ /* Ignore */
|
# define __attribute_malloc__ /* Ignore */
|
||||||
@ -219,26 +294,41 @@
|
|||||||
# define __attribute_alloc_size__(params) /* Ignore. */
|
# define __attribute_alloc_size__(params) /* Ignore. */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Tell the compiler which argument to an allocation function
|
||||||
|
indicates the alignment of the allocation. */
|
||||||
|
#if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__alloc_align__)
|
||||||
|
# define __attribute_alloc_align__(param) \
|
||||||
|
__attribute__ ((__alloc_align__ param))
|
||||||
|
#else
|
||||||
|
# define __attribute_alloc_align__(param) /* Ignore. */
|
||||||
|
#endif
|
||||||
|
|
||||||
/* At some point during the gcc 2.96 development the `pure' attribute
|
/* At some point during the gcc 2.96 development the `pure' attribute
|
||||||
for functions was introduced. We don't want to use it unconditionally
|
for functions was introduced. We don't want to use it unconditionally
|
||||||
(although this would be possible) since it generates warnings. */
|
(although this would be possible) since it generates warnings. */
|
||||||
#if __GNUC_PREREQ (2,96)
|
#if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__pure__)
|
||||||
# define __attribute_pure__ __attribute__ ((__pure__))
|
# define __attribute_pure__ __attribute__ ((__pure__))
|
||||||
#else
|
#else
|
||||||
# define __attribute_pure__ /* Ignore */
|
# define __attribute_pure__ /* Ignore */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* This declaration tells the compiler that the value is constant. */
|
/* This declaration tells the compiler that the value is constant. */
|
||||||
#if __GNUC_PREREQ (2,5)
|
#if __GNUC_PREREQ (2,5) || __glibc_has_attribute (__const__)
|
||||||
# define __attribute_const__ __attribute__ ((__const__))
|
# define __attribute_const__ __attribute__ ((__const__))
|
||||||
#else
|
#else
|
||||||
# define __attribute_const__ /* Ignore */
|
# define __attribute_const__ /* Ignore */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __GNUC_PREREQ (2,7) || __glibc_has_attribute (__unused__)
|
||||||
|
# define __attribute_maybe_unused__ __attribute__ ((__unused__))
|
||||||
|
#else
|
||||||
|
# define __attribute_maybe_unused__ /* Ignore */
|
||||||
|
#endif
|
||||||
|
|
||||||
/* At some point during the gcc 3.1 development the `used' attribute
|
/* At some point during the gcc 3.1 development the `used' attribute
|
||||||
for functions was introduced. We don't want to use it unconditionally
|
for functions was introduced. We don't want to use it unconditionally
|
||||||
(although this would be possible) since it generates warnings. */
|
(although this would be possible) since it generates warnings. */
|
||||||
#if __GNUC_PREREQ (3,1)
|
#if __GNUC_PREREQ (3,1) || __glibc_has_attribute (__used__)
|
||||||
# define __attribute_used__ __attribute__ ((__used__))
|
# define __attribute_used__ __attribute__ ((__used__))
|
||||||
# define __attribute_noinline__ __attribute__ ((__noinline__))
|
# define __attribute_noinline__ __attribute__ ((__noinline__))
|
||||||
#else
|
#else
|
||||||
@ -247,7 +337,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Since version 3.2, gcc allows marking deprecated functions. */
|
/* Since version 3.2, gcc allows marking deprecated functions. */
|
||||||
#if __GNUC_PREREQ (3,2)
|
#if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__deprecated__)
|
||||||
# define __attribute_deprecated__ __attribute__ ((__deprecated__))
|
# define __attribute_deprecated__ __attribute__ ((__deprecated__))
|
||||||
#else
|
#else
|
||||||
# define __attribute_deprecated__ /* Ignore */
|
# define __attribute_deprecated__ /* Ignore */
|
||||||
@ -256,8 +346,8 @@
|
|||||||
/* Since version 4.5, gcc also allows one to specify the message printed
|
/* Since version 4.5, gcc also allows one to specify the message printed
|
||||||
when a deprecated function is used. clang claims to be gcc 4.2, but
|
when a deprecated function is used. clang claims to be gcc 4.2, but
|
||||||
may also support this feature. */
|
may also support this feature. */
|
||||||
#if __GNUC_PREREQ (4,5) || \
|
#if __GNUC_PREREQ (4,5) \
|
||||||
__glibc_clang_has_extension (__attribute_deprecated_with_message__)
|
|| __glibc_has_extension (__attribute_deprecated_with_message__)
|
||||||
# define __attribute_deprecated_msg__(msg) \
|
# define __attribute_deprecated_msg__(msg) \
|
||||||
__attribute__ ((__deprecated__ (msg)))
|
__attribute__ ((__deprecated__ (msg)))
|
||||||
#else
|
#else
|
||||||
@ -270,7 +360,7 @@
|
|||||||
If several `format_arg' attributes are given for the same function, in
|
If several `format_arg' attributes are given for the same function, in
|
||||||
gcc-3.0 and older, all but the last one are ignored. In newer gccs,
|
gcc-3.0 and older, all but the last one are ignored. In newer gccs,
|
||||||
all designated arguments are considered. */
|
all designated arguments are considered. */
|
||||||
#if __GNUC_PREREQ (2,8)
|
#if __GNUC_PREREQ (2,8) || __glibc_has_attribute (__format_arg__)
|
||||||
# define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x)))
|
# define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x)))
|
||||||
#else
|
#else
|
||||||
# define __attribute_format_arg__(x) /* Ignore */
|
# define __attribute_format_arg__(x) /* Ignore */
|
||||||
@ -280,7 +370,7 @@
|
|||||||
attribute for functions was introduced. We don't want to use it
|
attribute for functions was introduced. We don't want to use it
|
||||||
unconditionally (although this would be possible) since it
|
unconditionally (although this would be possible) since it
|
||||||
generates warnings. */
|
generates warnings. */
|
||||||
#if __GNUC_PREREQ (2,97)
|
#if __GNUC_PREREQ (2,97) || __glibc_has_attribute (__format__)
|
||||||
# define __attribute_format_strfmon__(a,b) \
|
# define __attribute_format_strfmon__(a,b) \
|
||||||
__attribute__ ((__format__ (__strfmon__, a, b)))
|
__attribute__ ((__format__ (__strfmon__, a, b)))
|
||||||
#else
|
#else
|
||||||
@ -288,19 +378,33 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* The nonnull function attribute marks pointer parameters that
|
/* The nonnull function attribute marks pointer parameters that
|
||||||
must not be NULL. Do not define __nonnull if it is already defined,
|
must not be NULL. This has the name __nonnull in glibc,
|
||||||
for portability when this file is used in Gnulib. */
|
and __attribute_nonnull__ in files shared with Gnulib to avoid
|
||||||
#ifndef __nonnull
|
collision with a different __nonnull in DragonFlyBSD 5.9. */
|
||||||
# if __GNUC_PREREQ (3,3)
|
#ifndef __attribute_nonnull__
|
||||||
# define __nonnull(params) __attribute__ ((__nonnull__ params))
|
# if __GNUC_PREREQ (3,3) || __glibc_has_attribute (__nonnull__)
|
||||||
|
# define __attribute_nonnull__(params) __attribute__ ((__nonnull__ params))
|
||||||
# else
|
# else
|
||||||
# define __nonnull(params)
|
# define __attribute_nonnull__(params)
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
#ifndef __nonnull
|
||||||
|
# define __nonnull(params) __attribute_nonnull__ (params)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* The returns_nonnull function attribute marks the return type of the function
|
||||||
|
as always being non-null. */
|
||||||
|
#ifndef __returns_nonnull
|
||||||
|
# if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__returns_nonnull__)
|
||||||
|
# define __returns_nonnull __attribute__ ((__returns_nonnull__))
|
||||||
|
# else
|
||||||
|
# define __returns_nonnull
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* If fortification mode, we warn about unused results of certain
|
/* If fortification mode, we warn about unused results of certain
|
||||||
function calls which can lead to problems. */
|
function calls which can lead to problems. */
|
||||||
#if __GNUC_PREREQ (3,4)
|
#if __GNUC_PREREQ (3,4) || __glibc_has_attribute (__warn_unused_result__)
|
||||||
# define __attribute_warn_unused_result__ \
|
# define __attribute_warn_unused_result__ \
|
||||||
__attribute__ ((__warn_unused_result__))
|
__attribute__ ((__warn_unused_result__))
|
||||||
# if defined __USE_FORTIFY_LEVEL && __USE_FORTIFY_LEVEL > 0
|
# if defined __USE_FORTIFY_LEVEL && __USE_FORTIFY_LEVEL > 0
|
||||||
@ -314,7 +418,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Forces a function to be always inlined. */
|
/* Forces a function to be always inlined. */
|
||||||
#if __GNUC_PREREQ (3,2)
|
#if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__always_inline__)
|
||||||
/* The Linux kernel defines __always_inline in stddef.h (283d7573), and
|
/* The Linux kernel defines __always_inline in stddef.h (283d7573), and
|
||||||
it conflicts with this definition. Therefore undefine it first to
|
it conflicts with this definition. Therefore undefine it first to
|
||||||
allow either header to be included first. */
|
allow either header to be included first. */
|
||||||
@ -327,7 +431,7 @@
|
|||||||
|
|
||||||
/* Associate error messages with the source location of the call site rather
|
/* Associate error messages with the source location of the call site rather
|
||||||
than with the source location inside the function. */
|
than with the source location inside the function. */
|
||||||
#if __GNUC_PREREQ (4,3)
|
#if __GNUC_PREREQ (4,3) || __glibc_has_attribute (__artificial__)
|
||||||
# define __attribute_artificial__ __attribute__ ((__artificial__))
|
# define __attribute_artificial__ __attribute__ ((__artificial__))
|
||||||
#else
|
#else
|
||||||
# define __attribute_artificial__ /* Ignore */
|
# define __attribute_artificial__ /* Ignore */
|
||||||
@ -370,12 +474,14 @@
|
|||||||
run in pedantic mode if the uses are carefully marked using the
|
run in pedantic mode if the uses are carefully marked using the
|
||||||
`__extension__' keyword. But this is not generally available before
|
`__extension__' keyword. But this is not generally available before
|
||||||
version 2.8. */
|
version 2.8. */
|
||||||
#if !__GNUC_PREREQ (2,8)
|
#if !(__GNUC_PREREQ (2,8) || defined __clang__)
|
||||||
# define __extension__ /* Ignore */
|
# define __extension__ /* Ignore */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* __restrict is known in EGCS 1.2 and above. */
|
/* __restrict is known in EGCS 1.2 and above, and in clang.
|
||||||
#if !__GNUC_PREREQ (2,92)
|
It works also in C++ mode (outside of arrays), but only when spelled
|
||||||
|
as '__restrict', not 'restrict'. */
|
||||||
|
#if !(__GNUC_PREREQ (2,92) || __clang_major__ >= 3)
|
||||||
# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
|
# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
|
||||||
# define __restrict restrict
|
# define __restrict restrict
|
||||||
# else
|
# else
|
||||||
@ -385,8 +491,9 @@
|
|||||||
|
|
||||||
/* ISO C99 also allows to declare arrays as non-overlapping. The syntax is
|
/* ISO C99 also allows to declare arrays as non-overlapping. The syntax is
|
||||||
array_name[restrict]
|
array_name[restrict]
|
||||||
GCC 3.1 supports this. */
|
GCC 3.1 and clang support this.
|
||||||
#if __GNUC_PREREQ (3,1) && !defined __GNUG__
|
This syntax is not usable in C++ mode. */
|
||||||
|
#if (__GNUC_PREREQ (3,1) || __clang_major__ >= 3) && !defined __cplusplus
|
||||||
# define __restrict_arr __restrict
|
# define __restrict_arr __restrict
|
||||||
#else
|
#else
|
||||||
# ifdef __GNUC__
|
# ifdef __GNUC__
|
||||||
@ -401,7 +508,7 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __GNUC__ >= 3
|
#if (__GNUC__ >= 3) || __glibc_has_builtin (__builtin_expect)
|
||||||
# define __glibc_unlikely(cond) __builtin_expect ((cond), 0)
|
# define __glibc_unlikely(cond) __builtin_expect ((cond), 0)
|
||||||
# define __glibc_likely(cond) __builtin_expect ((cond), 1)
|
# define __glibc_likely(cond) __builtin_expect ((cond), 1)
|
||||||
#else
|
#else
|
||||||
@ -409,15 +516,10 @@
|
|||||||
# define __glibc_likely(cond) (cond)
|
# define __glibc_likely(cond) (cond)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __has_attribute
|
|
||||||
# define __glibc_has_attribute(attr) __has_attribute (attr)
|
|
||||||
#else
|
|
||||||
# define __glibc_has_attribute(attr) 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (!defined _Noreturn \
|
#if (!defined _Noreturn \
|
||||||
&& (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
|
&& (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
|
||||||
&& !__GNUC_PREREQ (4,7))
|
&& !(__GNUC_PREREQ (4,7) \
|
||||||
|
|| (3 < __clang_major__ + (5 <= __clang_minor__))))
|
||||||
# if __GNUC_PREREQ (2,8)
|
# if __GNUC_PREREQ (2,8)
|
||||||
# define _Noreturn __attribute__ ((__noreturn__))
|
# define _Noreturn __attribute__ ((__noreturn__))
|
||||||
# else
|
# else
|
||||||
@ -434,22 +536,63 @@
|
|||||||
# define __attribute_nonstring__
|
# define __attribute_nonstring__
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Undefine (also defined in libc-symbols.h). */
|
||||||
|
#undef __attribute_copy__
|
||||||
|
#if __GNUC_PREREQ (9, 0)
|
||||||
|
/* Copies attributes from the declaration or type referenced by
|
||||||
|
the argument. */
|
||||||
|
# define __attribute_copy__(arg) __attribute__ ((__copy__ (arg)))
|
||||||
|
#else
|
||||||
|
# define __attribute_copy__(arg)
|
||||||
|
#endif
|
||||||
|
|
||||||
#if (!defined _Static_assert && !defined __cplusplus \
|
#if (!defined _Static_assert && !defined __cplusplus \
|
||||||
&& (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
|
&& (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
|
||||||
&& (!__GNUC_PREREQ (4, 6) || defined __STRICT_ANSI__))
|
&& (!(__GNUC_PREREQ (4, 6) || __clang_major__ >= 4) \
|
||||||
|
|| defined __STRICT_ANSI__))
|
||||||
# define _Static_assert(expr, diagnostic) \
|
# define _Static_assert(expr, diagnostic) \
|
||||||
extern int (*__Static_assert_function (void)) \
|
extern int (*__Static_assert_function (void)) \
|
||||||
[!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })]
|
[!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })]
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* The #ifndef lets Gnulib avoid including these on non-glibc
|
/* Gnulib avoids including these, as they don't work on non-glibc or
|
||||||
platforms, where the includes typically do not exist. */
|
older glibc platforms. */
|
||||||
#ifndef __WORDSIZE
|
#ifndef __GNULIB_CDEFS
|
||||||
# include <bits/wordsize.h>
|
# include <bits/wordsize.h>
|
||||||
# include <bits/long-double.h>
|
# include <bits/long-double.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
|
#if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
|
||||||
|
# ifdef __REDIRECT
|
||||||
|
|
||||||
|
/* Alias name defined automatically. */
|
||||||
|
# define __LDBL_REDIR(name, proto) ... unused__ldbl_redir
|
||||||
|
# define __LDBL_REDIR_DECL(name) \
|
||||||
|
extern __typeof (name) name __asm (__ASMNAME ("__" #name "ieee128"));
|
||||||
|
|
||||||
|
/* Alias name defined automatically, with leading underscores. */
|
||||||
|
# define __LDBL_REDIR2_DECL(name) \
|
||||||
|
extern __typeof (__##name) __##name \
|
||||||
|
__asm (__ASMNAME ("__" #name "ieee128"));
|
||||||
|
|
||||||
|
/* Alias name defined manually. */
|
||||||
|
# define __LDBL_REDIR1(name, proto, alias) ... unused__ldbl_redir1
|
||||||
|
# define __LDBL_REDIR1_DECL(name, alias) \
|
||||||
|
extern __typeof (name) name __asm (__ASMNAME (#alias));
|
||||||
|
|
||||||
|
# define __LDBL_REDIR1_NTH(name, proto, alias) \
|
||||||
|
__REDIRECT_NTH (name, proto, alias)
|
||||||
|
# define __REDIRECT_NTH_LDBL(name, proto, alias) \
|
||||||
|
__LDBL_REDIR1_NTH (name, proto, __##alias##ieee128)
|
||||||
|
|
||||||
|
/* Unused. */
|
||||||
|
# define __REDIRECT_LDBL(name, proto, alias) ... unused__redirect_ldbl
|
||||||
|
# define __LDBL_REDIR_NTH(name, proto) ... unused__ldbl_redir_nth
|
||||||
|
|
||||||
|
# else
|
||||||
|
_Static_assert (0, "IEEE 128-bits long double requires redirection on this platform");
|
||||||
|
# endif
|
||||||
|
#elif defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
|
||||||
# define __LDBL_COMPAT 1
|
# define __LDBL_COMPAT 1
|
||||||
# ifdef __REDIRECT
|
# ifdef __REDIRECT
|
||||||
# define __LDBL_REDIR1(name, proto, alias) __REDIRECT (name, proto, alias)
|
# define __LDBL_REDIR1(name, proto, alias) __REDIRECT (name, proto, alias)
|
||||||
@ -458,6 +601,8 @@
|
|||||||
# define __LDBL_REDIR1_NTH(name, proto, alias) __REDIRECT_NTH (name, proto, alias)
|
# define __LDBL_REDIR1_NTH(name, proto, alias) __REDIRECT_NTH (name, proto, alias)
|
||||||
# define __LDBL_REDIR_NTH(name, proto) \
|
# define __LDBL_REDIR_NTH(name, proto) \
|
||||||
__LDBL_REDIR1_NTH (name, proto, __nldbl_##name)
|
__LDBL_REDIR1_NTH (name, proto, __nldbl_##name)
|
||||||
|
# define __LDBL_REDIR2_DECL(name) \
|
||||||
|
extern __typeof (__##name) __##name __asm (__ASMNAME ("__nldbl___" #name));
|
||||||
# define __LDBL_REDIR1_DECL(name, alias) \
|
# define __LDBL_REDIR1_DECL(name, alias) \
|
||||||
extern __typeof (name) name __asm (__ASMNAME (#alias));
|
extern __typeof (name) name __asm (__ASMNAME (#alias));
|
||||||
# define __LDBL_REDIR_DECL(name) \
|
# define __LDBL_REDIR_DECL(name) \
|
||||||
@ -468,11 +613,13 @@
|
|||||||
__LDBL_REDIR1_NTH (name, proto, __nldbl_##alias)
|
__LDBL_REDIR1_NTH (name, proto, __nldbl_##alias)
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
#if !defined __LDBL_COMPAT || !defined __REDIRECT
|
#if (!defined __LDBL_COMPAT && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0) \
|
||||||
|
|| !defined __REDIRECT
|
||||||
# define __LDBL_REDIR1(name, proto, alias) name proto
|
# define __LDBL_REDIR1(name, proto, alias) name proto
|
||||||
# define __LDBL_REDIR(name, proto) name proto
|
# define __LDBL_REDIR(name, proto) name proto
|
||||||
# define __LDBL_REDIR1_NTH(name, proto, alias) name proto __THROW
|
# define __LDBL_REDIR1_NTH(name, proto, alias) name proto __THROW
|
||||||
# define __LDBL_REDIR_NTH(name, proto) name proto __THROW
|
# define __LDBL_REDIR_NTH(name, proto) name proto __THROW
|
||||||
|
# define __LDBL_REDIR2_DECL(name)
|
||||||
# define __LDBL_REDIR_DECL(name)
|
# define __LDBL_REDIR_DECL(name)
|
||||||
# ifdef __REDIRECT
|
# ifdef __REDIRECT
|
||||||
# define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias)
|
# define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias)
|
||||||
@ -503,7 +650,7 @@
|
|||||||
check is required to enable the use of generic selection. */
|
check is required to enable the use of generic selection. */
|
||||||
#if !defined __cplusplus \
|
#if !defined __cplusplus \
|
||||||
&& (__GNUC_PREREQ (4, 9) \
|
&& (__GNUC_PREREQ (4, 9) \
|
||||||
|| __glibc_clang_has_extension (c_generic_selections) \
|
|| __glibc_has_extension (c_generic_selections) \
|
||||||
|| (!defined __GNUC__ && defined __STDC_VERSION__ \
|
|| (!defined __GNUC__ && defined __STDC_VERSION__ \
|
||||||
&& __STDC_VERSION__ >= 201112L))
|
&& __STDC_VERSION__ >= 201112L))
|
||||||
# define __HAVE_GENERIC_SELECTION 1
|
# define __HAVE_GENERIC_SELECTION 1
|
||||||
@ -511,4 +658,50 @@
|
|||||||
# define __HAVE_GENERIC_SELECTION 0
|
# define __HAVE_GENERIC_SELECTION 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __GNUC_PREREQ (10, 0)
|
||||||
|
/* Designates a 1-based positional argument ref-index of pointer type
|
||||||
|
that can be used to access size-index elements of the pointed-to
|
||||||
|
array according to access mode, or at least one element when
|
||||||
|
size-index is not provided:
|
||||||
|
access (access-mode, <ref-index> [, <size-index>]) */
|
||||||
|
# define __attr_access(x) __attribute__ ((__access__ x))
|
||||||
|
/* For _FORTIFY_SOURCE == 3 we use __builtin_dynamic_object_size, which may
|
||||||
|
use the access attribute to get object sizes from function definition
|
||||||
|
arguments, so we can't use them on functions we fortify. Drop the object
|
||||||
|
size hints for such functions. */
|
||||||
|
# if __USE_FORTIFY_LEVEL == 3
|
||||||
|
# define __fortified_attr_access(a, o, s) __attribute__ ((__access__ (a, o)))
|
||||||
|
# else
|
||||||
|
# define __fortified_attr_access(a, o, s) __attr_access ((a, o, s))
|
||||||
|
# endif
|
||||||
|
# if __GNUC_PREREQ (11, 0)
|
||||||
|
# define __attr_access_none(argno) __attribute__ ((__access__ (__none__, argno)))
|
||||||
|
# else
|
||||||
|
# define __attr_access_none(argno)
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
# define __fortified_attr_access(a, o, s)
|
||||||
|
# define __attr_access(x)
|
||||||
|
# define __attr_access_none(argno)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __GNUC_PREREQ (11, 0)
|
||||||
|
/* Designates dealloc as a function to call to deallocate objects
|
||||||
|
allocated by the declared function. */
|
||||||
|
# define __attr_dealloc(dealloc, argno) \
|
||||||
|
__attribute__ ((__malloc__ (dealloc, argno)))
|
||||||
|
# define __attr_dealloc_free __attr_dealloc (__builtin_free, 1)
|
||||||
|
#else
|
||||||
|
# define __attr_dealloc(dealloc, argno)
|
||||||
|
# define __attr_dealloc_free
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Specify that a function such as setjmp or vfork may return
|
||||||
|
twice. */
|
||||||
|
#if __GNUC_PREREQ (4, 1)
|
||||||
|
# define __attribute_returns_twice__ __attribute__ ((__returns_twice__))
|
||||||
|
#else
|
||||||
|
# define __attribute_returns_twice__ /* Ignore. */
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* sys/cdefs.h */
|
#endif /* sys/cdefs.h */
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
/* provide a chdir function that tries not to fail due to ENAMETOOLONG
|
/* provide a chdir function that tries not to fail due to ENAMETOOLONG
|
||||||
Copyright (C) 2004-2020 Free Software Foundation, Inc.
|
Copyright (C) 2004-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
/* provide a chdir function that tries not to fail due to ENAMETOOLONG
|
/* provide a chdir function that tries not to fail due to ENAMETOOLONG
|
||||||
Copyright (C) 2004-2005, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 2004-2005, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/* Change access permissions of a file at a directory.
|
||||||
|
|
||||||
|
Copyright (C) 2012-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This file is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License,
|
||||||
|
or (at your option) any later version.
|
||||||
|
|
||||||
|
This file is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#define CHMODAT_INLINE _GL_EXTERN_INLINE
|
#define CHMODAT_INLINE _GL_EXTERN_INLINE
|
||||||
#include "openat.h"
|
#include "openat.h"
|
||||||
|
22
lib/chown.c
22
lib/chown.c
@ -1,19 +1,19 @@
|
|||||||
/* provide consistent interface to chown for systems that don't interpret
|
/* provide consistent interface to chown for systems that don't interpret
|
||||||
an ID of -1 as meaning "don't change the corresponding ID".
|
an ID of -1 as meaning "don't change the corresponding ID".
|
||||||
|
|
||||||
Copyright (C) 1997, 2004-2007, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 1997, 2004-2007, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
(at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
/* written by Jim Meyering */
|
/* written by Jim Meyering */
|
||||||
@ -33,8 +33,8 @@
|
|||||||
|
|
||||||
/* Simple stub that always fails with ENOSYS, for mingw. */
|
/* Simple stub that always fails with ENOSYS, for mingw. */
|
||||||
int
|
int
|
||||||
chown (const char *file _GL_UNUSED, uid_t uid _GL_UNUSED,
|
chown (_GL_UNUSED const char *file, _GL_UNUSED uid_t uid,
|
||||||
gid_t gid _GL_UNUSED)
|
_GL_UNUSED gid_t gid)
|
||||||
{
|
{
|
||||||
errno = ENOSYS;
|
errno = ENOSYS;
|
||||||
return -1;
|
return -1;
|
||||||
@ -87,7 +87,7 @@ rpl_chown (const char *file, uid_t uid, gid_t gid)
|
|||||||
on the symlink itself. To work around that, we open the
|
on the symlink itself. To work around that, we open the
|
||||||
file (but this can fail due to lack of read or write permission) and
|
file (but this can fail due to lack of read or write permission) and
|
||||||
use fchown on the resulting descriptor. */
|
use fchown on the resulting descriptor. */
|
||||||
int open_flags = O_NONBLOCK | O_NOCTTY;
|
int open_flags = O_NONBLOCK | O_NOCTTY | O_CLOEXEC;
|
||||||
int fd = open (file, O_RDONLY | open_flags);
|
int fd = open (file, O_RDONLY | open_flags);
|
||||||
if (0 <= fd
|
if (0 <= fd
|
||||||
|| (errno == EACCES
|
|| (errno == EACCES
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/* Change owner of a file at a directory.
|
||||||
|
|
||||||
|
Copyright (C) 2012-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This file is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License,
|
||||||
|
or (at your option) any later version.
|
||||||
|
|
||||||
|
This file is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#define CHOWNAT_INLINE _GL_EXTERN_INLINE
|
#define CHOWNAT_INLINE _GL_EXTERN_INLINE
|
||||||
#include "openat.h"
|
#include "openat.h"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* Convert string to double in the current locale, falling back on the C locale.
|
/* Convert string to double in the current locale, falling back on the C locale.
|
||||||
|
|
||||||
Copyright 2019-2020 Free Software Foundation, Inc.
|
Copyright 2019-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
double cl_strtod (char const *, char **restrict);
|
double cl_strtod (char const *, char **restrict)
|
||||||
long double cl_strtold (char const *, char **restrict);
|
_GL_ATTRIBUTE_NONNULL ((1));
|
||||||
|
long double cl_strtold (char const *, char **restrict)
|
||||||
|
_GL_ATTRIBUTE_NONNULL ((1));
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
/* cloexec.c - set or clear the close-on-exec descriptor flag
|
/* cloexec.c - set or clear the close-on-exec descriptor flag
|
||||||
|
|
||||||
Copyright (C) 1991, 2004-2006, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 1991, 2004-2006, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
(at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
The code is taken from glibc/manual/llio.texi */
|
/* The code is taken from glibc/manual/llio.texi */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
|
@ -1,21 +1,19 @@
|
|||||||
/* cloexec.c - set or clear the close-on-exec descriptor flag
|
/* cloexec.c - set or clear the close-on-exec descriptor flag
|
||||||
|
|
||||||
Copyright (C) 2004, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 2004, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
(at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/* Close a stream, with nicer error checking than fclose's.
|
/* Close a stream, with nicer error checking than fclose's.
|
||||||
|
|
||||||
Copyright (C) 1998-2002, 2004, 2006-2020 Free Software Foundation, Inc.
|
Copyright (C) 1998-2002, 2004, 2006-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
|
@ -1,2 +1,20 @@
|
|||||||
|
/* Close a stream, with nicer error checking than fclose's.
|
||||||
|
|
||||||
|
Copyright (C) 2006-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This file is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License,
|
||||||
|
or (at your option) any later version.
|
||||||
|
|
||||||
|
This file is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int close_stream (FILE *stream);
|
int close_stream (FILE *stream);
|
||||||
|
24
lib/close.c
24
lib/close.c
@ -1,17 +1,17 @@
|
|||||||
/* close replacement.
|
/* close replacement.
|
||||||
Copyright (C) 2008-2020 Free Software Foundation, Inc.
|
Copyright (C) 2008-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
(at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
@ -28,7 +28,8 @@
|
|||||||
|
|
||||||
#undef close
|
#undef close
|
||||||
|
|
||||||
#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
#if defined _WIN32 && !defined __CYGWIN__
|
||||||
|
# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
|
||||||
static int
|
static int
|
||||||
close_nothrow (int fd)
|
close_nothrow (int fd)
|
||||||
{
|
{
|
||||||
@ -36,7 +37,7 @@ close_nothrow (int fd)
|
|||||||
|
|
||||||
TRY_MSVC_INVAL
|
TRY_MSVC_INVAL
|
||||||
{
|
{
|
||||||
result = close (fd);
|
result = _close (fd);
|
||||||
}
|
}
|
||||||
CATCH_MSVC_INVAL
|
CATCH_MSVC_INVAL
|
||||||
{
|
{
|
||||||
@ -47,6 +48,9 @@ close_nothrow (int fd)
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
# else
|
||||||
|
# define close_nothrow _close
|
||||||
|
# endif
|
||||||
#else
|
#else
|
||||||
# define close_nothrow close
|
# define close_nothrow close
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/* Stop reading the entries of a directory.
|
/* Stop reading the entries of a directory.
|
||||||
Copyright (C) 2006-2020 Free Software Foundation, Inc.
|
Copyright (C) 2006-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This file is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Lesser General Public License as
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
published by the Free Software Foundation; either version 2.1 of the
|
||||||
(at your option) any later version.
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This file is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/* Close standard input, rewinding seekable stdin if necessary.
|
/* Close standard input, rewinding seekable stdin if necessary.
|
||||||
|
|
||||||
Copyright (C) 2007, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 2007, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/* Close standard input, rewinding seekable stdin if necessary.
|
/* Close standard input, rewinding seekable stdin if necessary.
|
||||||
|
|
||||||
Copyright (C) 2007, 2009-2020 Free Software Foundation, Inc.
|
Copyright (C) 2007, 2009-2022 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
/* Close standard output and standard error, exiting with a diagnostic on error.
|
/* Close standard output and standard error, exiting with a diagnostic on error.
|
||||||
|
|
||||||
Copyright (C) 1998-2002, 2004, 2006, 2008-2020 Free Software Foundation,
|
Copyright (C) 1998-2002, 2004, 2006, 2008-2022 Free Software Foundation,
|
||||||
Inc.
|
Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
/* Close standard output and standard error.
|
/* Close standard output and standard error.
|
||||||
|
|
||||||
Copyright (C) 1998, 2000, 2003-2004, 2006, 2008-2020 Free Software
|
Copyright (C) 1998, 2000, 2003-2004, 2006, 2008-2022 Free Software
|
||||||
Foundation, Inc.
|
Foundation, Inc.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
|
1192
lib/config.h
1192
lib/config.h
File diff suppressed because it is too large
Load Diff
1152
lib/config.hin
1152
lib/config.hin
File diff suppressed because it is too large
Load Diff
@ -2,30 +2,30 @@
|
|||||||
#if HAVE_WINSOCK2_H
|
#if HAVE_WINSOCK2_H
|
||||||
# include <winsock2.h> /* avoid mingw pollution on DATADIR */
|
# include <winsock2.h> /* avoid mingw pollution on DATADIR */
|
||||||
#endif
|
#endif
|
||||||
#define PREFIX "/data/coreutils"
|
#define PREFIX "/usr/local"
|
||||||
#define EXEC_PREFIX "/data/coreutils"
|
#define EXEC_PREFIX "/usr/local"
|
||||||
#define BINDIR "/data/coreutils/bin"
|
#define BINDIR "/usr/local/bin"
|
||||||
#define SBINDIR "/data/coreutils/sbin"
|
#define SBINDIR "/usr/local/sbin"
|
||||||
#define LIBEXECDIR "/data/coreutils/libexec"
|
#define LIBEXECDIR "/usr/local/libexec"
|
||||||
#define DATAROOTDIR "/data/coreutils/share"
|
#define DATAROOTDIR "/usr/local/share"
|
||||||
#define DATADIR "/data/coreutils/share"
|
#define DATADIR "/usr/local/share"
|
||||||
#define SYSCONFDIR "/data/coreutils/etc"
|
#define SYSCONFDIR "/usr/local/etc"
|
||||||
#define SHAREDSTATEDIR "/data/coreutils/com"
|
#define SHAREDSTATEDIR "/usr/local/com"
|
||||||
#define LOCALSTATEDIR "/data/coreutils/var"
|
#define LOCALSTATEDIR "/usr/local/var"
|
||||||
#define RUNSTATEDIR "/data/coreutils/var/run"
|
#define RUNSTATEDIR "/usr/local/var/run"
|
||||||
#define INCLUDEDIR "/data/coreutils/include"
|
#define INCLUDEDIR "/usr/local/include"
|
||||||
#define OLDINCLUDEDIR "/usr/include"
|
#define OLDINCLUDEDIR "/usr/include"
|
||||||
#define DOCDIR "/data/coreutils/share/doc/coreutils"
|
#define DOCDIR "/usr/local/share/doc/coreutils"
|
||||||
#define INFODIR "/data/coreutils/share/info"
|
#define INFODIR "/usr/local/share/info"
|
||||||
#define HTMLDIR "/data/coreutils/share/doc/coreutils"
|
#define HTMLDIR "/usr/local/share/doc/coreutils"
|
||||||
#define DVIDIR "/data/coreutils/share/doc/coreutils"
|
#define DVIDIR "/usr/local/share/doc/coreutils"
|
||||||
#define PDFDIR "/data/coreutils/share/doc/coreutils"
|
#define PDFDIR "/usr/local/share/doc/coreutils"
|
||||||
#define PSDIR "/data/coreutils/share/doc/coreutils"
|
#define PSDIR "/usr/local/share/doc/coreutils"
|
||||||
#define LIBDIR "/data/coreutils/lib"
|
#define LIBDIR "/usr/local/lib"
|
||||||
#define LISPDIR "/data/coreutils/share/emacs/site-lisp"
|
#define LISPDIR "/usr/local/share/emacs/site-lisp"
|
||||||
#define LOCALEDIR "/data/coreutils/share/locale"
|
#define LOCALEDIR "/usr/local/share/locale"
|
||||||
#define MANDIR "/data/coreutils/share/man"
|
#define MANDIR "/usr/local/share/man"
|
||||||
#define PKGDATADIR "/data/coreutils/share/coreutils"
|
#define PKGDATADIR "/usr/local/share/coreutils"
|
||||||
#define PKGINCLUDEDIR "/data/coreutils/include/coreutils"
|
#define PKGINCLUDEDIR "/usr/local/include/coreutils"
|
||||||
#define PKGLIBDIR "/data/coreutils/lib/coreutils"
|
#define PKGLIBDIR "/usr/local/lib/coreutils"
|
||||||
#define PKGLIBEXECDIR "/data/coreutils/libexec/coreutils"
|
#define PKGLIBEXECDIR "/usr/local/libexec/coreutils"
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user