Skip to content

Commit f7ec5d7

Browse files
evelikovlucasdemarchi
authored andcommitted
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 <emil.l.velikov@gmail.com> Reviewed-by: Lucas De Marchi <demarchi@kernel.org> Link: #421 Signed-off-by: Lucas De Marchi <demarchi@kernel.org>
1 parent 6188542 commit f7ec5d7

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

libkmod/libkmod-index.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
#include <sys/param.h>
77

8-
#include <arpa/inet.h>
98
#include <assert.h>
9+
#include <endian.h>
1010
#include <errno.h>
1111
#include <fnmatch.h>
1212
#include <inttypes.h>
@@ -225,7 +225,7 @@ static bool read_u32s(FILE *in, uint32_t *l, size_t n)
225225
return false;
226226
}
227227
for (i = 0; i < n; i++)
228-
l[i] = ntohl(l[i]);
228+
l[i] = be32toh(l[i]);
229229
return true;
230230
}
231231

@@ -662,7 +662,7 @@ static inline uint32_t read_u32_mm(const void **p)
662662
v = get_unaligned((const uint32_t *)addr);
663663

664664
*p = addr + sizeof(uint32_t);
665-
return ntohl(v);
665+
return be32toh(v);
666666
}
667667

668668
static inline uint8_t read_char_mm(const void **p)

tools/depmod.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
* Copyright (C) 2011-2013 ProFUSION embedded systems
55
*/
66

7-
#include <arpa/inet.h>
87
#include <assert.h>
98
#include <ctype.h>
109
#include <dirent.h>
10+
#include <endian.h>
1111
#include <errno.h>
1212
#include <getopt.h>
1313
#include <limits.h>
@@ -402,7 +402,7 @@ static uint32_t index_write__node(const struct index_node *node, FILE *out,
402402
} else {
403403
uint32_t mask = index_get_mask(child);
404404
child_offs[i] =
405-
htonl((offset + node->size + sizes) | mask);
405+
htobe32((offset + node->size + sizes) | mask);
406406
sizes += child->total;
407407
}
408408
}
@@ -428,11 +428,11 @@ static uint32_t index_write__node(const struct index_node *node, FILE *out,
428428
value_count = 0;
429429
for (v = node->values; v != NULL; v = v->next)
430430
value_count++;
431-
u = htonl(value_count);
431+
u = htobe32(value_count);
432432
fwrite(&u, sizeof(u), 1, out);
433433

434434
for (v = node->values; v != NULL; v = v->next) {
435-
u = htonl(v->priority);
435+
u = htobe32(v->priority);
436436
fwrite(&u, sizeof(u), 1, out);
437437
fputs(v->value, out);
438438
fputc('\0', out);
@@ -462,13 +462,13 @@ static void index_write(struct index_node *node, FILE *out)
462462

463463
index_calculate_size(node);
464464

465-
u = htonl(INDEX_MAGIC);
465+
u = htobe32(INDEX_MAGIC);
466466
fwrite(&u, sizeof(u), 1, out);
467-
u = htonl(INDEX_VERSION);
467+
u = htobe32(INDEX_VERSION);
468468
fwrite(&u, sizeof(u), 1, out);
469469

470470
/* Write offset of first node */
471-
u = htonl(first_off | index_get_mask(node));
471+
u = htobe32(first_off | index_get_mask(node));
472472
fwrite(&u, sizeof(u), 1, out);
473473

474474
/* Dump trie */

0 commit comments

Comments
 (0)