DragonFly BSD
DragonFly submit List (threaded) for 2004-07
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

strtonum(3)


From: "Andre Nathan" <andre@xxxxxxxxxxxxxxx>
Date: Sun, 25 Jul 2004 02:16:59 -0300 (BRT)

Hello

The patches at [1] add the strtonum(3) function (an OpenBSD extension) to
DragonFly. It is meant to be an easy and safe to use replacement for
strtoul(3) and the like. From the manual page:

"Using strtonum() correctly is meant to be simpler than the alternative
functions.

  int iterations;
  const char *errstr;

  iterations = strtonum(optarg, 1, 64, &errstr);
  if (errstr)
      errx(1, "number of iterations is %s: %s", errstr, optarg);

The above example will guarantee that the value of iterations is between 1
and 64.

[...]

The existing alternatives, such as atoi(3) and strtol(3) are either
impossible or difficult to use safely."

The code from OpenBSD was not modified apart from really minor style changes.

I'll submit patches for some userland programs to use this function later
if it is commited.

Best regards,
Andre

[1]http://andre.people.digirati.com.br/bsd/dragonfly/patches/strtonum/



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