X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fatoin.c;h=50a8381f8a806bb860a324ea71947bed75c67419;hb=7bfdd9cdcbfd12d6690278c9b56a7ac26b2457e9;hp=e7718c5797de6e45cae412325a4f5337317078ec;hpb=ee6ab2ee3a9ee1a8c65d7272ec7fba1d886f5af0;p=yaz-moved-to-github.git diff --git a/src/atoin.c b/src/atoin.c index e7718c5..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-2008 Index Data + * Copyright (C) 1995-2011 Index Data * See the file LICENSE for details. */ @@ -16,25 +16,33 @@ #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 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab