make sure WIN32 sections do NOT kick in for cygwin compiles
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Wed, 6 Apr 2005 22:40:53 +0000 (22:40 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Wed, 6 Apr 2005 22:40:53 +0000 (22:40 +0000)
git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@363 a5681a0c-68f1-0310-ab6d-d61299d08faa

12 files changed:
src/rrd_afm.c
src/rrd_cgi.c
src/rrd_graph.c
src/rrd_nan_inf.c
src/rrd_open.c
src/rrd_restore.c
src/rrd_rpncalc.c
src/rrd_tool.c
src/rrd_tool.h
src/rrd_update.c
src/rrd_xport.c
src/rrdupdate.c

index b9996f4..04abde5 100644 (file)
@@ -4,7 +4,7 @@
  * rrd_afm.h  Parsing afm tables to find width of strings.
  ****************************************************************************/
 
  * 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"
 #include "../confignt/config.h"
 #else
 #include "config.h"
index 5fc5a62..dac2755 100644 (file)
@@ -443,7 +443,7 @@ char* rrdgetenv(long argc, const char **args) {
        if (envvar) {
                return stralloc(envvar);
        } else {
        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]);
                _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 {
        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]);
                _snprintf(buf, sizeof(buf), "[ERROR:_getvar_'%s'_failed", args[0]);
 #else
                 snprintf(buf, sizeof(buf), "[ERROR:_getvar_'%s'_failed", args[0]);
index 0152dd1..367d352 100644 (file)
@@ -9,7 +9,7 @@
 
 #include "rrd_tool.h"
 
 
 #include "rrd_tool.h"
 
-#ifdef WIN32
+#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
 #include <io.h>
 #include <fcntl.h>
 #endif
 #include <io.h>
 #include <fcntl.h>
 #endif
@@ -27,9 +27,6 @@
 /* some constant definitions */
 
 
 /* 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 */
 
 #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;
   
   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
     /* 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;i<DIM(graph_col);i++)
         im->graph_col[i]=graph_col[i];
     
     for(i=0;i<DIM(graph_col);i++)
         im->graph_col[i]=graph_col[i];
-#ifdef WIN32
+
+#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
     {
             char *windir; 
     {
             char *windir; 
+           char rrd_win_default_font[1000];
             windir = getenv("windir");
             /* %windir% is something like D:\windows or C:\winnt */
             if (windir != NULL) {
             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");
                     strcat(rrd_win_default_font,"\\fonts\\cour.ttf");
-                    for(i=0;i<DIM(text_prop);i++)
-                            strcpy(text_prop[i].font,rrd_win_default_font);
-            }
+                    for(i=0;i<DIM(text_prop);i++){
+                            strncpy(text_prop[i].font,rrd_win_default_font,sizeof(text_prop[i].font)-1);
+                            text_prop[i].font[sizeof(text_prop[i].font)-1] = '\0';
+                     }
     }
 #endif
     }
 #endif
+    {
+            char *deffont; 
+            deffont = getenv("RRD_DEFAULT_FONT");
+            /* %windir% is something like D:\windows or C:\winnt */
+            if (deffont != NULL) {
+                 for(i=0;i<DIM(text_prop);i++){
+                       strncpy(text_prop[i].font,deffont,sizeof(text_prop[i].font)-1);
+                       text_prop[i].font[sizeof(text_prop[i].font)-1] = '\0';
+                }
+            }
+    }
     for(i=0;i<DIM(text_prop);i++){        
       im->text_prop[i].size = text_prop[i].size;
       strcpy(im->text_prop[i].font,text_prop[i].font);
     for(i=0;i<DIM(text_prop);i++){        
       im->text_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_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;
                if((int)(im->xlab_user.gridtm = tmt_conv(scan_gtm)) == -1){
                    rrd_set_error("unknown keyword %s",scan_gtm);
                    return;
index ce0873e..f40555d 100644 (file)
@@ -1,6 +1,6 @@
 #include "rrd_nan_inf.h"
 
 #include "rrd_nan_inf.h"
 
-#if defined(WIN32)
+#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
 
 #include <math.h>
 
 
 #include <math.h>
 
index 2ceabae..5f5a08e 100644 (file)
@@ -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) {
     
     rrd_init(rrd);
     if (rdwr == RRD_READONLY) {
-#ifndef WIN32
+#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
        mode = "r";
 #else
        mode = "rb";
 #endif
     } else {
        mode = "r";
 #else
        mode = "rb";
 #endif
     } else {
-#ifndef WIN32
+#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
        mode = "r+";
 #else
        mode = "rb+";
        mode = "r+";
 #else
        mode = "rb+";
index 3857f96..3315c69 100644 (file)
@@ -8,7 +8,7 @@
 #include "rrd_rpncalc.h"
 #include <fcntl.h>
 
 #include "rrd_rpncalc.h"
 #include <fcntl.h>
 
-#ifdef WIN32
+#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
 #include <io.h>
 #define open _open
 #define close _close
 #include <io.h>
 #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 {
     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;
       fdflags = O_RDWR|O_BINARY|O_CREAT;
 #else
       fdflags = O_WRONLY|O_CREAT;
index 21ec8f0..73bef2f 100644 (file)
@@ -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 */
         
         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);
             _itoa(rpnc[i].val,buffer,10);
 #else
             sprintf(buffer,"%d",rpnc[i].val);
index e2bd1db..e6caff7 100644 (file)
@@ -23,10 +23,10 @@ void PrintUsage(char *cmd)
 
     char help_main[] =
           "RRDtool 1.2rc3  Copyright 1997-2005 by Tobias Oetiker <tobi@oetiker.ch>\n"
 
     char help_main[] =
           "RRDtool 1.2rc3  Copyright 1997-2005 by Tobias Oetiker <tobi@oetiker.ch>\n"
-#ifndef WIN32
-           "               Compiled " MAKE_TIMESTAMP "\n\n"
-#else
+#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
            "               Compiled " __DATE__ " " __TIME__ "\n\n"
            "               Compiled " __DATE__ " " __TIME__ "\n\n"
+#else
+           "               Compiled " MAKE_TIMESTAMP "\n\n"
 #endif          
           "Usage: rrdtool [options] command command_options\n\n";
 
 #endif          
           "Usage: rrdtool [options] command command_options\n\n";
 
index f39cbe3..37f4a7e 100644 (file)
@@ -11,7 +11,7 @@ extern "C" {
 #ifndef _RRD_TOOL_H
 #define _RRD_TOOL_H
 
 #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
 #include "../confignt/config.h"
 #else
 #ifdef HAVE_CONFIG_H
@@ -95,14 +95,7 @@ extern int getrusage(int, struct rusage *);
 
 #include "rrd.h"
 
 
 #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 */
 
 
 /* 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);
 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 */
 #endif
 
 /* local include files -- need to be after the system ones */
index 728db8e..0f0bf3d 100644 (file)
@@ -13,7 +13,7 @@
  #include <sys/mman.h>
 #endif
 
  #include <sys/mman.h>
 #endif
 
-#ifdef WIN32
+#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
  #include <sys/locking.h>
  #include <sys/stat.h>
  #include <io.h>
  #include <sys/locking.h>
  #include <sys/stat.h>
  #include <io.h>
@@ -24,7 +24,7 @@
 
 #include "rrd_is_thread_safe.h"
 
 
 #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.
 /*
  * 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)
        {
         * 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+");
          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)
 #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);
 
        {
     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 ) {
     struct _stat st;
 
     if ( _fstat( rrd_fd, &st ) == 0 ) {
@@ -1445,6 +1437,14 @@ LockRRD(FILE *rrdfile)
     } else {
            rcstat = -1;
     }
     } 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
        }
 
 #endif
        }
 
index 158d726..43f84f9 100644 (file)
@@ -10,7 +10,7 @@
 #include "rrd_graph.h"
 #include "rrd_xport.h"
 
 #include "rrd_graph.h"
 #include "rrd_xport.h"
 
-#ifdef WIN32
+#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
 #include <io.h>
 #include <fcntl.h>
 #endif
 #include <io.h>
 #include <fcntl.h>
 #endif
index e61cea4..ed9b3f8 100644 (file)
@@ -24,7 +24,7 @@
 #include <sys/types.h>
 #include <fcntl.h>
 
 #include <sys/types.h>
 #include <fcntl.h>
 
-#ifdef WIN32
+#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
  #include <sys/locking.h>
  #include <sys/stat.h>
  #include <io.h>
  #include <sys/locking.h>
  #include <sys/stat.h>
  #include <io.h>
@@ -1088,10 +1088,10 @@ rrd_update(int argc, char **argv)
         * critical except during the burning cycles. */
        if (schedule_smooth)
        {
         * 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+");
          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)
 #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);
 
        {
     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 ) {
                struct _stat st;
 
                if ( _fstat( rrd_fd, &st ) == 0 ) {
@@ -1150,6 +1142,14 @@ LockRRD(FILE *rrdfile)
                } else {
                        stat = -1;
                }
                } 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
        }
 
 #endif
        }