Re: alx-0008 - Standardize strtoi(3) and strtou(3) from NetBSD
Alejandro Colomar <[email protected]> Thu, 20 Mar 2025 01:19:04 +0100
| Newsgroups | gmane.os.netbsd.devel.general |
|---|---|
| Message-ID | <vjwcgdc46zm7a2wp3smlvhjaalsc7pwywpgdktpgzgb7fgz7mz@sgc4rza73aju> |
--zi7jik3yn7fzerqs Content-Type: text/plain; protected-headers=v1; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable From: Alejandro Colomar <[email protected]> To: Thorsten Glaser <[email protected]> Cc: Bruno Haible <[email protected]>, [email protected], [email protected], [email protected], [email protected], christos <[email protected]>, =?utf-8?B?xJBvw6BuIFRy4bqnbiBDw7RuZw==?= Danh <[email protected]>, Paul Eggert <[email protected]>, Eli Schwartz <[email protected]>, Guillem Jover <[email protected]>, Iker Pedrosa <[email protected]>, Michael Vetter <[email protected]>, Robert Elz <[email protected]>, [email protected], Sam James <[email protected]>, "Serge E. Hallyn" <[email protected]> Subject: Re: alx-0008 - Standardize strtoi(3) and strtou(3) from NetBSD References: <mgcfwxfmv3kpfnkkf6uj63kx5tdzl64p2zg2us4ntsu6q5xkwj@k52z5yyiywoo> <3237498.fEcJ0Lxnt5@nimes> <jx4664ishtl34eg2npdrv5fkfdiczqnlq3vjuacjrupjvh377x@gddcftzgwmfq> <4085563.2iPT33SAM4@nimes> <x34jdlyb6gf6asojjhzwpol5schyz4llk2ebrtzpb7ryje52u6@smbvzpoqcf6v> <[email protected]> MIME-Version: 1.0 In-Reply-To: <[email protected]> Hi Thorsten, On Thu, Mar 20, 2025 at 12:52:07AM +0100, Thorsten Glaser wrote: > On Thu, 20 Mar 2025, Alejandro Colomar wrote: >=20 > >> At the same time, disallowing a leading '-' sign > >> is a benefit as well. I consider it a misfeature that strtoul() parses > >> "-3" successfully and returns ULONG_MAX-2, which was most certainly > >> not intended by the user. > > > >Agree; it is a misfeature. >=20 > What? >=20 > From a user=E2=80=99s PoV, this is hugely useful, and many other > read-unsigned-integer-value routines handle this similarily > (of course using whatever range they have) and C also defines > this, so from an implementor=E2=80=99s PoV this is no trouble. Can you clarify how this is useful as a programmer? I have replaced *all* calls to strtoul(3) et al. in shadow-utils by my strtou_noneg(), and never ever saw a valid use case of that feature. > The other user=E2=80=99s PoV thing would be to allow 0x prefixing, > but that needs an entire duplication of the inner loop, so > I can see why people would want to exclude that. I don't understand what you mean. strtou(3) supports 0x strings as long as you specify 0 or 16 as the base. alx@devuan:~/tmp$ cat hex.c=20 #include <bsd/inttypes.h> #include <stdio.h> int main(void) { int status, n; char *end; n =3D strtou("0xF", &end, 0, 0, 1000, &status); printf("%d\n", n); printf("%s\n", end); printf("%d\n", status); n =3D strtou("0xF", &end, 16, 0, 1000, &status); printf("%d\n", n); printf("%s\n", end); printf("%d\n", status); } alx@devuan:~/tmp$ gcc -Wall -Wextra hex.c -lbsd alx@devuan:~/tmp$ ./a.out=20 15 0 15 0 Have a lovely night! Alex --=20 <https://www.alejandro-colomar.es/> --zi7jik3yn7fzerqs Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmfbXvgACgkQ64mZXMKQ wqk1XBAAvJX3Tbse2eXWIu3xzIErfe4B/+X8u7VgbbZIJDIlIlOsvm51gIqqOfLx XuzbbQXbt80b2zMxa9aBwY5DZWDIeafn9x9ga5lUdmQt3vbz6VIAQSAM/ZHMiFxD bU/EKsiTNaXi0yp4CbiUzvTx+qjvIuzb7GOoeGpMxCQKWQkt83QM/MNxVyxRvbOl IZJfqnC+AFoOW1NMw8qJLyo9jZF1HSrxUYEbn+kmhl0uqEoXgZ3gnoMPIf8gw0XG c4ntrZttCksLffIx2MrX2KpsUVDtr3EE0s/yz+T1ZgI2zJ5iipFW/LJRyfUOpONn jWNdhmvuhR1QtBNCXi1XhMSBU3F8QngJzPPyGZurE77S4G9Rj0lEQSuUYT4CqqzS s7VODG5S3+gTLYRt0CWxAY9AJJXTkp5oEoOquP3kzhy6JhQe33+zqz2U4tyOkVqb yx/ieyMe5LojZGxR3aJ0xNkCgA6eOyZ4ynDC5Ax1+YzBGOOGu9N+eYR3bz/1rHda JV7HeaKW8XbQV86ViYZjI5PNNVjR9nxIgLDCupRE4BUFtPKu/pJ2AButukAh85yD HH2/wtV5sabaoN1x8RvbxziJ3A0k5OoOP4m3zmiOAT8UECBP/VfHCWXiwevWC/C6 eB9zkkievM+Ap11RLfxjNGaJg1ue4tS9MSb0vLEhth46+7wCuGc= =5nkI -----END PGP SIGNATURE----- --zi7jik3yn7fzerqs--