4 ms·
NetBSD's strtoi and strtoimax seem like the better alternative to strtonum. 1. It is defined for intmax_t instead of long long. 2. It supports various bases.
by fafner 12y ago
NetBSD's strtoi and strtoimax seem like the better alternative to strtonum.
1. It is defined for intmax_t instead of long long.
2. It supports various bases. (At least I regularly need hex or base36)
3. It can deal with trailing characters.
4. There are matching strtou and strtoumax operations
It's of course bad if NetBSD introduces an strtonum, which behaves differently from the OpenBSD one. But maybe the OpenBSD folks should look into strtoi and strtoimax instead of blindly following their "invented here" principle...
- darklajid 12y agoThat's basically all mentioned in his post about the design [1] from 2011 and he seems to dismiss all these cases. Is that reasonable? No clue, I don't write/know/do C.. 1: http://www.tedunangst.com/flak/post/the-design-of-strtonum http://www.tedunangst.com/flak/post/the-design-of-strtonum
- fafner 12y agoI don't think it's reasonable. The way they implemented strtonum might match their particular use case in OpenSSH/LibreSSL. But if they want to make it a libc function and popularise it then they should concern themselves with other use cases and opinions, especially when they pick a bold name as strtonum. It's not a surprising outcome that others are reluctant to follow them and they have clashes in behaviour or naming.