Skip to contentSkip to conversation

nfsdcltrack: don't assume time_t is long int

PATCH New Đoàn Trần Công Danh 1 participant 1 message Feb 22, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfsdcltrack: don't assume time_t is long int

In musl 1.2.x, time_t is defined to 64 bit integer unconditionally. Let's not assume time_t is long int, but always cast to int64_t for printf(3).

---
inttypes.h and PRId64 is being used by utils/idmapd, so I think we won't have more incompatibility problem with this change.

 utils/nfsdcltrack/nfsdcltrack.c | 3 ++-
 utils/nfsdcltrack/sqlite.c      | 5 +++--
 2 files changed, 5 insertions(+), 3 deletions(-)
utils/nfsdcltrack/nfsdcltrack.c +2 -1
index e926f1c0..5edf0ca4 100644
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <ctype.h>
 #include <errno.h>
+#include <inttypes.h>
 #include <stdbool.h>
 #include <getopt.h>
 #include <string.h>
@@ -525,7 +526,7 @@ cltrack_gracedone(const char *timestr)
 	if (*tail)
 		return -EINVAL;
 
-	xlog(D_GENERAL, "%s: grace done. gracetime=%ld", __func__, gracetime);
+	xlog(D_GENERAL, "%s: grace done. gracetime=%" PRId64, __func__, (int64_t)gracetime);
 
 	ret = sqlite_remove_unreclaimed(gracetime);
 
utils/nfsdcltrack/sqlite.c +3 -2
index f79aebb3..4ac805b3 100644
@@ -40,6 +40,7 @@
 
 #include <dirent.h>
 #include <errno.h>
+#include <inttypes.h>
 #include <stdio.h>
 #include <stdbool.h>
 #include <string.h>
@@ -544,8 +545,8 @@ sqlite_remove_unreclaimed(time_t grace_start)
 	int ret;
 	char *err = NULL;
 
-	ret = snprintf(buf, sizeof(buf), "DELETE FROM clients WHERE time < %ld",
-			grace_start);
+	ret = snprintf(buf, sizeof(buf), "DELETE FROM clients WHERE time < %" PRId64,
+			(int64_t)grace_start);
 	if (ret < 0) {
 		return ret;
 	} else if ((size_t)ret >= sizeof(buf)) {
Signature · 1 line
2.30.1.629.g12f37433bd