From deba7db48c7897a6302d3d706887bbddc3604c00 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 11 Mar 1997 13:43:33 +0000 Subject: Merge from Lite2 --- usr.bin/col/col.c | 6 ++++- usr.bin/cut/cut.c | 3 ++- usr.bin/dirname/dirname.c | 3 ++- usr.bin/du/du.c | 3 ++- usr.bin/finger/finger.1 | 11 +++++--- usr.bin/finger/finger.c | 39 +++++++++++++++++---------- usr.bin/finger/lprint.c | 9 ++++--- usr.bin/finger/net.c | 7 +++-- usr.bin/finger/sprint.c | 9 ++++--- usr.bin/finger/util.c | 64 ++++++++++++++------------------------------- usr.bin/fstat/fstat.c | 11 +++++--- usr.bin/head/head.c | 8 +++--- usr.bin/hexdump/hexsyntax.c | 4 ++- usr.bin/hexdump/odsyntax.c | 8 +++--- usr.bin/look/look.c | 7 +++-- usr.bin/mt/mt.c | 10 ++++--- usr.bin/tr/tr.c | 5 +++- 17 files changed, 115 insertions(+), 92 deletions(-) diff --git a/usr.bin/col/col.c b/usr.bin/col/col.c index 37dc304..e911688 100644 --- a/usr.bin/col/col.c +++ b/usr.bin/col/col.c @@ -41,7 +41,7 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)col.c 8.3 (Berkeley) 4/2/94"; +static char sccsid[] = "@(#)col.c 8.5 (Berkeley) 5/4/95"; #endif /* not lint */ #include @@ -49,6 +49,7 @@ static char sccsid[] = "@(#)col.c 8.3 (Berkeley) 4/2/94"; #include #include #include +#include #include #define BS '\b' /* backspace */ @@ -299,6 +300,9 @@ main(argc, argv) l->l_max_col = cur_col; cur_col++; } + if (max_line == 0) + exit(0); /* no lines, so just exit */ + /* goto the last line that had a character on it */ for (; l->l_next; l = l->l_next) this_line++; diff --git a/usr.bin/cut/cut.c b/usr.bin/cut/cut.c index 2c887ff..15e1524 100644 --- a/usr.bin/cut/cut.c +++ b/usr.bin/cut/cut.c @@ -41,7 +41,7 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)cut.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)cut.c 8.3 (Berkeley) 5/4/95"; #endif /* not lint */ #include @@ -50,6 +50,7 @@ static char sccsid[] = "@(#)cut.c 8.1 (Berkeley) 6/6/93"; #include #include #include +#include int cflag; char dchar; diff --git a/usr.bin/dirname/dirname.c b/usr.bin/dirname/dirname.c index 0c27e07..9698ba4 100644 --- a/usr.bin/dirname/dirname.c +++ b/usr.bin/dirname/dirname.c @@ -38,11 +38,12 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)dirname.c 8.3 (Berkeley) 4/2/94"; +static char sccsid[] = "@(#)dirname.c 8.4 (Berkeley) 5/4/95"; #endif /* not lint */ #include #include +#include void usage __P((void)); diff --git a/usr.bin/du/du.c b/usr.bin/du/du.c index 47f797f..c473e79 100644 --- a/usr.bin/du/du.c +++ b/usr.bin/du/du.c @@ -41,7 +41,7 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)du.c 8.4 (Berkeley) 4/1/94"; +static char sccsid[] = "@(#)du.c 8.5 (Berkeley) 5/4/95"; #endif /* not lint */ #include @@ -54,6 +54,7 @@ static char sccsid[] = "@(#)du.c 8.4 (Berkeley) 4/1/94"; #include #include #include +#include int linkchk __P((FTSENT *)); void usage __P((void)); diff --git a/usr.bin/finger/finger.1 b/usr.bin/finger/finger.1 index 272cb17..9d0755c 100644 --- a/usr.bin/finger/finger.1 +++ b/usr.bin/finger/finger.1 @@ -1,4 +1,4 @@ -.\" Copyright (c) 1989, 1990, 1993 +.\" Copyright (c) 1989, 1990, 1993, 1994 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -29,9 +29,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)finger.1 8.2 (Berkeley) 2/16/94 +.\" @(#)finger.1 8.3 (Berkeley) 5/5/94 .\" -.Dd February 16, 1994 +.Dd May 5, 1994 .Dt FINGER 1 .Os BSD 4 .Sh NAME @@ -192,6 +192,11 @@ utilizes the following environment variable, if it exists: This variable may be set with favored options to .Nm finger . .El +.Sh FILES +.Bl -tag -width /var/log/lastlog -compact +.It Pa /var/log/lastlog +last login data base +.El .Sh SEE ALSO .Xr chpass 1 , .Xr w 1 , diff --git a/usr.bin/finger/finger.c b/usr.bin/finger/finger.c index 657426f..9235d13 100644 --- a/usr.bin/finger/finger.c +++ b/usr.bin/finger/finger.c @@ -51,7 +51,7 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)finger.c 8.2 (Berkeley) 9/30/93"; +static char sccsid[] = "@(#)finger.c 8.5 (Berkeley) 5/4/95"; #endif /* not lint */ /* @@ -69,16 +69,21 @@ static char sccsid[] = "@(#)finger.c 8.2 (Berkeley) 9/30/93"; */ #include + +#include +#include +#include #include -#include #include -#include -#include #include #include #include +#include +#include +#include #include #include + #include "finger.h" DB *db; @@ -185,7 +190,7 @@ main(argc, argv) lflag_print(); else sflag_print(); - exit(0); + return (0); } static void @@ -199,7 +204,7 @@ loginlist() char name[UT_NAMESIZE + 1]; if (!freopen(_PATH_UTMP, "r", stdin)) - err("%s: %s", _PATH_UTMP, strerror(errno)); + err(1, "%s", _PATH_UTMP); name[UT_NAMESIZE] = NULL; while (fread((char *)&user, sizeof(user), 1, stdin) == 1) { if (!user.ut_name[0]) @@ -216,12 +221,15 @@ loginlist() } if (db && lflag) for (sflag = R_FIRST;; sflag = R_NEXT) { + PERSON *tmp; + r = (*db->seq)(db, &key, &data, sflag); if (r == -1) - err("db seq: %s", strerror(errno)); + err(1, "db seq"); if (r == 1) break; - enter_lastlog(*(PERSON **)data.data); + memmove(&tmp, data.data, sizeof tmp); + enter_lastlog(tmp); } } @@ -239,7 +247,7 @@ userlist(argc, argv) if ((nargv = malloc((argc+1) * sizeof(char *))) == NULL || (used = calloc(argc, sizeof(int))) == NULL) - err("%s", strerror(errno)); + err(1, NULL); /* Pull out all network requests. */ for (ap = p = argv, np = nargv; *p; ++p) @@ -260,13 +268,13 @@ userlist(argc, argv) */ if (mflag) for (p = argv; *p; ++p) - if ((pw = getpwnam(*p)) && !hide(pw)) + if (((pw = getpwnam(*p)) != NULL) && !hide(pw)) enter_person(pw); else (void)fprintf(stderr, "finger: %s: no such user\n", *p); else { - while (pw = getpwent()) { + while ((pw = getpwent()) != NULL) { for (p = argv, ip = used; *p; ++p, ++ip) if (match(pw, *p) && !hide(pw)) { enter_person(pw); @@ -294,7 +302,7 @@ net: for (p = nargv; *p;) { * appropriate data whenever a match occurs. */ if (!freopen(_PATH_UTMP, "r", stdin)) - err("%s: %s", _PATH_UTMP, strerror(errno)); + err(1, "%s", _PATH_UTMP); while (fread((char *)&user, sizeof(user), 1, stdin) == 1) { if (!user.ut_name[0]) continue; @@ -304,11 +312,14 @@ net: for (p = nargv; *p;) { } if (db) for (sflag = R_FIRST;; sflag = R_NEXT) { + PERSON *tmp; + r = (*db->seq)(db, &key, &data, sflag); if (r == -1) - err("db seq: %s", strerror(errno)); + err(1, "db seq"); if (r == 1) break; - enter_lastlog(*(PERSON **)data.data); + memmove(&tmp, data.data, sizeof tmp); + enter_lastlog(tmp); } } diff --git a/usr.bin/finger/lprint.c b/usr.bin/finger/lprint.c index 93e4a9b..847f26d 100644 --- a/usr.bin/finger/lprint.c +++ b/usr.bin/finger/lprint.c @@ -35,7 +35,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)lprint.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)lprint.c 8.3 (Berkeley) 4/28/95"; #endif /* not lint */ #include @@ -44,6 +44,7 @@ static char sccsid[] = "@(#)lprint.c 8.1 (Berkeley) 6/6/93"; #include #include #include +#include #include #include #include @@ -71,15 +72,17 @@ lflag_print() extern int pplan; register PERSON *pn; register int sflag, r; + PERSON *tmp; DBT data, key; for (sflag = R_FIRST;; sflag = R_NEXT) { r = (*db->seq)(db, &key, &data, sflag); if (r == -1) - err("db seq: %s", strerror(errno)); + err(1, "db seq"); if (r == 1) break; - pn = *(PERSON **)data.data; + memmove(&tmp, data.data, sizeof tmp); + pn = tmp; if (sflag != R_FIRST) putchar('\n'); lprint(pn); diff --git a/usr.bin/finger/net.c b/usr.bin/finger/net.c index 4f04c04..1173847 100644 --- a/usr.bin/finger/net.c +++ b/usr.bin/finger/net.c @@ -35,7 +35,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)net.c 8.3 (Berkeley) 1/2/94"; +static char sccsid[] = "@(#)net.c 8.4 (Berkeley) 4/28/95"; #endif /* not lint */ #include @@ -144,9 +144,8 @@ netfinger(name) * it isn't a space, we can simply set the 7th bit. Every ASCII * character with bit 7 set is printable. */ - if (fp = fdopen(s, "r")) { - int lastc = '\n'; - + lastc = 0; + if ((fp = fdopen(s, "r")) != NULL) { while ((c = getc(fp)) != EOF) { if (c == 0x0d) { if (lastc == '\r') /* ^M^M - skip dupes */ diff --git a/usr.bin/finger/sprint.c b/usr.bin/finger/sprint.c index 329c433..07218aa 100644 --- a/usr.bin/finger/sprint.c +++ b/usr.bin/finger/sprint.c @@ -35,13 +35,14 @@ */ #ifndef lint -static char sccsid[] = "@(#)sprint.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)sprint.c 8.3 (Berkeley) 4/28/95"; #endif /* not lint */ #include #include #include #include +#include #include #include #include @@ -61,6 +62,7 @@ sflag_print() register WHERE *w; register int sflag, r, namelen; char p[80]; + PERSON *tmp; DBT data, key; /* @@ -88,10 +90,11 @@ sflag_print() for (sflag = R_FIRST;; sflag = R_NEXT) { r = (*db->seq)(db, &key, &data, sflag); if (r == -1) - err("db seq: %s", strerror(errno)); + err(1, "db seq"); if (r == 1) break; - pn = *(PERSON **)data.data; + memmove(&tmp, data.data, sizeof tmp); + pn = tmp; for (w = pn->whead; w != NULL; w = w->next) { namelen = MAXREALNAME; diff --git a/usr.bin/finger/util.c b/usr.bin/finger/util.c index da1bb40..6931f86 100644 --- a/usr.bin/finger/util.c +++ b/usr.bin/finger/util.c @@ -35,13 +35,14 @@ */ #ifndef lint -static char sccsid[] = "@(#)util.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)util.c 8.3 (Berkeley) 4/28/95"; #endif /* not lint */ #include #include #include #include +#include #include #include #include @@ -81,14 +82,14 @@ match(pw, user) if ((p = strtok(p, ",")) == NULL) return(0); - for (t = name; *t = *p; ++p) + for (t = name; (*t = *p) != '\0'; ++p) if (*t == '&') { (void)strcpy(t, pw->pw_name); while (*++t); } else ++t; - for (t = name; p = strtok(t, "\t "); t = NULL) + for (t = name; (p = strtok(t, "\t ")) != NULL; t = NULL) if (!strcasecmp(p, user)) return(1); return(0); @@ -170,17 +171,18 @@ enter_person(pw) if (db == NULL && (db = dbopen(NULL, O_RDWR, 0, DB_BTREE, NULL)) == NULL) - err("%s", strerror(errno)); + err(1, NULL); key.data = pw->pw_name; key.size = strlen(pw->pw_name); - switch((*db->get)(db, &key, &data, 0)) { + switch ((*db->get)(db, &key, &data, 0)) { case 0: - return(*(PERSON **)data.data); + memmove(&pn, data.data, sizeof pn); + return (pn); default: case -1: - err("db get: %s", strerror(errno)); + err(1, "db get"); /* NOTREACHED */ case 1: ++entries; @@ -191,8 +193,8 @@ enter_person(pw) data.size = sizeof(PERSON *); data.data = &pn; if ((*db->put)(db, &key, &data, 0)) - err("%s", strerror(errno)); - return(pn); + err(1, "db put"); + return (pn); } } @@ -204,6 +206,7 @@ find_person(name) register int cnt; DBT data, key; + PERSON *p; char buf[UT_NAMESIZE + 1]; if (!db) @@ -219,7 +222,10 @@ find_person(name) key.data = buf; key.size = cnt; - return((*db->get)(db, &key, &data, 0) ? NULL : *(PERSON **)data.data); + if ((*db->get)(db, &key, &data, 0)) + return (NULL); + memmove(&p, data.data, sizeof p); + return (p); } PERSON * @@ -228,7 +234,7 @@ palloc() PERSON *p; if ((p = malloc((u_int) sizeof(PERSON))) == NULL) - err("%s", strerror(errno)); + err(1, NULL); return(p); } @@ -239,7 +245,7 @@ walloc(pn) register WHERE *w; if ((w = malloc((u_int) sizeof(WHERE))) == NULL) - err("%s", strerror(errno)); + err(1, NULL); if (pn->whead == NULL) pn->whead = pn->wtail = w; else { @@ -309,8 +315,7 @@ find_idle_and_ttywrite(w) (void)snprintf(tbuf, sizeof(tbuf), "%s/%s", _PATH_DEV, w->tty); if (stat(tbuf, &sb) < 0) { - (void)fprintf(stderr, - "finger: %s: %s\n", tbuf, strerror(errno)); + warn(tbuf); return; } w->idletime = now < sb.st_atime ? 0 : now - sb.st_atime; @@ -343,7 +348,7 @@ userinfo(pn, pw) /* ampersands get replaced by the login name */ if (!(p = strsep(&bp, ","))) return; - for (t = name; *t = *p; ++p) + for (t = name; (*t = *p) != '\0'; ++p) if (*t == '&') { (void)strcpy(t, pw->pw_name); if (islower(*t)) @@ -373,35 +378,6 @@ userinfo(pn, pw) } } -#if __STDC__ -#include -#else -#include -#endif - -void -#if __STDC__ -err(const char *fmt, ...) -#else -err(fmt, va_alist) - char *fmt; - va_dcl -#endif -{ - va_list ap; -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - (void)fprintf(stderr, "finger: "); - (void)vfprintf(stderr, fmt, ap); - va_end(ap); - (void)fprintf(stderr, "\n"); - exit(1); - /* NOTREACHED */ -} - /* * Is this user hiding from finger? * If ~/.nofinger exists, return 1 (hide), else return 0 (nohide). diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c index fbfaacb..84fd799 100644 --- a/usr.bin/fstat/fstat.c +++ b/usr.bin/fstat/fstat.c @@ -38,7 +38,7 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)fstat.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #endif /* not lint */ #include @@ -65,7 +65,9 @@ static char sccsid[] = "@(#)fstat.c 8.1 (Berkeley) 6/6/93"; #include #include #include +#define KERNEL #include +#undef KERNEL #include #undef NFS @@ -79,12 +81,14 @@ static char sccsid[] = "@(#)fstat.c 8.1 (Berkeley) 6/6/93"; #include #include #include +#include #include #include #include #include #include #include +#include #define TEXT -1 #define CDIR -2 @@ -164,6 +168,7 @@ main(argc, argv) struct kinfo_proc *p, *plast; int arg, ch, what; char *memf, *nlistf; + char buf[_POSIX2_LINE_MAX]; int cnt; arg = 0; @@ -238,8 +243,8 @@ main(argc, argv) if (nlistf != NULL || memf != NULL) setgid(getgid()); - if ((kd = kvm_open(nlistf, memf, NULL, O_RDONLY, NULL)) == NULL) { - fprintf(stderr, "fstat: %s\n", kvm_geterr(kd)); + if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf)) == NULL) { + fprintf(stderr, "fstat: %s\n", buf); exit(1); } #ifdef notdef diff --git a/usr.bin/head/head.c b/usr.bin/head/head.c index 9c13591..d154d53 100644 --- a/usr.bin/head/head.c +++ b/usr.bin/head/head.c @@ -38,15 +38,17 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)head.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)head.c 8.2 (Berkeley) 5/4/95"; #endif /* not lint */ #include + +#include #include +#include #include #include -#include -#include +#include /* * head - give the first few lines of a stream or of each of a set of files diff --git a/usr.bin/hexdump/hexsyntax.c b/usr.bin/hexdump/hexsyntax.c index e03804d..2c13db2 100644 --- a/usr.bin/hexdump/hexsyntax.c +++ b/usr.bin/hexdump/hexsyntax.c @@ -32,7 +32,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)hexsyntax.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)hexsyntax.c 8.2 (Berkeley) 5/4/95"; #endif /* not lint */ #include @@ -40,6 +40,8 @@ static char sccsid[] = "@(#)hexsyntax.c 8.1 (Berkeley) 6/6/93"; #include #include #include +#include + #include "hexdump.h" off_t skip; /* bytes to skip */ diff --git a/usr.bin/hexdump/odsyntax.c b/usr.bin/hexdump/odsyntax.c index 642f6c2..b6143f0 100644 --- a/usr.bin/hexdump/odsyntax.c +++ b/usr.bin/hexdump/odsyntax.c @@ -32,14 +32,16 @@ */ #ifndef lint -static char sccsid[] = "@(#)odsyntax.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)odsyntax.c 8.2 (Berkeley) 5/4/95"; #endif /* not lint */ #include -#include -#include #include +#include +#include +#include + #include "hexdump.h" int deprecated; diff --git a/usr.bin/look/look.c b/usr.bin/look/look.c index daef12f..da972bd 100644 --- a/usr.bin/look/look.c +++ b/usr.bin/look/look.c @@ -41,7 +41,7 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)look.c 8.1 (Berkeley) 6/14/93"; +static char sccsid[] = "@(#)look.c 8.2 (Berkeley) 5/4/95"; #endif /* not lint */ /* @@ -58,12 +58,15 @@ static char sccsid[] = "@(#)look.c 8.1 (Berkeley) 6/14/93"; #include #include +#include #include #include +#include #include #include #include -#include +#include + #include "pathnames.h" /* diff --git a/usr.bin/mt/mt.c b/usr.bin/mt/mt.c index 0eb9a1f..c5adecb 100644 --- a/usr.bin/mt/mt.c +++ b/usr.bin/mt/mt.c @@ -38,7 +38,7 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)mt.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)mt.c 8.2 (Berkeley) 5/4/95"; #endif /* not lint */ /* @@ -48,12 +48,14 @@ static char sccsid[] = "@(#)mt.c 8.1 (Berkeley) 6/6/93"; #include #include #include -#include + +#include #include -#include +#include #include -#include +#include #include +#include /* the appropriate sections of are also #ifdef'd for FreeBSD */ #if defined(__FreeBSD__) diff --git a/usr.bin/tr/tr.c b/usr.bin/tr/tr.c index 1713875..2dc5402 100644 --- a/usr.bin/tr/tr.c +++ b/usr.bin/tr/tr.c @@ -38,14 +38,17 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)tr.c 8.1 (Berkeley) 6/6/93"; +static char sccsid[] = "@(#)tr.c 8.2 (Berkeley) 5/4/95"; #endif /* not lint */ #include #include + #include #include #include +#include + #include "extern.h" static int string1[NCHARS] = { -- cgit v1.1