X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fatoin.c;h=4ee031307476fb943f35ce16566360955755a114;hp=47f5cd84dc9159bfdb2a29affe771278594aa94e;hb=dd5e6e2ecc4d8d51095059c13ce725d263d99601;hpb=05c274ef315384faafcc5900c17468f0ea2474e6 diff --git a/src/atoin.c b/src/atoin.c index 47f5cd8..4ee0313 100644 --- a/src/atoin.c +++ b/src/atoin.c @@ -1,11 +1,9 @@ -/* - * Copyright (c) 1997-2004, Index Data +/* This file is part of the YAZ toolkit. + * Copyright (C) Index Data * See the file LICENSE for details. - * - * $Id: atoin.c,v 1.3 2004-10-15 00:18:59 adam Exp $ */ -/** +/** * \file atoin.c * \brief Implements atoi_n function. */ @@ -15,22 +13,38 @@ #endif #include -#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++; + 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 + * c-file-style: "Stroustrup" + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +