diff options
author | dteske <dteske@FreeBSD.org> | 2016-02-03 00:51:38 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2016-02-03 00:51:38 +0000 |
commit | 5f95bf68114f2eb19fc30a8fb38352f8e0135f2a (patch) | |
tree | 23066f472ec6bdb5de172f28e4dfebe899f7db60 | |
parent | e5ae512d17e6046ae62a9952cb51217771139be4 (diff) | |
download | FreeBSD-src-5f95bf68114f2eb19fc30a8fb38352f8e0135f2a.zip FreeBSD-src-5f95bf68114f2eb19fc30a8fb38352f8e0135f2a.tar.gz |
Define f_sprintf() dynamically at inclusion time
No need to check/re-check capabilities that won't change at runtime.
-rw-r--r-- | usr.sbin/bsdconfig/share/strings.subr | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/usr.sbin/bsdconfig/share/strings.subr b/usr.sbin/bsdconfig/share/strings.subr index 1a4fe6e..f1dbbd7 100644 --- a/usr.sbin/bsdconfig/share/strings.subr +++ b/usr.sbin/bsdconfig/share/strings.subr @@ -154,20 +154,25 @@ f_substr() # Similar to sprintf(3), write a string into $var_to_set using printf(1) syntax # (`$format [$arguments ...]'). # -f_sprintf() -{ - local __var_to_set="$1" - shift 1 # var_to_set - - case "$BASH_VERSION" in - 3.1*|4.*) - local __tmp +case "$BASH_VERSION" in +3.1*|4.*) + f_sprintf() + { + local __var_to_set="$1" __tmp + shift 1 # var_to_set printf -v __tmp "$@" eval "$__var_to_set"=\"\${__tmp%\$NL}\" - ;; - *) eval "$__var_to_set"=\$\( printf -- \"\$@\" \) - esac -} + } + ;; +*) + # NB: On FreeBSD, sh(1) runs this faster than bash(1) runs the above + f_sprintf() + { + local __var_to_set="$1" + shift 1 # var_to_set + eval "$__var_to_set"=\$\( printf -- \"\$@\" \) + } +esac # f_vsprintf $var_to_set $format $format_args # |