X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fatoin.c;h=29692a45baa01fd062ffcbb6a2dd4919f3111ca8;hb=3c287bc1d48ee6a1f300054c2cebd0ba312bd5b9;hp=0239f822562c62b7783902e085a269cb7a3e83d2;hpb=fb6d99a0c7e07d9cc4a315c447deaf6564a85505;p=yaz-moved-to-github.git diff --git a/src/atoin.c b/src/atoin.c index 0239f82..29692a4 100644 --- a/src/atoin.c +++ b/src/atoin.c @@ -1,8 +1,6 @@ -/* - * Copyright (C) 1995-2005, Index Data ApS +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2011 Index Data * See the file LICENSE for details. - * - * $Id: atoin.c,v 1.7 2005-06-25 15:46:03 adam Exp $ */ /** @@ -15,28 +13,36 @@ #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 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab