From bac209eb1d120c27acc1ede8fa7dfef81f3eaaf1 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/program@363 a5681a0c-68f1-0310-ab6d-d61299d08faa --- src/rrd_afm.c | 2 +- src/rrd_cgi.c | 4 ++-- src/rrd_graph.c | 33 +++++++++++++++++++++++---------- src/rrd_nan_inf.c | 2 +- src/rrd_open.c | 4 ++-- src/rrd_restore.c | 4 ++-- src/rrd_rpncalc.c | 2 +- src/rrd_tool.c | 6 +++--- src/rrd_tool.h | 19 ++++++++++--------- src/rrd_update.c | 28 ++++++++++++++-------------- src/rrd_xport.c | 2 +- src/rrdupdate.c | 26 +++++++++++++------------- 12 files changed, 73 insertions(+), 59 deletions(-) diff --git a/src/rrd_afm.c b/src/rrd_afm.c index b9996f4..04abde5 100644 --- a/src/rrd_afm.c +++ b/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/src/rrd_cgi.c b/src/rrd_cgi.c index 5fc5a62..dac2755 100644 --- a/src/rrd_cgi.c +++ b/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/src/rrd_graph.c b/src/rrd_graph.c index 0152dd1..367d352 100644 --- a/src/rrd_graph.c +++ b/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/src/rrd_nan_inf.c b/src/rrd_nan_inf.c index ce0873e..f40555d 100644 --- a/src/rrd_nan_inf.c +++ b/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/src/rrd_open.c b/src/rrd_open.c index 2ceabae..5f5a08e 100644 --- a/src/rrd_open.c +++ b/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/src/rrd_restore.c b/src/rrd_restore.c index 3857f96..3315c69 100644 --- a/src/rrd_restore.c +++ b/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/src/rrd_rpncalc.c b/src/rrd_rpncalc.c index 21ec8f0..73bef2f 100644 --- a/src/rrd_rpncalc.c +++ b/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/src/rrd_tool.c b/src/rrd_tool.c index e2bd1db..e6caff7 100644 --- a/src/rrd_tool.c +++ b/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/src/rrd_tool.h b/src/rrd_tool.h index f39cbe3..37f4a7e 100644 --- a/src/rrd_tool.h +++ b/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/src/rrd_update.c b/src/rrd_update.c index 728db8e..0f0bf3d 100644 --- a/src/rrd_update.c +++ b/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/src/rrd_xport.c b/src/rrd_xport.c index 158d726..43f84f9 100644 --- a/src/rrd_xport.c +++ b/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/src/rrdupdate.c b/src/rrdupdate.c index e61cea4..ed9b3f8 100644 --- a/src/rrdupdate.c +++ b/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.11.0