summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2023-10-15 19:53:55 +0200
committerLeah Neukirchen <leah@vuxu.org>2023-10-15 19:53:55 +0200
commit0949ed4e42c107ae1f3ad51a52339878a4f61c18 (patch)
treef78e26d827572f955475f776e62b9407a02ea324
parentf9ad993a1586436a539721f84058bf63055c8ac5 (diff)
downloadmico-0949ed4e42c107ae1f3ad51a52339878a4f61c18.tar.gz
mico-0949ed4e42c107ae1f3ad51a52339878a4f61c18.tar.xz
mico-0949ed4e42c107ae1f3ad51a52339878a4f61c18.zip
mico-store: use htonll
-rw-r--r--mico-store.c18
1 files changed, 5 insertions, 13 deletions
diff --git a/mico-store.c b/mico-store.c
index 8bccad1..6ee1833 100644
--- a/mico-store.c
+++ b/mico-store.c
@@ -115,8 +115,6 @@ zip_t *zip;
 void
 reset_stream()
 {
-	printf("RESET\n");
-
 	ts = (struct bitfile){ 0 };
 	vs = (struct bitfile){ 0 };
 	ts.output = open_memstream(&ts.mem, &ts.memlen);
@@ -131,6 +129,8 @@ reset_stream()
         putbits1_msb(&vs, 32, 0);
 }
 
+#define htonll(x) ((1==htonl(1)) ? (x) : ((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))
+
 void
 write_stream(char *name)
 {
@@ -149,16 +149,10 @@ write_stream(char *name)
 	if (s)
 		*s = 0;
 
-	fprintf(stderr, "%s: %ld + %ld\n", name, ts.memlen, vs.memlen);
-	fprintf(stderr, "name=%s\n", path);
-
 	/* patch in length */
-	uint32_t h = htonl((uint32_t)(ts.nevents >> 32));
-	uint32_t l = htonl((uint32_t)(ts.nevents & 0xffffffff));
-	memcpy(ts.mem + 8, &h, sizeof h);
-	memcpy(ts.mem + 8 + sizeof h, &l, sizeof l);
-	memcpy(vs.mem + 8, &h, sizeof h);
-	memcpy(vs.mem + 8 + sizeof h, &l, sizeof l);
+	uint64_t nevents = htonll(ts.nevents);
+	memcpy(ts.mem + 8, &nevents, sizeof nevents);
+	memcpy(vs.mem + 8, &nevents, sizeof nevents);
 
 	// time_t mtime = metrics[m].value[0].t / 1000;
 	snprintf(path, sizeof path, "%s/time.dd", prefix);
@@ -238,8 +232,6 @@ main(int argc, char *argv[])
 		memcpy(name, line, start-line);
 		name[start-line] = 0;
 
-		printf("LINE |%s| |%s| |%s|\n", line, name, lastname);
-
 		if (strcmp(name, lastname) != 0) {
 			if (*lastname)
 				write_stream(lastname);