From aff0a2728543eee1ac21f3fa02f171caae8d9362 Mon Sep 17 00:00:00 2001 From: oetiker Date: Tue, 18 Nov 2008 17:19:17 +0000 Subject: [PATCH] win32 portability patch and win32/rrdlib.vcproj file for the source -- christof wegmann Christof.Wegmann with exitgames.com some fixes to make the result work on unix again ... git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1677 a5681a0c-68f1-0310-ab6d-d61299d08faa --- CONTRIBUTORS | 1 + src/rrd.h | 22 +- src/rrd_client.h | 24 ++ src/rrd_create.c | 20 +- src/rrd_daemon.c | 13 +- src/rrd_diff.c | 1 + src/rrd_error.c | 4 +- src/rrd_fetch.c | 4 +- src/rrd_first.c | 1 + src/rrd_format.c | 4 +- src/rrd_getopt.c | 51 ++-- src/rrd_getopt.h | 20 +- src/rrd_getopt1.c | 34 +-- src/rrd_graph.c | 40 ++-- src/rrd_graph.h | 4 + src/rrd_hw.c | 2 + src/rrd_hw_math.c | 1 - src/rrd_hw_update.c | 1 - src/rrd_info.c | 8 +- src/rrd_open.c | 68 ++++-- src/rrd_parsetime.c | 5 +- src/rrd_resize.c | 8 +- src/rrd_restore.c | 13 +- src/rrd_rpncalc.c | 14 +- src/rrd_thread_safe_nt.c | 21 +- src/rrd_tool.c | 3 +- src/rrd_tune.c | 4 +- src/rrd_update.c | 2 +- src/rrd_xport.c | 10 +- win32/config.h | 9 +- win32/rrdlib.vcproj | 613 +++++++++++++++++++++++++++++++++++++++++++++++ 31 files changed, 861 insertions(+), 164 deletions(-) create mode 100644 win32/rrdlib.vcproj diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 02b72a7..ee5c263 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -83,3 +83,4 @@ Alexander Lucke (lucke with dns-net.de) of DNS:NET Internet Services (www.dns-net.de) http://rrdtool.org Hedley Simons Nicola Worthington +Wegmann, Christof 1.3/trunk win32 port diff --git a/src/rrd.h b/src/rrd.h index b40251f..90286d1 100644 --- a/src/rrd.h +++ b/src/rrd.h @@ -53,10 +53,17 @@ extern "C" { #define _RRDLIB_H #include /* for off_t */ + +#ifndef WIN32 #include /* for off_t */ +#else + typedef size_t ssize_t; + typedef long off_t; +#endif + #include #include /* for FILE */ - +#include /* Formerly rrd_nan_inf.h */ #ifndef DNAN @@ -79,9 +86,9 @@ extern "C" { /* information about an rrd file */ typedef struct rrd_file_t { - off_t header_len; /* length of the header of this rrd file */ - off_t file_len; /* total size of the rrd file */ - off_t pos; /* current pos in file */ + size_t header_len; /* length of the header of this rrd file */ + size_t file_len; /* total size of the rrd file */ + size_t pos; /* current pos in file */ void *pvt; } rrd_file_t; @@ -271,15 +278,18 @@ extern "C" { } rrd_context_t; /* returns the current per-thread rrd_context */ - rrd_context_t *rrd_get_context( - void); + rrd_context_t *rrd_get_context(void); +#ifdef WIN32 +/* this was added by the win32 porters Christof.Wegmann@exitgames.com */ + rrd_context_t *rrd_force_new_context(void); int rrd_proc_start_end( rrd_time_value_t *, rrd_time_value_t *, time_t *, time_t *); +#endif /* HELPER FUNCTIONS */ void rrd_set_error( diff --git a/src/rrd_client.h b/src/rrd_client.h index 1776c2b..90b78f8 100644 --- a/src/rrd_client.h +++ b/src/rrd_client.h @@ -22,7 +22,20 @@ #ifndef __RRD_CLIENT_H #define __RRD_CLIENT_H 1 +#ifndef WIN32 #include +#else +# include + typedef signed char int8_t; + typedef unsigned char uint8_t; + typedef signed int int16_t; + typedef unsigned int uint16_t; + typedef signed long int int32_t; + typedef unsigned long int uint32_t; + typedef signed long long int int64_t; + typedef unsigned long long int uint64_t; +#endif + #ifndef RRDCACHED_DEFAULT_ADDRESS # define RRDCACHED_DEFAULT_ADDRESS "unix:/tmp/rrdcached.sock" @@ -31,6 +44,10 @@ #define RRDCACHED_DEFAULT_PORT "42217" #define ENV_RRDCACHED_ADDRESS "RRDCACHED_ADDRESS" + +// Windows version has no daemon/client support + +#ifndef WIN32 int rrdc_connect (const char *addr); int rrdc_is_connected(const char *daemon_addr); int rrdc_disconnect (void); @@ -41,6 +58,13 @@ int rrdc_update (const char *filename, int values_num, int rrdc_flush (const char *filename); int rrdc_flush_if_daemon (const char *opt_daemon, const char *filename); +#else +# define rrdc_flush_if_daemon(a,b) 0 +# define rrdc_connect(a) 0 +# define rrdc_is_connected(a) 0 +# define rrdc_flush(a) 0 +# define rrdc_update(a,b,c) 0 +#endif struct rrdc_stats_s { diff --git a/src/rrd_create.c b/src/rrd_create.c index 48a4d8f..f5dbd58 100644 --- a/src/rrd_create.c +++ b/src/rrd_create.c @@ -14,6 +14,10 @@ #include "rrd_is_thread_safe.h" +#ifdef WIN32 +# include +#endif + unsigned long FnvHash( const char *str); int create_hw_contingent_rras( @@ -124,14 +128,14 @@ int rrd_create_r( /* init rrd clean */ rrd_init(&rrd); /* static header */ - if ((rrd.stat_head = calloc(1, sizeof(stat_head_t))) == NULL) { + if ((rrd.stat_head = (stat_head_t*)calloc(1, sizeof(stat_head_t))) == NULL) { rrd_set_error("allocating rrd.stat_head"); rrd_free2(&rrd); return (-1); } /* live header */ - if ((rrd.live_head = calloc(1, sizeof(live_head_t))) == NULL) { + if ((rrd.live_head = (live_head_t*)calloc(1, sizeof(live_head_t))) == NULL) { rrd_set_error("allocating rrd.live_head"); rrd_free2(&rrd); return (-1); @@ -162,7 +166,7 @@ int rrd_create_r( if (strncmp(argv[i], "DS:", 3) == 0) { size_t old_size = sizeof(ds_def_t) * (rrd.stat_head->ds_cnt); - if ((rrd.ds_def = rrd_realloc(rrd.ds_def, + if ((rrd.ds_def = (ds_def_t*)rrd_realloc(rrd.ds_def, old_size + sizeof(ds_def_t))) == NULL) { rrd_set_error("allocating rrd.ds_def"); @@ -231,7 +235,7 @@ int rrd_create_r( size_t old_size = sizeof(rra_def_t) * (rrd.stat_head->rra_cnt); int row_cnt; - if ((rrd.rra_def = rrd_realloc(rrd.rra_def, + if ((rrd.rra_def = (rra_def_t*)rrd_realloc(rrd.rra_def, old_size + sizeof(rra_def_t))) == NULL) { rrd_set_error("allocating rrd.rra_def"); @@ -606,7 +610,7 @@ int create_hw_contingent_rras( (rrd->stat_head->rra_cnt)++; /* allocate the memory for the 4 contingent RRAs */ old_size = sizeof(rra_def_t) * (rrd->stat_head->rra_cnt); - if ((rrd->rra_def = rrd_realloc(rrd->rra_def, + if ((rrd->rra_def = (rra_def_t*)rrd_realloc(rrd->rra_def, old_size + 4 * sizeof(rra_def_t))) == NULL) { rrd_free2(rrd); @@ -694,7 +698,7 @@ int rrd_create_fn( rrd_write(rrd_file_dn, rrd->live_head, sizeof(live_head_t)); - if ((rrd->pdp_prep = calloc(1, sizeof(pdp_prep_t))) == NULL) { + if ((rrd->pdp_prep = (pdp_prep_t*)calloc(1, sizeof(pdp_prep_t))) == NULL) { rrd_set_error("allocating pdp_prep"); rrd_free2(rrd); rrd_close(rrd_file_dn); @@ -710,7 +714,7 @@ int rrd_create_fn( for (i = 0; i < rrd->stat_head->ds_cnt; i++) rrd_write(rrd_file_dn, rrd->pdp_prep, sizeof(pdp_prep_t)); - if ((rrd->cdp_prep = calloc(1, sizeof(cdp_prep_t))) == NULL) { + if ((rrd->cdp_prep = (cdp_prep_t*)calloc(1, sizeof(cdp_prep_t))) == NULL) { rrd_set_error("allocating cdp_prep"); rrd_free2(rrd); rrd_close(rrd_file_dn); @@ -757,7 +761,7 @@ int rrd_create_fn( /* now, we must make sure that the rest of the rrd struct is properly initialized */ - if ((rrd->rra_ptr = calloc(1, sizeof(rra_ptr_t))) == NULL) { + if ((rrd->rra_ptr = (rra_ptr_t*)calloc(1, sizeof(rra_ptr_t))) == NULL) { rrd_set_error("allocating rra_ptr"); rrd_free2(rrd); rrd_close(rrd_file_dn); diff --git a/src/rrd_daemon.c b/src/rrd_daemon.c index 68216cb..6445e55 100644 --- a/src/rrd_daemon.c +++ b/src/rrd_daemon.c @@ -75,19 +75,24 @@ #include "rrd_client.h" #include + +#ifndef WIN32 #include -#include #include -#include #include -#include #include +# include + +#else + +#endif +#include +#include #include #include #include #include -#include #include #include #include diff --git a/src/rrd_diff.c b/src/rrd_diff.c index 093a293..2b5cb66 100644 --- a/src/rrd_diff.c +++ b/src/rrd_diff.c @@ -35,6 +35,7 @@ * *****************************************************************************/ +#include #include "rrd_tool.h" double rrd_diff( diff --git a/src/rrd_error.c b/src/rrd_error.c index d8c6eed..d816c22 100644 --- a/src/rrd_error.c +++ b/src/rrd_error.c @@ -30,9 +30,11 @@ * *************************************************************************** */ -#include "rrd_tool.h" +#include #include +#include "rrd_tool.h" + #define MAXLEN 4096 #define ERRBUFLEN 256 #define CTX (rrd_get_context()) diff --git a/src/rrd_fetch.c b/src/rrd_fetch.c index 83b0cf6..abfe66c 100644 --- a/src/rrd_fetch.c +++ b/src/rrd_fetch.c @@ -258,7 +258,7 @@ int rrd_fetch_fn( } for (i = 0; (unsigned long) i < rrd.stat_head->ds_cnt; i++) { - if ((((*ds_namv)[i]) = malloc(sizeof(char) * DS_NAM_SIZE)) == NULL) { + if ((((*ds_namv)[i]) = (char*)malloc(sizeof(char) * DS_NAM_SIZE)) == NULL) { rrd_set_error("malloc fetch ds_namv entry"); goto err_free_ds_namv; } @@ -358,7 +358,7 @@ int rrd_fetch_fn( ** database is the one with time stamp (t+s) which means t to t+s. */ *ds_cnt = rrd.stat_head->ds_cnt; - if (((*data) = malloc(*ds_cnt * rows * sizeof(rrd_value_t))) == NULL) { + if (((*data) = (rrd_value_t*)malloc(*ds_cnt * rows * sizeof(rrd_value_t))) == NULL) { rrd_set_error("malloc fetch data area"); goto err_free_all_ds_namv; } diff --git a/src/rrd_first.c b/src/rrd_first.c index 82b99f3..4fb4a4e 100644 --- a/src/rrd_first.c +++ b/src/rrd_first.c @@ -6,6 +6,7 @@ * Initial version by Burton Strauss, ntopSupport.com - 3/2005 *****************************************************************************/ +#include #include "rrd_tool.h" diff --git a/src/rrd_format.c b/src/rrd_format.c index 55653a5..4e53e19 100644 --- a/src/rrd_format.c +++ b/src/rrd_format.c @@ -62,7 +62,7 @@ enum dst_en dst_conv( converter(DERIVE, DST_DERIVE) converter(COMPUTE, DST_CDEF) rrd_set_error("unknown data acquisition function '%s'", string); - return (-1); + return (enum dst_en)(-1); } @@ -81,7 +81,7 @@ enum cf_en cf_conv( converter(DEVSEASONAL, CF_DEVSEASONAL) converter(FAILURES, CF_FAILURES) rrd_set_error("unknown consolidation function '%s'", string); - return (-1); + return (enum cf_en)(-1); } #undef converter diff --git a/src/rrd_getopt.c b/src/rrd_getopt.c index 50a61e8..dbb3f3f 100644 --- a/src/rrd_getopt.c +++ b/src/rrd_getopt.c @@ -30,7 +30,8 @@ #define _NO_PROTO #endif -#if !defined (__STDC__) || !__STDC__ + +#if !defined WIN32 && (!defined (__STDC__) || !__STDC__) /* This is a separate conditional since some stdc systems reject `defined (const)'. */ #ifndef const @@ -207,11 +208,7 @@ static char *posixly_correct; char *getenv( ); -static char *my_index( - str, - chr) - const char *str; - int chr; +static char* my_index(const char* str, int chr) { while (*str) { if (*str == chr) @@ -288,9 +285,7 @@ static void exchange( char **); #endif -static void exchange( - argv) - char **argv; +static void exchange(char** argv) { int bottom = first_nonopt; int middle = last_nonopt; @@ -346,13 +341,9 @@ static const char *_getopt_initialize( char *const *, const char *); #endif -static const char *_getopt_initialize( - argc, - argv, - optstring) - int argc; - char *const *argv; - const char *optstring; +static const char* _getopt_initialize(int argc, + char** argv, + const char* optstring) { /* Start processing options with ARGV-element 1 (since ARGV-element 0 is the program name); the sequence of previously skipped @@ -455,19 +446,12 @@ static const char *_getopt_initialize( If LONG_ONLY is nonzero, '-' as well as '--' can introduce long-named options. */ -int _getopt_internal( - argc, - argv, - optstring, - longopts, - longind, - long_only) - int argc; - char *const *argv; - const char *optstring; - const struct option *longopts; - int *longind; - int long_only; +int _getopt_internal(int argc, + char** argv, + const char *optstring, + const struct option *longopts, + int* longind, + int long_only) { optarg = NULL; @@ -868,12 +852,9 @@ int _getopt_internal( } int getopt( - argc, - argv, - optstring) - int argc; - char *const *argv; - const char *optstring; + int argc, + char** argv, + const char* optstring) { return _getopt_internal(argc, argv, optstring, (const struct option *) 0, (int *) 0, 0); diff --git a/src/rrd_getopt.h b/src/rrd_getopt.h index 91906ef..1d443f1 100644 --- a/src/rrd_getopt.h +++ b/src/rrd_getopt.h @@ -132,15 +132,17 @@ extern "C" { int *longind, int long_only); #else /* not __STDC__ */ - extern int getopt( - ); - extern int getopt_long( - ); - extern int getopt_long_only( - ); - - extern int _getopt_internal( - ); + int getopt_long(int argc, + char **argv, + const char *options, + const struct option *long_options, + int *opt_index); + int _getopt_internal(int argc, + char **argv, + const char *shortopts, + const struct option *longopts, + int *longind, + int long_only); #endif /* __STDC__ */ #ifdef __cplusplus diff --git a/src/rrd_getopt1.c b/src/rrd_getopt1.c index 075bc8d..1ace77e 100644 --- a/src/rrd_getopt1.c +++ b/src/rrd_getopt1.c @@ -20,7 +20,7 @@ Boston, MA 02111-1307, USA. */ -#if !defined (__STDC__) || !__STDC__ +#if !defined WIN32 && (!defined (__STDC__) || !__STDC__) /* This is a separate conditional since some stdc systems reject `defined (const)'. */ #ifndef const @@ -65,17 +65,11 @@ #define NULL 0 #endif -int getopt_long( - argc, - argv, - options, - long_options, - opt_index) - int argc; - char *const *argv; - const char *options; - const struct option *long_options; - int *opt_index; +int getopt_long(int argc, + char** argv, + const char* options, + const struct option* long_options, + int* opt_index) { return _getopt_internal(argc, argv, options, long_options, opt_index, 0); } @@ -85,17 +79,11 @@ int getopt_long( but does match a short option, it is parsed as a short option instead. */ -int getopt_long_only( - argc, - argv, - options, - long_options, - opt_index) - int argc; - char *const *argv; - const char *options; - const struct option *long_options; - int *opt_index; +int getopt_long_only(int argc, + char** argv, + const char* options, + const struct option* long_options, + int* opt_index) { return _getopt_internal(argc, argv, options, long_options, opt_index, 1); } diff --git a/src/rrd_graph.c b/src/rrd_graph.c index a24889f..1618e62 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -236,7 +236,7 @@ enum gf_en gf_conv( conv_if(XPORT, GF_XPORT); conv_if(SHIFT, GF_SHIFT); - return (-1); + return (enum gf_en)(-1); } enum gfx_if_en if_conv( @@ -248,7 +248,7 @@ enum gfx_if_en if_conv( conv_if(EPS, IF_EPS); conv_if(PDF, IF_PDF); - return (-1); + return (enum gfx_if_en)(-1); } enum tmt_en tmt_conv( @@ -262,7 +262,7 @@ enum tmt_en tmt_conv( conv_if(WEEK, TMT_WEEK); conv_if(MONTH, TMT_MONTH); conv_if(YEAR, TMT_YEAR); - return (-1); + return (enum tmt_en)(-1); } enum grc_en grc_conv( @@ -280,7 +280,7 @@ enum grc_en grc_conv( conv_if(AXIS, GRC_AXIS); conv_if(FRAME, GRC_FRAME); - return -1; + return (enum grc_en)(-1); } enum text_prop_en text_prop_conv( @@ -293,7 +293,7 @@ enum text_prop_en text_prop_conv( conv_if(UNIT, TEXT_PROP_UNIT); conv_if(LEGEND, TEXT_PROP_LEGEND); conv_if(WATERMARK, TEXT_PROP_WATERMARK); - return -1; + return (enum text_prop_en)(-1); } @@ -303,7 +303,7 @@ int im_free( image_desc_t *im) { unsigned long i, ii; - cairo_status_t status = 0; + cairo_status_t status = (cairo_status_t) 0; if (im == NULL) return 0; @@ -427,7 +427,7 @@ void si_unit( if (im->unitsexponent != 9999) { /* unitsexponent = 9, 6, 3, 0, -3, -6, -9, etc */ - viewdigits = floor(im->unitsexponent / 3); + viewdigits = floor((double)(im->unitsexponent / 3)); } else { viewdigits = digits; } @@ -1053,7 +1053,7 @@ int data_calc( /* add one entry to the array that keeps track of the step sizes of the * data sources going into the CDEF. */ if ((steparray = - rrd_realloc(steparray, + (long*)rrd_realloc(steparray, (++stepcnt + 1) * sizeof(*steparray))) == NULL) { rrd_set_error("realloc steparray"); @@ -1121,7 +1121,7 @@ int data_calc( */ im->gdes[gdi].step = lcd(steparray); free(steparray); - if ((im->gdes[gdi].data = malloc(((im->gdes[gdi].end - + if ((im->gdes[gdi].data = (rrd_value_t*)malloc(((im->gdes[gdi].end - im->gdes[gdi].start) / im->gdes[gdi].step) * sizeof(double))) == NULL) { @@ -1211,7 +1211,7 @@ int data_proc( for (i = 0; i < im->gdes_c; i++) { if ((im->gdes[i].gf == GF_LINE) || (im->gdes[i].gf == GF_AREA) || (im->gdes[i].gf == GF_TICK)) { - if ((im->gdes[i].p_data = malloc((im->xsize + 1) + if ((im->gdes[i].p_data = (rrd_value_t*)malloc((im->xsize + 1) * sizeof(rrd_value_t))) == NULL) { rrd_set_error("malloc data_proc"); return -1; @@ -1568,7 +1568,7 @@ int print_calc( rrd_infoval_t prline; if (im->gdes[i].strftm) { - prline.u_str = malloc((FMT_LEG_LEN + 2) * sizeof(char)); + prline.u_str = (char*)malloc((FMT_LEG_LEN + 2) * sizeof(char)); strftime(prline.u_str, FMT_LEG_LEN, im->gdes[i].format, &tmvdef); } else if (bad_format(im->gdes[i].format)) { @@ -1669,7 +1669,7 @@ int leg_place( char *tab; if (!(im->extra_flags & NOLEGEND) & !(im->extra_flags & ONLY_GRAPH)) { - if ((legspace = malloc(im->gdes_c * sizeof(int))) == NULL) { + if ((legspace = (int*)malloc(im->gdes_c * sizeof(int))) == NULL) { rrd_set_error("malloc for legspace"); return -1; } @@ -2070,7 +2070,7 @@ double frexp10( double mnt; int iexp; - iexp = floor(log(fabs(x)) / log(10)); + iexp = floor(log((double)fabs(x)) / log((double)10)); mnt = x / pow(10.0, iexp); if (mnt >= 10.0) { iexp++; @@ -2944,10 +2944,10 @@ static cairo_status_t cairo_output( *data, unsigned int length) { - image_desc_t *im = closure; + image_desc_t *im = (image_desc_t*)closure; im->rendered_image = - realloc(im->rendered_image, im->rendered_image_size + length); + (unsigned char*)realloc(im->rendered_image, im->rendered_image_size + length); if (im->rendered_image == NULL) return CAIRO_STATUS_WRITE_ERROR; memcpy(im->rendered_image + im->rendered_image_size, data, length); @@ -3566,13 +3566,13 @@ int rrd_graph( if (strcmp(walker->key, "image_info") == 0) { prlines++; if (((*prdata) = - rrd_realloc((*prdata), + (char**)rrd_realloc((*prdata), (prlines + 1) * sizeof(char *))) == NULL) { rrd_set_error("realloc prdata"); return 0; } /* imginfo goes to position 0 in the prdata array */ - (*prdata)[prlines - 1] = malloc((strlen(walker->value.u_str) + (*prdata)[prlines - 1] = (char*)malloc((strlen(walker->value.u_str) + 2) * sizeof(char)); strcpy((*prdata)[prlines - 1], walker->value.u_str); (*prdata)[prlines] = NULL; @@ -3597,12 +3597,12 @@ int rrd_graph( } else if (strncmp(walker->key, "print", 5) == 0) { /* keys are prdate[0..] */ prlines++; if (((*prdata) = - rrd_realloc((*prdata), + (char**)rrd_realloc((*prdata), (prlines + 1) * sizeof(char *))) == NULL) { rrd_set_error("realloc prdata"); return 0; } - (*prdata)[prlines - 1] = malloc((strlen(walker->value.u_str) + (*prdata)[prlines - 1] = (char*)malloc((strlen(walker->value.u_str) + 2) * sizeof(char)); (*prdata)[prlines] = NULL; strcpy((*prdata)[prlines - 1], walker->value.u_str); @@ -4537,7 +4537,7 @@ int vdef_calc( case VDEF_PERCENT:{ rrd_value_t *array; int field; - if ((array = malloc(steps * sizeof(double))) == NULL) { + if ((array = (rrd_value_t*)malloc(steps * sizeof(double))) == NULL) { rrd_set_error("malloc VDEV_PERCENT"); return -1; } diff --git a/src/rrd_graph.h b/src/rrd_graph.h index 8b86e86..6681390 100644 --- a/src/rrd_graph.h +++ b/src/rrd_graph.h @@ -14,6 +14,10 @@ #include "rrd_tool.h" #include "rrd_rpncalc.h" +#ifdef WIN32 +# include +# define MAXPATH MAX_PATH +#endif #define ALTYGRID 0x01 /* use alternative y grid algorithm */ #define ALTAUTOSCALE 0x02 /* use alternative algorithm to find lower and upper bounds */ diff --git a/src/rrd_hw.c b/src/rrd_hw.c index e563926..6f2c507 100644 --- a/src/rrd_hw.c +++ b/src/rrd_hw.c @@ -6,6 +6,8 @@ * Initial version by Jake Brutlag, WebTV Networks, 5/1/00 *****************************************************************************/ +#include + #include "rrd_tool.h" #include "rrd_hw.h" #include "rrd_hw_math.h" diff --git a/src/rrd_hw_math.c b/src/rrd_hw_math.c index 7ce9dc2..05fbf02 100644 --- a/src/rrd_hw_math.c +++ b/src/rrd_hw_math.c @@ -4,7 +4,6 @@ #include "rrd_tool.h" #include "rrd_hw_math.h" -#include "rrd_config.h" /***************************************************************************** * RRDtool supports both the additive and multiplicative Holt-Winters methods. diff --git a/src/rrd_hw_update.c b/src/rrd_hw_update.c index 9514380..90a8a52 100644 --- a/src/rrd_hw_update.c +++ b/src/rrd_hw_update.c @@ -4,7 +4,6 @@ #include "rrd_tool.h" #include "rrd_format.h" -#include "rrd_config.h" #include "rrd_hw_math.h" #include "rrd_hw_update.h" diff --git a/src/rrd_info.c b/src/rrd_info.c index 3b5364a..174bf1a 100644 --- a/src/rrd_info.c +++ b/src/rrd_info.c @@ -24,7 +24,7 @@ char *sprintf_alloc( int maxlen = 1024 + strlen(fmt); char *str = NULL; va_list argp; - str = malloc(sizeof(char) * (maxlen + 1)); + str = (char*)malloc(sizeof(char) * (maxlen + 1)); if (str != NULL) { va_start(argp, fmt); #ifdef HAVE_VSNPRINTF @@ -45,7 +45,7 @@ rrd_info_t { rrd_info_t *next; - next = malloc(sizeof(*next)); + next = (rrd_info_t*)malloc(sizeof(*next)); next->next = (rrd_info_t *) 0; if (info) info->next = next; @@ -62,13 +62,13 @@ rrd_info_t next->value.u_int = value.u_int; break; case RD_I_STR: - next->value.u_str = malloc(sizeof(char) * (strlen(value.u_str) + 1)); + next->value.u_str = (char*)malloc(sizeof(char) * (strlen(value.u_str) + 1)); strcpy(next->value.u_str, value.u_str); break; case RD_I_BLO: next->value.u_blo.size = value.u_blo.size; next->value.u_blo.ptr = - malloc(sizeof(unsigned char) * value.u_blo.size); + (unsigned char *)malloc(sizeof(unsigned char) * value.u_blo.size); memcpy(next->value.u_blo.ptr, value.u_blo.ptr, value.u_blo.size); break; } diff --git a/src/rrd_open.c b/src/rrd_open.c index 654005f..5598546 100644 --- a/src/rrd_open.c +++ b/src/rrd_open.c @@ -6,10 +6,33 @@ * $Id$ *****************************************************************************/ +#include +#include +#include + #include "rrd_tool.h" #include "unused.h" #define MEMBLK 8192 +#ifdef WIN32 +# define random() rand() +# define srandom(x) srand(x) +# define getpid() 0 + +#define _LK_UNLCK 0 /* Unlock */ +#define _LK_LOCK 1 /* Lock */ +#define _LK_NBLCK 2 /* Non-blocking lock */ +#define _LK_RLCK 3 /* Lock for read only */ +#define _LK_NBRLCK 4 /* Non-blocking lock for read only */ + + +#define LK_UNLCK _LK_UNLCK +#define LK_LOCK _LK_LOCK +#define LK_NBLCK _LK_NBLCK +#define LK_RLCK _LK_RLCK +#define LK_NBRLCK _LK_NBRLCK +#endif + /* DEBUG 2 prints information obtained via mincore(2) */ #define DEBUG 1 /* do not calculate exact madvise hints but assume 1 page for headers and @@ -34,7 +57,7 @@ #define __rrd_read(dst, dst_t, cnt) { \ size_t wanted = sizeof(dst_t)*(cnt); \ size_t got; \ - if ((dst = malloc(wanted)) == NULL) { \ + if ((dst = (dst_t*)malloc(wanted)) == NULL) { \ rrd_set_error(#dst " malloc"); \ goto out_nullify_head; \ } \ @@ -73,7 +96,7 @@ rrd_file_t *rrd_open( rrd_t *rrd, unsigned rdwr) { - int i; + unsigned long ui; int flags = 0; int version; @@ -85,8 +108,8 @@ rrd_file_t *rrd_open( struct stat statb; rrd_file_t *rrd_file = NULL; rrd_simple_file_t *rrd_simple_file = NULL; - off_t newfile_size = 0; - off_t header_len, value_cnt, data_len; + size_t newfile_size = 0; + size_t header_len, value_cnt, data_len; /* Are we creating a new file? */ if((rdwr & RRD_CREAT) && (rrd->stat_head != NULL)) @@ -102,15 +125,15 @@ rrd_file_t *rrd_open( sizeof(rra_ptr_t) * rrd->stat_head->rra_cnt; value_cnt = 0; - for (i = 0; i < rrd->stat_head->rra_cnt; i++) - value_cnt += rrd->stat_head->ds_cnt * rrd->rra_def[i].row_cnt; + for (ui = 0; ui < rrd->stat_head->rra_cnt; ui++) + value_cnt += rrd->stat_head->ds_cnt * rrd->rra_def[ui].row_cnt; data_len = sizeof(rrd_value_t) * value_cnt; newfile_size = header_len + data_len; } - rrd_file = malloc(sizeof(rrd_file_t)); + rrd_file = (rrd_file_t*)malloc(sizeof(rrd_file_t)); if (rrd_file == NULL) { rrd_set_error("allocating rrd_file descriptor for '%s'", file_name); return NULL; @@ -313,12 +336,11 @@ rrd_file_t *rrd_open( { unsigned long row_cnt = 0; - unsigned long i; - for (i=0; istat_head->rra_cnt; i++) - row_cnt += rrd->rra_def[i].row_cnt; + for (ui=0; uistat_head->rra_cnt; ui++) + row_cnt += rrd->rra_def[ui].row_cnt; - off_t correct_len = rrd_file->header_len + + size_t correct_len = rrd_file->header_len + sizeof(rrd_value_t) * row_cnt * rrd->stat_head->ds_cnt; if (correct_len > rrd_file->file_len) @@ -357,7 +379,7 @@ void mincore_print( rrd_simple_file = (rrd_simple_file_t *)rrd_file->pvt; #ifdef HAVE_MMAP /* pretty print blocks in core */ - off_t off; + size_t off; unsigned char *vec; ssize_t _page_size = sysconf(_SC_PAGESIZE); @@ -438,9 +460,9 @@ void rrd_dontneed( { rrd_simple_file_t *rrd_simple_file = (rrd_simple_file_t *)rrd_file->pvt; #if defined USE_MADVISE || defined HAVE_POSIX_FADVISE - off_t dontneed_start; - off_t rra_start; - off_t active_block; + size_t dontneed_start; + size_t rra_start; + size_t active_block; unsigned long i; ssize_t _page_size = sysconf(_SC_PAGESIZE); @@ -622,7 +644,7 @@ ssize_t rrd_write( { rrd_simple_file_t *rrd_simple_file = (rrd_simple_file_t *)rrd_file->pvt; #ifdef HAVE_MMAP - int old_size = rrd_file->file_len; + size_t old_size = rrd_file->file_len; if (count == 0) return 0; if (buf == NULL) @@ -651,12 +673,14 @@ ssize_t rrd_write( void rrd_flush( rrd_file_t *rrd_file) { +#ifndef WIN32 rrd_simple_file_t *rrd_simple_file; rrd_simple_file = (rrd_simple_file_t *)rrd_file->pvt; if (fdatasync(rrd_simple_file->fd) != 0) { rrd_set_error("flushing fd %d: %s", rrd_simple_file->fd, rrd_strerror(errno)); } +#endif } @@ -718,10 +742,10 @@ void rrd_freemem( * aligning RRAs within stripes, or other performance enhancements */ void rrd_notify_row( - rrd_file_t *rrd_file, - int rra_idx, - unsigned long rra_row, - time_t rra_time) + rrd_file_t *rrd_file __attribute__((unused)), + int rra_idx __attribute__((unused)), + unsigned long rra_row __attribute__((unused)), + time_t rra_time __attribute__((unused))) { } @@ -733,8 +757,8 @@ void rrd_notify_row( * don't change to a new disk block at the same time */ unsigned long rrd_select_initial_row( - rrd_file_t *rrd_file, - int rra_idx, + rrd_file_t *rrd_file __attribute__((unused)), + int rra_idx __attribute__((unused)), rra_def_t *rra ) { diff --git a/src/rrd_parsetime.c b/src/rrd_parsetime.c index 7fa3559..f3a8e2e 100644 --- a/src/rrd_parsetime.c +++ b/src/rrd_parsetime.c @@ -114,8 +114,11 @@ /* Local headers */ -#include "rrd_tool.h" #include +#include +#include + +#include "rrd_tool.h" /* Structures and unions */ diff --git a/src/rrd_resize.c b/src/rrd_resize.c index 32a501a..d84096c 100644 --- a/src/rrd_resize.c +++ b/src/rrd_resize.c @@ -6,6 +6,8 @@ * Initial version by Alex van den Bogaerdt *****************************************************************************/ +#include + #include "rrd_tool.h" int rrd_resize( @@ -88,14 +90,14 @@ int rrd_resize( rrd_init(&rrdnew); /* These need to be initialised before calling rrd_open() with the RRD_CREATE flag */ - if ((rrdnew.stat_head = calloc(1, sizeof(stat_head_t))) == NULL) { + if ((rrdnew.stat_head = (stat_head_t*)calloc(1, sizeof(stat_head_t))) == NULL) { rrd_set_error("allocating stat_head for new RRD"); rrd_free(&rrdold); rrd_close(rrd_file); return (-1); } - if ((rrdnew.rra_def = malloc(sizeof(rra_def_t) * rrdold.stat_head->rra_cnt)) == NULL) { + if ((rrdnew.rra_def = (rra_def_t *)malloc(sizeof(rra_def_t) * rrdold.stat_head->rra_cnt)) == NULL) { rrd_set_error("allocating rra_def for new RRD"); rrd_free(&rrdnew); rrd_free(&rrdold); @@ -125,7 +127,7 @@ int rrd_resize( return (-1); } /*XXX: do one write for those parts of header that are unchanged */ - if ((rrdnew.rra_ptr = malloc(sizeof(rra_ptr_t) * rrdold.stat_head->rra_cnt)) == NULL) { + if ((rrdnew.rra_ptr = (rra_ptr_t *)malloc(sizeof(rra_ptr_t) * rrdold.stat_head->rra_cnt)) == NULL) { rrd_set_error("allocating rra_ptr for new RRD"); rrd_free(&rrdnew); rrd_free(&rrdold); diff --git a/src/rrd_restore.c b/src/rrd_restore.c index ab8b138..f803ab6 100644 --- a/src/rrd_restore.c +++ b/src/rrd_restore.c @@ -31,7 +31,18 @@ #include #include #include -#include + + +#ifndef WIN32 +# include /* for off_t */ +#else +# define random() rand() +# define srandom(x) srand(x) +# define getpid() 0 + typedef size_t ssize_t; + typedef long off_t; +#endif + #include #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) # include diff --git a/src/rrd_rpncalc.c b/src/rrd_rpncalc.c index d83c0f4..b5f6bcc 100644 --- a/src/rrd_rpncalc.c +++ b/src/rrd_rpncalc.c @@ -4,11 +4,13 @@ * rrd_rpncalc.c RPN calculator functions ****************************************************************************/ +#include +#include +#include + #include "rrd_tool.h" #include "rrd_rpncalc.h" // #include "rrd_graph.h" -#include -#include short addop2str( enum op_en op, @@ -73,7 +75,7 @@ rpnp_t *rpn_expand( if (rpnp == NULL) return NULL; for (i = 0; rpnc[i].op != OP_END; ++i) { - rpnp[i].op = (long) rpnc[i].op; + rpnp[i].op = rpnc[i].op; if (rpnp[i].op == OP_NUMBER) { rpnp[i].val = (double) rpnc[i].val; } else if (rpnp[i].op == OP_VARIABLE || rpnp[i].op == OP_PREV_OTHER) { @@ -106,7 +108,7 @@ void rpn_compact2str( (*str)[offset++] = ','; #define add_op(VV,VVV) \ - if (addop2str(rpnc[i].op, VV, VVV, str, &offset) == 1) continue; + if (addop2str((enum op_en)(rpnc[i].op), VV, VVV, str, &offset) == 1) continue; if (rpnc[i].op == OP_NUMBER) { /* convert a short into a string */ @@ -132,7 +134,7 @@ void rpn_compact2str( #undef add_op #define add_op(VV,VVV) \ - if (addop2str(rpnc[i].op, VV, #VVV, str, &offset) == 1) continue; + if (addop2str((enum op_en)rpnc[i].op, VV, #VVV, str, &offset) == 1) continue; add_op(OP_ADD, +) add_op(OP_SUB, -) @@ -465,7 +467,7 @@ short rpn_calc( if (stptr + 5 > rpnstack->dc_stacksize) { /* could move this to a separate function */ rpnstack->dc_stacksize += rpnstack->dc_stackblock; - rpnstack->s = rrd_realloc(rpnstack->s, + rpnstack->s = (double*)rrd_realloc(rpnstack->s, (rpnstack->dc_stacksize) * sizeof(*(rpnstack->s))); if (rpnstack->s == NULL) { diff --git a/src/rrd_thread_safe_nt.c b/src/rrd_thread_safe_nt.c index eee5543..e0dad45 100644 --- a/src/rrd_thread_safe_nt.c +++ b/src/rrd_thread_safe_nt.c @@ -38,7 +38,7 @@ static void context_destroy_context( static void context_init_context( void) { - if (!InterlockedExchange(&context_key_once, 1)) { + if (!InterlockedExchange((LONG*)(&context_key_once), 1)) { context_key = TlsAlloc(); InitializeCriticalSection(&CriticalSection); atexit(context_destroy_context); @@ -51,7 +51,7 @@ rrd_context_t *rrd_get_context( context_init_context(); - ctx = TlsGetValue(context_key); + ctx = (rrd_context_t*)TlsGetValue(context_key); if (!ctx) { ctx = rrd_new_context(); TlsSetValue(context_key, ctx); @@ -59,6 +59,23 @@ rrd_context_t *rrd_get_context( return ctx; } + +/* this was added by the win32 porters Christof.Wegmann@exitgames.com */ + +rrd_context_t *rrd_force_new_context( + void) +{ + rrd_context_t *ctx; + + context_init_context(); + + ctx = rrd_new_context(); + TlsSetValue(context_key, ctx); + + return ctx; +} + + #undef strerror const char *rrd_strerror( int err) diff --git a/src/rrd_tool.c b/src/rrd_tool.c index 051631c..4da8019 100644 --- a/src/rrd_tool.c +++ b/src/rrd_tool.c @@ -70,8 +70,7 @@ void PrintUsage( const char *help_dump = N_("* dump - dump an RRD to XML\n\n" - "\trrdtool dump filename.rrd >filename.xml\n" - "\t\t[--header|-h {xsd,dtd}]\n\n"); + "\trrdtool dump filename.rrd >filename.xml\n\n"); const char *help_info = N_("* info - returns the configuration and status of the RRD\n\n" diff --git a/src/rrd_tune.c b/src/rrd_tune.c index 89559af..0df0476 100644 --- a/src/rrd_tune.c +++ b/src/rrd_tune.c @@ -39,10 +39,12 @@ * *****************************************************************************/ +#include +#include + #include "rrd_tool.h" #include "rrd_rpncalc.h" #include "rrd_hw.h" -#include int set_hwarg( rrd_t *rrd, diff --git a/src/rrd_update.c b/src/rrd_update.c index 1d9d515..72a9905 100644 --- a/src/rrd_update.c +++ b/src/rrd_update.c @@ -449,7 +449,7 @@ int rrd_update( { rc = rrdc_update (argv[optind], /* file */ argc - optind - 1, /* values_num */ - (void *) (argv + optind + 1)); /* values */ + (const char *const *) (argv + optind + 1)); /* values */ if (rc > 0) rrd_set_error("Failed sending the values to rrdcached: %s", rrd_strerror (rc)); diff --git a/src/rrd_xport.c b/src/rrd_xport.c index 225fba5..8204469 100644 --- a/src/rrd_xport.c +++ b/src/rrd_xport.c @@ -233,20 +233,20 @@ int rrd_xport_fn( } /* a list of referenced gdes */ - ref_list = malloc(sizeof(int) * (*col_cnt)); + ref_list = (int*)malloc(sizeof(int) * (*col_cnt)); if (ref_list == NULL) return -1; /* a list to save pointers to the column's legend entry */ /* this is a return value! */ - legend_list = malloc(sizeof(char *) * (*col_cnt)); + legend_list = (char**)malloc(sizeof(char *) * (*col_cnt)); if (legend_list == NULL) { free(ref_list); return -1; } /* lets find the step size we have to use for xport */ - step_list = malloc(sizeof(long)*((*col_cnt)+1)); + step_list = (long*)malloc(sizeof(long)*((*col_cnt)+1)); step_list_ptr = step_list; j = 0; for (i = 0; i < im->gdes_c; i++) { @@ -259,7 +259,7 @@ int rrd_xport_fn( /* reserve room for one legend entry */ /* is FMT_LEG_LEN + 5 the correct size? */ if ((legend_list[j] = - malloc(sizeof(char) * (FMT_LEG_LEN + 5))) == NULL) { + (char*)malloc(sizeof(char) * (FMT_LEG_LEN + 5))) == NULL) { free(ref_list); *data = NULL; while (--j > -1) @@ -293,7 +293,7 @@ int rrd_xport_fn( /* this is a return value! */ row_cnt = ((*end) - (*start)) / (*step); if (((*data) = - malloc((*col_cnt) * row_cnt * sizeof(rrd_value_t))) == NULL) { + (rrd_value_t*)malloc((*col_cnt) * row_cnt * sizeof(rrd_value_t))) == NULL) { free(ref_list); free(legend_list); rrd_set_error("malloc xport data area"); diff --git a/win32/config.h b/win32/config.h index d3bf6e6..6199234 100644 --- a/win32/config.h +++ b/win32/config.h @@ -20,6 +20,7 @@ #define HAVE_MKTIME 1 #define HAVE_STRFTIME 1 #define HAVE_STRING_H 1 +#define HAVE_STDLIB_H 1 #define HAVE_VSNPRINTF 1 #define HAVE_SYS_TYPES_H 1 #define HAVE_SYS_STAT_H 1 @@ -27,17 +28,17 @@ /* Define to 1 if you have the ANSI C header files. */ #define STDC_HEADERS 1 -#define NUMVERS 1.2015 +#define NUMVERS 1.3020 #define PACKAGE_NAME "rrdtool" -#define PACKAGE_VERSION "1.2.15" +#define PACKAGE_VERSION "1.3.2" #define PACKAGE_STRING PACKAGE_NAME " " PACKAGE_VERSION #define isinf(a) (_fpclass(a) == _FPCLASS_NINF || _fpclass(a) == _FPCLASS_PINF) #define isnan _isnan #define finite _finite #define snprintf _snprintf -#define vsnprintf _vsnprintf -#define strftime strftime_ +//#define vsnprintf _vsnprintf +//#define strftime strftime_ #define NO_NULL_REALLOC 1 #if NO_NULL_REALLOC diff --git a/win32/rrdlib.vcproj b/win32/rrdlib.vcproj new file mode 100644 index 0000000..bae4a95 --- /dev/null +++ b/win32/rrdlib.vcproj @@ -0,0 +1,613 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.11.0