f8ab9c48d0fa4e036fb76e7c89c4b64148ba4d0c
1 /*****************************************************************************
2 * RRDtool 1.2.23 Copyright by Tobi Oetiker, 1997-2007
3 *****************************************************************************
4 * rrd_tool.h Common Header File
5 *****************************************************************************/
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
10 #ifndef _RRD_TOOL_H
11 #define _RRD_TOOL_H
13 #ifdef HAVE_CONFIG_H
14 #include "../rrd_config.h"
15 #elif defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
16 #include "../win32/config.h"
17 #endif
19 #include "rrd.h"
21 #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
23 /* Win32 only includes */
25 #include <float.h> /* for _isnan */
26 #include <io.h> /* for chdir */
28 struct tm* localtime_r(const time_t *timep, struct tm* result);
29 char* ctime_r(const time_t *timep, char* result);
30 struct tm* gmtime_r(const time_t *timep, struct tm* result);
31 char *strtok_r(char *str, const char *sep, char **last);
33 #else
35 /* unix-only includes */
36 #if !defined isnan && !defined HAVE_ISNAN
37 int isnan(double value);
38 #endif
40 #endif
42 /* local include files -- need to be after the system ones */
43 #include "rrd_getopt.h"
44 #include "rrd_format.h"
46 #ifndef max
47 #define max(a,b) ((a) > (b) ? (a) : (b))
48 #endif
50 #ifndef min
51 #define min(a,b) ((a) < (b) ? (a) : (b))
52 #endif
54 #define DIM(x) (sizeof(x)/sizeof(x[0]))
56 /* rrd info interface */
57 enum info_type { RD_I_VAL=0,
58 RD_I_CNT,
59 RD_I_STR,
60 RD_I_INT };
62 typedef union infoval {
63 unsigned long u_cnt;
64 rrd_value_t u_val;
65 char *u_str;
66 int u_int;
67 } infoval;
69 typedef struct info_t {
70 char *key;
71 enum info_type type;
72 union infoval value;
73 struct info_t *next;
74 } info_t;
76 info_t *rrd_info(int, char **);
77 int rrd_lastupdate(int argc, char **argv, time_t *last_update,
78 unsigned long *ds_cnt, char ***ds_namv, char ***last_ds);
79 info_t *rrd_update_v(int, char **);
80 char * sprintf_alloc(char *, ...);
81 info_t *info_push(info_t *, char *, enum info_type, infoval);
83 /* HELPER FUNCTIONS */
85 int PngSize(FILE *, long *, long *);
87 int rrd_create_fn(const char *file_name, rrd_t *rrd);
88 int rrd_fetch_fn(const char *filename, enum cf_en cf_idx,
89 time_t *start,time_t *end,
90 unsigned long *step,
91 unsigned long *ds_cnt,
92 char ***ds_namv,
93 rrd_value_t **data);
95 void rrd_free(rrd_t *rrd);
96 void rrd_freemem(void *mem);
97 void rrd_init(rrd_t *rrd);
99 rrd_file_t* rrd_open(const char * const file_name, rrd_t *rrd, unsigned rdwr);
100 int rrd_close(rrd_file_t* rrd_file);
101 ssize_t rrd_read(rrd_file_t* rrd_file, void*buf, size_t count);
102 ssize_t rrd_write(rrd_file_t* rrd_file, const void*buf, size_t count);
103 void rrd_flush(rrd_file_t* rrd_file);
104 off_t rrd_seek(rrd_file_t* rrd_file, off_t off, int whence);
105 off_t rrd_tell(rrd_file_t* rrd_file);
106 int readfile(const char *file, char **buffer, int skipfirst);
108 #define RRD_READONLY 0
109 #define RRD_READWRITE 1
110 #define RRD_CREAT 2
112 enum cf_en cf_conv(const char *string);
113 enum dst_en dst_conv(char *string);
114 long ds_match(rrd_t *rrd,char *ds_nam);
115 double rrd_diff(char *a, char *b);
117 /* rrd_strerror is thread safe, but still it uses a global buffer
118 (but one per thread), thus subsequent calls within a single
119 thread overwrite the same buffer */
120 const char *rrd_strerror(int err);
122 #endif
124 #ifdef __cplusplus
125 }
126 #endif