Date: Mon, 9 May 2011 11:11:41 -0600 From: Warner Losh <imp@bsdimp.com> To: Jilles Tjoelker <jilles@stack.nl> Cc: freebsd-rc@FreeBSD.org Subject: Re: [PATCH] Use printf(1) builtin for hexprint function in etc/network.subr Message-ID: <92B456D2-9EF2-4F1A-8F06-8FFBB44F59B5@bsdimp.com> In-Reply-To: <20110508123745.GA83320@stack.nl> References: <20110508123745.GA83320@stack.nl>
next in thread | previous in thread | raw e-mail | index | archive | help
Isn't printf located in /usr, and isn't /usr not guaranteed to be around = when these routines are used? Warner On May 8, 2011, at 6:37 AM, Jilles Tjoelker wrote: > Now that printf(1) is a shell builtin, there is no need to emulate it > anymore. >=20 > It may be faster to use printf directly but the function is useful for > compatibility. >=20 > Index: etc/network.subr > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- etc/network.subr (revision 220966) > +++ etc/network.subr (working copy) > @@ -1333,38 +1333,14 @@ > # Echo decimal number $arg (single digit) in hexadecimal format. > hexdigit() > { > - if [ $1 -lt 10 ]; then > - echo $1 > - else > - case $1 in > - 10) echo a ;; > - 11) echo b ;; > - 12) echo c ;; > - 13) echo d ;; > - 14) echo e ;; > - 15) echo f ;; > - esac > - fi > + printf '%x\n' "$1" > } >=20 > # hexprint arg > # Echo decimal number $arg (multiple digits) in hexadecimal = format. > hexprint() > { > - local val str dig > - val=3D$1 > - str=3D'' > - dig=3D`hexdigit $((${val} & 15))` > - str=3D${dig}${str} > - val=3D$((${val} >> 4)) > - > - while [ ${val} -gt 0 ]; do > - dig=3D`hexdigit $((${val} & 15))` > - str=3D${dig}${str} > - val=3D$((${val} >> 4)) > - done > - > - echo ${str} > + printf '%x\n' "$1" > } >=20 > is_wired_interface() >=20 > --=20 > Jilles Tjoelker > _______________________________________________ > freebsd-rc@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-rc > To unsubscribe, send any mail to "freebsd-rc-unsubscribe@freebsd.org" >=20 >=20
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?92B456D2-9EF2-4F1A-8F06-8FFBB44F59B5>