strtonum(3)

看板DFBSD_submit作者時間21年前 (2004/07/25 21:32), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/8 (看更多)
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/
文章代碼(AID): #110xPY00 (DFBSD_submit)
文章代碼(AID): #110xPY00 (DFBSD_submit)