From owner-svn-src-all@FreeBSD.ORG Wed May 20 22:19:22 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6846E106564A; Wed, 20 May 2009 22:19:22 +0000 (UTC) (envelope-from gnn@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 57BBB8FC16; Wed, 20 May 2009 22:19:22 +0000 (UTC) (envelope-from gnn@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n4KMJMdh045803; Wed, 20 May 2009 22:19:22 GMT (envelope-from gnn@svn.freebsd.org) Received: (from gnn@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n4KMJMT9045802; Wed, 20 May 2009 22:19:22 GMT (envelope-from gnn@svn.freebsd.org) Message-Id: <200905202219.n4KMJMT9045802@svn.freebsd.org> From: "George V. Neville-Neil" Date: Wed, 20 May 2009 22:19:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r192486 - head/usr.bin/perror X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 May 2009 22:19:22 -0000 Author: gnn Date: Wed May 20 22:19:22 2009 New Revision: 192486 URL: http://svn.freebsd.org/changeset/base/192486 Log: A few more style changes as well as a more broad allowance for errors to be given by the caller. Change output to be easier for use in scripts. Submitted by: bce Modified: head/usr.bin/perror/perror.c Modified: head/usr.bin/perror/perror.c ============================================================================== --- head/usr.bin/perror/perror.c Wed May 20 22:13:21 2009 (r192485) +++ head/usr.bin/perror/perror.c Wed May 20 22:19:22 2009 (r192486) @@ -31,48 +31,40 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include -#define MAX_ERR 256 - -static void -usage() -{ - - fprintf(stderr, "usage: perror number\n"); - fprintf(stderr, "number must be between 1 and %d\n", ELAST); - exit(1); -} +static void usage(); int main(int argc, char **argv) { - - char errstr[MAX_ERR]; char *cp; - int errnum; + char *errstr; + long errnum; if (argc != 2) usage(); + errno = 0; + errnum = strtol(argv[1], &cp, 0); - if (((errnum == 0) && (errno == EINVAL)) || (*cp != '\0')) { - fprintf(stderr, "Argument %s not a number.\n", argv[1]); - usage(); - } + if (errno != 0) + err(1, NULL); - if ((errnum <=0) || (errnum > ELAST)) { - fprintf(stderr, "Number %d out of range.\n", errnum); - usage(); - } - - if (strerror_r(errnum, errstr, sizeof(errstr)) < 0) { - fprintf(stderr, "Could not find error number %d.\n", errnum); - usage(); - } + if ((errstr = strerror(errnum)) == NULL) + err(1, NULL); - printf("Error %d is \"%s\"\n", errnum, errstr); + printf("%s\n", errstr); exit(0); } + +static void +usage() +{ + fprintf(stderr, "usage: perror number\n"); + exit(1); +} +