X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fatoin.c;h=d22f84fabb012942af60a74aea0929743ba1e102;hp=e9b20e64be39078608bc7b28211c59ef5cf2c31f;hb=e7e9d6ab325472e8f103409f34ba853cdb314f2e;hpb=5475567b7f05fbc245cedb1b3ecdbc63ac671685 diff --git a/src/atoin.c b/src/atoin.c index e9b20e6..d22f84f 100644 --- a/src/atoin.c +++ b/src/atoin.c @@ -1,8 +1,6 @@ -/* - * Copyright (c) 1997-2004, Index Data +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2010 Index Data * See the file LICENSE for details. - * - * $Id: atoin.c,v 1.5 2004-12-16 08:59:56 adam Exp $ */ /** @@ -18,19 +16,35 @@ #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++; + 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 + */ +