~kirkland/errno/trunk

« back to all changes in this revision

Viewing changes to errno

  • Committer: Dustin Kirkland
  • Date: 2011-01-24 06:28:44 UTC
  • Revision ID: kirkland@ubuntu.com-20110124062844-7lspshf0mcilnhnc
* === added directory debian, === added directory debian/source,
  debian/compat, debian/control, debian/copyright, debian/install,
  debian/manpages, debian/rules, debian/source/format, errno, errno.1:
  - initial checkin
  - moving errno from ubuntu-dev-tools to a new package/project;
    maintainer of ubuntu-dev-tools rejects errno as an appropriate
    ubuntu-dev-tool, LP: #666540

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh -e
 
2
#
 
3
#    errno - search POSIX error codes by error number, error name,
 
4
#            or error description
 
5
#
 
6
#    Copyright (C) 2010 Dustin Kirkland <kirkland@ubuntu.com>
 
7
#
 
8
#    Authors:
 
9
#        Dustin Kirkland <kirkland@ubuntu.com>
 
10
#        Kees Cook <kees@ubuntu.com>
 
11
#        Scott Moser <smoser@ubuntu.com>
 
12
#
 
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.
 
16
#
 
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.
 
21
#
 
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/>.
 
24
 
 
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)
 
28
else
 
29
        headers="/usr/include/asm-generic/errno*.h"
 
30
fi
 
31
 
 
32
code="$1"
 
33
 
 
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}
 
38
        else
 
39
                # Input is not a number, search for any matching strings
 
40
                sed -n "s,^#define\s\+\(.*${code}.*\),\1,Ip" ${headers}
 
41
        fi
 
42
done