From 89c1b154cda0037438ca71a59069cd6c73bfecee Mon Sep 17 00:00:00 2001 From: oetiker Date: Tue, 2 Dec 2008 22:04:16 +0000 Subject: [PATCH] make rrdtool compile on windows with cv++. check out win32/rrdlib.vcproj. -- Christof.Wegmann with exitgames.com git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.3@1684 a5681a0c-68f1-0310-ab6d-d61299d08faa --- program/Makefile.am | 2 +- program/src/rrd.h | 11 + program/src/rrd_create.c | 33 ++- program/src/rrd_diff.c | 4 + program/src/rrd_dump.c | 5 + program/src/rrd_error.c | 4 + program/src/rrd_fetch.c | 8 +- program/src/rrd_first.c | 3 + program/src/rrd_format.c | 4 +- program/src/rrd_getopt.c | 34 +++ program/src/rrd_getopt.h | 16 ++ program/src/rrd_getopt1.c | 19 +- program/src/rrd_gfx.c | 2 +- program/src/rrd_graph.c | 54 ++--- program/src/rrd_graph.h | 4 + program/src/rrd_hw.c | 4 + program/src/rrd_hw_math.c | 2 + program/src/rrd_hw_update.c | 2 + program/src/rrd_info.c | 12 +- program/src/rrd_lastupdate.c | 4 + program/src/rrd_open.c | 25 ++- program/src/rrd_parsetime.c | 5 + program/src/rrd_resize.c | 60 ++++- program/src/rrd_restore.c | 25 ++- program/src/rrd_rpncalc.c | 14 +- program/src/rrd_thread_safe_nt.c | 18 +- program/src/rrd_tune.c | 4 + program/src/rrd_update.c | 6 +- program/src/rrd_xport.c | 10 +- program/win32/config.h | 9 +- program/win32/rrdlib.vcproj | 367 +++++++++++++++++++++++++++++++ 31 files changed, 699 insertions(+), 71 deletions(-) create mode 100644 program/win32/rrdlib.vcproj diff --git a/program/Makefile.am b/program/Makefile.am index 9f20a78b..7b6595e5 100644 --- a/program/Makefile.am +++ b/program/Makefile.am @@ -14,7 +14,7 @@ SUBDIRS = $(PO) src examples doc bindings EXTRA_DIST = COPYRIGHT CHANGES WIN32-BUILD-TIPS.txt TODO CONTRIBUTORS THREADS \ intltool-extract.in intltool-merge.in intltool-update.in \ rrdtool.spec favicon.ico win32/config.h win32/rrd.dsp \ - win32/rrd.vcproj win32/rrdtool.dsp win32/rrdtool.dsw \ + win32/rrdlib.vcproj win32/rrd.vcproj win32/rrdtool.dsp win32/rrdtool.dsw \ win32/rrdtool.vcproj win32/Makefile \ win32/rrd_config.h.msvc netware/Makefile diff --git a/program/src/rrd.h b/program/src/rrd.h index 0fde235d..a7879236 100644 --- a/program/src/rrd.h +++ b/program/src/rrd.h @@ -53,7 +53,15 @@ extern "C" { #define _RRDLIB_H #include /* for off_t */ + +#ifndef WIN32 #include /* for off_t */ +#else +#include +typedef size_t ssize_t; +typedef long off_t; +#endif + #include #include /* for FILE */ @@ -264,6 +272,9 @@ extern "C" { rrd_context_t *rrd_get_context( void); +#ifdef WIN32 +rrd_context_t *rrd_force_new_context(void); +#endif int rrd_proc_start_end( rrd_time_value_t *, diff --git a/program/src/rrd_create.c b/program/src/rrd_create.c index 446067da..aa27f75b 100644 --- a/program/src/rrd_create.c +++ b/program/src/rrd_create.c @@ -14,6 +14,11 @@ #include "rrd_is_thread_safe.h" +#ifdef WIN32 +#include +#include +#endif + unsigned long FnvHash( const char *str); int create_hw_contingent_rras( @@ -126,14 +131,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); @@ -164,7 +169,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"); @@ -233,7 +238,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"); @@ -608,7 +613,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); @@ -697,7 +702,7 @@ int rrd_create_fn( write(rrd_file, 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); close(rrd_file); @@ -713,7 +718,7 @@ int rrd_create_fn( for (i = 0; i < rrd->stat_head->ds_cnt; i++) write(rrd_file, 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); close(rrd_file); @@ -760,7 +765,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); close(rrd_file); @@ -796,7 +801,11 @@ int rrd_create_fn( unkn_cnt -= 512; } free(unknown); + +#ifndef WIN32 fdatasync(rrd_file); +#endif + rrd_free2(rrd); if (close(rrd_file) == -1) { rrd_set_error("creating rrd: %s", rrd_strerror(errno)); @@ -830,9 +839,17 @@ long int rra_random_row( rra_def_t *rra) { if (!rand_init) { +#ifdef WIN32 + srand((unsigned int) time(NULL) + (unsigned int) getpid()); +#else srandom((unsigned int) time(NULL) + (unsigned int) getpid()); +#endif rand_init++; } +#ifdef WIN32 + return rand() % rra->row_cnt; +#else return random() % rra->row_cnt; +#endif } diff --git a/program/src/rrd_diff.c b/program/src/rrd_diff.c index 4fe6835b..eec345a1 100644 --- a/program/src/rrd_diff.c +++ b/program/src/rrd_diff.c @@ -37,6 +37,10 @@ #include "rrd_tool.h" +#ifdef WIN32 +#include +#endif + double rrd_diff( char *a, char *b) diff --git a/program/src/rrd_dump.c b/program/src/rrd_dump.c index ff385d43..6f723b77 100644 --- a/program/src/rrd_dump.c +++ b/program/src/rrd_dump.c @@ -41,6 +41,11 @@ * checkin * *****************************************************************************/ + +#ifdef WIN32 +#include +#endif + #include "rrd_tool.h" #include "rrd_rpncalc.h" diff --git a/program/src/rrd_error.c b/program/src/rrd_error.c index d21e300d..fe65f846 100644 --- a/program/src/rrd_error.c +++ b/program/src/rrd_error.c @@ -33,6 +33,10 @@ #include "rrd_tool.h" #include +#ifdef WIN32 +#include +#endif + #define MAXLEN 4096 #define ERRBUFLEN 256 #define CTX (rrd_get_context()) diff --git a/program/src/rrd_fetch.c b/program/src/rrd_fetch.c index bb895daa..370dc1fb 100644 --- a/program/src/rrd_fetch.c +++ b/program/src/rrd_fetch.c @@ -52,6 +52,10 @@ * *****************************************************************************/ +#ifdef WIN32 +#include +#endif + #include "rrd_tool.h" #include "rrd_is_thread_safe.h" @@ -227,7 +231,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; } @@ -327,7 +331,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/program/src/rrd_first.c b/program/src/rrd_first.c index 3d2f02b1..c0cce104 100644 --- a/program/src/rrd_first.c +++ b/program/src/rrd_first.c @@ -8,6 +8,9 @@ #include "rrd_tool.h" +#ifdef WIN32 +#include +#endif time_t rrd_first( int argc, diff --git a/program/src/rrd_format.c b/program/src/rrd_format.c index 34f9ddf5..13a7185d 100644 --- a/program/src/rrd_format.c +++ b/program/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/program/src/rrd_getopt.c b/program/src/rrd_getopt.c index 50a61e88..57266302 100644 --- a/program/src/rrd_getopt.c +++ b/program/src/rrd_getopt.c @@ -30,6 +30,8 @@ #define _NO_PROTO #endif +#ifndef WIN32 + #if !defined (__STDC__) || !__STDC__ /* This is a separate conditional since some stdc systems reject `defined (const)'. */ @@ -38,6 +40,7 @@ #endif #endif +#endif // WIN32 #ifdef HAVE_CONFIG_H #include "../rrd_config.h" @@ -207,11 +210,15 @@ static char *posixly_correct; char *getenv( ); +#ifdef WIN32 +static char* my_index(const char* str, int chr) +#else // WIN32 static char *my_index( str, chr) const char *str; int chr; +#endif // wIN32 { while (*str) { if (*str == chr) @@ -288,9 +295,13 @@ static void exchange( char **); #endif +#ifdef WIN32 +static void exchange(char** argv) +#else // WIN32 static void exchange( argv) char **argv; +#endif // WIN32 { int bottom = first_nonopt; int middle = last_nonopt; @@ -346,6 +357,12 @@ static const char *_getopt_initialize( char *const *, const char *); #endif + +#ifdef WIN32 +static const char* _getopt_initialize(int argc, + char** argv, + const char* optstring) +#else // WIN32 static const char *_getopt_initialize( argc, argv, @@ -353,6 +370,7 @@ static const char *_getopt_initialize( int argc; char *const *argv; const char *optstring; +#endif // WIN32 { /* Start processing options with ARGV-element 1 (since ARGV-element 0 is the program name); the sequence of previously skipped @@ -455,6 +473,14 @@ static const char *_getopt_initialize( If LONG_ONLY is nonzero, '-' as well as '--' can introduce long-named options. */ +#ifdef WIN32 +int _getopt_internal(int argc, + char** argv, + const char *optstring, + const struct option *longopts, + int* longind, + int long_only) +#else // WIN32 int _getopt_internal( argc, argv, @@ -468,6 +494,7 @@ int _getopt_internal( const struct option *longopts; int *longind; int long_only; +#endif // WIN32 { optarg = NULL; @@ -867,6 +894,12 @@ int _getopt_internal( } } +#ifdef WIN32 +int getopt( + int argc, + char** argv, + const char* optstring) +#else // WIN32 int getopt( argc, argv, @@ -874,6 +907,7 @@ int getopt( int argc; char *const *argv; const char *optstring; +#endif // WIN32 { return _getopt_internal(argc, argv, optstring, (const struct option *) 0, (int *) 0, 0); diff --git a/program/src/rrd_getopt.h b/program/src/rrd_getopt.h index 91906efe..89a5da6d 100644 --- a/program/src/rrd_getopt.h +++ b/program/src/rrd_getopt.h @@ -132,6 +132,20 @@ extern "C" { int *longind, int long_only); #else /* not __STDC__ */ + +#ifdef WIN32 + 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); +#else // WIN32 extern int getopt( ); extern int getopt_long( @@ -141,6 +155,8 @@ extern "C" { extern int _getopt_internal( ); +#endif // WIN32 + #endif /* __STDC__ */ #ifdef __cplusplus diff --git a/program/src/rrd_getopt1.c b/program/src/rrd_getopt1.c index 075bc8da..724e1a5d 100644 --- a/program/src/rrd_getopt1.c +++ b/program/src/rrd_getopt1.c @@ -19,7 +19,7 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - +#ifndef WIN32 #if !defined (__STDC__) || !__STDC__ /* This is a separate conditional since some stdc systems reject `defined (const)'. */ @@ -27,6 +27,7 @@ #define const #endif #endif +#endif // WIN32 #ifdef HAVE_CONFIG_H #include "../rrd_config.h" @@ -65,6 +66,13 @@ #define NULL 0 #endif +#ifdef WIN32 +int getopt_long(int argc, + char** argv, + const char* options, + const struct option* long_options, + int* opt_index) +#else // WIN32 int getopt_long( argc, argv, @@ -76,6 +84,7 @@ int getopt_long( const char *options; const struct option *long_options; int *opt_index; +#endif // WIN32 { return _getopt_internal(argc, argv, options, long_options, opt_index, 0); } @@ -85,6 +94,13 @@ int getopt_long( but does match a short option, it is parsed as a short option instead. */ +#ifdef WIN32 +int getopt_long_only(int argc, + char** argv, + const char* options, + const struct option* long_options, + int* opt_index) +#else // WIN32 int getopt_long_only( argc, argv, @@ -96,6 +112,7 @@ int getopt_long_only( const char *options; const struct option *long_options; int *opt_index; +#endif // WIN32 { return _getopt_internal(argc, argv, options, long_options, opt_index, 1); } diff --git a/program/src/rrd_gfx.c b/program/src/rrd_gfx.c index 2b19e323..a45ad6e3 100644 --- a/program/src/rrd_gfx.c +++ b/program/src/rrd_gfx.c @@ -154,7 +154,7 @@ static PangoLayout *gfx_prep_text( pango_layout_set_tabs(layout, tab_array); pango_tab_array_free(tab_array); } - pfd = pango_layout_get_font_description(layout); + pfd = (PangoFontDescription*)(pango_layout_get_font_description(layout)); if (!pfd || !pango_font_description_equal (pfd,font_desc)){ pango_layout_set_font_description(layout, font_desc); diff --git a/program/src/rrd_graph.c b/program/src/rrd_graph.c index 41f99f6c..35893e2f 100644 --- a/program/src/rrd_graph.c +++ b/program/src/rrd_graph.c @@ -234,7 +234,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( @@ -246,7 +246,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( @@ -260,7 +260,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( @@ -278,7 +278,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( @@ -291,7 +291,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); } @@ -301,7 +301,7 @@ int im_free( image_desc_t *im) { unsigned long i, ii; - cairo_status_t status = 0; + cairo_status_t status = CAIRO_STATUS_SUCCESS; if (im == NULL) return 0; @@ -421,7 +421,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; } @@ -1017,9 +1017,9 @@ 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) { + 1) * sizeof(*steparray)))) == NULL) { rrd_set_error("realloc steparray"); rpnstack_free(&rpnstack); return -1; @@ -1085,10 +1085,10 @@ 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) { + * sizeof(double)))) == NULL) { rrd_set_error("malloc im->gdes[gdi].data"); rpnstack_free(&rpnstack); return -1; @@ -1175,8 +1175,8 @@ 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) - * sizeof(rrd_value_t))) == NULL) { + 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; } @@ -1532,7 +1532,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)) { @@ -1633,7 +1633,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; } @@ -2034,7 +2034,7 @@ double frexp10( double mnt; int iexp; - iexp = floor(log(fabs(x)) / log(10)); + iexp = floor(log((double)(fabs(x))) / log(10.0)); mnt = x / pow(10.0, iexp); if (mnt >= 10.0) { iexp++; @@ -2908,10 +2908,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); @@ -3530,14 +3530,14 @@ int rrd_graph( if (strcmp(walker->key, "image_info") == 0) { prlines++; if (((*prdata) = - rrd_realloc((*prdata), - (prlines + 1) * sizeof(char *))) == NULL) { + (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) - + 2) * sizeof(char)); + (*prdata)[prlines - 1] = (char*)(malloc((strlen(walker->value.u_str) + + 2) * sizeof(char))); strcpy((*prdata)[prlines - 1], walker->value.u_str); (*prdata)[prlines] = NULL; } @@ -3561,13 +3561,13 @@ int rrd_graph( } else if (strncmp(walker->key, "print", 5) == 0) { /* keys are prdate[0..] */ prlines++; if (((*prdata) = - rrd_realloc((*prdata), - (prlines + 1) * sizeof(char *))) == NULL) { + (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) - + 2) * sizeof(char)); + (*prdata)[prlines - 1] = (char*)(malloc((strlen(walker->value.u_str) + + 2) * sizeof(char))); (*prdata)[prlines] = NULL; strcpy((*prdata)[prlines - 1], walker->value.u_str); } else if (strcmp(walker->key, "image") == 0) { @@ -4476,7 +4476,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/program/src/rrd_graph.h b/program/src/rrd_graph.h index 62765086..704fe5ea 100644 --- a/program/src/rrd_graph.h +++ b/program/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/program/src/rrd_hw.c b/program/src/rrd_hw.c index bd5a1afa..80e030ab 100644 --- a/program/src/rrd_hw.c +++ b/program/src/rrd_hw.c @@ -11,6 +11,10 @@ #include "rrd_hw_math.h" #include "rrd_hw_update.h" +#ifdef WIN32 +#include +#endif + #define hw_dep_idx(rrd, rra_idx) rrd->rra_def[rra_idx].par[RRA_dependent_rra_idx].u_cnt /* #define DEBUG */ diff --git a/program/src/rrd_hw_math.c b/program/src/rrd_hw_math.c index 7ce9dc26..5aa2895e 100644 --- a/program/src/rrd_hw_math.c +++ b/program/src/rrd_hw_math.c @@ -4,7 +4,9 @@ #include "rrd_tool.h" #include "rrd_hw_math.h" +#ifndef WIN32 #include "rrd_config.h" +#endif /***************************************************************************** * RRDtool supports both the additive and multiplicative Holt-Winters methods. diff --git a/program/src/rrd_hw_update.c b/program/src/rrd_hw_update.c index 95143805..8a5f7003 100644 --- a/program/src/rrd_hw_update.c +++ b/program/src/rrd_hw_update.c @@ -4,7 +4,9 @@ #include "rrd_tool.h" #include "rrd_format.h" +#ifndef WIN32 #include "rrd_config.h" +#endif #include "rrd_hw_math.h" #include "rrd_hw_update.h" diff --git a/program/src/rrd_info.c b/program/src/rrd_info.c index b83640fa..62499059 100644 --- a/program/src/rrd_info.c +++ b/program/src/rrd_info.c @@ -8,6 +8,10 @@ #include "rrd_rpncalc.h" #include +#ifdef WIN32 +#include +#endif + /* proto */ rrd_info_t *rrd_info( int, @@ -23,7 +27,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 @@ -44,7 +48,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; @@ -61,13 +65,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/program/src/rrd_lastupdate.c b/program/src/rrd_lastupdate.c index 264fa29b..104cc03d 100644 --- a/program/src/rrd_lastupdate.c +++ b/program/src/rrd_lastupdate.c @@ -8,6 +8,10 @@ #include "rrd_rpncalc.h" #include +#ifdef WIN32 +#include +#endif + int rrd_lastupdate( int argc, char **argv, diff --git a/program/src/rrd_open.c b/program/src/rrd_open.c index 06afabe1..e5f20c9a 100644 --- a/program/src/rrd_open.c +++ b/program/src/rrd_open.c @@ -8,6 +8,13 @@ #include "rrd_tool.h" #include "unused.h" + +#ifdef WIN32 +#include +#include +#include +#endif + #define MEMBLK 8192 /* DEBUG 2 prints information obtained via mincore(2) */ @@ -34,7 +41,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; \ } \ @@ -66,7 +73,13 @@ rrd_file_t *rrd_open( unsigned rdwr) { int flags = 0; + +/* Win32 can't use S_IRUSR flag */ +#ifndef WIN32 mode_t mode = S_IRUSR; +#else + int mode = 0; +#endif int version; #ifdef HAVE_MMAP @@ -86,7 +99,7 @@ rrd_file_t *rrd_open( free(rrd->stat_head); } rrd_init(rrd); - 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; @@ -111,7 +124,9 @@ rrd_file_t *rrd_open( #endif } else { if (rdwr & RRD_READWRITE) { +#ifndef WIN32 // Win32 can't use this mode mode |= S_IWUSR; +#endif flags |= O_RDWR; #ifdef HAVE_MMAP mm_flags = MAP_SHARED; @@ -557,10 +572,16 @@ ssize_t rrd_write( void rrd_flush( rrd_file_t *rrd_file) { +/* + * Win32 can only flush files by FlushFileBuffers function, + * but it works with HANDLE hFile, not FILE. So skipping + */ +#ifndef WIN32 if (fdatasync(rrd_file->fd) != 0) { rrd_set_error("flushing fd %d: %s", rrd_file->fd, rrd_strerror(errno)); } +#endif } diff --git a/program/src/rrd_parsetime.c b/program/src/rrd_parsetime.c index 7fa35593..6bf7d68f 100644 --- a/program/src/rrd_parsetime.c +++ b/program/src/rrd_parsetime.c @@ -117,6 +117,11 @@ #include "rrd_tool.h" #include +#ifdef WIN32 +#include +#include +#endif + /* Structures and unions */ enum { /* symbols */ diff --git a/program/src/rrd_resize.c b/program/src/rrd_resize.c index 803c961b..a26dee42 100644 --- a/program/src/rrd_resize.c +++ b/program/src/rrd_resize.c @@ -8,6 +8,10 @@ #include "rrd_tool.h" +#ifdef WIN32 +#include +#endif + int rrd_resize( int argc, char **argv) @@ -85,7 +89,7 @@ int rrd_resize( } /* the size of the new file */ /* yes we are abusing the float cookie for this, aargh */ - 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); @@ -108,7 +112,7 @@ int rrd_resize( return (-1); } /*XXX: do one write for those parts of header that are unchanged */ - if ((rrdnew.stat_head = malloc(sizeof(stat_head_t))) == NULL) { + if ((rrdnew.stat_head = (stat_head_t*)malloc(sizeof(stat_head_t))) == NULL) { rrd_set_error("allocating stat_head for new RRD"); rrd_free(&rrdnew); rrd_free(&rrdold); @@ -117,7 +121,7 @@ int rrd_resize( return (-1); } - 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); @@ -126,7 +130,7 @@ int rrd_resize( 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); @@ -135,6 +139,7 @@ int rrd_resize( return (-1); } +#ifndef WIN32 memcpy(rrdnew.stat_head,rrdold.stat_head,sizeof(stat_head_t)); rrdnew.ds_def = rrdold.ds_def; memcpy(rrdnew.rra_def,rrdold.rra_def,sizeof(rra_def_t) * rrdold.stat_head->rra_cnt); @@ -142,7 +147,54 @@ int rrd_resize( rrdnew.pdp_prep = rrdold.pdp_prep; rrdnew.cdp_prep = rrdold.cdp_prep; memcpy(rrdnew.rra_ptr,rrdold.rra_ptr,sizeof(rra_ptr_t) * rrdold.stat_head->rra_cnt); +#else // WIN32 + /* + * For windows Other fields also should be allocated. Crashes otherwise + */ + + if ((rrdnew.ds_def = (ds_def_t*)malloc(sizeof(ds_def_t) * rrdold.stat_head->ds_cnt)) == NULL) { + rrd_set_error("allocating ds_def for new RRD"); + rrd_free(&rrdnew); + rrd_free(&rrdold); + rrd_close(rrd_file); + rrd_close(rrd_out_file); + return (-1); + } + + if ((rrdnew.live_head = (live_head_t*)malloc(sizeof(live_head_t))) == NULL) { + rrd_set_error("allocating live_head for new RRD"); + rrd_free(&rrdnew); + rrd_free(&rrdold); + rrd_close(rrd_file); + rrd_close(rrd_out_file); + return (-1); + } + if ((rrdnew.pdp_prep = (pdp_prep_t*)malloc(sizeof(pdp_prep_t))) == NULL) { + rrd_set_error("allocating pdp_prep for new RRD"); + rrd_free(&rrdnew); + rrd_free(&rrdold); + rrd_close(rrd_file); + rrd_close(rrd_out_file); + return (-1); + } + + if ((rrdnew.cdp_prep = (cdp_prep_t*)malloc(sizeof(cdp_prep_t))) == NULL) { + rrd_set_error("allocating cdp_prep for new RRD"); + rrd_free(&rrdnew); + rrd_free(&rrdold); + rrd_close(rrd_file); + rrd_close(rrd_out_file); + return (-1); + } + memcpy(rrdnew.stat_head,rrdold.stat_head,sizeof(stat_head_t)); + memcpy(rrdnew.ds_def,rrdold.ds_def,sizeof(ds_def_t) * rrdold.stat_head->ds_cnt); + memcpy(rrdnew.rra_def,rrdold.rra_def,sizeof(rra_def_t) * rrdold.stat_head->rra_cnt); + memcpy(rrdnew.live_head,rrdold.live_head,sizeof(live_head_t)); + memcpy(rrdnew.pdp_prep,rrdold.pdp_prep,sizeof(pdp_prep_t)); + memcpy(rrdnew.cdp_prep,rrdold.cdp_prep,sizeof(cdp_prep_t)); + memcpy(rrdnew.rra_ptr,rrdold.rra_ptr,sizeof(rra_ptr_t) * rrdold.stat_head->rra_cnt); +#endif // WIN32 version = atoi(rrdold.stat_head->version); switch (version) { diff --git a/program/src/rrd_restore.c b/program/src/rrd_restore.c index f8777b4e..2335f592 100644 --- a/program/src/rrd_restore.c +++ b/program/src/rrd_restore.c @@ -31,13 +31,17 @@ #include #include #include -#include #include -#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) + +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) +#include # include # define open _open # define close _close +#else +# include #endif + #include #include "rrd_tool.h" #include "rrd_rpncalc.h" @@ -132,6 +136,15 @@ static int get_double_from_node( return (-1); } +#ifdef WIN32 + if (strcmp(str_ptr, " NaN ") == 0) + { + *value = DNAN; + xmlFree(str_ptr); + return 0; + } +#endif + end_ptr = NULL; temp = strtod(str_ptr, &end_ptr); xmlFree(str_ptr); @@ -695,7 +708,11 @@ static int parse_tag_rra( } /* Set the RRA pointer to a random location */ +#ifdef WIN32 + cur_rra_ptr->cur_row = rand() % cur_rra_def->row_cnt; +#else cur_rra_ptr->cur_row = random() % cur_rra_def->row_cnt; +#endif return (status); } /* int parse_tag_rra */ @@ -1043,7 +1060,11 @@ int rrd_restore( { rrd_t *rrd; +#ifdef WIN32 + srand((unsigned int) time(NULL)); +#else srandom((unsigned int) time(NULL) + (unsigned int) getpid()); +#endif /* init rrd clean */ optind = 0; opterr = 0; /* initialize getopt */ diff --git a/program/src/rrd_rpncalc.c b/program/src/rrd_rpncalc.c index 48ac26f0..2e7868b7 100644 --- a/program/src/rrd_rpncalc.c +++ b/program/src/rrd_rpncalc.c @@ -10,6 +10,10 @@ #include #include +#ifdef WIN32 +#include +#endif + short addop2str( enum op_en op, enum op_en op_type, @@ -73,7 +77,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 = (enum op_en) 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 +110,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 +136,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, -) @@ -461,9 +465,9 @@ 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))); + sizeof(*(rpnstack->s)))); if (rpnstack->s == NULL) { rrd_set_error("RPN stack overflow"); return -1; diff --git a/program/src/rrd_thread_safe_nt.c b/program/src/rrd_thread_safe_nt.c index 0655e832..597fe88e 100644 --- a/program/src/rrd_thread_safe_nt.c +++ b/program/src/rrd_thread_safe_nt.c @@ -22,7 +22,7 @@ static CRITICAL_SECTION CriticalSection; /* Once-only initialisation of the key */ -static DWORD context_key_once = 0; +static volatile LONG context_key_once = 0; /* Free the thread-specific rrd_context - we might actually use @@ -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,20 @@ rrd_context_t *rrd_get_context( return ctx; } +#ifdef WIN32 + 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; + } +#endif + #undef strerror const char *rrd_strerror( int err) diff --git a/program/src/rrd_tune.c b/program/src/rrd_tune.c index 484b0b4b..5dfac782 100644 --- a/program/src/rrd_tune.c +++ b/program/src/rrd_tune.c @@ -44,6 +44,10 @@ #include "rrd_hw.h" #include +#ifdef WIN32 +#include +#endif + int set_hwarg( rrd_t *rrd, enum cf_en cf, diff --git a/program/src/rrd_update.c b/program/src/rrd_update.c index fdaca577..288454c4 100644 --- a/program/src/rrd_update.c +++ b/program/src/rrd_update.c @@ -17,6 +17,10 @@ #include +#ifdef WIN32 +#include +#endif + #include "rrd_hw.h" #include "rrd_rpncalc.h" @@ -1496,7 +1500,7 @@ static int update_cdp_prep( if (elapsed_pdp_st > 2) { reset_cdp(rrd, elapsed_pdp_st, pdp_temp, last_seasonal_coef, seasonal_coef, rra_idx, ds_idx, cdp_idx, - current_cf); + (enum cf_en)current_cf); } } diff --git a/program/src/rrd_xport.c b/program/src/rrd_xport.c index cda248a0..4071f47b 100644 --- a/program/src/rrd_xport.c +++ b/program/src/rrd_xport.c @@ -206,20 +206,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++) { @@ -232,7 +232,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) @@ -266,7 +266,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/program/win32/config.h b/program/win32/config.h index d3bf6e63..53db0d52 100644 --- a/program/win32/config.h +++ b/program/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.3040 #define PACKAGE_NAME "rrdtool" -#define PACKAGE_VERSION "1.2.15" +#define PACKAGE_VERSION "1.3.4" #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/program/win32/rrdlib.vcproj b/program/win32/rrdlib.vcproj new file mode 100644 index 00000000..00a8b012 --- /dev/null +++ b/program/win32/rrdlib.vcproj @@ -0,0 +1,367 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.30.2