merge 64-bit fixes from Fernando Lucas Rodriguez <fernando_lr@terra.es>
[debian/gcpegg] / storage.c
index ac36436e8ff40c3f384bdd2a9df0c0d72e7003ca..2abe2de973e1aeb61f61d28a56658634fe60047a 100644 (file)
--- a/storage.c
+++ b/storage.c
@@ -43,7 +43,7 @@
    an error on the following declaration, disable it for your
    platform. */
 
-extern char *strdup (const char *s1);
+/*extern char *strdup (const char *s1);*/
 
 /* Eventually, these might deal with making a safe copy or mounting
    and unmounting a partition. Until such time as we actually do
@@ -77,7 +77,7 @@ static int32 next_poss_fn(char *fn, uint32 tindex, int16 eggid);
 struct seekopt {
     char filename[256];
     uint32 last_time;
-    long next_packet;
+    int32 next_packet;
 };
 
 static struct seekopt seekOpt[SEEK_OPT_MAX];
@@ -217,11 +217,12 @@ int32 InitStorage(char *path) {
 int32 SavePacket(EggCarton *cart) {
   FILE         *fp;
   char         *packet, datatmp[255], datafile[255], *sp;
-  int32        pktime, res;
+  uint32       pktime, res;
 
   pktime = cart->records[0].timestamp;
 #ifdef STORAGE_DEBUG
-  fprintf(stderr, "SavePacket for %lu: %s", pktime, asctime(gmtime((time_t *) &pktime)));
+  time_t pktime_val = pktime;
+  fprintf(stderr, "SavePacket for %u: %s", pktime, asctime(gmtime(&pktime_val)));
 #endif
 
   /* Generate the file name corresponding to the date of
@@ -285,8 +286,9 @@ int32 OpenDatabase(DBRec *dbp, uint32 tindex, int16 eggid) {
   int32        res;
 
 #ifdef STORAGE_DEBUG
-  fprintf(stderr, "OpenDatabase: Egg = %d, tindex = %ld %s",
-    eggid, tindex, asctime(gmtime((time_t *) &tindex)));
+  time_t tindex_val = tindex;
+  fprintf(stderr, "OpenDatabase: Egg = %d, tindex = %u %s",
+    eggid, tindex, asctime(gmtime(&tindex_val)));
 #endif
   dbp->eggind = 0;
   dbp->fp = NULL;
@@ -344,7 +346,7 @@ static int32 LoadNextPacket(DBRec *dbp, uint32 tindex, int16 eggid, EggCarton *c
     findex = PROJSTART;
   }
 #ifdef STORAGE_DEBUG
-  fprintf(stderr, "LoadNextPacket(%s, %lu, %d)\n", dbp->fn, tindex, eggid);
+  fprintf(stderr, "LoadNextPacket(%s, %u, %d)\n", dbp->fn, tindex, eggid);
 #endif
 
   /* See if the start address for this request is present
@@ -364,20 +366,22 @@ static int32 LoadNextPacket(DBRec *dbp, uint32 tindex, int16 eggid, EggCarton *c
          seekOpt[i].last_time == tindex) {
          fseek(dbp->fp, seekOpt[i].next_packet, SEEK_SET);
 #ifdef STORAGE_DEBUG
-          fprintf(stderr, "LoadNextPacket; Seek optimised [%ld] to %ld for\n    file %s at %lu %s",
+        time_t last_time_val = seekOpt[i].last_time;
+        fprintf(stderr, "LoadNextPacket; Seek optimised [%d] to %d for\n    file %s at %u %s",
              i,
              seekOpt[i].next_packet, 
              seekOpt[i].filename,
              seekOpt[i].last_time,
-             asctime(gmtime((time_t *) &(seekOpt[i].last_time))));
+             asctime(gmtime(&last_time_val)));
 
 #endif
          break;
       }
       if (i == seekOptIndex) {
 #ifdef STORAGE_DEBUG
-          fprintf(stderr, "LoadNextPacket; Cannot optimise seek in file %s\n    at %lu %s",
-             dbp->fn, tindex, asctime(gmtime((time_t *) &(tindex))));
+        time_t tindex_val = tindex;
+          fprintf(stderr, "LoadNextPacket; Cannot optimise seek in file %s\n    at %u %s",
+             dbp->fn, tindex, asctime(gmtime(&tindex_val)));
 #endif
          break;                      /* Search wrapped table--cannot optimise */
       }
@@ -396,13 +400,15 @@ static int32 LoadNextPacket(DBRec *dbp, uint32 tindex, int16 eggid, EggCarton *c
 #define SECONDS_PER_DAY (24L * 60 * 60)
       findex = ((findex / SECONDS_PER_DAY) + 1) * SECONDS_PER_DAY;
 #ifdef STORAGE_DEBUG
-      fprintf(stderr, "LoadNextPacket; EOF, CloseDatabase, findex = %lu: %s",
-         findex, asctime(gmtime((time_t *) &findex)));
+     time_t findex_val = findex;
+      fprintf(stderr, "LoadNextPacket; EOF, CloseDatabase, findex = %u: %s",
+         findex, asctime(gmtime(&findex_val)));
 #endif
       if (findex > now) {
 #ifdef STORAGE_DEBUG
-          fprintf(stderr, "LoadNextPacket; EOF findex = %lu > now = %lu %s",
-         findex, now, asctime(gmtime((time_t *) &now)));
+     time_t now_val = now;
+          fprintf(stderr, "LoadNextPacket; EOF findex = %u > now = %u %s",
+         findex, now, asctime(gmtime(&now_val)));
 #endif
        return ERR_EOF;
       }
@@ -427,12 +433,13 @@ fprintf(stderr, "Eggid = %d Packet.eggid = %d\n", eggid, pktbuf.hdr.eggid);
        seekOpt[seekOptIndex].last_time = pktbuf.records[pktbuf.hdr.numrec - 1].timestamp;
        seekOpt[seekOptIndex].next_packet = ftell(dbp->fp);
 #ifdef STORAGE_DEBUG
-        fprintf(stderr, "LoadNextPacket; Seek optimisation[%d] for %s\n    to address %ld for time %lu %s",
+     time_t last_time_val = seekOpt[seekOptIndex].last_time;
+        fprintf(stderr, "LoadNextPacket; Seek optimisation[%d] for %s\n    to address %d for time %u %s",
            seekOptIndex,
            seekOpt[seekOptIndex].filename,
            seekOpt[seekOptIndex].next_packet, 
            seekOpt[seekOptIndex].last_time,
-           asctime(gmtime((time_t *) &(seekOpt[seekOptIndex].last_time))));
+           asctime(gmtime(&last_time_val)));
 #endif
        seekOptIndex = (seekOptIndex + 1) % SEEK_OPT_MAX;
        return ERR_NONE;
@@ -495,8 +502,9 @@ static int32 next_filename(char *fn, uint32 tindex, int16 eggid,
   char         ldf[255];
 
 #ifdef STORAGE_DEBUG
-  fprintf(stderr, "next_filename: egg = %d, mustexist = %d, tindex = %lu %s",
-    eggid, mustexist, tindex, asctime(gmtime((time_t *) &tindex)));
+  time_t tindex_val = tindex;
+  fprintf(stderr, "next_filename: egg = %d, mustexist = %d, tindex = %u %s",
+    eggid, mustexist, tindex, asctime(gmtime(&tindex_val)));
 #endif
   if (eggid < 0 && !mustexist) {
 #ifdef STORAGE_DEBUG
@@ -557,10 +565,11 @@ static int32 next_poss_fn(char *fn, uint32 tindex, int16 eggid) {
   int16        eggind;
   struct tm    *tm;
 
-  tm = gmtime((time_t *) &tindex);
+  time_t time_index = tindex;
+  tm = gmtime(&time_index);
   strftime(datatmp, 255, datafmt, tm);
 #ifdef STORAGE_DEBUG
-  fprintf(stderr, "next_poss_fn: egg = %d, tindex = %lu %s",
+  fprintf(stderr, "next_poss_fn: egg = %d, tindex = %u %s",
     eggid, tindex, asctime(tm));
 #endif