Skip to content

Commit 10b843e

Browse files
authored
Merge pull request systemd#13649 from keszybz/arphrd-minimization
Arphrd minimization
2 parents 37afb0a + 35bdba2 commit 10b843e

File tree

5 files changed

+21
-38
lines changed

5 files changed

+21
-38
lines changed

src/basic/arphrd-list.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,6 @@ static const struct arphrd_name* lookup_arphrd(register const char *str, registe
1212
#include "arphrd-from-name.h"
1313
#include "arphrd-to-name.h"
1414

15-
const char *arphrd_to_name(int id) {
16-
17-
if (id <= 0)
18-
return NULL;
19-
20-
if ((size_t) id >= ELEMENTSOF(arphrd_names))
21-
return NULL;
22-
23-
return arphrd_names[id];
24-
}
25-
2615
int arphrd_from_name(const char *name) {
2716
const struct arphrd_name *sc;
2817

@@ -34,7 +23,3 @@ int arphrd_from_name(const char *name) {
3423

3524
return sc->id;
3625
}
37-
38-
int arphrd_max(void) {
39-
return ELEMENTSOF(arphrd_names);
40-
}

src/basic/arphrd-list.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@
33

44
const char *arphrd_to_name(int id);
55
int arphrd_from_name(const char *name);
6-
7-
int arphrd_max(void);

src/basic/arphrd-to-name.awk

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
BEGIN{
2-
print "static const char* const arphrd_names[] = { "
2+
print "const char *arphrd_to_name(int id) {"
3+
print " switch(id) {"
34
}
4-
!/CISCO/ {
5-
printf " [ARPHRD_%s] = \"%s\",\n", $1, $1
5+
!/^HDLC$/ {
6+
printf " case ARPHRD_%s: return \"%s\";\n", $1, $1
67
}
78
END{
8-
print "};"
9+
print " default: return NULL;"
10+
print " }"
11+
print "}"
912
}

src/test/test-arphrd-list.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
11
/* SPDX-License-Identifier: LGPL-2.1+ */
22

33
#include <linux/if_arp.h>
4-
#include <string.h>
54

6-
#include "macro.h"
75
#include "string-util.h"
6+
#include "tests.h"
87

9-
_unused_ \
10-
static const struct arphrd_name* lookup_arphrd(register const char *str, register GPERF_LEN_TYPE len);
11-
12-
#include "arphrd-from-name.h"
138
#include "arphrd-list.h"
14-
#include "arphrd-to-name.h"
159

1610
int main(int argc, const char *argv[]) {
11+
test_setup_logging(LOG_INFO);
12+
13+
for (int i = 0; i <= ARPHRD_VOID + 1; i++) {
14+
const char *name;
1715

18-
unsigned i;
16+
name = arphrd_to_name(i);
17+
if (name) {
18+
log_info("%i: %s", i, name);
1919

20-
for (i = 1; i < ELEMENTSOF(arphrd_names); i++) {
21-
if (arphrd_names[i]) {
22-
assert_se(streq(arphrd_to_name(i), arphrd_names[i]));
23-
assert_se(arphrd_from_name(arphrd_names[i]) == (int) i);
20+
assert_se(arphrd_from_name(name) == i);
2421
}
2522
}
2623

27-
assert_se(arphrd_to_name(arphrd_max()) == NULL);
28-
assert_se(arphrd_to_name(0) == NULL);
24+
assert_se(arphrd_to_name(ARPHRD_VOID + 1) == NULL);
2925
assert_se(arphrd_from_name("huddlduddl") == -EINVAL);
3026
assert_se(arphrd_from_name("") == -EINVAL);
3127

src/test/test-mountpoint-util.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ static void test_mnt_id(void) {
8181
continue;
8282
}
8383

84-
log_debug("mnt ids of %s are %i, %i\n", p, mnt_id, mnt_id2);
85-
86-
if (mnt_id == mnt_id2)
84+
if (mnt_id == mnt_id2) {
85+
log_debug("mnt ids of %s is %i\n", p, mnt_id);
8786
continue;
87+
} else
88+
log_debug("mnt ids of %s are %i, %i\n", p, mnt_id, mnt_id2);
8889

8990
/* The ids don't match? If so, then there are two mounts on the same path, let's check if
9091
* that's really the case */

0 commit comments

Comments
 (0)