tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: strtonum(3) from OpenBSD?



On Thu, Aug 06, 2009 at 11:38:18PM +0200, Marc Balmer wrote:
> you missed to read my answer to Thor's mail before mailing me this, I  
> guess.  if strtonum is consider a repetition of the strsuftoll mistake, 
> we could think of an API that resolves the mistake.

There is not much that can be done to improve on the basic strtol,
which also has the advantage of being standard.

Maybe

   size_t strfindinteger(const char *str, int base);
   int strreadint(const char *str, int base, int *result);
   int strnreadint(const char *str, size_t len, int base, int *result);
   int strreadlong(const char *str, int base, long *result);
   int strnreadlong(const char *str, size_t len, int base, long *result);
         :

etc. where the "find" function is a juiced-up strspn and the read
functions convert (possibly bounded) integer text that's already been
found into a value, and return either 0 or -1.

The basic trouble arises from trying to pack too much in while
retaining the simple API concept of atoi().

-- 
David A. Holland
dholland%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index