Merge pull request #10970 from yuwata/from-name-return-negative-errno

util: make *_from_name() returns negative errno on error
This commit is contained in:
Yu Watanabe
2018-11-29 03:18:03 +09:00
committed by GitHub
15 changed files with 66 additions and 36 deletions
+2 -1
View File
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include <errno.h>
#include <string.h>
#include <sys/socket.h>
@@ -29,7 +30,7 @@ int af_from_name(const char *name) {
sc = lookup_af(name, strlen(name));
if (!sc)
return AF_UNSPEC;
return -EINVAL;
return sc->id;
}
+2 -1
View File
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include <errno.h>
#include <net/if_arp.h>
#include <string.h>
@@ -29,7 +30,7 @@ int arphrd_from_name(const char *name) {
sc = lookup_arphrd(name, strlen(name));
if (!sc)
return 0;
return -EINVAL;
return sc->id;
}
-22
View File
@@ -1,22 +0,0 @@
#!/usr/bin/env python3
"""Generate %-from-name.gperf from %-list.txt
"""
import sys
name, prefix, input = sys.argv[1:]
print("""\
%{
#if __GNUC__ >= 7
_Pragma("GCC diagnostic ignored \\"-Wimplicit-fallthrough\\"")
#endif
%}""")
print("""\
struct {}_name {{ const char* name; int id; }};
%null-strings
%%""".format(name))
for line in open(input):
print("{0}, {1}{0}".format(line.rstrip(), prefix))
@@ -1,6 +0,0 @@
#!/bin/sh
set -eu
$1 -dM -include netinet/in.h - </dev/null | \
awk '/^#define[ \t]+IPPROTO_[^ \t]+[ \t]+[^ \t]/ { print $2; }' | \
sed -e 's/IPPROTO_//'
+1 -11
View File
@@ -179,8 +179,6 @@ basic_sources = files('''
missing_h = files('missing.h')
generate_gperfs = find_program('generate-gperfs.py')
generate_af_list = find_program('generate-af-list.sh')
af_list_txt = custom_target(
'af-list.txt',
@@ -209,19 +207,11 @@ errno_list_txt = custom_target(
command : [generate_errno_list, cpp],
capture : true)
generate_socket_protocol_list = find_program('generate-socket-protocol-list.sh')
socket_protocol_list_txt = custom_target(
'socket-protocol-list.txt',
output : 'socket-protocol-list.txt',
command : [generate_socket_protocol_list, cpp],
capture : true)
generated_gperf_headers = []
foreach item : [['af', af_list_txt, 'af', ''],
['arphrd', arphrd_list_txt, 'arphrd', 'ARPHRD_'],
['cap', cap_list_txt, 'capability', ''],
['errno', errno_list_txt, 'errno', ''],
['socket-protocol', socket_protocol_list_txt, 'socket_protocol', 'IPPROTO_']]
['errno', errno_list_txt, 'errno', '']]
fname = '@0@-from-name.gperf'.format(item[0])
gperf_file = custom_target(
-9
View File
@@ -1,9 +0,0 @@
BEGIN{
print "static const char* const socket_protocol_names[] = { "
}
!/HOPOPTS/ {
printf " [IPPROTO_%s] = \"%s\",\n", $1, tolower($1)
}
END{
print "};"
}