From 99ddf5fd61178b6a4a6628fb57f73ae87dd5d57e Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Tue, 10 Aug 2010 14:40:13 -0400 Subject: [PATCH] add an errno utility, LP: #612267 add optimizations from Scott Moser --- debian/changelog | 2 +- errno | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/debian/changelog b/debian/changelog index 0a8e6f5..1fcee85 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,7 +2,7 @@ ubuntu-dev-tools (0.102) UNRELEASED; urgency=low [ Dustin Kirkland ] * errno, doc/errno.1, debian/control, debian/copyright, setup.py: - - add an errno utility, LP: #61226 + - add an errno utility, LP: #612267 -- Dustin Kirkland Tue, 10 Aug 2010 11:41:10 -0400 diff --git a/errno b/errno index 4960bd1..33c1044 100755 --- a/errno +++ b/errno @@ -2,8 +2,14 @@ # # errno - search POSIX error codes by error number, error name, # or error description +# # Copyright (C) 2010 Dustin Kirkland # +# Authors: +# Dustin Kirkland +# Kees Cook +# Scott Moser +# # 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. @@ -16,7 +22,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -if $(which gcc >/dev/null); then +if which gcc >/dev/null; then # Header finding trick from Kees Cook headers=$(echo "#include " | gcc -E - | grep "\.h" | awk -F\" '{print $2}' | sort -u) else @@ -25,10 +31,12 @@ 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 +for code in "${@}"; do + if [ "$code" -le 0 -o "$code" -ge 0 ] 2>/dev/null; then + # Input is a number, search for a particular matching code + sed -n "s,^#define\s\+\([^[:space:]]\+\s\+${code}\s.*\),\1,p" ${headers} + else + # Input is not a number, search for any matching strings + sed -n "s,^#define\s\+\(.*${code}.*\),\1,Ip" ${headers} + fi +done