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