Buffer overflow fix
[yaz-moved-to-github.git] / util / atoin.c
1 /*
2  * Copyright (c) 1997, Index Data
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: atoin.c,v $
7  * Revision 1.4  2002-08-26 09:25:56  adam
8  * Buffer overflow fix
9  *
10  * Revision 1.3  2000/02/29 13:44:55  adam
11  * Check for config.h (currently not generated).
12  *
13  * Revision 1.2  1999/11/30 13:47:12  adam
14  * Improved installation. Moved header files to include/yaz.
15  *
16  * Revision 1.1  1997/09/04 07:52:27  adam
17  * Moved atoi_n function to separate source file.
18  *
19  */
20
21 #if HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #include <string.h>
26 #include <ctype.h>
27 #include <yaz/yaz-util.h>
28
29 int atoi_n (const char *buf, int len)
30 {
31     int val = 0;
32
33     while (--len >= 0)
34     {
35         if (isdigit (*buf))
36             val = val*10 + (*buf - '0');
37         buf++;
38     }
39     return val;
40 }
41
42 /*
43   UCS-4 <- ISO-8859-1
44   (unsigned long) ch = ch & 255;
45
46   ISO-8859-1 -> UCS-4
47   if (ch > 255)
48       invalid sequence
49   else
50       ch = ch;
51
52   UCS-4 -> UTF-8
53   if (ch <= 0x7f)
54       ch = ch;
55   else if c(h <= 0x7ff)
56   {
57       str[0] = 0xc0 + (ch & (0xff < 6));
58       str[1] = 0x80 + ch & 0x7ff;
59   }
60   else if (ch <= 0xffff)
61   {
62
63
64
65   }
66
67
68
69 */ 
70   
71