Compile time improvments for NetWare and Win32 -- Guenter Knauf gk.gknw.de
[rrdtool.git] / src / rrd_tool.h
1 /*****************************************************************************
2  * RRDtool 1.2.12  Copyright by Tobi Oetiker, 1997-2005
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 #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) && !defined(HAVE_CONFIG_H)
15 #include "../confignt/config.h"
16 #else
17 #ifdef HAVE_CONFIG_H
18 #include <config.h>
19 #endif
20 #endif
21
22 #ifdef MUST_DISABLE_SIGFPE
23 #include <signal.h>
24 #endif
25
26 #ifdef MUST_DISABLE_FPMASK
27 #include <floatingpoint.h>
28 #endif
29     
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <errno.h>
33 #include <string.h>
34 #include <time.h>
35 #include <ctype.h>
36
37 #if HAVE_SYS_PARAM_H
38 #  include <sys/param.h>
39 #endif
40
41 #ifndef MAXPATH
42 #  define MAXPATH 1024
43 #endif
44
45 #if HAVE_MATH_H
46 # include <math.h>
47 #endif
48 /* Sorry: don't know autoconf as well how to check the exist of
49    dirent.h ans sys/stat.h
50 */
51
52 #if HAVE_DIRENT_H
53 # include <dirent.h>
54 # define NAMLEN(dirent) strlen((dirent)->d_name)
55 #else
56 # define dirent direct
57 # define NAMLEN(dirent) (dirent)->d_namlen
58 # if HAVE_SYS_NDIR_H
59 #  include <sys/ndir.h>
60 # endif
61 # if HAVE_SYS_DIR_H
62 #  include <sys/dir.h>
63 # endif
64 # if HAVE_NDIR_H
65 #  include <ndir.h>
66 # endif
67 #endif
68
69 #if HAVE_SYS_TYPES_H
70 # include <sys/types.h>
71 #endif
72
73 #if HAVE_SYS_STAT_H
74 # include <sys/stat.h>
75 #endif
76
77
78 #if HAVE_UNISTD_H
79 # include <unistd.h>
80 #endif
81 #if HAVE_SYS_TIME_H
82 # include <sys/time.h>
83 #endif
84 #if HAVE_SYS_TIMES_H
85 # include <sys/times.h>
86 #endif
87 #if HAVE_SYS_RESOURCE_H
88 # include <sys/resource.h>
89 #if (defined(__svr4__) && defined(__sun__))
90 /* Solaris headers (pre 2.6) don't have a getrusage prototype.
91    Use this instead. */
92 extern int getrusage(int, struct rusage *);
93 #endif /* __svr4__ && __sun__ */
94 #endif
95
96 #include "rrd.h"
97
98 #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
99
100 /* Win32 only includes */
101
102 #include <float.h>        /* for _isnan  */
103 #include <io.h>           /* for chdir   */
104 #ifdef __MINGW32__
105 #define localtime_r(a,b) localtime(a)
106 #define ctime_r(a,b) ctime(a)
107 #define gmtime_r(a,b) gmtime(a)
108 #define strtok_r(a,b,c) strtok(a,b)
109 #else
110 #define isnan _isnan
111 #define finite _finite
112 #define isinf(a) (_fpclass(a) == _FPCLASS_NINF || _fpclass(a) == _FPCLASS_PINF)
113 struct tm* localtime_r(const time_t *timep, struct tm* result);
114 char* ctime_r(const time_t *timep, char* result);
115 struct tm* gmtime_r(const time_t *timep, struct tm* result);
116 char *strtok_r(char *str, const char *sep, char **last);
117 #endif
118
119 #else
120
121 /* unix-only includes */
122 #ifndef isnan
123 int isnan(double value);
124 #endif
125
126 #endif
127
128 /* local include files -- need to be after the system ones */
129 #include "getopt.h"
130 #include "rrd_format.h"
131
132 #ifndef max
133 #define max(a,b) ((a) > (b) ? (a) : (b))
134 #endif
135
136 #ifndef min
137 #define min(a,b) ((a) < (b) ? (a) : (b))
138 #endif                                                   
139
140 #define DIM(x) (sizeof(x)/sizeof(x[0]))
141
142 /* rrd info interface */
143 enum info_type   { RD_I_VAL=0,
144                RD_I_CNT,
145                RD_I_STR, 
146                    RD_I_INT };
147
148 typedef union infoval { 
149     unsigned long u_cnt; 
150     rrd_value_t   u_val;
151     char         *u_str;
152     int           u_int;
153 } infoval;
154
155 typedef struct info_t {
156     char            *key;
157     enum info_type  type;
158     union infoval   value;
159     struct info_t   *next;
160 } info_t;
161
162 info_t *rrd_info(int, char **);
163 info_t *rrd_update_v(int, char **);
164 char * sprintf_alloc(char *, ...);
165 info_t *info_push(info_t *, char *, enum info_type, infoval);
166
167 /* HELPER FUNCTIONS */
168
169 int PngSize(FILE *, long *, long *);
170
171 int rrd_create_fn(char *file_name, rrd_t *rrd);
172 int rrd_fetch_fn(char *filename, enum cf_en cf_idx,
173                  time_t *start,time_t *end,
174                  unsigned long *step,
175                  unsigned long *ds_cnt,
176                  char        ***ds_namv,
177                  rrd_value_t **data);
178
179 void rrd_free(rrd_t *rrd);
180 void rrd_freemem(void *mem);
181 void rrd_init(rrd_t *rrd);
182
183 int rrd_open(const char *file_name, FILE **in_file, rrd_t *rrd, int rdwr);
184 int readfile(const char *file, char **buffer, int skipfirst);
185
186 #define RRD_READONLY    0
187 #define RRD_READWRITE   1
188
189 enum cf_en cf_conv(char *string);
190 enum dst_en dst_conv(char *string);
191 long ds_match(rrd_t *rrd,char *ds_nam);
192 double rrd_diff(char *a, char *b);
193
194     /* rrd_strerror is thread safe, but still it uses a global buffer
195        (but one per thread), thus subsequent calls within a single
196        thread overwrite the same buffer */
197 const char *rrd_strerror(int err);
198
199 #endif
200
201 #ifdef  __cplusplus
202 }
203 #endif