--- rrdtool-1.4.7/src/rrd.h	2012-01-24 11:08:48.000000000 +0100
+++ src/src/rrd.h	2024-08-07 19:17:45.247663788 +0200
@@ -71,6 +71,16 @@
 #include <stdio.h>      /* for FILE */
 #include <string.h>
 
+#include <stdint.h>
+#if UINTPTR_MAX == 0xffffffff
+typedef int32_t rrdtime_t;
+#elif UINTPTR_MAX == 0xffffffffffffffff
+typedef int64_t rrdtime_t;
+#else
+#error "could not guess arch long size"
+#endif
+
+
 /* Formerly rrd_nan_inf.h */
 #ifndef DNAN
 # define DNAN rrd_set_to_DNAN()
@@ -179,8 +189,8 @@
     int       rrd_fetch(
     int,
     char **,
-    time_t *,
-    time_t *,
+    rrdtime_t *,
+    rrdtime_t *,
     unsigned long *,
     unsigned long *,
     char ***,
@@ -194,11 +204,11 @@
     int       rrd_tune(
     int,
     char **);
-    time_t    rrd_last(
+    rrdtime_t    rrd_last(
     int,
     char **);
     int rrd_lastupdate(int argc, char **argv);
-    time_t    rrd_first(
+    rrdtime_t    rrd_first(
     int,
     char **);
     int       rrd_resize(
@@ -212,8 +222,8 @@
     int,
     char **,
     int *,
-    time_t *,
-    time_t *,
+    rrdtime_t *,
+    rrdtime_t *,
     unsigned long *,
     unsigned long *,
     char ***,
@@ -227,7 +237,7 @@
     int       rrd_create_r(
     const char *filename,
     unsigned long pdp_step,
-    time_t last_up,
+    rrdtime_t last_up,
     int argc,
     const char **argv);
     rrd_info_t *rrd_info_r(
@@ -243,8 +253,8 @@
     int rrd_fetch_r (
             const char *filename,
             const char *cf,
-            time_t *start,
-            time_t *end,
+            rrdtime_t *start,
+            rrdtime_t *end,
             unsigned long *step,
             unsigned long *ds_cnt,
             char ***ds_namv,
@@ -252,13 +262,13 @@
     int       rrd_dump_r(
     const char *filename,
     char *outname);
-    time_t    rrd_last_r (const char *filename);
+    rrdtime_t    rrd_last_r (const char *filename);
     int rrd_lastupdate_r (const char *filename,
-            time_t *ret_last_update,
+            rrdtime_t *ret_last_update,
             unsigned long *ret_ds_count,
             char ***ret_ds_names,
             char ***ret_last_ds);
-    time_t    rrd_first_r(
+    rrdtime_t    rrd_first_r(
     const char *filename,
     int rraindex);
 
@@ -305,8 +315,8 @@
 int       rrd_proc_start_end(
     rrd_time_value_t *,
     rrd_time_value_t *,
-    time_t *,
-    time_t *);
+    rrdtime_t *,
+    rrdtime_t *);
 
 /* HELPER FUNCTIONS */
     void      rrd_set_error(
@@ -419,7 +429,7 @@
     rrd_file_t *rrd_file,
     int rra_idx,
     unsigned long rra_row,
-    time_t rra_time)
+    rrdtime_t rra_time)
               RRD_DEPRECATED;
     unsigned long rrd_select_initial_row(
     rrd_file_t *rrd_file,
diff -ru rrdtool-1.4.7/src/rrd_cgi.c src/src/rrd_cgi.c
--- rrdtool-1.4.7/src/rrd_cgi.c	2012-01-24 11:08:48.000000000 +0100
+++ src/src/rrd_cgi.c	2024-08-07 19:11:58.487842823 +0200
@@ -114,7 +114,7 @@
 
 /** HTTP protocol needs special format, and GMT time **/
 char     *http_time(
-    time_t *);
+    rrdtime_t *);
 
 /* return a pointer to newly allocated copy of this string */
 char     *stralloc(
@@ -562,7 +562,7 @@
                "Content-Length: %zd\n", strlen(buffer));
 
         if (labs(goodfor) > 0) {
-            time_t    now;
+            rrdtime_t    now;
 
             now = time(NULL);
             printf("Last-Modified: %s\n", http_time(&now));
@@ -733,7 +733,7 @@
     char     *parsetime_error = NULL;
     char      formatted[MAX_STRFTIME_SIZE];
     struct tm *the_tm;
-    time_t    start_tmp, end_tmp;
+    rrdtime_t    start_tmp, end_tmp;
 
     /* Make sure that we were given the right number of args */
     if (argc != 4) {
@@ -984,7 +984,7 @@
     long argc,
     const char **args)
 {
-    time_t    last;
+    rrdtime_t    last;
     struct tm tm_last;
     char     *buf;
 
@@ -1016,7 +1016,7 @@
     long argc,
     const char **args)
 {
-    time_t    now = time(NULL);
+    rrdtime_t    now = time(NULL);
     struct tm tm_now;
     char     *buf;
 
@@ -1308,7 +1308,7 @@
 }
 
 char     *http_time(
-    time_t *now)
+    rrdtime_t *now)
 {
     struct tm *tmptime;
     static char buf[60];
diff -ru rrdtool-1.4.7/src/rrd_create.c src/src/rrd_create.c
--- rrdtool-1.4.7/src/rrd_create.c	2012-01-24 11:08:48.000000000 +0100
+++ src/src/rrd_create.c	2024-08-07 19:11:58.487842823 +0200
@@ -45,7 +45,7 @@
     };
     int       option_index = 0;
     int       opt;
-    time_t    last_up = time(NULL) - 10;
+    rrdtime_t    last_up = time(NULL) - 10;
     unsigned long pdp_step = 300;
     rrd_time_value_t last_up_tv;
     char     *parsetime_error = NULL;
@@ -119,7 +119,7 @@
 int rrd_create_r(
     const char *filename,
     unsigned long pdp_step,
-    time_t last_up,
+    rrdtime_t last_up,
     int argc,
     const char **argv)
 {
diff -ru rrdtool-1.4.7/src/rrd_daemon.c src/src/rrd_daemon.c
--- rrdtool-1.4.7/src/rrd_daemon.c	2011-12-16 08:29:44.000000000 +0100
+++ src/src/rrd_daemon.c	2024-08-07 19:11:58.487842823 +0200
@@ -128,7 +128,7 @@
   int family;
 
   /* state for BATCH processing */
-  time_t batch_start;
+  rrdtime_t batch_start;
   int batch_cmd;
 
   /* buffered IO */
@@ -150,7 +150,7 @@
 typedef struct command_s command_t;
 /* note: guard against "unused" warnings in the handlers */
 #define DISPATCH_PROTO	listen_socket_t UNUSED(*sock),\
-			time_t UNUSED(now),\
+			rrdtime_t UNUSED(now),\
 			char  UNUSED(*buffer),\
 			size_t UNUSED(buffer_size)
 
@@ -178,7 +178,7 @@
   char *file;
   char **values;
   size_t values_num;
-  time_t last_flush_time;
+  rrdtime_t last_flush_time;
   double last_update_stamp;
 #define CI_FLAGS_IN_TREE  (1<<0)
 #define CI_FLAGS_IN_QUEUE (1<<1)
@@ -190,8 +190,8 @@
 
 struct callback_flush_data_s
 {
-  time_t now;
-  time_t abs_timeout;
+  rrdtime_t now;
+  rrdtime_t abs_timeout;
   char **keys;
   size_t keys_num;
 };
@@ -639,7 +639,7 @@
   return 0;
 } /* }}} */
 
-static void wipe_ci_values(cache_item_t *ci, time_t when)
+static void wipe_ci_values(cache_item_t *ci, rrdtime_t when)
 {
   ci->values = NULL;
   ci->values_num = 0;
@@ -2001,7 +2001,7 @@
   int fail_cnt = 0;
   uint64_t line = 0;
   char entry[CMD_MAX];
-  time_t now;
+  rrdtime_t now;
 
   if (file == NULL) return 0;
 
@@ -2233,7 +2233,7 @@
     char *cmd;
     ssize_t cmd_len;
     ssize_t rbytes;
-    time_t now;
+    rrdtime_t now;
 
     struct pollfd pollfd;
     int status;
diff -ru rrdtool-1.4.7/src/rrd_dump.c src/src/rrd_dump.c
--- rrdtool-1.4.7/src/rrd_dump.c	2012-01-24 11:08:48.000000000 +0100
+++ src/src/rrd_dump.c	2024-08-07 19:17:15.890729766 +0200
@@ -134,7 +134,9 @@
         rrd.stat_head->pdp_step);
 
 #ifdef HAVE_STRFTIME
-    localtime_r(&rrd.live_head->last_up, &tm);
+    time_t last_up = rrd.live_head->last_up;
+    localtime_r(&last_up, &tm);
+    rrd.live_head->last_up = 
     strftime(somestring, 255, "%Y-%m-%d %H:%M:%S %Z", &tm);
 #else
 # error "Need strftime"
diff -ru rrdtool-1.4.7/src/rrd_fetch.c src/src/rrd_fetch.c
--- rrdtool-1.4.7/src/rrd_fetch.c	2012-01-24 11:08:48.000000000 +0100
+++ src/src/rrd_fetch.c	2024-08-07 19:11:58.487842823 +0200
@@ -61,8 +61,8 @@
 int rrd_fetch(
     int argc,
     char **argv,
-    time_t *start,
-    time_t *end,        /* which time frame do you want ?
+    rrdtime_t *start,
+    rrdtime_t *end,        /* which time frame do you want ?
                          * will be changed to represent reality */
     unsigned long *step,    /* which stepsize do you want? 
                              * will be changed to represent reality */
@@ -71,7 +71,7 @@
     rrd_value_t **data)
 {                       /* two dimensional array containing the data */
     long      step_tmp = 1;
-    time_t    start_tmp = 0, end_tmp = 0;
+    rrdtime_t    start_tmp = 0, end_tmp = 0;
     const char *cf;
     char *opt_daemon = NULL;
     int status;
@@ -183,8 +183,8 @@
 int rrd_fetch_r(
     const char *filename,   /* name of the rrd */
     const char *cf,     /* which consolidation function ? */
-    time_t *start,
-    time_t *end,        /* which time frame do you want ?
+    rrdtime_t *start,
+    rrdtime_t *end,        /* which time frame do you want ?
                          * will be changed to represent reality */
     unsigned long *step,    /* which stepsize do you want? 
                              * will be changed to represent reality */
@@ -205,8 +205,8 @@
 int rrd_fetch_fn(
     const char *filename,   /* name of the rrd */
     enum cf_en cf_idx,  /* which consolidation function ? */
-    time_t *start,
-    time_t *end,        /* which time frame do you want ?
+    rrdtime_t *start,
+    rrdtime_t *end,        /* which time frame do you want ?
                          * will be changed to represent reality */
     unsigned long *step,    /* which stepsize do you want? 
                              * will be changed to represent reality */
@@ -215,7 +215,7 @@
     rrd_value_t **data)
 {                       /* two dimensional array containing the data */
     long      i, ii;
-    time_t    cal_start, cal_end, rra_start_time, rra_end_time;
+    rrdtime_t    cal_start, cal_end, rra_start_time, rra_end_time;
     long      best_full_rra = 0, best_part_rra = 0, chosen_rra =
         0, rra_pointer = 0;
     long      best_full_step_diff = 0, best_part_step_diff =
diff -ru rrdtool-1.4.7/src/rrd_fetch_libdbi.c src/src/rrd_fetch_libdbi.c
--- rrdtool-1.4.7/src/rrd_fetch_libdbi.c	2012-01-24 09:20:45.000000000 +0100
+++ src/src/rrd_fetch_libdbi.c	2024-08-07 19:11:58.487842823 +0200
@@ -20,7 +20,7 @@
 /* the prototypes */
 static void _sql_close(struct sql_table_helper* th);
 static int _sql_setparam(struct sql_table_helper* th,char* key, char* value);
-static int _sql_fetchrow(struct sql_table_helper* th,time_t *timestamp, rrd_value_t *value,int ordered);
+static int _sql_fetchrow(struct sql_table_helper* th,rrdtime_t *timestamp, rrd_value_t *value,int ordered);
 static char* _find_next_separator(char* start,char separator);
 static char* _find_next_separator_twice(char*start,char separator);
 static char _hexcharhelper(char c);
@@ -201,10 +201,10 @@
   return 0;
 }
 
-static int _sql_fetchrow(struct sql_table_helper* th,time_t *timestamp, rrd_value_t *value,int ordered) {
+static int _sql_fetchrow(struct sql_table_helper* th,rrdtime_t *timestamp, rrd_value_t *value,int ordered) {
   char* dbi_errstr=NULL;
   char sql[10240];
-  time_t startt=0,endt=0;
+  rrdtime_t startt=0,endt=0;
   /*connect to the database if needed */
   if (! th->conn) {
       rrd_set_error( "libdbi no parameters set for libdbi",th->filename,dbi_errstr);
@@ -367,8 +367,8 @@
 rrd_fetch_fn_libdbi(
     const char     *filename,  /* name of the rrd */
     enum cf_en     UNUSED(cf_idx), /* consolidation function */
-    time_t         *start,
-    time_t         *end,       /* which time frame do you want ?
+    rrdtime_t         *start,
+    rrdtime_t         *end,       /* which time frame do you want ?
 			        * will be changed to represent reality */
     unsigned long  *step,      /* which stepsize do you want? 
 				* will be changed to represent reality */
diff -ru rrdtool-1.4.7/src/rrd_first.c src/src/rrd_first.c
--- rrdtool-1.4.7/src/rrd_first.c	2012-01-24 11:08:48.000000000 +0100
+++ src/src/rrd_first.c	2024-08-07 19:11:58.487842823 +0200
@@ -10,7 +10,7 @@
 #include "rrd_tool.h"
 
 
-time_t rrd_first(
+rrdtime_t rrd_first(
     int argc,
     char **argv)
 {
@@ -57,12 +57,12 @@
 }
 
 
-time_t rrd_first_r(
+rrdtime_t rrd_first_r(
     const char *filename,
     const int rraindex)
 {
     off_t     rra_start, timer;
-    time_t    then = -1;
+    rrdtime_t    then = -1;
     rrd_t     rrd;
     rrd_file_t *rrd_file;
 
diff -ru rrdtool-1.4.7/src/rrd_format.c src/src/rrd_format.c
--- rrdtool-1.4.7/src/rrd_format.c	2012-01-24 11:08:48.000000000 +0100
+++ src/src/rrd_format.c	2024-08-07 19:11:58.487842823 +0200
@@ -108,7 +108,7 @@
     return sizeof(stat_head_t) + \
         sizeof(ds_def_t) * rrd->stat_head->ds_cnt + \
         sizeof(rra_def_t) * rrd->stat_head->rra_cnt + \
-        ( atoi(rrd->stat_head->version) < 3 ? sizeof(time_t) : sizeof(live_head_t) ) + \
+        ( atoi(rrd->stat_head->version) < 3 ? sizeof(rrdtime_t) : sizeof(live_head_t) ) + \
         sizeof(pdp_prep_t) * rrd->stat_head->ds_cnt + \
         sizeof(cdp_prep_t) * rrd->stat_head->ds_cnt * rrd->stat_head->rra_cnt + \
         sizeof(rra_ptr_t) * rrd->stat_head->rra_cnt;
diff -ru rrdtool-1.4.7/src/rrd_format.h src/src/rrd_format.h
--- rrdtool-1.4.7/src/rrd_format.h	2024-08-07 19:18:54.518294823 +0200
+++ src/src/rrd_format.h	2024-08-07 19:11:58.487842823 +0200
@@ -279,7 +279,7 @@
  ****************************************************************************/
 
 typedef struct live_head_t {
-    time_t    last_up;  /* when was rrd last updated */
+    rrdtime_t    last_up;  /* when was rrd last updated */
     long      last_up_usec; /* micro seconds part of the
                                update timestamp. Always >= 0 */
 } live_head_t;
@@ -396,7 +396,7 @@
     ds_def_t *ds_def;   /* list of data source definitions */
     rra_def_t *rra_def; /* list of round robin archive def */
     live_head_t *live_head; /* rrd v >= 3 last_up with us */
-    time_t   *legacy_last_up;   /* rrd v < 3 last_up time */
+    rrdtime_t   *legacy_last_up;   /* rrd v < 3 last_up time */
     pdp_prep_t *pdp_prep;   /* pdp data prep area */
     cdp_prep_t *cdp_prep;   /* cdp prep area */
     rra_ptr_t *rra_ptr; /* list of rra pointers */
diff -ru rrdtool-1.4.7/src/rrd_graph.c src/src/rrd_graph.c
--- rrdtool-1.4.7/src/rrd_graph.c	2012-01-24 11:08:48.000000000 +0100
+++ src/src/rrd_graph.c	2024-08-07 19:11:58.487842823 +0200
@@ -176,7 +176,7 @@
 /* initialize with xtr(im,0); */
 int xtr(
     image_desc_t *im,
-    time_t mytime)
+    rrdtime_t mytime)
 {
     static double pixie;
 
@@ -644,8 +644,8 @@
 void reduce_data(
     enum cf_en cf,      /* which consolidation function ? */
     unsigned long cur_step, /* step the data currently is in */
-    time_t *start,      /* start, end and step as requested ... */
-    time_t *end,        /* ... by the application will be   ... */
+    rrdtime_t *start,      /* start, end and step as requested ... */
+    rrdtime_t *end,        /* ... by the application will be   ... */
     unsigned long *step,    /* ... adjusted to represent reality    */
     unsigned long *ds_cnt,  /* number of data sources in file */
     rrd_value_t **data)
@@ -991,7 +991,7 @@
     int       dataidx;
     long     *steparray, rpi;
     int       stepcnt;
-    time_t    now;
+    rrdtime_t    now;
     rpnstack_t rpnstack;
 
     rpnstack_init(&rpnstack);
@@ -1162,7 +1162,7 @@
 
                 /* 3rd arg of rpn_calc is for OP_VARIABLE lookups;
                  * in this case we are advancing by timesteps;
-                 * we use the fact that time_t is a synonym for long
+                 * we use the fact that rrdtime_t is a synonym for long
                  */
                 if (rpn_calc(rpnp, &rpnstack, (long) now,
                              im->gdes[gdi].data, ++dataidx) == -1) {
@@ -1393,8 +1393,8 @@
 
 /* identify the point where the first gridline, label ... gets placed */
 
-time_t find_first_time(
-    time_t start,       /* what is the initial time */
+rrdtime_t find_first_time(
+    rrdtime_t start,       /* what is the initial time */
     enum tmt_en baseint,    /* what is the basic interval */
     long basestep       /* how many if these do we jump a time */
     )
@@ -1460,14 +1460,14 @@
 }
 
 /* identify the point where the next gridline, label ... gets placed */
-time_t find_next_time(
-    time_t current,     /* what is the initial time */
+rrdtime_t find_next_time(
+    rrdtime_t current,     /* what is the initial time */
     enum tmt_en baseint,    /* what is the basic interval */
     long basestep       /* how many if these do we jump a time */
     )
 {
     struct tm tm;
-    time_t    madetime;
+    rrdtime_t    madetime;
 
     localtime_r(&current, &tm);
 
@@ -1532,7 +1532,7 @@
     int       prline_cnt = 0;
 
     /* wow initializing tmvdef is quite a task :-) */
-    time_t    now = time(NULL);
+    rrdtime_t    now = time(NULL);
 
     localtime_r(&now, &tmvdef);
     for (i = 0; i < im->gdes_c; i++) {
@@ -2462,7 +2462,7 @@
     image_desc_t *im)
 {
     int       xlab_sel; /* which sort of label and grid ? */
-    time_t    ti, tilab, timajor;
+    rrdtime_t    ti, tilab, timajor;
     long      factor;
     char      graph_label[100];
     double    X0, Y0, Y1;   /* points for filled graph and more */
@@ -4185,7 +4185,7 @@
     int       stroff;
     char     *parsetime_error = NULL;
     char      scan_gtm[12], scan_mtm[12], scan_ltm[12], col_nam[12];
-    time_t    start_tmp = 0, end_tmp = 0;
+    rrdtime_t    start_tmp = 0, end_tmp = 0;
     long      long_tmp;
     rrd_time_value_t start_tv, end_tv;
     long unsigned int color;
diff -ru rrdtool-1.4.7/src/rrd_graph.h src/src/rrd_graph.h
--- rrdtool-1.4.7/src/rrd_graph.h	2011-12-15 17:07:05.000000000 +0100
+++ src/src/rrd_graph.h	2024-08-07 19:11:58.487842823 +0200
@@ -117,7 +117,7 @@
     enum vdef_op_en op;
     double    param;    /* parameter for function, if applicable */
     double    val;      /* resulting value */
-    time_t    when;     /* timestamp, if applicable */
+    rrdtime_t    when;     /* timestamp, if applicable */
 } vdef_t;
 
 typedef struct xlab_t {
@@ -172,18 +172,18 @@
     int       strftm;   /* should the VDEF legend be formated with strftime */
     double    leg_x, leg_y; /* location of legend */
     double    yrule;    /* value for y rule line and for VDEF */
-    time_t    xrule;    /* time for x rule line and for VDEF */
+    rrdtime_t    xrule;    /* time for x rule line and for VDEF */
     vdef_t    vf;       /* instruction for VDEF function */
     rpnp_t   *rpnp;     /* instructions for CDEF function */
 
     /* SHIFT implementation */
     int       shidx;    /* gdes reference for offset (-1 --> constant) */
-    time_t    shval;    /* offset if shidx is -1 */
-    time_t    shift;    /* current shift applied */
+    rrdtime_t    shval;    /* offset if shidx is -1 */
+    rrdtime_t    shift;    /* current shift applied */
 
     /* description of data fetched for the graph element */
-    time_t    start, end;   /* timestaps for first and last data element */
-    time_t    start_orig, end_orig; /* timestaps for first and last data element */
+    rrdtime_t    start, end;   /* timestaps for first and last data element */
+    rrdtime_t    start_orig, end_orig; /* timestaps for first and last data element */
     unsigned long step; /* time between samples */
     unsigned long step_orig;    /* time between samples */
     unsigned long ds_cnt;   /* how many data sources are there in the fetch */
@@ -228,7 +228,7 @@
     double    ygridstep;    /* user defined step for y grid */
     int       ylabfact; /* every how many y grid shall a label be written ? */
     double    tabwidth; /* tabwdith */
-    time_t    start, end;   /* what time does the graph cover */
+    rrdtime_t    start, end;   /* what time does the graph cover */
     unsigned long step; /* any preference for the default step ? */
     rrd_value_t minval, maxval; /* extreme values in the data */
     int       rigid;    /* do not expand range even with 
@@ -288,7 +288,7 @@
 /* Prototypes */
 int       xtr(
     image_desc_t *,
-    time_t);
+    rrdtime_t);
 double    ytr(
     image_desc_t *,
     double);
@@ -318,8 +318,8 @@
 void      reduce_data(
     enum cf_en,
     unsigned long,
-    time_t *,
-    time_t *,
+    rrdtime_t *,
+    rrdtime_t *,
     unsigned long *,
     unsigned long *,
     rrd_value_t **);
@@ -337,12 +337,12 @@
     image_desc_t *);
 int       data_proc(
     image_desc_t *);
-time_t    find_first_time(
-    time_t,
+rrdtime_t    find_first_time(
+    rrdtime_t,
     enum tmt_en,
     long);
-time_t    find_next_time(
-    time_t,
+rrdtime_t    find_next_time(
+    rrdtime_t,
     enum tmt_en,
     long);
 int       print_calc(
diff -ru rrdtool-1.4.7/src/rrd_graph_helper.c src/src/rrd_graph_helper.c
--- rrdtool-1.4.7/src/rrd_graph_helper.c	2012-01-24 11:08:48.000000000 +0100
+++ src/src/rrd_graph_helper.c	2024-08-07 19:11:58.487842823 +0200
@@ -888,7 +888,7 @@
     char      command[7];   /* step, start, end, reduce */
     char      tmpstr[256];
     rrd_time_value_t start_tv, end_tv;
-    time_t    start_tmp = 0, end_tmp = 0;
+    rrdtime_t    start_tmp = 0, end_tmp = 0;
     char     *parsetime_error = NULL;
 
     start_tv.type = end_tv.type = ABSOLUTE_TIME;
diff -ru rrdtool-1.4.7/src/rrd_last.c src/src/rrd_last.c
--- rrdtool-1.4.7/src/rrd_last.c	2012-01-24 11:08:48.000000000 +0100
+++ src/src/rrd_last.c	2024-08-07 19:11:58.487842823 +0200
@@ -9,7 +9,7 @@
 #include "rrd_tool.h"
 #include "rrd_client.h"
 
-time_t rrd_last(
+rrdtime_t rrd_last(
     int argc,
     char **argv)
 {
@@ -65,10 +65,10 @@
     return (rrd_last_r (argv[optind]));
 }
 
-time_t rrd_last_r(
+rrdtime_t rrd_last_r(
     const char *filename)
 {
-    time_t    lastup = -1;
+    rrdtime_t    lastup = -1;
     rrd_file_t *rrd_file;
 
     rrd_t     rrd;
diff -ru rrdtool-1.4.7/src/rrd_lastupdate.c src/src/rrd_lastupdate.c
--- rrdtool-1.4.7/src/rrd_lastupdate.c	2012-01-24 11:08:48.000000000 +0100
+++ src/src/rrd_lastupdate.c	2024-08-07 19:11:58.487842823 +0200
@@ -12,7 +12,7 @@
 
 int rrd_lastupdate (int argc, char **argv)
 {
-    time_t    last_update;
+    rrdtime_t    last_update;
     char    **ds_names;
     char    **last_ds;
     unsigned long ds_count, i;
@@ -90,7 +90,7 @@
 } /* int rrd_lastupdate */
 
 int rrd_lastupdate_r(const char *filename,
-        time_t *ret_last_update,
+        rrdtime_t *ret_last_update,
         unsigned long *ret_ds_count,
         char ***ret_ds_names,
         char ***ret_last_ds)
diff -ru rrdtool-1.4.7/src/rrd_open.c src/src/rrd_open.c
--- rrdtool-1.4.7/src/rrd_open.c	2012-01-24 11:08:48.000000000 +0100
+++ src/src/rrd_open.c	2024-08-07 19:11:58.487842823 +0200
@@ -356,9 +356,9 @@
         }
 #if defined USE_MADVISE
         /* the live_head will be needed soonish, so hint accordingly */
-        madvise(data + PAGE_START(offset), sizeof(time_t), MADV_WILLNEED);
+        madvise(data + PAGE_START(offset), sizeof(rrdtime_t), MADV_WILLNEED);
 #endif
-        __rrd_read(rrd->legacy_last_up, time_t,
+        __rrd_read(rrd->legacy_last_up, rrdtime_t,
                    1);
 
         rrd->live_head->last_up = *rrd->legacy_last_up;
@@ -785,7 +785,7 @@
     rrd_file_t UNUSED(*rrd_file),
     int UNUSED(rra_idx),
     unsigned long UNUSED(rra_row),
-    time_t UNUSED(rra_time))
+    rrdtime_t UNUSED(rra_time))
 {
 }
 
diff -ru rrdtool-1.4.7/src/rrd_parsetime.c src/src/rrd_parsetime.c
--- rrdtool-1.4.7/src/rrd_parsetime.c	2010-11-11 17:12:17.000000000 +0100
+++ src/src/rrd_parsetime.c	2024-08-07 19:18:32.658095657 +0200
@@ -666,7 +666,7 @@
         year += 100;    /* Allow year 2000-2037 to be specified as   */
     }
     /* 00-37 until the problem of 2038 year will */
-    /* arise for unices with 32-bit time_t :)    */
+    /* arise for unices with 32-bit rrdtime_t :)    */
     if (year < 70) {
         panic(e("won't handle dates before epoch (01/01/1970), sorry"));
     }
@@ -999,8 +999,8 @@
 int rrd_proc_start_end(
     rrd_time_value_t * start_tv,
     rrd_time_value_t * end_tv,
-    time_t *start,
-    time_t *end)
+    rrdtime_t *start,
+    rrdtime_t *end)
 {
     if (start_tv->type == RELATIVE_TO_END_TIME &&   /* same as the line above */
         end_tv->type == RELATIVE_TO_START_TIME) {
@@ -1022,9 +1022,11 @@
 
     if (start_tv->type == RELATIVE_TO_END_TIME) {
         struct tm tmtmp;
+        time_t tend;
 
-        *end = mktime(&(end_tv->tm)) + end_tv->offset;
-        tmtmp = *localtime(end);    /* reinit end including offset */
+        tend = mktime(&(end_tv->tm)) + end_tv->offset;
+        tmtmp = *localtime(&tend);    /* reinit end including offset */
+        *end = tend;
         tmtmp.tm_mday += start_tv->tm.tm_mday;
         tmtmp.tm_mon += start_tv->tm.tm_mon;
         tmtmp.tm_year += start_tv->tm.tm_year;
@@ -1035,9 +1037,11 @@
     }
     if (end_tv->type == RELATIVE_TO_START_TIME) {
         struct tm tmtmp;
+        time_t tstart;
 
-        *start = mktime(&(start_tv->tm)) + start_tv->offset;
-        tmtmp = *localtime(start);
+        tstart = mktime(&(start_tv->tm)) + start_tv->offset;
+        tmtmp = *localtime(&tstart);
+        *start = tstart;
         tmtmp.tm_mday += end_tv->tm.tm_mday;
         tmtmp.tm_mon += end_tv->tm.tm_mon;
         tmtmp.tm_year += end_tv->tm.tm_year;
diff -ru rrdtool-1.4.7/src/rrd_restore.c src/src/rrd_restore.c
--- rrdtool-1.4.7/src/rrd_restore.c	2012-01-24 11:08:48.000000000 +0100
+++ src/src/rrd_restore.c	2024-08-07 19:11:58.491176185 +0200
@@ -219,12 +219,12 @@
 }
 
  
-static int get_xml_time_t(
+static int get_xml_rrdtime_t(
     xmlTextReaderPtr reader,
-    time_t *value)
+    rrdtime_t *value)
 {    
     xmlChar *text;
-    time_t temp;    
+    rrdtime_t temp;    
     if ((text = get_xml_text(reader)) != NULL){
         errno = 0;        
 #ifdef TIME_T_IS_32BIT
@@ -233,7 +233,7 @@
 #ifdef TIME_T_IS_64BIT
         temp = strtoll((char *)text,NULL, 0);        
 #else
-        if (sizeof(time_t) == 4){
+        if (sizeof(rrdtime_t) == 4){
             temp = strtol((char *)text,NULL, 0);
         } else {
             temp = strtoll((char *)text,NULL, 0);
@@ -241,7 +241,7 @@
 #endif
 #endif    
         if (errno>0){
-            rrd_set_error("ling %d: get_xml_time_t from '%s' %s",
+            rrd_set_error("ling %d: get_xml_rrdtime_t from '%s' %s",
                           xmlTextReaderGetParserLineNumber(reader),
                           text,rrd_strerror(errno));
             xmlFree(text);            
@@ -252,7 +252,7 @@
         return 0;
     }
     return -1;
-} /* get_xml_time_t */
+} /* get_xml_rrdtime_t */
 
 static int get_xml_ulong(
     xmlTextReaderPtr reader,
@@ -1025,7 +1025,7 @@
             status = get_xml_ulong(reader,
                                         &rrd->stat_head->pdp_step);
         else if (xmlStrcasecmp(element, (const xmlChar *) "lastupdate") == 0) {
-                status = get_xml_time_t(reader, &rrd->live_head->last_up);
+                status = get_xml_rrdtime_t(reader, &rrd->live_head->last_up);
         }
         else if (xmlStrcasecmp(element, (const xmlChar *) "ds") == 0){            
             xmlFree(element);
diff -ru rrdtool-1.4.7/src/rrd_rpncalc.c src/src/rrd_rpncalc.c
--- rrdtool-1.4.7/src/rrd_rpncalc.c	2012-01-24 11:08:48.000000000 +0100
+++ src/src/rrd_rpncalc.c	2024-08-07 19:13:49.235515869 +0200
@@ -813,7 +813,7 @@
 		/* the real calculation */
 		double val=DNAN;
 		/* the info on the datasource */
-		time_t  dsstep = (time_t) rpnp[rpi - 1].step;
+		rrdtime_t  dsstep = (rrdtime_t) rpnp[rpi - 1].step;
 		int    dscount = rpnp[rpi - 1].ds_cnt;
 		int   locstep = (int)ceil((float)locstepsize/(float)dsstep);
 
@@ -880,8 +880,8 @@
                 rrd_set_error("malformed trend arguments");
                 return -1;
             } else {
-                time_t    dur = (time_t) rpnstack->s[stptr];
-                time_t    step = (time_t) rpnp[rpi - 2].step;
+                rrdtime_t    dur = (rrdtime_t) rpnstack->s[stptr];
+                rrdtime_t    step = (rrdtime_t) rpnp[rpi - 2].step;
 
                 if (output_idx + 1 >= (int) ceil((float) dur / (float) step)) {
                     int       ignorenan = (rpnp[rpi].op == OP_TREND);
diff -ru rrdtool-1.4.7/src/rrd_thread_safe_nt.c src/src/rrd_thread_safe_nt.c
--- rrdtool-1.4.7/src/rrd_thread_safe_nt.c	2012-01-24 11:08:48.000000000 +0100
+++ src/src/rrd_thread_safe_nt.c	2024-08-07 19:11:58.491176185 +0200
@@ -98,7 +98,7 @@
  * there much be a re-entrant version of these somewhere in win32 land
  */
 struct tm *localtime_r(
-    const time_t *timep,
+    const rrdtime_t *timep,
     struct tm *result)
 {
     struct tm *local;
@@ -113,7 +113,7 @@
 }
 
 char     *ctime_r(
-    const time_t *timep,
+    const rrdtime_t *timep,
     char *result)
 {
     char     *local;
@@ -128,7 +128,7 @@
 }
 
 struct tm *gmtime_r(
-    const time_t *timep,
+    const rrdtime_t *timep,
     struct tm *result)
 {
     struct tm *local;
diff -ru rrdtool-1.4.7/src/rrd_tool.c src/src/rrd_tool.c
--- rrdtool-1.4.7/src/rrd_tool.c	2012-01-24 11:08:48.000000000 +0100
+++ src/src/rrd_tool.c	2024-08-07 19:11:58.491176185 +0200
@@ -678,7 +678,7 @@
     else if (strcmp("update", argv[1]) == 0)
         rrd_update(argc - 1, &argv[1]);
     else if (strcmp("fetch", argv[1]) == 0) {
-        time_t    start, end, ti;
+        rrdtime_t    start, end, ti;
         unsigned long step, ds_cnt, i, ii;
         rrd_value_t *data, *datai;
         char    **ds_namv;
@@ -706,7 +706,7 @@
 #ifdef HAVE_RRD_GRAPH
         int       xxsize;
         unsigned long int j = 0;
-        time_t    start, end, ti;
+        rrdtime_t    start, end, ti;
         unsigned long step, col_cnt, row_cnt;
         rrd_value_t *data, *ptr;
         char    **legend_v;
diff -ru rrdtool-1.4.7/src/rrd_tool.h src/src/rrd_tool.h
--- rrdtool-1.4.7/src/rrd_tool.h	2012-01-24 11:08:48.000000000 +0100
+++ src/src/rrd_tool.h	2024-08-07 19:11:58.491176185 +0200
@@ -28,13 +28,13 @@
 #include <io.h>         /* for chdir   */
 
     struct tm *localtime_r(
-    const time_t *timep,
+    const rrdtime_t *timep,
     struct tm *result);
     char     *ctime_r(
-    const time_t *timep,
+    const rrdtime_t *timep,
     char *result);
     struct tm *gmtime_r(
-    const time_t *timep,
+    const rrdtime_t *timep,
     struct tm *result);
     char     *strtok_r(
     char *str,
@@ -87,8 +87,8 @@
     rrd_t *rrd);
     int rrd_fetch_fn (const char *filename,
             enum cf_en cf_idx,
-            time_t *start,
-            time_t *end,
+            rrdtime_t *start,
+            rrdtime_t *end,
             unsigned long *step,
             unsigned long *ds_cnt,
             char ***ds_namv,
@@ -97,7 +97,7 @@
 
 #ifdef HAVE_LIBDBI
 int rrd_fetch_fn_libdbi(const char *filename, enum cf_en cf_idx,
- 			time_t *start,time_t *end,
+ 			rrdtime_t *start,rrdtime_t *end,
  			unsigned long *step,
  			unsigned long *ds_cnt,
  			char        ***ds_namv,
diff -ru rrdtool-1.4.7/src/rrd_update.c src/src/rrd_update.c
--- rrdtool-1.4.7/src/rrd_update.c	2024-08-07 19:19:02.985038635 +0200
+++ src/src/rrd_update.c	2024-08-07 19:11:58.491176185 +0200
@@ -34,7 +34,7 @@
 
 #ifndef __MINGW32__
 struct timeval {
-    time_t    tv_sec;   /* seconds */
+    rrdtime_t    tv_sec;   /* seconds */
     long      tv_usec;  /* microseconds */
 };
 #endif
@@ -97,7 +97,7 @@
     rrd_t *rrd,
     rrd_file_t *rrd_file,
     unsigned long rra_begin,
-    time_t *current_time,
+    rrdtime_t *current_time,
     unsigned long *current_time_usec,
     rrd_value_t *pdp_temp,
     rrd_value_t *pdp_new,
@@ -116,7 +116,7 @@
     long *tmpl_idx,
     char *input,
     unsigned long tmpl_cnt,
-    time_t *current_time,
+    rrdtime_t *current_time,
     unsigned long *current_time_usec,
     int version);
 
@@ -124,7 +124,7 @@
     rrd_t *rrd,
     char timesyntax,
     char **updvals,
-    time_t *current_time,
+    rrdtime_t *current_time,
     unsigned long *current_time_usec,
     int version);
 
@@ -254,7 +254,7 @@
     rrd_file_t *rrd_file,
     unsigned long *rra_step_cnt,
     unsigned long rra_begin,
-    time_t current_time,
+    rrdtime_t current_time,
     unsigned long *skip_update,
     rrd_info_t ** pcdp_summary);
 
@@ -264,7 +264,7 @@
     unsigned long rra_idx,
     unsigned short CDP_scratch_idx,
     rrd_info_t ** pcdp_summary,
-    time_t rra_time);
+    rrdtime_t rra_time);
 
 static int smooth_all_rras(
     rrd_t *rrd,
@@ -296,7 +296,7 @@
  * current_time_usec is set to 0 if the version number is 1 or 2.
  */
 static void initialize_time(
-    time_t *current_time,
+    rrdtime_t *current_time,
     unsigned long *current_time_usec,
     int version)
 {
@@ -502,7 +502,7 @@
                          * transported by the tmplt index */
     unsigned long tmpl_cnt = 2; /* time and data */
     rrd_t     rrd;
-    time_t    current_time = 0;
+    rrdtime_t    current_time = 0;
     unsigned long current_time_usec = 0;    /* microseconds part of current time */
     char    **updvals;
     int       schedule_smooth = 0;
@@ -771,7 +771,7 @@
     rrd_t *rrd,
     rrd_file_t *rrd_file,
     unsigned long rra_begin,
-    time_t *current_time,
+    rrdtime_t *current_time,
     unsigned long *current_time_usec,
     rrd_value_t *pdp_temp,
     rrd_value_t *pdp_new,
@@ -874,7 +874,7 @@
     long *tmpl_idx,
     char *input,
     unsigned long tmpl_cnt,
-    time_t *current_time,
+    rrdtime_t *current_time,
     unsigned long *current_time_usec,
     int version)
 {
@@ -940,7 +940,7 @@
     rrd_t *rrd,
     char timesyntax,
     char **updvals,
-    time_t *current_time,
+    rrdtime_t *current_time,
     unsigned long *current_time_usec,
     int version)
 {
@@ -1900,13 +1900,13 @@
     rrd_file_t *rrd_file,
     unsigned long *rra_step_cnt,
     unsigned long rra_begin,
-    time_t current_time,
+    rrdtime_t current_time,
     unsigned long *skip_update,
     rrd_info_t ** pcdp_summary)
 {
     unsigned long rra_idx;
     unsigned long rra_start;
-    time_t    rra_time = 0; /* time of update for a RRA */
+    rrdtime_t    rra_time = 0; /* time of update for a RRA */
 
     unsigned long ds_cnt = rrd->stat_head->ds_cnt;
     
@@ -1986,7 +1986,7 @@
     unsigned long rra_idx,
     unsigned short CDP_scratch_idx,
     rrd_info_t ** pcdp_summary,
-    time_t rra_time)
+    rrdtime_t rra_time)
 {
     unsigned long ds_idx, cdp_idx;
     rrd_infoval_t iv;
@@ -2078,7 +2078,7 @@
         }
     } else {
         if (rrd_write(rrd_file, rrd->legacy_last_up,
-                      sizeof(time_t) * 1) != sizeof(time_t) * 1) {
+                      sizeof(rrdtime_t) * 1) != sizeof(rrdtime_t) * 1) {
             rrd_set_error("rrd_write live_head to rrd");
             return -1;
         }
diff -ru rrdtool-1.4.7/src/rrd_xport.c src/src/rrd_xport.c
--- rrdtool-1.4.7/src/rrd_xport.c	2012-01-24 11:08:48.000000000 +0100
+++ src/src/rrd_xport.c	2024-08-07 19:11:58.491176185 +0200
@@ -22,8 +22,8 @@
     int,
     char **,
     int *,
-    time_t *,
-    time_t *,
+    rrdtime_t *,
+    rrdtime_t *,
     unsigned long *,
     unsigned long *,
     char ***,
@@ -31,8 +31,8 @@
 
 int       rrd_xport_fn(
     image_desc_t *,
-    time_t *,
-    time_t *,
+    rrdtime_t *,
+    rrdtime_t *,
     unsigned long *,
     unsigned long *,
     char ***,
@@ -45,8 +45,8 @@
     int argc,
     char **argv,
     int UNUSED(*xsize),
-    time_t *start,
-    time_t *end,        /* which time frame do you want ?
+    rrdtime_t *start,
+    rrdtime_t *end,        /* which time frame do you want ?
                          * will be changed to represent reality */
     unsigned long *step,    /* which stepsize do you want? 
                              * will be changed to represent reality */
@@ -55,7 +55,7 @@
     rrd_value_t **data)
 {                       /* two dimensional array containing the data */
     image_desc_t im;
-    time_t    start_tmp = 0, end_tmp = 0;
+    rrdtime_t    start_tmp = 0, end_tmp = 0;
     rrd_time_value_t start_tv, end_tv;
     char     *parsetime_error = NULL;
 
@@ -186,8 +186,8 @@
 
 int rrd_xport_fn(
     image_desc_t *im,
-    time_t *start,
-    time_t *end,        /* which time frame do you want ?
+    rrdtime_t *start,
+    rrdtime_t *end,        /* which time frame do you want ?
                          * will be changed to represent reality */
     unsigned long *step,    /* which stepsize do you want? 
                              * will be changed to represent reality */
@@ -305,7 +305,7 @@
     for (dst_row = 0; (int) dst_row < (int) row_cnt; dst_row++) {
         for (i = 0; i < (int) (*col_cnt); i++) {
             long vidx = im->gdes[ref_list[i]].vidx;
-            time_t now = *start + dst_row * *step;
+            rrdtime_t now = *start + dst_row * *step;
             (*dstptr++) = im->gdes[vidx].data[(unsigned long)
                                               floor((double)
                                                     (now - im->gdes[vidx].start)
