3
# errno - search POSIX error codes by error number, error name,
6
# Copyright (C) 2010 Dustin Kirkland <kirkland@ubuntu.com>
9
# Dustin Kirkland <kirkland@ubuntu.com>
10
# Kees Cook <kees@ubuntu.com>
11
# Scott Moser <smoser@ubuntu.com>
13
# This program is free software: you can redistribute it and/or modify
14
# it under the terms of the GNU General Public License as published by
15
# the Free Software Foundation, version 3 of the License.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU General Public License for more details.
22
# You should have received a copy of the GNU General Public License
23
# along with this program. If not, see <http://www.gnu.org/licenses/>.
25
if which gcc >/dev/null; then
26
# Header finding trick from Kees Cook <kees@ubuntu.com>
27
headers=$(echo "#include <asm/errno.h>" | gcc -E - | grep "\.h" | awk -F\" '{print $2}' | sort -u)
29
headers="/usr/include/asm-generic/errno*.h"
34
for code in "${@}"; do
35
if [ "$code" -le 0 -o "$code" -ge 0 ] 2>/dev/null; then
36
# Input is a number, search for a particular matching code
37
sed -n "s,^#define\s\+\([^[:space:]]\+\s\+${code}\s.*\),\1,p" ${headers}
39
# Input is not a number, search for any matching strings
40
sed -n "s,^#define\s\+\(.*${code}.*\),\1,Ip" ${headers}