git: 67163bc485a5 - main - nvmecontrol: Create letoh to generically convert to host order
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 17 Apr 2024 03:33:40 UTC
The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=67163bc485a56d960b72fb26f19685682b92dd6b commit 67163bc485a56d960b72fb26f19685682b92dd6b Author: Warner Losh <imp@FreeBSD.org> AuthorDate: 2024-04-16 22:35:33 +0000 Commit: Warner Losh <imp@FreeBSD.org> CommitDate: 2024-04-17 03:30:17 +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 --- 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);