]> git.itanic.dy.fi Git - rrdd/blob - string.c
Use long long instead of ints when parsing cpu tics
[rrdd] / string.c
1 #include "string.h"
2
3 int dec_to_int(char *src, char **dst)
4 {
5         int ret;
6
7         while(((*src < '0') || (*src > '9')) && *src)
8                 src++;
9
10         ret = atoi(src);
11
12         if (dst) {
13                 while(((*src >= '0') && (*src <= '9')) && *src)
14                         src++;
15                 *dst = src;
16         }
17
18         return ret;
19 }
20
21 int dec_to_longlong(char *src, char **dst)
22 {
23         int ret;
24
25         while(((*src < '0') || (*src > '9')) && *src)
26                 src++;
27
28         ret = atoll(src);
29
30         if (dst) {
31                 while(((*src >= '0') && (*src <= '9')) && *src)
32                         src++;
33                 *dst = src;
34         }
35
36         return ret;
37 }
38
39 float dec_to_float(char *src, char **dst)
40 {
41         float ret;
42
43         while(((*src < '0') || (*src > '9')) && *src)
44                 src++;
45
46         ret = atof(src);
47
48         if (dst) {
49                 while((((*src >= '0') && (*src <= '9')) || (*src =='.')) && *src)
50                         src++;
51                 *dst = src;
52         }
53
54         return ret;
55 }
56
57 /*
58  * Copy white space separated stirng from *src to *word
59  *
60  * src:  source
61  * dst:  place where store the end of word pointer from source string
62  * word: destination where to copy the string
63  * size: maximum size of bytes to copy to the output buffer
64  *
65  * return the number of bytes copied
66  */
67
68 int get_word(char *src, char **dst, char *word, int size)
69 {
70         int ret = 0;
71         while(((*src == ' ') || (*src == '\t') || (*src == '\n')) && *src)
72                 src++;
73
74         while(((*src != ' ') && (*src != '\t') && (*src != '\n')) && *src && (ret < (size - 1))) {
75                 *word = *src;
76                 word++;
77                 src++;
78                 ret++;
79         }
80         *word = 0;
81
82         if (dst)
83                 *dst = src;
84
85         return ret;
86 }
87