xbps-src: abstract away non-portable stat(1)

This implements semi-portable abstractions for both GNU and BSD
flavors of stat.
This commit is contained in:
q66 2023-09-11 04:30:55 +02:00 committed by Đoàn Trần Công Danh
parent 4349108b68
commit 937272e967
6 changed files with 43 additions and 7 deletions

View file

@ -1,5 +1,41 @@
# vim: set ts=4 sw=4 et:
# A portable abstraction for stat(1)
#
# The stat(1) command has different syntaxes between GNU flavor
# and BSD flavor; implementations generally follow one or the other
#
if ! stat -c "%s" / > /dev/null 2>&1; then
# BSD stat
stat_size() {
stat -f %z "$1"
}
stat_inode() {
stat -f %i "$1"
}
stat_mtime() {
stat -f %m "$1"
}
else
# GNU stat
stat_size() {
stat -c %s "$1"
}
stat_inode() {
stat -c %i "$1"
}
stat_mtime() {
stat -c %Y "$1"
}
fi
run_func() {
local func="$1" desc="$2" funcname="$3" restoretrap= logpipe= logfile= teepid=