On 12.03.2018 21:12, Daniel P. Berrangé wrote: > From: "Daniel P. Berrange" <berra...@redhat.com> > > There are qemu_strtoNN functions for various sized integers. This adds two > more for plain int & unsigned int types, with suitable range checking. >
There is a prior art in NetBSD with strtoi(3) and strtou(3). http://netbsd.gw.com/cgi-bin/man-cgi?strtoi++NetBSD-current http://netbsd.gw.com/cgi-bin/man-cgi?strtou++NetBSD-current This is a clean room alternative for strtonum(3) with compat with some other OSes. The original code is in: https://github.com/NetBSD/src/blob/trunk/common/lib/libc/stdlib/ It uses a wrapper for regular strtol(3)-like functions and strtol_l(3). A simpler strtoi(3) wrapper is used in dhcpcd: https://github.com/NetBSD/src/blob/trunk/external/bsd/dhcpcd/dist/compat/ It has one difference compared to new POSIX (release 2016 or so) - no conversion at all is ECANCELED, not EINVAL. I think ECANCELED makes more sense and is distinguishable with input base error, and should be preserved.
Description: OpenPGP digital signature