Code

22c404f960cb4e15794fd37449c6d3b700d869ce
[pkg-rrdtool.git] / src / rrd_tool.h
1 /*****************************************************************************
2  * RRDtool 1.2.27  Copyright by Tobi Oetiker, 1997-2008
3  *****************************************************************************
4  * rrd_tool.h   Common Header File
5  *****************************************************************************/
6 #ifdef  __cplusplus
7 extern "C" {
8 #endif
11 #ifndef _RRD_TOOL_H
12 #define _RRD_TOOL_H
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
20 #ifdef MUST_DISABLE_SIGFPE
21 #include <signal.h>
22 #endif
24 #ifdef MUST_DISABLE_FPMASK
25 #include <floatingpoint.h>
26 #endif
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <errno.h>
31 #include <string.h>
32 #include <ctype.h>
34 #if HAVE_SYS_PARAM_H
35 #  include <sys/param.h>
36 #endif
38 #ifndef MAXPATH
39 #  define MAXPATH 1024
40 #endif
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 */
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
66 #if HAVE_SYS_TYPES_H
67 # include <sys/types.h>
68 #endif
70 #if HAVE_SYS_STAT_H
71 # include <sys/stat.h>
72 #endif
74 #if HAVE_STRINGS_H
75 # include <strings.h>
76 #endif
78 #include "rrd.h"
80 #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
82 /* Win32 only includes */
84 #include <float.h>        /* for _isnan  */
85 #include <io.h>           /* for chdir   */
87 struct tm* localtime_r(const time_t *timep, struct tm* result);
88 char* ctime_r(const time_t *timep, char* result);
89 struct tm* gmtime_r(const time_t *timep, struct tm* result);
90 char *strtok_r(char *str, const char *sep, char **last);
92 #else
94 /* unix-only includes */
95 #if !defined isnan && !defined HAVE_ISNAN
96 int isnan(double value);
97 #endif
99 #endif
101 /* local include files -- need to be after the system ones */
102 #include "rrd_getopt.h"
103 #include "rrd_format.h"
105 #ifndef max
106 #define max(a,b) ((a) > (b) ? (a) : (b))
107 #endif
109 #ifndef min
110 #define min(a,b) ((a) < (b) ? (a) : (b))
111 #endif                                                   
113 #define DIM(x) (sizeof(x)/sizeof(x[0]))
115 /* rrd info interface */
116 enum info_type   { RD_I_VAL=0,
117                RD_I_CNT,
118                RD_I_STR, 
119                    RD_I_INT };
121 typedef union infoval { 
122     unsigned long u_cnt; 
123     rrd_value_t   u_val;
124     char         *u_str;
125     int           u_int;
126 } infoval;
128 typedef struct info_t {
129     char            *key;
130     enum info_type  type;
131     union infoval   value;
132     struct info_t   *next;
133 } info_t;
135 info_t *rrd_info(int, char **);
136 int rrd_lastupdate(int argc, char **argv, time_t *last_update,
137                 unsigned long *ds_cnt, char ***ds_namv, char ***last_ds);
138 info_t *rrd_update_v(int, char **);
139 char * sprintf_alloc(char *, ...);
140 info_t *info_push(info_t *, char *, enum info_type, infoval);
142 /* HELPER FUNCTIONS */
144 int PngSize(FILE *, long *, long *);
146 int rrd_create_fn(const char *file_name, rrd_t *rrd);
147 int rrd_fetch_fn(const char *filename, enum cf_en cf_idx,
148                  time_t *start,time_t *end,
149                  unsigned long *step,
150                  unsigned long *ds_cnt,
151                  char        ***ds_namv,
152                  rrd_value_t **data);
154 void rrd_free(rrd_t *rrd);
155 void rrd_freemem(void *mem);
156 void rrd_init(rrd_t *rrd);
158 int rrd_open(const char *file_name, FILE **in_file, rrd_t *rrd, int rdwr);
159 int readfile(const char *file, char **buffer, int skipfirst);
161 #define RRD_READONLY    0
162 #define RRD_READWRITE   1
164 enum cf_en cf_conv(const char *string);
165 enum dst_en dst_conv(char *string);
166 long ds_match(rrd_t *rrd,char *ds_nam);
167 double rrd_diff(char *a, char *b);
169     /* rrd_strerror is thread safe, but still it uses a global buffer
170        (but one per thread), thus subsequent calls within a single
171        thread overwrite the same buffer */
172 const char *rrd_strerror(int err);
174 #endif
176 #ifdef  __cplusplus
178 #endif