]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Fix 64-bit time_t in fprintf, printf (MSVC) 856/head
authorWolfgang Stöggl <c72578@yahoo.de>
Sun, 31 Dec 2017 13:38:29 +0000 (14:38 +0100)
committerWolfgang Stöggl <c72578@yahoo.de>
Sun, 31 Dec 2017 13:38:29 +0000 (14:38 +0100)
- In VS2005 and later, the default size for time_t is 64-bit, unless
  _USE_32BIT_TIME_T has been defined to use a 32-bit time_t ...

- Fixes MSVC compiler warnings:
  ./src\rrd_graph_helper.c(1465): warning C4477: 'fprintf' :
  format string '%li' requires an argument of type 'long',
  but variadic argument 1 has type 'time_t'

  ./src\rrd_lastupdate.c(83): warning C4477: 'printf' :
  format string '%10lu' requires an argument of type 'unsigned long',
  but variadic argument 1 has type 'time_t'

  ./src\rrd_tool.c(720): warning C4477: 'printf' : format string '%ld'
  requires an argument of type 'long', but variadic argument 1 has type
  'time_t'
  ./src\rrd_tool.c(724): warning C4477: 'printf' : format string '%ld'
  requires an argument of type 'long', but variadic argument 1 has type
  'time_t'
  ./src\rrd_tool.c(742): warning C4477: 'printf' : format string
  '%10lu' requires an argument of type 'unsigned long', but variadic
  argument 1 has type 'time_t'

src/rrd_graph_helper.c
src/rrd_lastupdate.c
src/rrd_tool.c

index a02720eef641b1bfeceacbdfc19030e935500ced..5d3f09298780a2ab526b19d0472ce061fd267d26 100644 (file)
@@ -1459,7 +1459,7 @@ static int parse_shift(enum gf_en gf,parsedargs_t* pa,image_desc_t *const im) {
   if (gdp->shidx>=0) {
     dprintf("SHIFTBY : %s (%i)\n",im->gdes[gdp->shidx].vname,gdp->shidx);
   } else {
-#ifdef __MINGW64__
+#if defined _WIN32 && SIZEOF_TIME_T == 8    /* in case of __MINGW64__, _WIN64 and _MSC_VER >= 1400 (ifndef _USE_32BIT_TIME_T) */
     dprintf("SHIFTBY : %lli\n",gdp->shval); /* argument 3 has type 'time_t {aka long long int}' */
 #else
     dprintf("SHIFTBY : %li\n",gdp->shval);
index 4e30878944ad8b890699183f56a14faa326a8f12..cca910290b15ada0021e76233d6b1e3aae4bede0 100644 (file)
@@ -77,8 +77,8 @@ int rrd_lastupdate (int argc, char **argv)
         printf(" %s", ds_names[i]);
     printf ("\n\n");
 
-#ifdef __MINGW64__
-    printf ("%10llu:", last_update);    /* argument 2 has type 'time_t {aka long long int} */
+#if defined _WIN32 && SIZEOF_TIME_T == 8    /* in case of __MINGW64__, _WIN64 and _MSC_VER >= 1400 (ifndef _USE_32BIT_TIME_T) */
+    printf ("%10llu:", last_update);        /* argument 2 has type 'time_t {aka long long int} */
 #else
     printf ("%10lu:", last_update);
 #endif
index bfaf73f14f695a1121a18e07e7930c7af7bfab74..1cb84c8c180cfc4b090863be6ea6dfa02ae9b13f 100644 (file)
@@ -717,11 +717,19 @@ static int HandleInputLine(
     else if (strcmp("resize", argv[1]) == 0)
         rrd_resize(argc - 1, &argv[1]);
     else if (strcmp("last", argv[1]) == 0)
+#if defined _WIN32 && SIZEOF_TIME_T == 8    /* in case of __MINGW64__, _WIN64 and _MSC_VER >= 1400 (ifndef _USE_32BIT_TIME_T) */
+        printf("%lld\n", rrd_last(argc - 1, &argv[1]));
+#else
         printf("%ld\n", rrd_last(argc - 1, &argv[1]));
+#endif
     else if (strcmp("lastupdate", argv[1]) == 0) {
         rrd_lastupdate(argc - 1, &argv[1]);
     } else if (strcmp("first", argv[1]) == 0)
+#if defined _WIN32 && SIZEOF_TIME_T == 8    /* in case of __MINGW64__, _WIN64 and _MSC_VER >= 1400 (ifndef _USE_32BIT_TIME_T) */
+        printf("%lld\n", rrd_first(argc - 1, &argv[1]));
+#else
         printf("%ld\n", rrd_first(argc - 1, &argv[1]));
+#endif
     else if (strcmp("update", argv[1]) == 0)
         rrd_update(argc - 1, &argv[1]);
     else if (strcmp("fetch", argv[1]) == 0) {
@@ -739,7 +747,11 @@ static int HandleInputLine(
                 printf("%20s", ds_namv[i]);
             printf("\n\n");
             for (ti = start + step; ti <= end; ti += step) {
+#if defined _WIN32 && SIZEOF_TIME_T == 8    /* in case of __MINGW64__, _WIN64 and _MSC_VER >= 1400 (ifndef _USE_32BIT_TIME_T) */
+                printf("%10llu:", ti);
+#else
                 printf("%10lu:", ti);
+#endif
                 for (ii = 0; ii < ds_cnt; ii++)
                     printf(" %0.10e", *(datai++));
                 printf("\n");