ZOOM: resultset setname managed by ODR
[yaz-moved-to-github.git] / src / atoin.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
5
6 /**
7  * \file atoin.c
8  * \brief Implements atoi_n function.
9  */
10
11 #if HAVE_CONFIG_H
12 #include <config.h>
13 #endif
14
15 #include <string.h>
16 #include <yaz/marcdisp.h>
17 #include <yaz/yaz-iconv.h>
18
19 int atoi_n(const char *buf, int len)
20 {
21     int val = 0;
22
23     while (--len >= 0)
24     {
25         if (yaz_isdigit(*buf))
26             val = val*10 + (*buf - '0');
27         buf++;
28     }
29     return val;
30 }
31
32 int atoi_n_check(const char *buf, int size, int *val)
33 {
34     int i;
35     for (i = 0; i < size; i++)
36         if (!yaz_isdigit(buf[i]))
37             return 0;
38     *val = atoi_n(buf, size);
39     return 1;
40 }
41
42 /*
43  * Local variables:
44  * c-basic-offset: 4
45  * c-file-style: "Stroustrup"
46  * indent-tabs-mode: nil
47  * End:
48  * vim: shiftwidth=4 tabstop=8 expandtab
49  */
50