summaryrefslogtreecommitdiffstats
path: root/usr.bin/fstat
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-07-08 11:02:48 +0000
committercharnier <charnier@FreeBSD.org>1997-07-08 11:02:48 +0000
commit47dc77937cfa740b63f95820f027e412b270f1fa (patch)
treeb543f0d06b40423b1c8a3d4a737b95ecb9d4c18b /usr.bin/fstat
parentc82bc63df1f55e24c93e4d46e99a64372736ff8a (diff)
downloadFreeBSD-src-47dc77937cfa740b63f95820f027e412b270f1fa.zip
FreeBSD-src-47dc77937cfa740b63f95820f027e412b270f1fa.tar.gz
Use err(3).
Diffstat (limited to 'usr.bin/fstat')
-rw-r--r--usr.bin/fstat/fstat.c57
1 files changed, 23 insertions, 34 deletions
diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c
index 4ffab31..c790e89 100644
--- a/usr.bin/fstat/fstat.c
+++ b/usr.bin/fstat/fstat.c
@@ -32,13 +32,17 @@
*/
#ifndef lint
-static char copyright[] =
+static const char copyright[] =
"@(#) Copyright (c) 1988, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
+#if 0
static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
#include <sys/param.h>
@@ -74,7 +78,7 @@ static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95";
#include <netinet/in_pcb.h>
#include <ctype.h>
-#include <errno.h>
+#include <err.h>
#include <fcntl.h>
#include <kvm.h>
#include <limits.h>
@@ -129,8 +133,7 @@ int maxfiles;
free(ofiles); \
ofiles = malloc((d) * sizeof(struct file *)); \
if (ofiles == NULL) { \
- fprintf(stderr, "fstat: %s\n", strerror(errno)); \
- exit(1); \
+ err(1, NULL); \
} \
maxfiles = (d); \
}
@@ -188,8 +191,7 @@ main(argc, argv)
if (pflg++)
usage();
if (!isdigit(*optarg)) {
- fprintf(stderr,
- "fstat: -p requires a process id\n");
+ warnx(" -p requires a process id");
usage();
}
what = KERN_PROC_PID;
@@ -198,11 +200,8 @@ main(argc, argv)
case 'u':
if (uflg++)
usage();
- if (!(passwd = getpwnam(optarg))) {
- fprintf(stderr, "%s: unknown uid\n",
- optarg);
- exit(1);
- }
+ if (!(passwd = getpwnam(optarg)))
+ errx(1, "%s: unknown uid", optarg);
what = KERN_PROC_UID;
arg = passwd->pw_uid;
break;
@@ -239,20 +238,14 @@ main(argc, argv)
if (nlistf != NULL || memf != NULL)
setgid(getgid());
- if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf)) == NULL) {
- fprintf(stderr, "fstat: %s\n", buf);
- exit(1);
- }
+ if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf)) == NULL)
+ errx(1, "%s", buf);
#ifdef notdef
- if (kvm_nlist(kd, nl) != 0) {
- fprintf(stderr, "fstat: no namelist: %s\n", kvm_geterr(kd));
- exit(1);
- }
+ if (kvm_nlist(kd, nl) != 0)
+ errx(1, "no namelist: %s", kvm_geterr(kd));
#endif
- if ((p = kvm_getprocs(kd, what, arg, &cnt)) == NULL) {
- fprintf(stderr, "fstat: %s\n", kvm_geterr(kd));
- exit(1);
- }
+ if ((p = kvm_getprocs(kd, what, arg, &cnt)) == NULL)
+ errx(1, "%s", kvm_geterr(kd));
if (nflg)
printf("%s",
"USER CMD PID FD DEV INUM MODE SZ|DV R/W");
@@ -301,7 +294,7 @@ void
dofiles(kp)
struct kinfo_proc *kp;
{
- int i, last;
+ int i;
struct file file;
struct filedesc0 filed0;
#define filed filed0.fd_fd
@@ -564,13 +557,11 @@ getmnton(m)
if (m == mt->m)
return (mt->mntonname);
if (!KVM_READ(m, &mount, sizeof(struct mount))) {
- fprintf(stderr, "can't read mount table at %x\n", m);
+ warnx("can't read mount table at %x", m);
return (NULL);
}
- if ((mt = malloc(sizeof (struct mtab))) == NULL) {
- fprintf(stderr, "fstat: %s\n", strerror(errno));
- exit(1);
- }
+ if ((mt = malloc(sizeof (struct mtab))) == NULL)
+ err(1, NULL);
mt->m = m;
bcopy(&mount.mnt_stat.f_mntonname[0], &mt->mntonname[0], MNAMELEN);
mt->next = mhead;
@@ -775,13 +766,11 @@ getfname(filename)
DEVS *cur;
if (stat(filename, &statbuf)) {
- fprintf(stderr, "fstat: %s: %s\n", filename, strerror(errno));
+ warn("%s", filename);
return(0);
}
- if ((cur = malloc(sizeof(DEVS))) == NULL) {
- fprintf(stderr, "fstat: %s\n", strerror(errno));
- exit(1);
- }
+ if ((cur = malloc(sizeof(DEVS))) == NULL)
+ err(1, NULL);
cur->next = devs;
devs = cur;
OpenPOWER on IntegriCloud