git: 05fe0588432a - stable/14 - nvmecontrol: Create letoh to generically convert to host order
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 27 Aug 2024 01:06:35 UTC
The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=05fe0588432aaf74077bc23b0db29889b49a3e40 commit 05fe0588432aaf74077bc23b0db29889b49a3e40 Author: Warner Losh <imp@FreeBSD.org> AuthorDate: 2024-04-16 22:35:33 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2024-08-26 18:31:02 +0000 nvmecontrol: Create letoh to generically convert to host order Using _Generic, create letoh which will generically convert uintXX_t types from little endian to host, regardless of the size. This name has been floated as a possible addition to endian.h. Sponsored by: Netflix Discussed with: jhb Reviewed by: chuck Differential Revision: https://reviews.freebsd.org/D44649 (cherry picked from commit 67163bc485a56d960b72fb26f19685682b92dd6b) --- sbin/nvmecontrol/nvmecontrol.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sbin/nvmecontrol/nvmecontrol.h b/sbin/nvmecontrol/nvmecontrol.h index ce717e5732c3..a098da4c9c45 100644 --- a/sbin/nvmecontrol/nvmecontrol.h +++ b/sbin/nvmecontrol/nvmecontrol.h @@ -60,6 +60,17 @@ struct kv_name { const char *name; }; +/* + * Generically convert little endian to host endian, based on the type of the thing + * being converted. Use the proposed name for future changes to endian.h. + */ +#define letoh(x) \ + _Generic(x, \ + uint8_t: (x), \ + uint16_t: le16toh(x), \ + uint32_t: le32toh(x), \ + uint64_t: le64toh(x)) + const char *kv_lookup(const struct kv_name *kv, size_t kv_count, uint32_t key); void logpage_register(struct logpage_function *p);