merge 64-bit fixes from Fernando Lucas Rodriguez <fernando_lr@terra.es>
[debian/gcpegg] / basket.c
index 487072bf798dd3b75fb5e1d57a7d984ae883dedc..5d20c66b39b02a9f3d94b6b97a7da13c3937ec69 100644 (file)
--- a/basket.c
+++ b/basket.c
@@ -91,6 +91,7 @@ static void updateHTML(void)
        int i;
        static uint32 lastHtml = 0;
        uint32 now = getzulutime(NULL);
+       time_t now_val;
        char udate[256], ustime[256];
         static char timeFormat[] = "%Y-%m-%d %T";
 
@@ -114,9 +115,11 @@ static void updateHTML(void)
                htmlFile[0] = 0;      /* Suppress further updates */
                return;
            }
-
-           strftime(udate, sizeof udate, timeFormat, gmtime((time_t *) &now));
-           strftime(ustime, sizeof ustime, timeFormat, gmtime((time_t *) &upsince));
+      
+      now_val = now;
+      strftime(udate, sizeof udate, timeFormat, gmtime(&now_val));
+      time_t upsince_val = upsince;
+      strftime(ustime, sizeof ustime, timeFormat, gmtime(&upsince_val));
 
             fprintf(hf, "\
 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n\
@@ -147,8 +150,10 @@ static void updateHTML(void)
                   strcpy(udate, "<td colspan=2 align=center><em>Never contacted</em>");
                   strcpy(ustime, "");
              } else {
-                  strftime(udate, sizeof udate, "<td align=center>%Y-%m-%d %T", gmtime((time_t *) &eggtable[i].lastupd));
-                  strftime(ustime, sizeof ustime, "<td align=center>%Y-%m-%d %T", gmtime((time_t *) &eggStatistics[i].firstPacket));
+                  time_t lastupd_val = eggtable[i].lastupd;
+                  strftime(udate, sizeof udate, "<td align=center>%Y-%m-%d %T", gmtime(&lastupd_val));
+                  time_t firstPacket_val = eggStatistics[i].firstPacket;
+                  strftime(ustime, sizeof ustime, "<td align=center>%Y-%m-%d %T", gmtime(&firstPacket_val));
              }
              if (eggtable[i].url == NULL) {
                  url1[0] = url2[0] = 0;
@@ -182,7 +187,7 @@ static void updateHTML(void)
                      coverage = 100;
                  }
 
-                  fprintf(hf, "<td align=center>%ld<td align=center>%ld<td align=center>%ld%%<td align=center>%.3f\n",
+                  fprintf(hf, "<td align=center>%d<td align=center>%d<td align=center>%d%%<td align=center>%.3f\n",
                          eggStatistics[i].trials,
                          eggStatistics[i].missing,
                          coverage,
@@ -214,8 +219,9 @@ static void updateHTML(void)
 </html>\n");
            fclose(hf);
 #ifdef DEBUG
+            now_val = now;
             fprintf(stderr, "Updating HTML file %s at %s",
-               htmlFile, asctime(gmtime((time_t *) &now)));
+               htmlFile, asctime(gmtime(&now_val)));
 #endif
        }
     }
@@ -437,9 +443,10 @@ int main(int argc, char *argv[]) {
 
        memcpy(&egg_now_time, pktbuf + 6, sizeof egg_now_time);
        egg_now_time = ntohl(egg_now_time);
-       fprintf(stderr, "Awake egg %d (%s) at its %lu: %s",
+       time_t egg_now_time_val = egg_now_time;
+       fprintf(stderr, "Awake egg %d (%s) at its %u: %s",
                pkt_eggid, eggtable[thisegg].name, egg_now_time,
-               asctime(gmtime((time_t *) &egg_now_time)));
+               asctime(gmtime(&egg_now_time_val)));
       }
 #endif
 
@@ -618,14 +625,14 @@ static int32 BasketReceiveDataPacket(char *pkt, int16 isegg, int16 thisegg,
      EggHeader packet. */
   
   dpktp = &dpk;
-  unpackShort(dpk.type);
-  unpackShort(dpk.pktsize);
-  unpackShort(dpk.eggid);
-  unpackShort(dpk.samp_rec);
-  unpackShort(dpk.sec_rec);
-  unpackShort(dpk.rec_pkt);
-  unpackByte(dpk.trialsz);
-  unpackShort(dpk.numrec);
+  unpack16(dpk.type);
+  unpack16(dpk.pktsize);
+  unpack16(dpk.eggid);
+  unpack16(dpk.samp_rec);
+  unpack16(dpk.sec_rec);
+  unpack16(dpk.rec_pkt);
+  unpack8(dpk.trialsz);
+  unpack16(dpk.numrec);
 
   /* This spoofing test is probably completely redundant now. */
 #ifndef EGG_DYNAMIC      
@@ -648,7 +655,7 @@ static int32 BasketReceiveDataPacket(char *pkt, int16 isegg, int16 thisegg,
     char *spktp = pktP;
 
     if (result.hdr.numrec > 0) {
-      unpackLong(stamp);
+      unpack32(stamp);
     }
     pktP = spktp;
     fprintf(stderr, "Received packet: %d records from egg %d (%s).\n",
@@ -660,19 +667,20 @@ static int32 BasketReceiveDataPacket(char *pkt, int16 isegg, int16 thisegg,
      transcribe to the result EggCarton.  */
   
   for (latest = 0, rec = 0; rec < result.hdr.numrec; rec++) {
-    unpackLong(result.records[rec].timestamp);  /* Record timestamp */
+    unpack32(result.records[rec].timestamp);    /* Record timestamp */
     if (result.records[rec].timestamp > latest)
       latest = result.records[rec].timestamp;
 #ifdef DEBUG
-    fprintf(stderr, "  %10lu  ", result.records[rec].timestamp);
+    fprintf(stderr, "  %10u  ", result.records[rec].timestamp);
 #endif
     /* Assumes sizeof(trial) = 1 */
-    unpackBytes(&(result.records[rec].trials), result.hdr.samp_rec);
+    unpack8s(&(result.records[rec].trials), result.hdr.samp_rec);
 #ifdef DEBUG
     for (i = 0; i < result.hdr.samp_rec; i++) {
       fprintf(stderr, "%3d ", result.records[rec].trials[i]);
     }
-    fprintf(stderr, "%s", asctime(gmtime((time_t *) &result.records[rec].timestamp)));
+    time_t timestamp_val = result.records[rec].timestamp;
+    fprintf(stderr, "%s", asctime(gmtime(&timestamp_val)));
 #endif
   }
 
@@ -749,10 +757,10 @@ static int32 BasketReceiveDataPacket(char *pkt, int16 isegg, int16 thisegg,
 static void MakeRequest(ReqPacket *pkt, uint16 eggid, uint32 whence) {
   char *pktP = (char *) pkt;
 
-  packShort(REQ_PACKET);
-  packShort((4 * sizeof(uint16)) + sizeof(uint32));
-  packShort(eggid);
-  packLong(whence);
+  pack16(REQ_PACKET);
+  pack16((4 * sizeof(uint16)) + sizeof(uint32));
+  pack16(eggid);
+  pack32(whence);
 }
 
 /*  MakeSettings  --  Create a settings packet.  This packet,
@@ -762,14 +770,14 @@ static void MakeRequest(ReqPacket *pkt, uint16 eggid, uint32 whence) {
 static void MakeSettings(SettingsPacket *pkt, uint16 eggid) {
   char *pktP = (char *) pkt;
 
-  packShort(SETTINGS_PACKET);
-  packShort((7 * sizeof(uint16)) + sizeof(uint32) + sizeof(trial));
-  packShort(eggid);
-  packLong(getzulutime(NULL));
-  packShort(protocol.samp_rec);
-  packShort(protocol.sec_rec);
-  packShort(protocol.rec_pkt);
-  packByte(protocol.trialsz);
+  pack16(SETTINGS_PACKET);
+  pack16((7 * sizeof(uint16)) + sizeof(uint32) + sizeof(trial));
+  pack16(eggid);
+  pack32(getzulutime(NULL));
+  pack16(protocol.samp_rec);
+  pack16(protocol.sec_rec);
+  pack16(protocol.rec_pkt);
+  pack8(protocol.trialsz);
 }
 
 /*  LoadEggStats  --  Initialise in-memory egg status table
@@ -828,7 +836,7 @@ static void SaveEggStats(void) {
   fprintf(fp, "# Status lines of form:\n");
   fprintf(fp, "#   STAT <eggname> <eggid> <lastupdzulu> <setupvalid>\n");
   for (i = 0; i < numeggs; i++) {
-    fprintf(fp, "STAT %s %d %ld %d\n",
+    fprintf(fp, "STAT %s %d %u %d\n",
            eggtable[i].name,
            eggtable[i].id,
            eggtable[i].lastupd,