X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fatoin.c;h=50a8381f8a806bb860a324ea71947bed75c67419;hp=7460220f7156f7cfb0e0668054de63a9aeb0a37f;hb=1fbd038d97d6e1bfe97270ecc17cca123bcc435c;hpb=379504a233e3e2cc85bca1e7b6d864f1395aec7c diff --git a/src/atoin.c b/src/atoin.c index 7460220..50a8381 100644 --- a/src/atoin.c +++ b/src/atoin.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2009 Index Data + * Copyright (C) 1995-2011 Index Data * See the file LICENSE for details. */ @@ -16,22 +16,29 @@ #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 (isdigit(*(const unsigned char *) 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 (!isdigit(i[(const unsigned char *) buf])) + return 0; + *val = atoi_n(buf, size); + return 1; +} + /* * Local variables: * c-basic-offset: 4