v4l-utils: fix formats under ppc/mips64
Subsystems (2)
PATCH 1/2 v4l-utils: fix formats under ppc/mips64
By default, these platforms use long instead of long long for __u64. __SANE_USERSPACE_TYPES__ fixes -Wformat warnings.
--- contrib/xc3028-firmware/firmware-tool.c | 2 ++ include/linux/compiler.h | 1 + utils/cec-compliance/cec-compliance.h | 2 ++ utils/cec-ctl/cec-ctl.cpp | 2 ++ utils/cec-ctl/cec-ctl.h | 2 ++ utils/cec-ctl/cec-pin.cpp | 2 ++ utils/cec-follower/cec-processing.cpp | 2 ++ utils/common/v4l2-info.h | 2 ++ utils/cx18-ctl/cx18-ctl.c | 2 ++ utils/ivtv-ctl/ivtv-ctl.c | 2 ++ utils/keytable/keytable.c | 2 ++ utils/media-ctl/media-ctl.c | 2 ++ utils/v4l2-compliance/v4l2-compliance.h | 2 ++ utils/v4l2-ctl/v4l2-ctl-common.cpp | 2 ++ utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 2 ++ utils/v4l2-ctl/v4l2-ctl.cpp | 2 ++ utils/v4l2-ctl/v4l2-ctl.h | 2 ++ utils/v4l2-dbg/v4l2-dbg.cpp | 2 ++ 18 files changed, 35 insertions(+)
contrib/xc3028-firmware/firmware-tool.c +2 -0
@@ -29,6 +29,8 @@#include <string.h> #include <unistd.h> +#include "linux/compiler.h" +#include <asm/byteorder.h> #include <asm/types.h>
include/linux/compiler.h +1 -0
@@ -1,6 +1,7 @@#ifndef __linux_compiler_h#define __linux_compiler_h +#define __SANE_USERSPACE_TYPES__#define __user#endif
utils/cec-compliance/cec-compliance.h +2 -0
@@ -8,6 +8,8 @@#ifndef _CEC_COMPLIANCE_H_#define _CEC_COMPLIANCE_H_ +#include "linux/compiler.h" +#include <linux/cec-funcs.h> #include "cec-htng-funcs.h"
utils/cec-ctl/cec-ctl.cpp +2 -0
@@ -20,6 +20,8 @@ #include <sys/time.h> #include <unistd.h> +#include "linux/compiler.h" + #include <linux/cec-funcs.h> #include "cec-htng-funcs.h" #include "cec-log.h"
utils/cec-ctl/cec-ctl.h +2 -0
@@ -6,6 +6,8 @@#ifndef _CEC_CTL_H_#define _CEC_CTL_H_ +#include "linux/compiler.h" +#include <cec-info.h> // cec-ctl.cpp
utils/cec-ctl/cec-pin.cpp +2 -0
@@ -3,6 +3,8 @@ * Copyright 2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved. */ +#include "linux/compiler.h" + #include <string> #include <linux/cec.h>
utils/cec-follower/cec-processing.cpp +2 -0
@@ -3,6 +3,8 @@ * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved. */ +#include "linux/compiler.h" + #include <cerrno> #include <ctime> #include <string>
utils/common/v4l2-info.h +2 -0
@@ -8,6 +8,8 @@#include <string> +#include "linux/compiler.h" +#include <linux/videodev2.h> #include <linux/v4l2-subdev.h>
utils/cx18-ctl/cx18-ctl.c +2 -0
@@ -34,6 +34,8 @@#include <sys/time.h> #include <math.h> +#include "linux/compiler.h" +#include <linux/videodev2.h> #include <v4l-getsubopt.h>
utils/ivtv-ctl/ivtv-ctl.c +2 -0
@@ -34,6 +34,8 @@#include <sys/time.h> #include <math.h> +#include "linux/compiler.h" +#include <linux/videodev2.h> #include <v4l-getsubopt.h>
utils/keytable/keytable.c +2 -0
@@ -12,6 +12,8 @@GNU General Public License for more details. */ +#include "linux/compiler.h" +#include <ctype.h> #include <errno.h> #include <fcntl.h>
utils/media-ctl/media-ctl.c +2 -0
@@ -34,6 +34,8 @@#include <string.h> #include <unistd.h> +#include "linux/compiler.h" +#include <linux/media.h> #include <linux/types.h> #include <linux/v4l2-mediabus.h>
utils/v4l2-compliance/v4l2-compliance.h +2 -0
@@ -26,6 +26,8 @@#include <string> #include <cstdint> +#include "linux/compiler.h" +#include <linux/videodev2.h> #include <linux/v4l2-subdev.h> #include <linux/media.h>
utils/v4l2-ctl/v4l2-ctl-common.cpp +2 -0
@@ -9,6 +9,8 @@ #include <sys/stat.h> #include <sys/sysmacros.h> +#include "linux/compiler.h" + #include <linux/media.h> #include "v4l2-ctl.h"
utils/v4l2-ctl/v4l2-ctl-streaming.cpp +2 -0
@@ -3,6 +3,8 @@ #include <netdb.h> #include <sys/types.h> +#include "linux/compiler.h" + #include <linux/media.h> #include "compiler.h"
utils/v4l2-ctl/v4l2-ctl.cpp +2 -0
@@ -27,6 +27,8 @@ #include <getopt.h> #include <sys/epoll.h> +#include "linux/compiler.h" + #include <linux/media.h> #include "v4l2-ctl.h"
utils/v4l2-ctl/v4l2-ctl.h +2 -0
@@ -1,6 +1,8 @@#ifndef _V4L2_CTL_H#define _V4L2_CTL_H +#include "linux/compiler.h" +#include <cstdint> #include <linux/videodev2.h> #include <linux/v4l2-subdev.h>
utils/v4l2-dbg/v4l2-dbg.cpp +2 -0
@@ -31,6 +31,8 @@ #include <sys/klog.h> #endif +#include "linux/compiler.h" + #include <linux/videodev2.h> #include <v4l-getsubopt.h>
Signature · 1 line
2.45.2
PATCH 2/2 v4l-utils: fix compilation with 64-bit time_t
musl since version 1.2.0 uses 64-bit time_t even on 32-bit. Cast to 64-bit for compatibility.
--- utils/cec-compliance/cec-compliance.cpp | 3 ++- utils/cec-compliance/cec-test-adapter.cpp | 5 +++-- utils/cec-ctl/cec-ctl.cpp | 19 ++++++++++--------- utils/cec-follower/cec-follower.cpp | 3 ++- utils/cec-follower/cec-processing.cpp | 3 ++- utils/keytable/keytable.c | 1 + utils/libv4l2util/v4l2_driver.c | 7 ++++--- utils/v4l2-tracer/retrace.cpp | 2 +- 8 files changed, 25 insertions(+), 18 deletions(-)
utils/cec-compliance/cec-compliance.cpp +2 -1
@@ -3,6 +3,7 @@ * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved. */ +#include <cinttypes> #include <sstream> #include <fcntl.h>
@@ -279,7 +280,7 @@ static std::string ts2s(__u64 ts) t = res.tv_sec; s = ctime(&t); s = s.substr(0, s.length() - 6); - sprintf(buf, "%03lu", res.tv_usec / 1000); + sprintf(buf, "%03" PRIu64, (uint64_t)res.tv_usec / 1000); return s + "." + buf; }
utils/cec-compliance/cec-test-adapter.cpp +3 -2
@@ -4,6 +4,7 @@ */ #include <cerrno> +#include <cinttypes> #include <ctime> #include <string>
@@ -1276,9 +1277,9 @@ static int testLostMsgs(struct node *node) printf("\t\tReceived messages: %d of which %d were CEC_MSG_CEC_VERSION\n", pending_rx_msgs, pending_rx_cec_version_msgs); if (pending_quick_msgs < pending_msgs) - printf("\t\tReceived %d messages immediately, and %d over %ld seconds\n", + printf("\t\tReceived %d messages immediately, and %d over %" PRIu64 " seconds\n", pending_quick_msgs, pending_msgs - pending_quick_msgs, - time(nullptr) - start); + (uint64_t)time(nullptr) - start); } print_sfts(sft[1][1], "SFTs for repeating messages (>= 7)"); print_sfts(sft[1][0], "SFTs for repeating remote messages (>= 7)");
utils/cec-ctl/cec-ctl.cpp +10 -9
@@ -6,6 +6,7 @@ #include <algorithm> #include <cctype> #include <cerrno> +#include <cinttypes> #include <cstring> #include <ctime> #include <map>
@@ -416,7 +417,7 @@ std::string ts2s(__u64 ts) strftime(buf, sizeof(buf), "%a %b %e %T.000000", &tm); } secs = last_secs + t - last_t; - sprintf(buf + 14, "%02u:%02u.%06lu", secs / 60, secs % 60, res.tv_usec); + sprintf(buf + 14, "%02u:%02u.%06d", secs / 60, secs % 60, (int)res.tv_usec); return buf; }
@@ -944,10 +945,10 @@ static void monitor(const struct node &node, __u32 monitor_time, const char *sto } fprintf(fstore, "# cec-ctl --store-pin\n"); fprintf(fstore, "# version %d\n", CEC_CTL_VERSION); - fprintf(fstore, "# start_monotonic %lu.%09lu\n", - start_monotonic.tv_sec, start_monotonic.tv_nsec); - fprintf(fstore, "# start_timeofday %lu.%06lu\n", - start_timeofday.tv_sec, start_timeofday.tv_usec); + fprintf(fstore, "# start_monotonic %" PRIu64 ".%09" PRIu64 "\n", + (uint64_t)start_monotonic.tv_sec, (uint64_t)start_monotonic.tv_nsec); + fprintf(fstore, "# start_timeofday %" PRIu64 ".%06" PRIu64 "\n", + (uint64_t)start_timeofday.tv_sec, (uint64_t)start_timeofday.tv_usec); fprintf(fstore, "# log_addr_mask 0x%04x\n", node.log_addr_mask); fprintf(fstore, "# phys_addr %x.%x.%x.%x\n", cec_phys_addr_exp(node.phys_addr));
@@ -986,10 +987,10 @@ static void monitor(const struct node &node, __u32 monitor_time, const char *sto */ clock_gettime(CLOCK_MONOTONIC, &start_monotonic); gettimeofday(&start_timeofday, nullptr); - fprintf(fstore, "# start_monotonic %lu.%09lu\n", - start_monotonic.tv_sec, start_monotonic.tv_nsec); - fprintf(fstore, "# start_timeofday %lu.%06lu\n", - start_timeofday.tv_sec, start_timeofday.tv_usec); + fprintf(fstore, "# start_monotonic %" PRIu64 ".%09" PRIu64 "\n", + (uint64_t)start_monotonic.tv_sec, (uint64_t)start_monotonic.tv_nsec); + fprintf(fstore, "# start_timeofday %" PRIu64 ".%06" PRIu64 "\n", + (uint64_t)start_timeofday.tv_sec, (uint64_t)start_timeofday.tv_usec); fflush(fstore); start_minute = now; }
utils/cec-follower/cec-follower.cpp +2 -1
@@ -3,6 +3,7 @@ * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved. */ +#include <cinttypes> #include <cstring> #include <ctime> #include <sstream>
@@ -354,7 +355,7 @@ void print_timers(struct node *node) printf("source: %s, ", source.c_str()); if (t.recording_seq) printf("rec-seq: 0x%x, ", t.recording_seq); - printf("needs: %ld %s\n", t.duration, "MB."); /* 1MB per second. */ + printf("needs: %" PRIu64 " %s\n", (uint64_t)t.duration, "MB."); /* 1MB per second. */ } printf("Total media space available for recording: "); if (node->state.media_space_available >= 0)
utils/cec-follower/cec-processing.cpp +2 -1
@@ -6,6 +6,7 @@ #include "linux/compiler.h" #include <cerrno> +#include <cinttypes> #include <ctime> #include <string>
@@ -74,7 +75,7 @@ static std::string ts2s(__u64 ts, bool wallclock) t = res.tv_sec; s = ctime(&t); s = s.substr(0, s.length() - 6); - sprintf(buf, "%03lu", res.tv_usec / 1000); + sprintf(buf, "%03" PRIu64, (uint64_t)res.tv_usec / 1000); return s + "." + buf; }
utils/keytable/keytable.c +1 -0
@@ -214,6 +214,7 @@ static enum sysfs_protocols parse_sysfs_protocol(const char *name, bool all_alloreturn SYSFS_INVALID ; } +__attribute__((format (printf,3 ,0 )))static void write_sysfs_protocols (enum sysfs_protocols protocols,FILE *fp,const char *fmt) {const struct protocol_map_entry *pme;
utils/libv4l2util/v4l2_driver.c +4 -3
@@ -15,6 +15,7 @@#include <assert.h> #include <errno.h> #include <fcntl.h> +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <string.h>
@@ -174,13 +175,13 @@ static void prt_buf_info(char *name,struct v4l2_buffer *p) {struct v4l2_timecode *tc=&p->timecode; - printf ("%s: %02ld:%02d:%02d.%08ld index=%d, type=%s, " + printf ("%s: %02" PRIu64 ":%02d:%02d.%08" PRIu64 " index=%d, type=%s, " "bytesused=%d, flags=0x%08x, " "field=%s, sequence=%d, memory=%s, offset=0x%08x, length=%d\n", - name, (p->timestamp.tv_sec/3600), + name, (uint64_t)(p->timestamp.tv_sec/3600), (int)(p->timestamp.tv_sec/60)%60, (int)(p->timestamp.tv_sec%60), - p->timestamp.tv_usec, + (uint64_t)p->timestamp.tv_usec, p->index, prt_names(p->type,v4l2_type_names), p->bytesused,p->flags,
utils/v4l2-tracer/retrace.cpp +1 -1
@@ -72,7 +72,7 @@ void retrace_mmap(json_object *mmap_obj, bool is_mmap64) (long) buf_address_retrace_pointer); if (is_verbose() || (errno != 0)) { - fprintf(stderr, "fd: %d, offset: %ld, ", fd_retrace, off); + fprintf(stderr, "fd: %d, offset: %lld, ", fd_retrace, (long long)off); if (is_mmap64) perror("mmap64"); else
Signature · 1 line
2.45.2
Re: [PATCH 2/2] v4l-utils: fix compilation with 64-bit time_t
ping?
Quoted 179 lines · Rosen Penev
musl since version 1.2.0 uses 64-bit
time_teven on 32-bit. Cast to 64-bit for compatibility.Signed-off-by Rosen Penev <[email protected]>--- utils/cec-compliance/cec-compliance.cpp | 3 ++- utils/cec-compliance/cec-test-adapter.cpp | 5 +++-- utils/cec-ctl/cec-ctl.cpp | 19 ++++++++++--------- utils/cec-follower/cec-follower.cpp | 3 ++- utils/cec-follower/cec-processing.cpp | 3 ++- utils/keytable/keytable.c | 1 + utils/libv4l2util/v4l2_driver.c | 7 ++++--- utils/v4l2-tracer/retrace.cpp | 2 +- 8 files changed, 25 insertions(+), 18 deletions(-)utils/cec-compliance/cec-compliance.cpp +2
-1@@ -3,6 +3,7 @@ * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved. */ +#include <cinttypes> #include <sstream> #include <fcntl.h>@@ -279,7 +280,7 @@ static std::string ts2s(__u64 ts) t = res.tv_sec; s = ctime(&t); s = s.substr(0, s.length() - 6); - sprintf(buf, "%03lu", res.tv_usec / 1000); + sprintf(buf, "%03" PRIu64, (uint64_t)res.tv_usec / 1000); return s + "." + buf; }utils/cec-compliance/cec-test-adapter.cpp +3
-2@@ -4,6 +4,7 @@ */ #include <cerrno> +#include <cinttypes> #include <ctime> #include <string>@@ -1276,9 +1277,9 @@ static int testLostMsgs(struct node *node) printf("\t\tReceived messages: %d of which %d were CEC_MSG_CEC_VERSION\n", pending_rx_msgs, pending_rx_cec_version_msgs); if (pending_quick_msgs < pending_msgs) - printf("\t\tReceived %d messages immediately, and %d over %ld seconds\n", + printf("\t\tReceived %d messages immediately, and %d over %" PRIu64 " seconds\n", pending_quick_msgs, pending_msgs - pending_quick_msgs, - time(nullptr) - start); + (uint64_t)time(nullptr) - start); } print_sfts(sft[1][1], "SFTs for repeating messages (>= 7)"); print_sfts(sft[1][0], "SFTs for repeating remote messages (>= 7)");utils/cec-ctl/cec-ctl.cpp +10
-9@@ -6,6 +6,7 @@ #include <algorithm> #include <cctype> #include <cerrno> +#include <cinttypes> #include <cstring> #include <ctime> #include <map>@@ -416,7 +417,7 @@ std::string ts2s(__u64 ts) strftime(buf, sizeof(buf), "%a %b %e %T.000000", &tm); } secs = last_secs + t - last_t; - sprintf(buf + 14, "%02u:%02u.%06lu", secs / 60, secs % 60, res.tv_usec); + sprintf(buf + 14, "%02u:%02u.%06d", secs / 60, secs % 60, (int)res.tv_usec); return buf; }@@ -944,10 +945,10 @@ static void monitor(const struct node &node, __u32 monitor_time, const char *sto } fprintf(fstore, "# cec-ctl --store-pin\n"); fprintf(fstore, "# version %d\n", CEC_CTL_VERSION); - fprintf(fstore, "# start_monotonic %lu.%09lu\n", - start_monotonic.tv_sec, start_monotonic.tv_nsec); - fprintf(fstore, "# start_timeofday %lu.%06lu\n", - start_timeofday.tv_sec, start_timeofday.tv_usec); + fprintf(fstore, "# start_monotonic %" PRIu64 ".%09" PRIu64 "\n", + (uint64_t)start_monotonic.tv_sec, (uint64_t)start_monotonic.tv_nsec); + fprintf(fstore, "# start_timeofday %" PRIu64 ".%06" PRIu64 "\n", + (uint64_t)start_timeofday.tv_sec, (uint64_t)start_timeofday.tv_usec); fprintf(fstore, "# log_addr_mask 0x%04x\n", node.log_addr_mask); fprintf(fstore, "# phys_addr %x.%x.%x.%x\n", cec_phys_addr_exp(node.phys_addr));@@ -986,10 +987,10 @@ static void monitor(const struct node &node, __u32 monitor_time, const char *sto */ clock_gettime(CLOCK_MONOTONIC, &start_monotonic); gettimeofday(&start_timeofday, nullptr); - fprintf(fstore, "# start_monotonic %lu.%09lu\n", - start_monotonic.tv_sec, start_monotonic.tv_nsec); - fprintf(fstore, "# start_timeofday %lu.%06lu\n", - start_timeofday.tv_sec, start_timeofday.tv_usec); + fprintf(fstore, "# start_monotonic %" PRIu64 ".%09" PRIu64 "\n", + (uint64_t)start_monotonic.tv_sec, (uint64_t)start_monotonic.tv_nsec); + fprintf(fstore, "# start_timeofday %" PRIu64 ".%06" PRIu64 "\n", + (uint64_t)start_timeofday.tv_sec, (uint64_t)start_timeofday.tv_usec); fflush(fstore); start_minute = now; }utils/cec-follower/cec-follower.cpp +2
-1@@ -3,6 +3,7 @@ * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved. */ +#include <cinttypes> #include <cstring> #include <ctime> #include <sstream>@@ -354,7 +355,7 @@ void print_timers(struct node *node) printf("source: %s, ", source.c_str()); if (t.recording_seq) printf("rec-seq: 0x%x, ", t.recording_seq); - printf("needs: %ld %s\n", t.duration, "MB."); /* 1MB per second. */ + printf("needs: %" PRIu64 " %s\n", (uint64_t)t.duration, "MB."); /* 1MB per second. */ } printf("Total media space available for recording: "); if (node->state.media_space_available >= 0)utils/cec-follower/cec-processing.cpp +2
-1@@ -6,6 +6,7 @@ #include "linux/compiler.h" #include <cerrno> +#include <cinttypes> #include <ctime> #include <string>@@ -74,7 +75,7 @@ static std::string ts2s(__u64 ts, bool wallclock) t = res.tv_sec; s = ctime(&t); s = s.substr(0, s.length() - 6); - sprintf(buf, "%03lu", res.tv_usec / 1000); + sprintf(buf, "%03" PRIu64, (uint64_t)res.tv_usec / 1000); return s + "." + buf; }utils/keytable/keytable.c +1
-0@@ -214,6 +214,7 @@ static enum sysfs_protocols parse_sysfs_protocol(const char *name, bool all_alloreturn SYSFS_INVALID ; } +__attribute__((format (printf,3 ,0 )))static void write_sysfs_protocols (enum sysfs_protocols protocols,FILE *fp,const char *fmt) {const struct protocol_map_entry *pme;utils/libv4l2util/v4l2_driver.c +1
-0@@ -15,6 +15,7 @@#include <assert.h> #include <errno.h> #include <fcntl.h> +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <string.h>
utils/libv4l2util/v4l2_driver.c static void prt_buf_info(char *name,struct v4l2_buffer *p) · line 178
Quoted 5 lines
utils/libv4l2util/v4l2_driver.c +1
-1@@ -174,13 +175,13 @@ static void prt_buf_info(char *name,struct v4l2_buffer *p) {struct v4l2_timecode *tc=&p->timecode; - printf ("%s: %02ld:%02d:%02d.%08ld index=%d, type=%s, " + printf ("%s: %02" PRIu64 ":%02d:%02d.%08" PRIu64 " index=%d, type=%s, "
This 100% fixes crashing under 32-bit musl as it prevents the second half of time_t being interpreted as %s.
Quoted 27 lines
utils/libv4l2util/v4l2_driver.c +2
-2"bytesused=%d, flags=0x%08x, " "field=%s, sequence=%d, memory=%s, offset=0x%08x, length=%d\n" , - name, (p->timestamp.tv_sec/3600 ), + name, (uint64_t )(p->timestamp.tv_sec/3600 ), (int )(p->timestamp.tv_sec/60 )%60 , (int )(p->timestamp.tv_sec%60 ), - p->timestamp.tv_usec, + (uint64_t )p->timestamp.tv_usec, p->index,prt_names (p->type,v4l2_type_names), p->bytesused,p->flags,utils/v4l2-tracer/retrace.cpp +1
-2@@ -72,7 +72,7 @@ void retrace_mmap(json_object *mmap_obj, bool is_mmap64) (long) buf_address_retrace_pointer); if (is_verbose() || (errno != 0)) { - fprintf(stderr, "fd: %d, offset: %ld, ", fd_retrace, off); + fprintf(stderr, "fd: %d, offset: %lld, ", fd_retrace, (long long)off); if (is_mmap64) perror("mmap64"); else --2.45.2
Re: [PATCH 2/2] v4l-utils: fix compilation with 64-bit time_t
In reply to Rosen PenevHi Rosen,
Apologies, I hadn't seen this patch, it was filed in my spam folder for some reason.
Quoted 28 lines · Rosen Penev
musl since version 1.2.0 uses 64-bit
time_teven on 32-bit. Cast to 64-bit for compatibility.Signed-off-by Rosen Penev <[email protected]>--- utils/cec-compliance/cec-compliance.cpp | 3 ++- utils/cec-compliance/cec-test-adapter.cpp | 5 +++-- utils/cec-ctl/cec-ctl.cpp | 19 ++++++++++--------- utils/cec-follower/cec-follower.cpp | 3 ++- utils/cec-follower/cec-processing.cpp | 3 ++- utils/keytable/keytable.c | 1 + utils/libv4l2util/v4l2_driver.c | 7 ++++--- utils/v4l2-tracer/retrace.cpp | 2 +- 8 files changed, 25 insertions(+), 18 deletions(-)utils/cec-compliance/cec-compliance.cpp +1
-0@@ -3,6 +3,7 @@ * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved. */ +#include <cinttypes> #include <sstream> #include <fcntl.h>
utils/cec-compliance/cec-compliance.cpp static std::string ts2s(__u64 ts) · line 283
Quoted 5 lines
utils/cec-compliance/cec-compliance.cpp +1
-1@@ -279,7 +280,7 @@ static std::string ts2s(__u64 ts) t = res.tv_sec; s = ctime(&t); s = s.substr(0, s.length() - 6); - sprintf(buf, "%03lu", res.tv_usec / 1000); + sprintf(buf, "%03" PRIu64, (uint64_t)res.tv_usec / 1000);
This doesn't make sense: why is res.tv_usec cast to a uint64_t? Is that field really a 64 bit value under musl? But in any case, tv_usec is limited to 999999, so if it is a 64 bit value under musl, then just cast it to unsigned long and leave the %03lu as-is.
The commit log is certainly insufficient since a lot of the changes in this patch have nothing to do with time_t but with tv_n/usec.
Why use PRIu64? That's not explained in the commit log either. I had to look that up, as I've never seen it used before.
As I understand it, musl doesn't support %llu in some cases? Looking at:
https://github.com/cloudius-systems/musl/blob/master/include/inttypes.h
it appears that PRIu64 can either be lu or llu. lu is used if UINTPTR_MAX == UINT64_MAX.
But if that is needed, then I expect to see a single patch converting every %lld and %llu in v4l-utils to use PRId/u64. Here it is only done for some time-related code.
Please don't mix changing to PRId/u64 with these time changes. If you believe that is needed, then do that as a final patch for all of v4l-utils. But the commit log should be very clear explaining why it is needed.
Regards,
Hans
Quoted 174 lines
utils/cec-compliance/cec-compliance.cpp +0
-0return s + "." + buf; }utils/cec-compliance/cec-test-adapter.cpp +3
-2@@ -4,6 +4,7 @@ */ #include <cerrno> +#include <cinttypes> #include <ctime> #include <string>@@ -1276,9 +1277,9 @@ static int testLostMsgs(struct node *node) printf("\t\tReceived messages: %d of which %d were CEC_MSG_CEC_VERSION\n", pending_rx_msgs, pending_rx_cec_version_msgs); if (pending_quick_msgs < pending_msgs) - printf("\t\tReceived %d messages immediately, and %d over %ld seconds\n", + printf("\t\tReceived %d messages immediately, and %d over %" PRIu64 " seconds\n", pending_quick_msgs, pending_msgs - pending_quick_msgs, - time(nullptr) - start); + (uint64_t)time(nullptr) - start); } print_sfts(sft[1][1], "SFTs for repeating messages (>= 7)"); print_sfts(sft[1][0], "SFTs for repeating remote messages (>= 7)");utils/cec-ctl/cec-ctl.cpp +10
-9@@ -6,6 +6,7 @@ #include <algorithm> #include <cctype> #include <cerrno> +#include <cinttypes> #include <cstring> #include <ctime> #include <map>@@ -416,7 +417,7 @@ std::string ts2s(__u64 ts) strftime(buf, sizeof(buf), "%a %b %e %T.000000", &tm); } secs = last_secs + t - last_t; - sprintf(buf + 14, "%02u:%02u.%06lu", secs / 60, secs % 60, res.tv_usec); + sprintf(buf + 14, "%02u:%02u.%06d", secs / 60, secs % 60, (int)res.tv_usec); return buf; }@@ -944,10 +945,10 @@ static void monitor(const struct node &node, __u32 monitor_time, const char *sto } fprintf(fstore, "# cec-ctl --store-pin\n"); fprintf(fstore, "# version %d\n", CEC_CTL_VERSION); - fprintf(fstore, "# start_monotonic %lu.%09lu\n", - start_monotonic.tv_sec, start_monotonic.tv_nsec); - fprintf(fstore, "# start_timeofday %lu.%06lu\n", - start_timeofday.tv_sec, start_timeofday.tv_usec); + fprintf(fstore, "# start_monotonic %" PRIu64 ".%09" PRIu64 "\n", + (uint64_t)start_monotonic.tv_sec, (uint64_t)start_monotonic.tv_nsec); + fprintf(fstore, "# start_timeofday %" PRIu64 ".%06" PRIu64 "\n", + (uint64_t)start_timeofday.tv_sec, (uint64_t)start_timeofday.tv_usec); fprintf(fstore, "# log_addr_mask 0x%04x\n", node.log_addr_mask); fprintf(fstore, "# phys_addr %x.%x.%x.%x\n", cec_phys_addr_exp(node.phys_addr));@@ -986,10 +987,10 @@ static void monitor(const struct node &node, __u32 monitor_time, const char *sto */ clock_gettime(CLOCK_MONOTONIC, &start_monotonic); gettimeofday(&start_timeofday, nullptr); - fprintf(fstore, "# start_monotonic %lu.%09lu\n", - start_monotonic.tv_sec, start_monotonic.tv_nsec); - fprintf(fstore, "# start_timeofday %lu.%06lu\n", - start_timeofday.tv_sec, start_timeofday.tv_usec); + fprintf(fstore, "# start_monotonic %" PRIu64 ".%09" PRIu64 "\n", + (uint64_t)start_monotonic.tv_sec, (uint64_t)start_monotonic.tv_nsec); + fprintf(fstore, "# start_timeofday %" PRIu64 ".%06" PRIu64 "\n", + (uint64_t)start_timeofday.tv_sec, (uint64_t)start_timeofday.tv_usec); fflush(fstore); start_minute = now; }utils/cec-follower/cec-follower.cpp +2
-1@@ -3,6 +3,7 @@ * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved. */ +#include <cinttypes> #include <cstring> #include <ctime> #include <sstream>@@ -354,7 +355,7 @@ void print_timers(struct node *node) printf("source: %s, ", source.c_str()); if (t.recording_seq) printf("rec-seq: 0x%x, ", t.recording_seq); - printf("needs: %ld %s\n", t.duration, "MB."); /* 1MB per second. */ + printf("needs: %" PRIu64 " %s\n", (uint64_t)t.duration, "MB."); /* 1MB per second. */ } printf("Total media space available for recording: "); if (node->state.media_space_available >= 0)utils/cec-follower/cec-processing.cpp +2
-1@@ -6,6 +6,7 @@ #include "linux/compiler.h" #include <cerrno> +#include <cinttypes> #include <ctime> #include <string>@@ -74,7 +75,7 @@ static std::string ts2s(__u64 ts, bool wallclock) t = res.tv_sec; s = ctime(&t); s = s.substr(0, s.length() - 6); - sprintf(buf, "%03lu", res.tv_usec / 1000); + sprintf(buf, "%03" PRIu64, (uint64_t)res.tv_usec / 1000); return s + "." + buf; }utils/keytable/keytable.c +1
-0@@ -214,6 +214,7 @@ static enum sysfs_protocols parse_sysfs_protocol(const char *name, bool all_alloreturn SYSFS_INVALID ; } +__attribute__((format (printf,3 ,0 )))static void write_sysfs_protocols (enum sysfs_protocols protocols,FILE *fp,const char *fmt) {const struct protocol_map_entry *pme;utils/libv4l2util/v4l2_driver.c +4
-3@@ -15,6 +15,7 @@#include <assert.h> #include <errno.h> #include <fcntl.h> +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -174,13 +175,13 @@ static void prt_buf_info(char *name,struct v4l2_buffer *p) {struct v4l2_timecode *tc=&p->timecode; - printf ("%s: %02ld:%02d:%02d.%08ld index=%d, type=%s, " + printf ("%s: %02" PRIu64 ":%02d:%02d.%08" PRIu64 " index=%d, type=%s, " "bytesused=%d, flags=0x%08x, " "field=%s, sequence=%d, memory=%s, offset=0x%08x, length=%d\n", - name, (p->timestamp.tv_sec/3600), + name, (uint64_t)(p->timestamp.tv_sec/3600), (int)(p->timestamp.tv_sec/60)%60, (int)(p->timestamp.tv_sec%60), - p->timestamp.tv_usec, + (uint64_t)p->timestamp.tv_usec, p->index, prt_names(p->type,v4l2_type_names), p->bytesused,p->flags,utils/v4l2-tracer/retrace.cpp +1
-1@@ -72,7 +72,7 @@ void retrace_mmap(json_object *mmap_obj, bool is_mmap64) (long) buf_address_retrace_pointer); if (is_verbose() || (errno != 0)) { - fprintf(stderr, "fd: %d, offset: %ld, ", fd_retrace, off); + fprintf(stderr, "fd: %d, offset: %lld, ", fd_retrace, (long long)off); if (is_mmap64) perror("mmap64"); else
Re: [PATCH 2/2] v4l-utils: fix compilation with 64-bit time_t
Quoted 32 lines · Hans Verkuil
Hi Rosen,
Apologies, I hadn't seen this patch, it was filed in my spam folder for some reason.
Quoted 26 lines · Rosen Penev
musl since version 1.2.0 uses 64-bit
time_teven on 32-bit. Cast to 64-bit for compatibility.Signed-off-by Rosen Penev <[email protected]>--- utils/cec-compliance/cec-compliance.cpp | 3 ++- utils/cec-compliance/cec-test-adapter.cpp | 5 +++-- utils/cec-ctl/cec-ctl.cpp | 19 ++++++++++--------- utils/cec-follower/cec-follower.cpp | 3 ++- utils/cec-follower/cec-processing.cpp | 3 ++- utils/keytable/keytable.c | 1 + utils/libv4l2util/v4l2_driver.c | 7 ++++--- utils/v4l2-tracer/retrace.cpp | 2 +- 8 files changed, 25 insertions(+), 18 deletions(-)utils/cec-compliance/cec-compliance.cpp +1
-0@@ -3,6 +3,7 @@ * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved. */ +#include <cinttypes> #include <sstream>
Quoted 12 lines
utils/cec-compliance/cec-compliance.cpp static std::string ts2s(__u64 ts) · line 283
Quoted 7 lines
utils/cec-compliance/cec-compliance.cpp +1
-1#include <fcntl.h>@@ -279,7 +280,7 @@ static std::string ts2s(__u64 ts) t = res.tv_sec; s = ctime(&t); s = s.substr(0, s.length() - 6); - sprintf(buf, "%03lu", res.tv_usec / 1000); + sprintf(buf, "%03" PRIu64, (uint64_t)res.tv_usec / 1000);This doesn't make sense: why is res.tv_usec cast to a
uint64_t? Is that field really a 64 bit value under musl? But in any case,tv_usecis limited to 999999, so if it is a 64 bit value under musl, then just cast it to unsigned long and leave the %03lu as-is.
That's suseconds_t which is 64-bit. I felt it would be safer to cast to 64-bit, but OK.
Quoted 3 lines
The commit log is certainly insufficient since a lot of the changes in this patch have nothing to do with
time_tbut with tv_n/usec.
include/alltypes.h.in:TYPEDEF _Int64 suseconds_t; : <-- from musl source.
Quoted 6 lines
Why use PRIu64? That's not explained in the commit log either. I had to look that up, as I've never seen it used before.
As I understand it, musl doesn't support %llu in some cases? Looking at:
Quoted 7 lines
https://github.com/cloudius-systems/musl/blob/master/include/inttypes.h
it appears that PRIu64 can either be lu or llu. lu is used if
UINTPTR_MAX==UINT64_MAX.But if that is needed, then I expect to see a single patch converting every %lld and %llu in v4l-utils to use PRId/u64. Here it is only done for some time-related code.
not exactly. kernel types use long long always. musl switches between both.
Quoted 184 lines
Please don't mix changing to PRId/u64 with these time changes. If you believe that is needed, then do that as a final patch for all of v4l-utils. But the commit log should be very clear explaining why it is needed.
Regards,
Hans
Quoted 174 lines
utils/cec-compliance/cec-compliance.cpp +0
-0return s + "." + buf; }utils/cec-compliance/cec-test-adapter.cpp +3
-2@@ -4,6 +4,7 @@ */ #include <cerrno> +#include <cinttypes> #include <ctime> #include <string>@@ -1276,9 +1277,9 @@ static int testLostMsgs(struct node *node) printf("\t\tReceived messages: %d of which %d were CEC_MSG_CEC_VERSION\n", pending_rx_msgs, pending_rx_cec_version_msgs); if (pending_quick_msgs < pending_msgs) - printf("\t\tReceived %d messages immediately, and %d over %ld seconds\n", + printf("\t\tReceived %d messages immediately, and %d over %" PRIu64 " seconds\n", pending_quick_msgs, pending_msgs - pending_quick_msgs, - time(nullptr) - start); + (uint64_t)time(nullptr) - start); } print_sfts(sft[1][1], "SFTs for repeating messages (>= 7)"); print_sfts(sft[1][0], "SFTs for repeating remote messages (>= 7)");utils/cec-ctl/cec-ctl.cpp +10
-9@@ -6,6 +6,7 @@ #include <algorithm> #include <cctype> #include <cerrno> +#include <cinttypes> #include <cstring> #include <ctime> #include <map>@@ -416,7 +417,7 @@ std::string ts2s(__u64 ts) strftime(buf, sizeof(buf), "%a %b %e %T.000000", &tm); } secs = last_secs + t - last_t; - sprintf(buf + 14, "%02u:%02u.%06lu", secs / 60, secs % 60, res.tv_usec); + sprintf(buf + 14, "%02u:%02u.%06d", secs / 60, secs % 60, (int)res.tv_usec); return buf; }@@ -944,10 +945,10 @@ static void monitor(const struct node &node, __u32 monitor_time, const char *sto } fprintf(fstore, "# cec-ctl --store-pin\n"); fprintf(fstore, "# version %d\n", CEC_CTL_VERSION); - fprintf(fstore, "# start_monotonic %lu.%09lu\n", - start_monotonic.tv_sec, start_monotonic.tv_nsec); - fprintf(fstore, "# start_timeofday %lu.%06lu\n", - start_timeofday.tv_sec, start_timeofday.tv_usec); + fprintf(fstore, "# start_monotonic %" PRIu64 ".%09" PRIu64 "\n", + (uint64_t)start_monotonic.tv_sec, (uint64_t)start_monotonic.tv_nsec); + fprintf(fstore, "# start_timeofday %" PRIu64 ".%06" PRIu64 "\n", + (uint64_t)start_timeofday.tv_sec, (uint64_t)start_timeofday.tv_usec); fprintf(fstore, "# log_addr_mask 0x%04x\n", node.log_addr_mask); fprintf(fstore, "# phys_addr %x.%x.%x.%x\n", cec_phys_addr_exp(node.phys_addr));@@ -986,10 +987,10 @@ static void monitor(const struct node &node, __u32 monitor_time, const char *sto */ clock_gettime(CLOCK_MONOTONIC, &start_monotonic); gettimeofday(&start_timeofday, nullptr); - fprintf(fstore, "# start_monotonic %lu.%09lu\n", - start_monotonic.tv_sec, start_monotonic.tv_nsec); - fprintf(fstore, "# start_timeofday %lu.%06lu\n", - start_timeofday.tv_sec, start_timeofday.tv_usec); + fprintf(fstore, "# start_monotonic %" PRIu64 ".%09" PRIu64 "\n", + (uint64_t)start_monotonic.tv_sec, (uint64_t)start_monotonic.tv_nsec); + fprintf(fstore, "# start_timeofday %" PRIu64 ".%06" PRIu64 "\n", + (uint64_t)start_timeofday.tv_sec, (uint64_t)start_timeofday.tv_usec); fflush(fstore); start_minute = now; }utils/cec-follower/cec-follower.cpp +2
-1@@ -3,6 +3,7 @@ * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved. */ +#include <cinttypes> #include <cstring> #include <ctime> #include <sstream>@@ -354,7 +355,7 @@ void print_timers(struct node *node) printf("source: %s, ", source.c_str()); if (t.recording_seq) printf("rec-seq: 0x%x, ", t.recording_seq); - printf("needs: %ld %s\n", t.duration, "MB."); /* 1MB per second. */ + printf("needs: %" PRIu64 " %s\n", (uint64_t)t.duration, "MB."); /* 1MB per second. */ } printf("Total media space available for recording: "); if (node->state.media_space_available >= 0)utils/cec-follower/cec-processing.cpp +2
-1@@ -6,6 +6,7 @@ #include "linux/compiler.h" #include <cerrno> +#include <cinttypes> #include <ctime> #include <string>@@ -74,7 +75,7 @@ static std::string ts2s(__u64 ts, bool wallclock) t = res.tv_sec; s = ctime(&t); s = s.substr(0, s.length() - 6); - sprintf(buf, "%03lu", res.tv_usec / 1000); + sprintf(buf, "%03" PRIu64, (uint64_t)res.tv_usec / 1000); return s + "." + buf; }utils/keytable/keytable.c +1
-0@@ -214,6 +214,7 @@ static enum sysfs_protocols parse_sysfs_protocol(const char *name, bool all_alloreturn SYSFS_INVALID ; } +__attribute__((format (printf,3 ,0 )))static void write_sysfs_protocols (enum sysfs_protocols protocols,FILE *fp,const char *fmt) {const struct protocol_map_entry *pme;utils/libv4l2util/v4l2_driver.c +4
-3@@ -15,6 +15,7 @@#include <assert.h> #include <errno.h> #include <fcntl.h> +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -174,13 +175,13 @@ static void prt_buf_info(char *name,struct v4l2_buffer *p) {struct v4l2_timecode *tc=&p->timecode; - printf ("%s: %02ld:%02d:%02d.%08ld index=%d, type=%s, " + printf ("%s: %02" PRIu64 ":%02d:%02d.%08" PRIu64 " index=%d, type=%s, " "bytesused=%d, flags=0x%08x, " "field=%s, sequence=%d, memory=%s, offset=0x%08x, length=%d\n", - name, (p->timestamp.tv_sec/3600), + name, (uint64_t)(p->timestamp.tv_sec/3600), (int)(p->timestamp.tv_sec/60)%60, (int)(p->timestamp.tv_sec%60), - p->timestamp.tv_usec, + (uint64_t)p->timestamp.tv_usec, p->index, prt_names(p->type,v4l2_type_names), p->bytesused,p->flags,utils/v4l2-tracer/retrace.cpp +1
-1@@ -72,7 +72,7 @@ void retrace_mmap(json_object *mmap_obj, bool is_mmap64) (long) buf_address_retrace_pointer); if (is_verbose() || (errno != 0)) { - fprintf(stderr, "fd: %d, offset: %ld, ", fd_retrace, off); + fprintf(stderr, "fd: %d, offset: %lld, ", fd_retrace, (long long)off); if (is_mmap64) perror("mmap64"); else
Re: [PATCH 2/2] v4l-utils: fix compilation with 64-bit time_t
Quoted 57 lines · Rosen Penev
Quoted 32 lines · Hans Verkuil
Hi Rosen,
Apologies, I hadn't seen this patch, it was filed in my spam folder for some reason.
Quoted 26 lines · Rosen Penev
musl since version 1.2.0 uses 64-bit
time_teven on 32-bit. Cast to 64-bit for compatibility.Signed-off-by Rosen Penev <[email protected]>--- utils/cec-compliance/cec-compliance.cpp | 3 ++- utils/cec-compliance/cec-test-adapter.cpp | 5 +++-- utils/cec-ctl/cec-ctl.cpp | 19 ++++++++++--------- utils/cec-follower/cec-follower.cpp | 3 ++- utils/cec-follower/cec-processing.cpp | 3 ++- utils/keytable/keytable.c | 1 + utils/libv4l2util/v4l2_driver.c | 7 ++++--- utils/v4l2-tracer/retrace.cpp | 2 +- 8 files changed, 25 insertions(+), 18 deletions(-)utils/cec-compliance/cec-compliance.cpp +1
-0@@ -3,6 +3,7 @@ * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved. */ +#include <cinttypes> #include <sstream>Quoted 12 lines
utils/cec-compliance/cec-compliance.cpp static std::string ts2s(__u64 ts) · line 283
Quoted 7 lines
utils/cec-compliance/cec-compliance.cpp +1
-1#include <fcntl.h>@@ -279,7 +280,7 @@ static std::string ts2s(__u64 ts) t = res.tv_sec; s = ctime(&t); s = s.substr(0, s.length() - 6); - sprintf(buf, "%03lu", res.tv_usec / 1000); + sprintf(buf, "%03" PRIu64, (uint64_t)res.tv_usec / 1000);This doesn't make sense: why is res.tv_usec cast to a
uint64_t? Is that field really a 64 bit value under musl? But in any case,tv_usecis limited to 999999, so if it is a 64 bit value under musl, then just cast it to unsigned long and leave the %03lu as-is.That's
suseconds_twhich is 64-bit. I felt it would be safer to cast to 64-bit, but OK.Quoted 3 lines
The commit log is certainly insufficient since a lot of the changes in this patch have nothing to do with
time_tbut with tv_n/usec.include/alltypes.h.in:TYPEDEF
_Int64suseconds_t; : <-- from musl source.Quoted 6 lines
Why use PRIu64? That's not explained in the commit log either. I had to look that up, as I've never seen it used before.
As I understand it, musl doesn't support %llu in some cases? Looking at:
Quoted 8 lines
Quoted 7 lines
https://github.com/cloudius-systems/musl/blob/master/include/inttypes.h
it appears that PRIu64 can either be lu or llu. lu is used if
UINTPTR_MAX==UINT64_MAX.But if that is needed, then I expect to see a single patch converting every %lld and %llu in v4l-utils to use PRId/u64. Here it is only done for some time-related code.
not exactly. kernel types use long long always. musl switches between both.
Sorry, I don't follow. Do you mean that a __u64 will always be 64 bit and can be formatted as %llu in musl? But types like suseconds_t can be either long or long long?
Or do you mean something else?
I would really prefer to avoid the use of PRIu64, and if casts to (__u64) would do that trick, than that sounds like an acceptable solution.
Regards,
Hans
Quoted 184 lines
Quoted 184 lines
Please don't mix changing to PRId/u64 with these time changes. If you believe that is needed, then do that as a final patch for all of v4l-utils. But the commit log should be very clear explaining why it is needed.
Regards,
Hans
Quoted 174 lines
utils/cec-compliance/cec-compliance.cpp +0
-0return s + "." + buf; }utils/cec-compliance/cec-test-adapter.cpp +3
-2@@ -4,6 +4,7 @@ */ #include <cerrno> +#include <cinttypes> #include <ctime> #include <string>@@ -1276,9 +1277,9 @@ static int testLostMsgs(struct node *node) printf("\t\tReceived messages: %d of which %d were CEC_MSG_CEC_VERSION\n", pending_rx_msgs, pending_rx_cec_version_msgs); if (pending_quick_msgs < pending_msgs) - printf("\t\tReceived %d messages immediately, and %d over %ld seconds\n", + printf("\t\tReceived %d messages immediately, and %d over %" PRIu64 " seconds\n", pending_quick_msgs, pending_msgs - pending_quick_msgs, - time(nullptr) - start); + (uint64_t)time(nullptr) - start); } print_sfts(sft[1][1], "SFTs for repeating messages (>= 7)"); print_sfts(sft[1][0], "SFTs for repeating remote messages (>= 7)");utils/cec-ctl/cec-ctl.cpp +10
-9@@ -6,6 +6,7 @@ #include <algorithm> #include <cctype> #include <cerrno> +#include <cinttypes> #include <cstring> #include <ctime> #include <map>@@ -416,7 +417,7 @@ std::string ts2s(__u64 ts) strftime(buf, sizeof(buf), "%a %b %e %T.000000", &tm); } secs = last_secs + t - last_t; - sprintf(buf + 14, "%02u:%02u.%06lu", secs / 60, secs % 60, res.tv_usec); + sprintf(buf + 14, "%02u:%02u.%06d", secs / 60, secs % 60, (int)res.tv_usec); return buf; }@@ -944,10 +945,10 @@ static void monitor(const struct node &node, __u32 monitor_time, const char *sto } fprintf(fstore, "# cec-ctl --store-pin\n"); fprintf(fstore, "# version %d\n", CEC_CTL_VERSION); - fprintf(fstore, "# start_monotonic %lu.%09lu\n", - start_monotonic.tv_sec, start_monotonic.tv_nsec); - fprintf(fstore, "# start_timeofday %lu.%06lu\n", - start_timeofday.tv_sec, start_timeofday.tv_usec); + fprintf(fstore, "# start_monotonic %" PRIu64 ".%09" PRIu64 "\n", + (uint64_t)start_monotonic.tv_sec, (uint64_t)start_monotonic.tv_nsec); + fprintf(fstore, "# start_timeofday %" PRIu64 ".%06" PRIu64 "\n", + (uint64_t)start_timeofday.tv_sec, (uint64_t)start_timeofday.tv_usec); fprintf(fstore, "# log_addr_mask 0x%04x\n", node.log_addr_mask); fprintf(fstore, "# phys_addr %x.%x.%x.%x\n", cec_phys_addr_exp(node.phys_addr));@@ -986,10 +987,10 @@ static void monitor(const struct node &node, __u32 monitor_time, const char *sto */ clock_gettime(CLOCK_MONOTONIC, &start_monotonic); gettimeofday(&start_timeofday, nullptr); - fprintf(fstore, "# start_monotonic %lu.%09lu\n", - start_monotonic.tv_sec, start_monotonic.tv_nsec); - fprintf(fstore, "# start_timeofday %lu.%06lu\n", - start_timeofday.tv_sec, start_timeofday.tv_usec); + fprintf(fstore, "# start_monotonic %" PRIu64 ".%09" PRIu64 "\n", + (uint64_t)start_monotonic.tv_sec, (uint64_t)start_monotonic.tv_nsec); + fprintf(fstore, "# start_timeofday %" PRIu64 ".%06" PRIu64 "\n", + (uint64_t)start_timeofday.tv_sec, (uint64_t)start_timeofday.tv_usec); fflush(fstore); start_minute = now; }utils/cec-follower/cec-follower.cpp +2
-1@@ -3,6 +3,7 @@ * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved. */ +#include <cinttypes> #include <cstring> #include <ctime> #include <sstream>@@ -354,7 +355,7 @@ void print_timers(struct node *node) printf("source: %s, ", source.c_str()); if (t.recording_seq) printf("rec-seq: 0x%x, ", t.recording_seq); - printf("needs: %ld %s\n", t.duration, "MB."); /* 1MB per second. */ + printf("needs: %" PRIu64 " %s\n", (uint64_t)t.duration, "MB."); /* 1MB per second. */ } printf("Total media space available for recording: "); if (node->state.media_space_available >= 0)utils/cec-follower/cec-processing.cpp +2
-1@@ -6,6 +6,7 @@ #include "linux/compiler.h" #include <cerrno> +#include <cinttypes> #include <ctime> #include <string>@@ -74,7 +75,7 @@ static std::string ts2s(__u64 ts, bool wallclock) t = res.tv_sec; s = ctime(&t); s = s.substr(0, s.length() - 6); - sprintf(buf, "%03lu", res.tv_usec / 1000); + sprintf(buf, "%03" PRIu64, (uint64_t)res.tv_usec / 1000); return s + "." + buf; }utils/keytable/keytable.c +1
-0@@ -214,6 +214,7 @@ static enum sysfs_protocols parse_sysfs_protocol(const char *name, bool all_alloreturn SYSFS_INVALID ; } +__attribute__((format (printf,3 ,0 )))static void write_sysfs_protocols (enum sysfs_protocols protocols,FILE *fp,const char *fmt) {const struct protocol_map_entry *pme;utils/libv4l2util/v4l2_driver.c +4
-3@@ -15,6 +15,7 @@#include <assert.h> #include <errno.h> #include <fcntl.h> +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -174,13 +175,13 @@ static void prt_buf_info(char *name,struct v4l2_buffer *p) {struct v4l2_timecode *tc=&p->timecode; - printf ("%s: %02ld:%02d:%02d.%08ld index=%d, type=%s, " + printf ("%s: %02" PRIu64 ":%02d:%02d.%08" PRIu64 " index=%d, type=%s, " "bytesused=%d, flags=0x%08x, " "field=%s, sequence=%d, memory=%s, offset=0x%08x, length=%d\n", - name, (p->timestamp.tv_sec/3600), + name, (uint64_t)(p->timestamp.tv_sec/3600), (int)(p->timestamp.tv_sec/60)%60, (int)(p->timestamp.tv_sec%60), - p->timestamp.tv_usec, + (uint64_t)p->timestamp.tv_usec, p->index, prt_names(p->type,v4l2_type_names), p->bytesused,p->flags,utils/v4l2-tracer/retrace.cpp +1
-1@@ -72,7 +72,7 @@ void retrace_mmap(json_object *mmap_obj, bool is_mmap64) (long) buf_address_retrace_pointer); if (is_verbose() || (errno != 0)) { - fprintf(stderr, "fd: %d, offset: %ld, ", fd_retrace, off); + fprintf(stderr, "fd: %d, offset: %lld, ", fd_retrace, (long long)off); if (is_mmap64) perror("mmap64"); else
Re: [PATCH 2/2] v4l-utils: fix compilation with 64-bit time_t
Quoted 63 lines · Hans Verkuil
Quoted 61 lines · Rosen Penev
Quoted 32 lines · Hans Verkuil
Hi Rosen,
Apologies, I hadn't seen this patch, it was filed in my spam folder for some reason.
Quoted 26 lines · Rosen Penev
musl since version 1.2.0 uses 64-bit
time_teven on 32-bit. Cast to 64-bit for compatibility.Signed-off-by Rosen Penev <[email protected]>--- utils/cec-compliance/cec-compliance.cpp | 3 ++- utils/cec-compliance/cec-test-adapter.cpp | 5 +++-- utils/cec-ctl/cec-ctl.cpp | 19 ++++++++++--------- utils/cec-follower/cec-follower.cpp | 3 ++- utils/cec-follower/cec-processing.cpp | 3 ++- utils/keytable/keytable.c | 1 + utils/libv4l2util/v4l2_driver.c | 7 ++++--- utils/v4l2-tracer/retrace.cpp | 2 +- 8 files changed, 25 insertions(+), 18 deletions(-)utils/cec-compliance/cec-compliance.cpp +1
-0@@ -3,6 +3,7 @@ * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved. */ +#include <cinttypes> #include <sstream>Quoted 12 lines
utils/cec-compliance/cec-compliance.cpp static std::string ts2s(__u64 ts) · line 283
Quoted 7 lines
utils/cec-compliance/cec-compliance.cpp +1
-1#include <fcntl.h>@@ -279,7 +280,7 @@ static std::string ts2s(__u64 ts) t = res.tv_sec; s = ctime(&t); s = s.substr(0, s.length() - 6); - sprintf(buf, "%03lu", res.tv_usec / 1000); + sprintf(buf, "%03" PRIu64, (uint64_t)res.tv_usec / 1000);This doesn't make sense: why is res.tv_usec cast to a
uint64_t? Is that field really a 64 bit value under musl? But in any case,tv_usecis limited to 999999, so if it is a 64 bit value under musl, then just cast it to unsigned long and leave the %03lu as-is.That's
suseconds_twhich is 64-bit. I felt it would be safer to cast to 64-bit, but OK.Quoted 3 lines
The commit log is certainly insufficient since a lot of the changes in this patch have nothing to do with
time_tbut with tv_n/usec.include/alltypes.h.in:TYPEDEF
_Int64suseconds_t; : <-- from musl source.Quoted 10 lines
Why use PRIu64? That's not explained in the commit log either. I had to look that up, as I've never seen it used before.
As I understand it, musl doesn't support %llu in some cases? Looking at:
https://github.com/cloudius-systems/musl/blob/master/include/inttypes.h
it appears that PRIu64 can either be lu or llu. lu is used if
UINTPTR_MAX==UINT64_MAX.
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
But if that is needed, then I expect to see a single patch converting every %lld and %llu in v4l-utils to use PRId/u64. Here it is only done for some time-related code.
not exactly. kernel types use long long always. musl switches between both.
Sorry, I don't follow. Do you mean that a
__u64will always be 64 bit and can be formatted as %llu in musl? But types likesuseconds_tcan be either long or long long?
__u64 is always long long, yes.
Quoted 5 lines
Or do you mean something else?
I would really prefer to avoid the use of PRIu64, and if casts to (
__u64) would do that trick, than that sounds like an acceptable solution.
Cleaner. Will rework.
Quoted 190 lines
Regards,
Hans
Quoted 184 lines
Quoted 184 lines
Please don't mix changing to PRId/u64 with these time changes. If you believe that is needed, then do that as a final patch for all of v4l-utils. But the commit log should be very clear explaining why it is needed.
Regards,
Hans
Quoted 174 lines
utils/cec-compliance/cec-compliance.cpp +0
-0return s + "." + buf; }utils/cec-compliance/cec-test-adapter.cpp +3
-2@@ -4,6 +4,7 @@ */ #include <cerrno> +#include <cinttypes> #include <ctime> #include <string>@@ -1276,9 +1277,9 @@ static int testLostMsgs(struct node *node) printf("\t\tReceived messages: %d of which %d were CEC_MSG_CEC_VERSION\n", pending_rx_msgs, pending_rx_cec_version_msgs); if (pending_quick_msgs < pending_msgs) - printf("\t\tReceived %d messages immediately, and %d over %ld seconds\n", + printf("\t\tReceived %d messages immediately, and %d over %" PRIu64 " seconds\n", pending_quick_msgs, pending_msgs - pending_quick_msgs, - time(nullptr) - start); + (uint64_t)time(nullptr) - start); } print_sfts(sft[1][1], "SFTs for repeating messages (>= 7)"); print_sfts(sft[1][0], "SFTs for repeating remote messages (>= 7)");utils/cec-ctl/cec-ctl.cpp +10
-9@@ -6,6 +6,7 @@ #include <algorithm> #include <cctype> #include <cerrno> +#include <cinttypes> #include <cstring> #include <ctime> #include <map>@@ -416,7 +417,7 @@ std::string ts2s(__u64 ts) strftime(buf, sizeof(buf), "%a %b %e %T.000000", &tm); } secs = last_secs + t - last_t; - sprintf(buf + 14, "%02u:%02u.%06lu", secs / 60, secs % 60, res.tv_usec); + sprintf(buf + 14, "%02u:%02u.%06d", secs / 60, secs % 60, (int)res.tv_usec); return buf; }@@ -944,10 +945,10 @@ static void monitor(const struct node &node, __u32 monitor_time, const char *sto } fprintf(fstore, "# cec-ctl --store-pin\n"); fprintf(fstore, "# version %d\n", CEC_CTL_VERSION); - fprintf(fstore, "# start_monotonic %lu.%09lu\n", - start_monotonic.tv_sec, start_monotonic.tv_nsec); - fprintf(fstore, "# start_timeofday %lu.%06lu\n", - start_timeofday.tv_sec, start_timeofday.tv_usec); + fprintf(fstore, "# start_monotonic %" PRIu64 ".%09" PRIu64 "\n", + (uint64_t)start_monotonic.tv_sec, (uint64_t)start_monotonic.tv_nsec); + fprintf(fstore, "# start_timeofday %" PRIu64 ".%06" PRIu64 "\n", + (uint64_t)start_timeofday.tv_sec, (uint64_t)start_timeofday.tv_usec); fprintf(fstore, "# log_addr_mask 0x%04x\n", node.log_addr_mask); fprintf(fstore, "# phys_addr %x.%x.%x.%x\n", cec_phys_addr_exp(node.phys_addr));@@ -986,10 +987,10 @@ static void monitor(const struct node &node, __u32 monitor_time, const char *sto */ clock_gettime(CLOCK_MONOTONIC, &start_monotonic); gettimeofday(&start_timeofday, nullptr); - fprintf(fstore, "# start_monotonic %lu.%09lu\n", - start_monotonic.tv_sec, start_monotonic.tv_nsec); - fprintf(fstore, "# start_timeofday %lu.%06lu\n", - start_timeofday.tv_sec, start_timeofday.tv_usec); + fprintf(fstore, "# start_monotonic %" PRIu64 ".%09" PRIu64 "\n", + (uint64_t)start_monotonic.tv_sec, (uint64_t)start_monotonic.tv_nsec); + fprintf(fstore, "# start_timeofday %" PRIu64 ".%06" PRIu64 "\n", + (uint64_t)start_timeofday.tv_sec, (uint64_t)start_timeofday.tv_usec); fflush(fstore); start_minute = now; }utils/cec-follower/cec-follower.cpp +2
-1@@ -3,6 +3,7 @@ * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved. */ +#include <cinttypes> #include <cstring> #include <ctime> #include <sstream>@@ -354,7 +355,7 @@ void print_timers(struct node *node) printf("source: %s, ", source.c_str()); if (t.recording_seq) printf("rec-seq: 0x%x, ", t.recording_seq); - printf("needs: %ld %s\n", t.duration, "MB."); /* 1MB per second. */ + printf("needs: %" PRIu64 " %s\n", (uint64_t)t.duration, "MB."); /* 1MB per second. */ } printf("Total media space available for recording: "); if (node->state.media_space_available >= 0)utils/cec-follower/cec-processing.cpp +2
-1@@ -6,6 +6,7 @@ #include "linux/compiler.h" #include <cerrno> +#include <cinttypes> #include <ctime> #include <string>@@ -74,7 +75,7 @@ static std::string ts2s(__u64 ts, bool wallclock) t = res.tv_sec; s = ctime(&t); s = s.substr(0, s.length() - 6); - sprintf(buf, "%03lu", res.tv_usec / 1000); + sprintf(buf, "%03" PRIu64, (uint64_t)res.tv_usec / 1000); return s + "." + buf; }utils/keytable/keytable.c +1
-0@@ -214,6 +214,7 @@ static enum sysfs_protocols parse_sysfs_protocol(const char *name, bool all_alloreturn SYSFS_INVALID ; } +__attribute__((format (printf,3 ,0 )))static void write_sysfs_protocols (enum sysfs_protocols protocols,FILE *fp,const char *fmt) {const struct protocol_map_entry *pme;utils/libv4l2util/v4l2_driver.c +4
-3@@ -15,6 +15,7 @@#include <assert.h> #include <errno.h> #include <fcntl.h> +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -174,13 +175,13 @@ static void prt_buf_info(char *name,struct v4l2_buffer *p) {struct v4l2_timecode *tc=&p->timecode; - printf ("%s: %02ld:%02d:%02d.%08ld index=%d, type=%s, " + printf ("%s: %02" PRIu64 ":%02d:%02d.%08" PRIu64 " index=%d, type=%s, " "bytesused=%d, flags=0x%08x, " "field=%s, sequence=%d, memory=%s, offset=0x%08x, length=%d\n", - name, (p->timestamp.tv_sec/3600), + name, (uint64_t)(p->timestamp.tv_sec/3600), (int)(p->timestamp.tv_sec/60)%60, (int)(p->timestamp.tv_sec%60), - p->timestamp.tv_usec, + (uint64_t)p->timestamp.tv_usec, p->index, prt_names(p->type,v4l2_type_names), p->bytesused,p->flags,utils/v4l2-tracer/retrace.cpp +1
-1@@ -72,7 +72,7 @@ void retrace_mmap(json_object *mmap_obj, bool is_mmap64) (long) buf_address_retrace_pointer); if (is_verbose() || (errno != 0)) { - fprintf(stderr, "fd: %d, offset: %ld, ", fd_retrace, off); + fprintf(stderr, "fd: %d, offset: %lld, ", fd_retrace, (long long)off); if (is_mmap64) perror("mmap64"); else
Hi Rosen,
Quoted 2 lines · Rosen Penev
By default, these platforms use long instead of long long for
__u64.__SANE_USERSPACE_TYPES__fixes -Wformat warnings.
I think this needs a more extensive commit message.
See e.g. https://lists.openembedded.org/g/openembedded-core/message/46881
(found after googling for __SANE_USERSPACE_TYPES__).
Quoted 41 lines
Signed-off-by Rosen Penev <[email protected]>--- contrib/xc3028-firmware/firmware-tool.c | 2 ++ include/linux/compiler.h | 1 + utils/cec-compliance/cec-compliance.h | 2 ++ utils/cec-ctl/cec-ctl.cpp | 2 ++ utils/cec-ctl/cec-ctl.h | 2 ++ utils/cec-ctl/cec-pin.cpp | 2 ++ utils/cec-follower/cec-processing.cpp | 2 ++ utils/common/v4l2-info.h | 2 ++ utils/cx18-ctl/cx18-ctl.c | 2 ++ utils/ivtv-ctl/ivtv-ctl.c | 2 ++ utils/keytable/keytable.c | 2 ++ utils/media-ctl/media-ctl.c | 2 ++ utils/v4l2-compliance/v4l2-compliance.h | 2 ++ utils/v4l2-ctl/v4l2-ctl-common.cpp | 2 ++ utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 2 ++ utils/v4l2-ctl/v4l2-ctl.cpp | 2 ++ utils/v4l2-ctl/v4l2-ctl.h | 2 ++ utils/v4l2-dbg/v4l2-dbg.cpp | 2 ++ 18 files changed, 35 insertions(+)contrib/xc3028-firmware/firmware-tool.c +2
-0@@ -29,6 +29,8 @@#include <string.h> #include <unistd.h> +#include "linux/compiler.h" +#include <asm/byteorder.h> #include <asm/types.h> include/linux/compiler.h +0
-0
include/linux/compiler.h line 4
Quoted 4 lines
include/linux/compiler.h +1
-0@@ -1,6 +1,7 @@#ifndef __linux_compiler_h#define __linux_compiler_h +#define __SANE_USERSPACE_TYPES__
This needs a comment as well.
Regards,
Hans
Quoted 211 lines
include/linux/compiler.h +0
-0#define __user#endif utils/cec-compliance/cec-compliance.h +2
-0@@ -8,6 +8,8 @@#ifndef _CEC_COMPLIANCE_H_#define _CEC_COMPLIANCE_H_ +#include "linux/compiler.h" +#include <linux/cec-funcs.h> #include "cec-htng-funcs.h" utils/cec-ctl/cec-ctl.cpp +2
-0@@ -20,6 +20,8 @@ #include <sys/time.h> #include <unistd.h> +#include "linux/compiler.h" + #include <linux/cec-funcs.h> #include "cec-htng-funcs.h" #include "cec-log.h"utils/cec-ctl/cec-ctl.h +2
-0@@ -6,6 +6,8 @@#ifndef _CEC_CTL_H_#define _CEC_CTL_H_ +#include "linux/compiler.h" +#include <cec-info.h> // cec-ctl.cpp utils/cec-ctl/cec-pin.cpp +2
-0@@ -3,6 +3,8 @@ * Copyright 2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved. */ +#include "linux/compiler.h" + #include <string> #include <linux/cec.h>utils/cec-follower/cec-processing.cpp +2
-0@@ -3,6 +3,8 @@ * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved. */ +#include "linux/compiler.h" + #include <cerrno> #include <ctime> #include <string>utils/common/v4l2-info.h +2
-0@@ -8,6 +8,8 @@#include <string> +#include "linux/compiler.h" +#include <linux/videodev2.h> #include <linux/v4l2-subdev.h> utils/cx18-ctl/cx18-ctl.c +2
-0@@ -34,6 +34,8 @@#include <sys/time.h> #include <math.h> +#include "linux/compiler.h" +#include <linux/videodev2.h> #include <v4l-getsubopt.h> utils/ivtv-ctl/ivtv-ctl.c +2
-0@@ -34,6 +34,8 @@#include <sys/time.h> #include <math.h> +#include "linux/compiler.h" +#include <linux/videodev2.h> #include <v4l-getsubopt.h> utils/keytable/keytable.c +2
-0@@ -12,6 +12,8 @@GNU General Public License for more details. */ +#include "linux/compiler.h" +#include <ctype.h> #include <errno.h> #include <fcntl.h> utils/media-ctl/media-ctl.c +2
-0@@ -34,6 +34,8 @@#include <string.h> #include <unistd.h> +#include "linux/compiler.h" +#include <linux/media.h> #include <linux/types.h> #include <linux/v4l2-mediabus.h> utils/v4l2-compliance/v4l2-compliance.h +2
-0@@ -26,6 +26,8 @@#include <string> #include <cstdint> +#include "linux/compiler.h" +#include <linux/videodev2.h> #include <linux/v4l2-subdev.h> #include <linux/media.h> utils/v4l2-ctl/v4l2-ctl-common.cpp +2
-0@@ -9,6 +9,8 @@ #include <sys/stat.h> #include <sys/sysmacros.h> +#include "linux/compiler.h" + #include <linux/media.h> #include "v4l2-ctl.h"utils/v4l2-ctl/v4l2-ctl-streaming.cpp +2
-0@@ -3,6 +3,8 @@ #include <netdb.h> #include <sys/types.h> +#include "linux/compiler.h" + #include <linux/media.h> #include "compiler.h"utils/v4l2-ctl/v4l2-ctl.cpp +2
-0@@ -27,6 +27,8 @@ #include <getopt.h> #include <sys/epoll.h> +#include "linux/compiler.h" + #include <linux/media.h> #include "v4l2-ctl.h"utils/v4l2-ctl/v4l2-ctl.h +2
-0@@ -1,6 +1,8 @@#ifndef _V4L2_CTL_H#define _V4L2_CTL_H +#include "linux/compiler.h" +#include <cstdint> #include <linux/videodev2.h> #include <linux/v4l2-subdev.h> utils/v4l2-dbg/v4l2-dbg.cpp +2
-0@@ -31,6 +31,8 @@ #include <sys/klog.h> #endif +#include "linux/compiler.h" + #include <linux/videodev2.h> #include <v4l-getsubopt.h>