From 0949ed4e42c107ae1f3ad51a52339878a4f61c18 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Sun, 15 Oct 2023 19:53:55 +0200 Subject: mico-store: use htonll --- mico-store.c | 18 +++++------------- 1 file 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); -- cgit 1.4.1