mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-13 08:01:09 +00:00
35 lines
1.3 KiB
Bash
Executable File
35 lines
1.3 KiB
Bash
Executable File
#!/bin/sh -e
|
|
#
|
|
# errno - search POSIX error codes by error number, error name,
|
|
# or error description
|
|
# Copyright (C) 2010 Dustin Kirkland <kirkland@ubuntu.com>
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
if $(which gcc >/dev/null); then
|
|
# Header finding trick from Kees Cook <kees@ubuntu.com>
|
|
headers=$(echo "#include <asm/errno.h>" | gcc -E - | grep "\.h" | awk -F\" '{print $2}' | sort -u)
|
|
else
|
|
headers="/usr/include/asm-generic/errno*.h"
|
|
fi
|
|
|
|
code="$1"
|
|
|
|
if echo "$code" | egrep -qs "^[0-9]+$"; then
|
|
# Input is a number, search for a particular matching code
|
|
egrep -h "^#define\s.*\s+$code\s+/" $headers | sed 's/^#define\s*//'
|
|
else
|
|
# Input is not a number, search for any matching strings
|
|
grep -hi "$code" $headers | sed 's/^#define\s*//'
|
|
fi
|