From ede902b85d3d3f14aeeb0251b4c91a11623e7dcd Mon Sep 17 00:00:00 2001 From: oetiker Date: Wed, 6 Apr 2005 22:40:53 +0000 Subject: [PATCH] make sure WIN32 sections do NOT kick in for cygwin compiles git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2@363 a5681a0c-68f1-0310-ab6d-d61299d08faa --- program/src/rrd_afm.c | 2 +- program/src/rrd_cgi.c | 4 ++-- program/src/rrd_graph.c | 33 +++++++++++++++++++++++---------- program/src/rrd_nan_inf.c | 2 +- program/src/rrd_open.c | 4 ++-- program/src/rrd_restore.c | 4 ++-- program/src/rrd_rpncalc.c | 2 +- program/src/rrd_tool.c | 6 +++--- program/src/rrd_tool.h | 19 ++++++++++--------- program/src/rrd_update.c | 28 ++++++++++++++-------------- program/src/rrd_xport.c | 2 +- program/src/rrdupdate.c | 26 +++++++++++++------------- 12 files changed, 73 insertions(+), 59 deletions(-) diff --git a/program/src/rrd_afm.c b/program/src/rrd_afm.c index b9996f45..04abde57 100644 --- a/program/src/rrd_afm.c +++ b/program/src/rrd_afm.c @@ -4,7 +4,7 @@ * rrd_afm.h Parsing afm tables to find width of strings. ****************************************************************************/ -#ifdef WIN32 +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) #include "../confignt/config.h" #else #include "config.h" diff --git a/program/src/rrd_cgi.c b/program/src/rrd_cgi.c index 5fc5a623..dac2755c 100644 --- a/program/src/rrd_cgi.c +++ b/program/src/rrd_cgi.c @@ -443,7 +443,7 @@ char* rrdgetenv(long argc, const char **args) { if (envvar) { return stralloc(envvar); } else { -#ifdef WIN32 +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) _snprintf(buf, sizeof(buf), "[ERROR:_getenv_'%s'_failed", args[0]); #else snprintf(buf, sizeof(buf), "[ERROR:_getenv_'%s'_failed", args[0]); @@ -463,7 +463,7 @@ char* rrdgetvar(long argc, const char **args) { if (value) { return stralloc(value); } else { -#ifdef WIN32 +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) _snprintf(buf, sizeof(buf), "[ERROR:_getvar_'%s'_failed", args[0]); #else snprintf(buf, sizeof(buf), "[ERROR:_getvar_'%s'_failed", args[0]); diff --git a/program/src/rrd_graph.c b/program/src/rrd_graph.c index 0152dd1a..367d3524 100644 --- a/program/src/rrd_graph.c +++ b/program/src/rrd_graph.c @@ -9,7 +9,7 @@ #include "rrd_tool.h" -#ifdef WIN32 +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) #include #include #endif @@ -27,9 +27,6 @@ /* some constant definitions */ -#ifdef WIN32 -char rrd_win_default_font[80]; -#endif #ifndef RRD_DEFAULT_FONT /* there is special code later to pick Cour.ttf when running on windows */ @@ -2570,7 +2567,7 @@ graph_paint(image_desc_t *im, char ***calcpr) if (strcmp(im->graphfile,"-")==0) { fo = im->graphhandle ? im->graphhandle : stdout; -#ifdef WIN32 +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) /* Change translation mode for stdout to BINARY */ _setmode( _fileno( fo ), O_BINARY ); #endif @@ -2769,19 +2766,34 @@ rrd_graph_init(image_desc_t *im) for(i=0;igraph_col[i]=graph_col[i]; -#ifdef WIN32 + +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) { char *windir; + char rrd_win_default_font[1000]; windir = getenv("windir"); /* %windir% is something like D:\windows or C:\winnt */ if (windir != NULL) { - strcpy(rrd_win_default_font,windir); + strncpy(rrd_win_default_font,windir,999); + rrd_win_default_font[999] = '\0'; strcat(rrd_win_default_font,"\\fonts\\cour.ttf"); - for(i=0;itext_prop[i].size = text_prop[i].size; strcpy(im->text_prop[i].font,text_prop[i].font); @@ -2911,6 +2923,7 @@ rrd_graph_options(int argc, char *argv[],image_desc_t *im) &im->xlab_user.precis, &stroff) == 7 && stroff != 0){ strncpy(im->xlab_form, optarg+stroff, sizeof(im->xlab_form) - 1); + im->xlab_form[sizeof(im->xlab_form)-1] = '\0'; if((int)(im->xlab_user.gridtm = tmt_conv(scan_gtm)) == -1){ rrd_set_error("unknown keyword %s",scan_gtm); return; diff --git a/program/src/rrd_nan_inf.c b/program/src/rrd_nan_inf.c index ce0873e5..f40555d2 100644 --- a/program/src/rrd_nan_inf.c +++ b/program/src/rrd_nan_inf.c @@ -1,6 +1,6 @@ #include "rrd_nan_inf.h" -#if defined(WIN32) +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) #include diff --git a/program/src/rrd_open.c b/program/src/rrd_open.c index 2ceabae1..5f5a08ee 100644 --- a/program/src/rrd_open.c +++ b/program/src/rrd_open.c @@ -78,13 +78,13 @@ rrd_open(const char *file_name, FILE **in_file, rrd_t *rrd, int rdwr) rrd_init(rrd); if (rdwr == RRD_READONLY) { -#ifndef WIN32 +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) mode = "r"; #else mode = "rb"; #endif } else { -#ifndef WIN32 +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) mode = "r+"; #else mode = "rb+"; diff --git a/program/src/rrd_restore.c b/program/src/rrd_restore.c index 3857f96f..3315c69c 100644 --- a/program/src/rrd_restore.c +++ b/program/src/rrd_restore.c @@ -8,7 +8,7 @@ #include "rrd_rpncalc.h" #include -#ifdef WIN32 +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) #include #define open _open #define close _close @@ -421,7 +421,7 @@ rrd_write(char *file_name, rrd_t *rrd, char force_overwrite) if (strcmp("-",file_name)==0){ rrd_file= stdout; } else { -#ifdef WIN32 +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) fdflags = O_RDWR|O_BINARY|O_CREAT; #else fdflags = O_WRONLY|O_CREAT; diff --git a/program/src/rrd_rpncalc.c b/program/src/rrd_rpncalc.c index 21ec8f00..73bef2f5 100644 --- a/program/src/rrd_rpncalc.c +++ b/program/src/rrd_rpncalc.c @@ -97,7 +97,7 @@ void rpn_compact2str(rpn_cdefds_t *rpnc,ds_def_t *ds_def,char **str) if (rpnc[i].op == OP_NUMBER) { /* convert a short into a string */ -#ifdef WIN32 +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) _itoa(rpnc[i].val,buffer,10); #else sprintf(buffer,"%d",rpnc[i].val); diff --git a/program/src/rrd_tool.c b/program/src/rrd_tool.c index e2bd1db3..e6caff77 100644 --- a/program/src/rrd_tool.c +++ b/program/src/rrd_tool.c @@ -23,10 +23,10 @@ void PrintUsage(char *cmd) char help_main[] = "RRDtool 1.2rc3 Copyright 1997-2005 by Tobias Oetiker \n" -#ifndef WIN32 - " Compiled " MAKE_TIMESTAMP "\n\n" -#else +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) " Compiled " __DATE__ " " __TIME__ "\n\n" +#else + " Compiled " MAKE_TIMESTAMP "\n\n" #endif "Usage: rrdtool [options] command command_options\n\n"; diff --git a/program/src/rrd_tool.h b/program/src/rrd_tool.h index f39cbe3d..37f4a7ed 100644 --- a/program/src/rrd_tool.h +++ b/program/src/rrd_tool.h @@ -11,7 +11,7 @@ extern "C" { #ifndef _RRD_TOOL_H #define _RRD_TOOL_H -#ifdef WIN32 +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) #include "../confignt/config.h" #else #ifdef HAVE_CONFIG_H @@ -95,14 +95,7 @@ extern int getrusage(int, struct rusage *); #include "rrd.h" -#ifndef WIN32 - -/* unix-only includes */ -#ifndef isnan -int isnan(double value); -#endif - -#else +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) /* Win32 only includes */ @@ -114,6 +107,14 @@ struct tm* localtime_r(const time_t *timep, struct tm* result); char* ctime_r(const time_t *timep, char* result); struct tm* gmtime_r(const time_t *timep, struct tm* result); char *strtok_r(char *str, const char *sep, char **last); + +#else + +/* unix-only includes */ +#ifndef isnan +int isnan(double value); +#endif + #endif /* local include files -- need to be after the system ones */ diff --git a/program/src/rrd_update.c b/program/src/rrd_update.c index 728db8e1..0f0bf3d5 100644 --- a/program/src/rrd_update.c +++ b/program/src/rrd_update.c @@ -13,7 +13,7 @@ #include #endif -#ifdef WIN32 +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) #include #include #include @@ -24,7 +24,7 @@ #include "rrd_is_thread_safe.h" -#ifdef WIN32 +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) /* * WIN32 does not have gettimeofday and struct timeval. This is a quick and dirty * replacement. @@ -1383,10 +1383,10 @@ _rrd_update(char *filename, char *template, int argc, char **argv, * critical except during the burning cycles. */ if (schedule_smooth) { -#ifndef WIN32 - rrd_file = fopen(filename,"r+"); -#else +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) rrd_file = fopen(filename,"rb+"); +#else + rrd_file = fopen(filename,"r+"); #endif rra_start = rra_begin; for (i = 0; i < rrd.stat_head -> rra_cnt; ++i) @@ -1429,15 +1429,7 @@ LockRRD(FILE *rrdfile) rrd_fd = fileno(rrdfile); { -#ifndef WIN32 - struct flock lock; - lock.l_type = F_WRLCK; /* exclusive write lock */ - lock.l_len = 0; /* whole file */ - lock.l_start = 0; /* start of file */ - lock.l_whence = SEEK_SET; /* end of file */ - - rcstat = fcntl(rrd_fd, F_SETLK, &lock); -#else +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) struct _stat st; if ( _fstat( rrd_fd, &st ) == 0 ) { @@ -1445,6 +1437,14 @@ LockRRD(FILE *rrdfile) } else { rcstat = -1; } +#else + struct flock lock; + lock.l_type = F_WRLCK; /* exclusive write lock */ + lock.l_len = 0; /* whole file */ + lock.l_start = 0; /* start of file */ + lock.l_whence = SEEK_SET; /* end of file */ + + rcstat = fcntl(rrd_fd, F_SETLK, &lock); #endif } diff --git a/program/src/rrd_xport.c b/program/src/rrd_xport.c index 158d7262..43f84f97 100644 --- a/program/src/rrd_xport.c +++ b/program/src/rrd_xport.c @@ -10,7 +10,7 @@ #include "rrd_graph.h" #include "rrd_xport.h" -#ifdef WIN32 +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) #include #include #endif diff --git a/program/src/rrdupdate.c b/program/src/rrdupdate.c index e61cea41..ed9b3f81 100644 --- a/program/src/rrdupdate.c +++ b/program/src/rrdupdate.c @@ -24,7 +24,7 @@ #include #include -#ifdef WIN32 +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) #include #include #include @@ -1088,10 +1088,10 @@ rrd_update(int argc, char **argv) * critical except during the burning cycles. */ if (schedule_smooth) { -#ifndef WIN32 - rrd_file = fopen(argv[optind],"r+"); -#else +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) rrd_file = fopen(argv[optind],"rb+"); +#else + rrd_file = fopen(argv[optind],"r+"); #endif rra_start = rra_begin; for (i = 0; i < rrd.stat_head -> rra_cnt; ++i) @@ -1134,15 +1134,7 @@ LockRRD(FILE *rrdfile) rrd_fd = fileno(rrdfile); { -#ifndef WIN32 - struct flock lock; - lock.l_type = F_WRLCK; /* exclusive write lock */ - lock.l_len = 0; /* whole file */ - lock.l_start = 0; /* start of file */ - lock.l_whence = SEEK_SET; /* end of file */ - - stat = fcntl(rrd_fd, F_SETLK, &lock); -#else +#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) struct _stat st; if ( _fstat( rrd_fd, &st ) == 0 ) { @@ -1150,6 +1142,14 @@ LockRRD(FILE *rrdfile) } else { stat = -1; } +#else + struct flock lock; + lock.l_type = F_WRLCK; /* exclusive write lock */ + lock.l_len = 0; /* whole file */ + lock.l_start = 0; /* start of file */ + lock.l_whence = SEEK_SET; /* end of file */ + + stat = fcntl(rrd_fd, F_SETLK, &lock); #endif } -- 2.30.2