YAZ 5.35.1
atoin.c
Go to the documentation of this file.
1/* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
4 */
5
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
19int 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
32int 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
int atoi_n_check(const char *buf, int size, int *val)
like atoi_n but checks for proper formatting
Definition atoin.c:32
int atoi_n(const char *buf, int len)
like atoi(3) except that it reads exactly len characters
Definition atoin.c:19
MARC conversion.
Header for YAZ iconv interface.
#define yaz_isdigit(x)
Definition yaz-iconv.h:86