fix printf format strings

There is a standard length modifier for displaying size_t values, so use
it rather than maintain a random arch list.

Unfortunately, there is no standard for displaying time_t values.  The
current code (1) assume some are longs and (2) casts some to long.  Change
all to case to unsigned long instead.

This will break in the year 2034 on 32bit systems, but maybe we just
don't care.

BUG=chromium:219015
TEST=`emerge-x32-generic punybench` now works
TEST=`emerge-link punybench` still works

Change-Id: I0c6cbef8489fd342ad2335543db08c5f076474a3
Reviewed-on: https://chromium-review.googlesource.com/193890
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/cpu.m/memcpy.c b/cpu.m/memcpy.c
index 5e8dde6..b52932b 100644
--- a/cpu.m/memcpy.c
+++ b/cpu.m/memcpy.c
@@ -9,7 +9,9 @@
 
 #include <sys/resource.h>
 #include <sys/time.h>
+#include <inttypes.h>
 #include <pthread.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -44,11 +46,17 @@
 void PrUsage (struct rusage *r)
 {
 	if (!resource_usage) return;
-	printf("utime = %ld.%06ld stime = %ld.%06ld minflt = %ld\n",
-		 r->ru_utime.tv_sec,
-		 (long)r->ru_utime.tv_usec,
-		 r->ru_stime.tv_sec,
-		 (long)r->ru_stime.tv_usec,
+	/* We cannot use 'long' as some 32bit systems define time_t as
+	 * as 64bit value.  Others define it as a 32bit value.  So we
+	 * have to explicitly cast it ourselves to get a stable printf
+	 * format string.
+	 */
+	printf("utime = %"PRIu64".%06"PRIu64" stime = %"PRIu64".%06"PRIu64" "
+		 "minflt = %ld\n",
+		 (uint64_t)r->ru_utime.tv_sec,
+		 (uint64_t)r->ru_utime.tv_usec,
+		 (uint64_t)r->ru_stime.tv_sec,
+		 (uint64_t)r->ru_stime.tv_usec,
 		 r->ru_minflt);
 #if 0
 		 struct timeval ru_utime; /* user time used */
diff --git a/file.m/timer.c b/file.m/timer.c
index d84cb97..23572ac 100644
--- a/file.m/timer.c
+++ b/file.m/timer.c
@@ -12,6 +12,8 @@
  +-------------------------------------------------------------------------*/
 
 #include <sys/time.h>
+#include <inttypes.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -81,9 +83,17 @@
 static void printTimer (Timer_s *timer)
 {
 	if (timer->key == 0) return;
-	printf("%8p: start=%ld.%.6ld delta=%ld.%.6ld\n", timer->key,
-				timer->start.tv_sec, (long)timer->start.tv_usec,
-				timer->delta.tv_sec, (long)timer->delta.tv_usec);
+	/* We cannot use 'long' as some 32bit systems define time_t as
+	 * as 64bit value.  Others define it as a 32bit value.  So we
+	 * have to explicitly cast it ourselves to get a stable printf
+	 * format string.
+	 */
+	printf("%8p: start=%"PRIu64".%.6"PRIu64" delta=%"PRIu64".%.6"PRIu64"\n",
+				timer->key,
+				(uint64_t)timer->start.tv_sec,
+				(uint64_t)timer->start.tv_usec,
+				(uint64_t)timer->delta.tv_sec,
+				(uint64_t)timer->delta.tv_usec);
 }
 
 void dumpTimersReverse (void)
diff --git a/libpuny.b/file.c b/libpuny.b/file.c
index a59ec94..3e4f11e 100644
--- a/libpuny.b/file.c
+++ b/libpuny.b/file.c
@@ -107,13 +107,7 @@
 		io_error("write", NULL);
 	}
 	if (rc != nbytes) {
-#ifdef __APPLE__
-		fprintf(stderr, "ERROR: write: wrote only %ld bytes of %ld\n",
-#elif __x86_64__
-		fprintf(stderr, "ERROR: write: wrote only %ld bytes of %ld\n",
-#else
-		fprintf(stderr, "ERROR: write: wrote only %d bytes of %d\n",
-#endif
+		fprintf(stderr, "ERROR: write: wrote only %zi bytes of %zu\n",
 			rc, nbytes);
 		exit(1);
 	}