[PATCH] alfred: Fix printing of timespec

Sven Eckelmann <[email protected]>
Newsgroups org.open-mesh.lists.batman
Message-ID <[email protected]>
musl on a 32 bit system still uses a 64-bit value (long long) for the
storage of tv_sec and tv_nsec. But the printf was evaluating these
arguments always only as long.

During the print of the nsec value, range of 0-999_999_999 is only
possible. 30 bit is therefore enough to store this range. For simplicity,
just use an unsigned int.

The second value on the other hand can get up to 64 bit on a 64-bit-unix
timestamp system. Just use long long for it to be on the safe side.

Signed-off-by: Sven Eckelmann <[email protected]>
---
 main.c   | 4 +++-
 server.c | 4 ++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/main.c b/main.c
index 0f242e8..71a6260 100644
--- a/main.c
+++ b/main.c
@@ -285,7 +285,9 @@ static struct globals *alfred_init(int argc, char *argv[])
 			sync_period = strtod(optarg, NULL);
 			globals->sync_period.tv_sec = (int)sync_period;
 			globals->sync_period.tv_nsec = (double)(sync_period - (int)sync_period) * 1e9;
-			printf(" ** Setting sync interval to: %.9f seconds (%ld.%09ld)\n", sync_period, globals->sync_period.tv_sec, globals->sync_period.tv_nsec);
+			printf(" ** Setting sync interval to: %.9f seconds (%lld.%09u)\n", sync_period,
+			       (long long)globals->sync_period.tv_sec,
+			       (unsigned int)globals->sync_period.tv_nsec);
 			break;
 		case '4':
 			globals->ipv4mode = true;
diff --git a/server.c b/server.c
index 0d792b0..c3d32a0 100644
--- a/server.c
+++ b/server.c
@@ -404,8 +404,8 @@ static void sync_period_timer(struct globals *globals,
 
 	if (globals->opmode == OPMODE_PRIMARY) {
 		/* we are a primary */
-		printf("[%ld.%09ld] announce primary ...\n",
-		       now.tv_sec, now.tv_nsec);
+		printf("[%lld.%09u] announce primary ...\n",
+		       (long long)now.tv_sec, (unsigned int)now.tv_nsec);
 		announce_primary(globals);
 		sync_data(globals);
 	} else {

---
base-commit: bdab2a4dd79716edd6c5ecdbda7bf38c8495083c
change-id: 20260308-t64-41cd12362bdc

Best regards,
-- 
Sven Eckelmann <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.