X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fatoin.c;h=9ae0d4f6c4b5495e9e09298bb306831357df3eb9;hb=a3e65bcd3250b107397675bc65b35b5939355025;hp=d7104d9d46b4cd394a33f29780862704eb134d3c;hpb=88d3bedf772316f87e1996f655ccf8d1e2589755;p=yaz-moved-to-github.git diff --git a/src/atoin.c b/src/atoin.c index d7104d9..9ae0d4f 100644 --- a/src/atoin.c +++ b/src/atoin.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2010 Index Data + * Copyright (C) 1995-2012 Index Data * See the file LICENSE for details. */ @@ -13,25 +13,32 @@ #endif #include -#include #include +#include -/** - * atoi_n: like atoi but reads at most len characters. - */ -int atoi_n (const char *buf, int len) +int atoi_n(const char *buf, int len) { int val = 0; while (--len >= 0) { - if (isdigit (*(const unsigned char *) buf)) + if (yaz_isdigit(*buf)) val = val*10 + (*buf - '0'); buf++; } return val; } +int atoi_n_check(const char *buf, int size, int *val) +{ + int i; + for (i = 0; i < size; i++) + if (!yaz_isdigit(buf[i])) + return 0; + *val = atoi_n(buf, size); + return 1; +} + /* * Local variables: * c-basic-offset: 4