1 /*****************************************************************************
2  * RRDtool 1.2.30  Copyright by Tobi Oetiker, 1997-2009
3  *****************************************************************************
4  * rrd_tool.h   Common Header File
5  *****************************************************************************/
6 #ifdef  __cplusplus
7 extern "C" {
8 #endif
9 
10 
11 #ifndef _RRD_TOOL_H
12 #define _RRD_TOOL_H
13 
14 #ifdef HAVE_CONFIG_H
15 #include "../rrd_config.h"
16 #elif defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
17 #include "../win32/config.h"
18 #endif
19 
20 #ifdef MUST_DISABLE_SIGFPE
21 #include <signal.h>
22 #endif
23 
24 #ifdef MUST_DISABLE_FPMASK
25 #include <floatingpoint.h>
26 #endif
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <errno.h>
31 #include <string.h>
32 #include <ctype.h>
33 
34 #if HAVE_SYS_PARAM_H
35 #  include <sys/param.h>
36 #endif
37 
38 #ifndef MAXPATH
39 #  define MAXPATH 1024
40 #endif
41 
42 #if HAVE_MATH_H
43 # include <math.h>
44 #endif
45 /* Sorry: don't know autoconf as well how to check the exist of
46    dirent.h ans sys/stat.h
47 */
48 
49 #if HAVE_DIRENT_H
50 # include <dirent.h>
51 # define NAMLEN(dirent) strlen((dirent)->d_name)
52 #else
53 # define dirent direct
54 # define NAMLEN(dirent) (dirent)->d_namlen
55 # if HAVE_SYS_NDIR_H
56 #  include <sys/ndir.h>
57 # endif
58 # if HAVE_SYS_DIR_H
59 #  include <sys/dir.h>
60 # endif
61 # if HAVE_NDIR_H
62 #  include <ndir.h>
63 # endif
64 #endif
65 
66 #if HAVE_SYS_TYPES_H
67 # include <sys/types.h>
68 #endif
69 
70 #if HAVE_SYS_STAT_H
71 # include <sys/stat.h>
72 #endif
73 
74 #if HAVE_STRINGS_H
75 # include <strings.h>
76 #endif
77 
78 #include "rrd.h"
79 
80 #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
81 
82 /* Win32 only includes */
83 
84 #include <float.h>        /* for _isnan  */
85 #include <io.h>           /* for chdir   */
86 #include <process.h>      /* for getpid  */
87 
88 #define random rand
89 #define srandom srand
90 
91 struct tm* localtime_r(const time_t *timep, struct tm* result);
92 char* ctime_r(const time_t *timep, char* result);
93 struct tm* gmtime_r(const time_t *timep, struct tm* result);
94 char *strtok_r(char *str, const char *sep, char **last);
95 
96 #else
97 
98 /* unix-only includes */
99 #if !defined isnan && !defined HAVE_ISNAN
100 int isnan(double value);
101 #endif
102 
103 #endif
104 
105 /* local include files -- need to be after the system ones */
106 #include "rrd_getopt.h"
107 #include "rrd_format.h"
108 
109 #ifndef max
110 #define max(a,b) ((a) > (b) ? (a) : (b))
111 #endif
112 
113 #ifndef min
114 #define min(a,b) ((a) < (b) ? (a) : (b))
115 #endif
116 
117 #define DIM(x) (sizeof(x)/sizeof(x[0]))
118 
119 /* rrd info interface */
120 enum info_type   { RD_I_VAL=0,
121 	       RD_I_CNT,
122 	       RD_I_STR,
123 		   RD_I_INT };
124 
125 typedef union infoval {
126     unsigned long u_cnt;
127     rrd_value_t   u_val;
128     char         *u_str;
129     int		  u_int;
130 } infoval;
131 
132 typedef struct info_t {
133     char            *key;
134     enum info_type  type;
135     union infoval   value;
136     struct info_t   *next;
137 } info_t;
138 
139 info_t *rrd_info(int, char **);
140 int rrd_lastupdate(int argc, char **argv, time_t *last_update,
141                 unsigned long *ds_cnt, char ***ds_namv, char ***last_ds);
142 info_t *rrd_update_v(int, char **);
143 char * sprintf_alloc(char *, ...);
144 info_t *info_push(info_t *, char *, enum info_type, infoval);
145 
146 /* HELPER FUNCTIONS */
147 
148 int PngSize(FILE *, long *, long *);
149 
150 int rrd_create_fn(const char *file_name, rrd_t *rrd);
151 int rrd_fetch_fn(const char *filename, enum cf_en cf_idx,
152 		 time_t *start,time_t *end,
153 		 unsigned long *step,
154 		 unsigned long *ds_cnt,
155 		 char        ***ds_namv,
156 		 rrd_value_t **data);
157 
158 void rrd_free(rrd_t *rrd);
159 void rrd_freemem(void *mem);
160 void rrd_init(rrd_t *rrd);
161 
162 int rrd_open(const char *file_name, FILE **in_file, rrd_t *rrd, int rdwr);
163 int readfile(const char *file, char **buffer, int skipfirst);
164 
165 #define RRD_READONLY    0
166 #define RRD_READWRITE   1
167 
168 enum cf_en cf_conv(const char *string);
169 enum dst_en dst_conv(char *string);
170 long ds_match(rrd_t *rrd,char *ds_nam);
171 double rrd_diff(char *a, char *b);
172 
173     /* rrd_strerror is thread safe, but still it uses a global buffer
174        (but one per thread), thus subsequent calls within a single
175        thread overwrite the same buffer */
176 const char *rrd_strerror(int err);
177 
178 #endif
179 
180 #ifdef  __cplusplus
181 }
182 #endif
183