Code

Imported upstream version 1.2.26
[pkg-rrdtool.git] / src / rrd_tool.h
1 /*****************************************************************************
2  * RRDtool 1.2.26  Copyright by Tobi Oetiker, 1997-2007
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_UNISTD_H
75 # include <unistd.h>
76 #endif
78 #if HAVE_STRINGS_H
79 # include <strings.h>
80 #endif
82 #if TIME_WITH_SYS_TIME
83 # include <sys/time.h>
84 # include <time.h>
85 #else
86 # if HAVE_SYS_TIME_H
87 #  include <sys/time.h>
88 # else
89 #  include <time.h>
90 # endif
91 #endif
93 #if HAVE_SYS_TIMES_H
94 # include <sys/times.h>
95 #endif
98 #if HAVE_SYS_RESOURCE_H
99 # include <sys/resource.h>
100 #if (defined(__svr4__) && defined(__sun__))
101 /* Solaris headers (pre 2.6) don't have a getrusage prototype.
102    Use this instead. */
103 extern int getrusage(int, struct rusage *);
104 #endif /* __svr4__ && __sun__ */
105 #endif
107 #include "rrd.h"
109 #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
111 /* Win32 only includes */
113 #include <float.h>        /* for _isnan  */
114 #include <io.h>           /* for chdir   */
116 struct tm* localtime_r(const time_t *timep, struct tm* result);
117 char* ctime_r(const time_t *timep, char* result);
118 struct tm* gmtime_r(const time_t *timep, struct tm* result);
119 char *strtok_r(char *str, const char *sep, char **last);
121 #else
123 /* unix-only includes */
124 #if !defined isnan && !defined HAVE_ISNAN
125 int isnan(double value);
126 #endif
128 #endif
130 /* local include files -- need to be after the system ones */
131 #include "rrd_getopt.h"
132 #include "rrd_format.h"
134 #ifndef max
135 #define max(a,b) ((a) > (b) ? (a) : (b))
136 #endif
138 #ifndef min
139 #define min(a,b) ((a) < (b) ? (a) : (b))
140 #endif                                                   
142 #define DIM(x) (sizeof(x)/sizeof(x[0]))
144 /* rrd info interface */
145 enum info_type   { RD_I_VAL=0,
146                RD_I_CNT,
147                RD_I_STR, 
148                    RD_I_INT };
150 typedef union infoval { 
151     unsigned long u_cnt; 
152     rrd_value_t   u_val;
153     char         *u_str;
154     int           u_int;
155 } infoval;
157 typedef struct info_t {
158     char            *key;
159     enum info_type  type;
160     union infoval   value;
161     struct info_t   *next;
162 } info_t;
164 info_t *rrd_info(int, char **);
165 int rrd_lastupdate(int argc, char **argv, time_t *last_update,
166                 unsigned long *ds_cnt, char ***ds_namv, char ***last_ds);
167 info_t *rrd_update_v(int, char **);
168 char * sprintf_alloc(char *, ...);
169 info_t *info_push(info_t *, char *, enum info_type, infoval);
171 /* HELPER FUNCTIONS */
173 int PngSize(FILE *, long *, long *);
175 int rrd_create_fn(const char *file_name, rrd_t *rrd);
176 int rrd_fetch_fn(const char *filename, enum cf_en cf_idx,
177                  time_t *start,time_t *end,
178                  unsigned long *step,
179                  unsigned long *ds_cnt,
180                  char        ***ds_namv,
181                  rrd_value_t **data);
183 void rrd_free(rrd_t *rrd);
184 void rrd_freemem(void *mem);
185 void rrd_init(rrd_t *rrd);
187 int rrd_open(const char *file_name, FILE **in_file, rrd_t *rrd, int rdwr);
188 int readfile(const char *file, char **buffer, int skipfirst);
190 #define RRD_READONLY    0
191 #define RRD_READWRITE   1
193 enum cf_en cf_conv(const char *string);
194 enum dst_en dst_conv(char *string);
195 long ds_match(rrd_t *rrd,char *ds_nam);
196 double rrd_diff(char *a, char *b);
198     /* rrd_strerror is thread safe, but still it uses a global buffer
199        (but one per thread), thus subsequent calls within a single
200        thread overwrite the same buffer */
201 const char *rrd_strerror(int err);
203 #endif
205 #ifdef  __cplusplus
207 #endif