mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-21 00:27:09 +02:00
lib.sh: check args for errors in fx_ and dx_
check that there are at least two arguments, and ensure that they are not empty. Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -130,6 +130,7 @@ unpad_one_byte()
|
|||||||
|
|
||||||
fx_()
|
fx_()
|
||||||
{
|
{
|
||||||
|
xchk fx_ "$@"
|
||||||
fd="$(mktemp || err "can't create tmpfile")" || err
|
fd="$(mktemp || err "can't create tmpfile")" || err
|
||||||
x_ rm -f "$fd" && x_ touch "$fd"
|
x_ rm -f "$fd" && x_ touch "$fd"
|
||||||
xx="$1" && shift 1
|
xx="$1" && shift 1
|
||||||
@@ -140,6 +141,7 @@ fx_()
|
|||||||
|
|
||||||
dx_()
|
dx_()
|
||||||
{
|
{
|
||||||
|
xchk dx_ "$@"
|
||||||
[ ! -f "$2" ] || while read -r fx; do
|
[ ! -f "$2" ] || while read -r fx; do
|
||||||
$1 "$fx" || return 1; :
|
$1 "$fx" || return 1; :
|
||||||
done < "$2" || err "dx_ $*: cannot read '$2'"; :
|
done < "$2" || err "dx_ $*: cannot read '$2'"; :
|
||||||
@@ -151,6 +153,25 @@ x_()
|
|||||||
[ $# -lt 1 ] || "$@" || err "Unhandled error for: $(echo "$@")"; :
|
[ $# -lt 1 ] || "$@" || err "Unhandled error for: $(echo "$@")"; :
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xchk()
|
||||||
|
{
|
||||||
|
[ $# -lt 3 ] && err "$1 needs at least two arguments: $(xprintf "$@")"
|
||||||
|
if [ -z "$2" ] || [ -z "$3" ]; then
|
||||||
|
err "arguments must not be empty in $1: \"$2\" \"$3\" "
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
xprintf()
|
||||||
|
{
|
||||||
|
xprintfargs=0
|
||||||
|
while [ $# -gt 0 ]; do
|
||||||
|
printf "\"%s\"" "$1"
|
||||||
|
xprintfargs=1
|
||||||
|
shift 1
|
||||||
|
done
|
||||||
|
[ $xprintfargs -gt 0 ] && printf "\n"; :
|
||||||
|
}
|
||||||
|
|
||||||
err()
|
err()
|
||||||
{
|
{
|
||||||
[ $# -lt 1 ] || printf "ERROR %s: %s\n" "$0" "$1" 1>&2 || :
|
[ $# -lt 1 ] || printf "ERROR %s: %s\n" "$0" "$1" 1>&2 || :
|
||||||
|
|||||||
Reference in New Issue
Block a user