From f7ec5d710db2e510d45c41fb0137ad2de50fb0aa Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Sun, 8 Feb 2026 14:43:31 +0000 Subject: [PATCH] Consistently use endian.h swapping API A handful of places are still using the old "networking" API. Swap that with the usual (no longer GNU/glibc specific) ntobe*/be*toh. Be that to stay consistent, to improve clarity or to celebrate that the later is part of POSIX (2024) - take your pick. Signed-off-by: Emil Velikov Reviewed-by: Lucas De Marchi Link: https://github.com/kmod-project/kmod/pull/421 Signed-off-by: Lucas De Marchi --- libkmod/libkmod-index.c | 6 +++--- tools/depmod.c | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libkmod/libkmod-index.c b/libkmod/libkmod-index.c index cd5cf0eb..e64fe1eb 100644 --- a/libkmod/libkmod-index.c +++ b/libkmod/libkmod-index.c @@ -5,8 +5,8 @@ #include -#include #include +#include #include #include #include @@ -225,7 +225,7 @@ static bool read_u32s(FILE *in, uint32_t *l, size_t n) return false; } for (i = 0; i < n; i++) - l[i] = ntohl(l[i]); + l[i] = be32toh(l[i]); return true; } @@ -662,7 +662,7 @@ static inline uint32_t read_u32_mm(const void **p) v = get_unaligned((const uint32_t *)addr); *p = addr + sizeof(uint32_t); - return ntohl(v); + return be32toh(v); } static inline uint8_t read_char_mm(const void **p) diff --git a/tools/depmod.c b/tools/depmod.c index 355483ad..c3d87640 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -4,10 +4,10 @@ * Copyright (C) 2011-2013 ProFUSION embedded systems */ -#include #include #include #include +#include #include #include #include @@ -402,7 +402,7 @@ static uint32_t index_write__node(const struct index_node *node, FILE *out, } else { uint32_t mask = index_get_mask(child); child_offs[i] = - htonl((offset + node->size + sizes) | mask); + htobe32((offset + node->size + sizes) | mask); sizes += child->total; } } @@ -428,11 +428,11 @@ static uint32_t index_write__node(const struct index_node *node, FILE *out, value_count = 0; for (v = node->values; v != NULL; v = v->next) value_count++; - u = htonl(value_count); + u = htobe32(value_count); fwrite(&u, sizeof(u), 1, out); for (v = node->values; v != NULL; v = v->next) { - u = htonl(v->priority); + u = htobe32(v->priority); fwrite(&u, sizeof(u), 1, out); fputs(v->value, out); fputc('\0', out); @@ -462,13 +462,13 @@ static void index_write(struct index_node *node, FILE *out) index_calculate_size(node); - u = htonl(INDEX_MAGIC); + u = htobe32(INDEX_MAGIC); fwrite(&u, sizeof(u), 1, out); - u = htonl(INDEX_VERSION); + u = htobe32(INDEX_VERSION); fwrite(&u, sizeof(u), 1, out); /* Write offset of first node */ - u = htonl(first_off | index_get_mask(node)); + u = htobe32(first_off | index_get_mask(node)); fwrite(&u, sizeof(u), 1, out); /* Dump trie */ -- 2.47.3