386BSD 0.1 development
[unix-history] / usr / src / usr.bin / last / last.c
index 4ba2265..99a4652 100644 (file)
@@ -2,17 +2,33 @@
  * Copyright (c) 1987 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1987 Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
@@ -22,7 +38,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)last.c     5.15 (Berkeley) %G%";
+static char sccsid[] = "@(#)last.c     5.18 (Berkeley) 3/1/91";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -108,13 +124,17 @@ main(argc, argv)
                        fputs("usage: last [-#] [-f file] [-t tty] [-h hostname] [user ...]\n", stderr);
                        exit(1);
                }
                        fputs("usage: last [-#] [-f file] [-t tty] [-h hostname] [user ...]\n", stderr);
                        exit(1);
                }
-       for (argv += optind; *argv; ++argv) {
+
+       if (argc) {
+               setlinebuf(stdout);
+               for (argv += optind; *argv; ++argv) {
 #define        COMPATIBILITY
 #ifdef COMPATIBILITY
 #define        COMPATIBILITY
 #ifdef COMPATIBILITY
-               /* code to allow "last p5" to work */
-               addarg(TTY_TYPE, ttyconv(*argv));
+                       /* code to allow "last p5" to work */
+                       addarg(TTY_TYPE, ttyconv(*argv));
 #endif
 #endif
-               addarg(USER_TYPE, *argv);
+                       addarg(USER_TYPE, *argv);
+               }
        }
        wtmp();
        exit(0);
        }
        wtmp();
        exit(0);
@@ -124,7 +144,6 @@ main(argc, argv)
  * wtmp --
  *     read through the wtmp file
  */
  * wtmp --
  *     read through the wtmp file
  */
-static
 wtmp()
 {
        register struct utmp    *bp;            /* current structure */
 wtmp()
 {
        register struct utmp    *bp;            /* current structure */
@@ -132,11 +151,11 @@ wtmp()
        struct stat     stb;                    /* stat of file for size */
        long    bl, delta,                      /* time difference */
                lseek(), time();
        struct stat     stb;                    /* stat of file for size */
        long    bl, delta,                      /* time difference */
                lseek(), time();
-       int     bytes, wfd,
-               onintr();
+       int     bytes, wfd;
        char    *ct, *crmsg,
                *asctime(), *ctime(), *strcpy();
        TTY     *addtty();
        char    *ct, *crmsg,
                *asctime(), *ctime(), *strcpy();
        TTY     *addtty();
+       void    onintr();
 
        if ((wfd = open(file, O_RDONLY, 0)) < 0 || fstat(wfd, &stb) == -1) {
                perror(file);
 
        if ((wfd = open(file, O_RDONLY, 0)) < 0 || fstat(wfd, &stb) == -1) {
                perror(file);
@@ -231,7 +250,6 @@ wtmp()
  * want --
  *     see if want this entry
  */
  * want --
  *     see if want this entry
  */
-static
 want(bp, check)
        register struct utmp *bp;
        int check;
 want(bp, check)
        register struct utmp *bp;
        int check;
@@ -273,7 +291,6 @@ want(bp, check)
  * addarg --
  *     add an entry to a linked list of arguments
  */
  * addarg --
  *     add an entry to a linked list of arguments
  */
-static
 addarg(type, arg)
        int type;
        char *arg;
 addarg(type, arg)
        int type;
        char *arg;
@@ -295,7 +312,7 @@ addarg(type, arg)
  * addtty --
  *     add an entry to a linked list of ttys
  */
  * addtty --
  *     add an entry to a linked list of ttys
  */
-static TTY *
+TTY *
 addtty(ttyname)
        char *ttyname;
 {
 addtty(ttyname)
        char *ttyname;
 {
@@ -318,7 +335,6 @@ addtty(ttyname)
  *     has a domain attached that is the same as the current domain, rip
  *     off the domain suffix since that's what login(1) does.
  */
  *     has a domain attached that is the same as the current domain, rip
  *     off the domain suffix since that's what login(1) does.
  */
-static
 hostconv(arg)
        char *arg;
 {
 hostconv(arg)
        char *arg;
 {
@@ -344,7 +360,7 @@ hostconv(arg)
  * ttyconv --
  *     convert tty to correct name.
  */
  * ttyconv --
  *     convert tty to correct name.
  */
-static char *
+char *
 ttyconv(arg)
        char *arg;
 {
 ttyconv(arg)
        char *arg;
 {
@@ -377,7 +393,7 @@ ttyconv(arg)
  * onintr --
  *     on interrupt, we inform the user how far we've gotten
  */
  * onintr --
  *     on interrupt, we inform the user how far we've gotten
  */
-static
+void
 onintr(signo)
        int signo;
 {
 onintr(signo)
        int signo;
 {