BSD 4_4_Lite1 release
[unix-history] / usr / src / usr.bin / last / last.c
index aeb7092..662a663 100644 (file)
@@ -1,18 +1,44 @@
 /*
 /*
- * Copyright (c) 1987 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1987, 1993, 1994
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * %sccs.include.redist.c%
+ * 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
-char copyright[] =
-"@(#) Copyright (c) 1987 Regents of the University of California.\n\
- All rights reserved.\n";
+static char copyright[] =
+"@(#) Copyright (c) 1987, 1993, 1994\n\
      The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)last.c     5.20 (Berkeley) %G%";
+static char sccsid[] = "@(#)last.c     8.2 (Berkeley) 4/2/94";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -132,8 +158,8 @@ main(argc, argv)
 void
 wtmp()
 {
 void
 wtmp()
 {
-       register struct utmp    *bp;            /* current structure */
-       register TTY    *T;                     /* tty list entry */
+       struct utmp     *bp;                    /* current structure */
+       TTY     *T;                             /* tty list entry */
        struct stat     stb;                    /* stat of file for size */
        long    bl, delta;                      /* time difference */
        int     bytes, wfd;
        struct stat     stb;                    /* stat of file for size */
        long    bl, delta;                      /* time difference */
        int     bytes, wfd;
@@ -246,10 +272,10 @@ wtmp()
  */
 int
 want(bp, check)
  */
 int
 want(bp, check)
-       register struct utmp *bp;
+       struct utmp *bp;
        int check;
 {
        int check;
 {
-       register ARG *step;
+       ARG *step;
 
        if (check)
                /*
 
        if (check)
                /*
@@ -262,24 +288,24 @@ want(bp, check)
                else if (!strncmp(bp->ut_line, "uucp", sizeof("uucp") - 1))
                        bp->ut_line[4] = '\0';
        if (!arglist)
                else if (!strncmp(bp->ut_line, "uucp", sizeof("uucp") - 1))
                        bp->ut_line[4] = '\0';
        if (!arglist)
-               return(YES);
+               return (YES);
 
        for (step = arglist; step; step = step->next)
                switch(step->type) {
                case HOST_TYPE:
                        if (!strncasecmp(step->name, bp->ut_host, UT_HOSTSIZE))
 
        for (step = arglist; step; step = step->next)
                switch(step->type) {
                case HOST_TYPE:
                        if (!strncasecmp(step->name, bp->ut_host, UT_HOSTSIZE))
-                               return(YES);
+                               return (YES);
                        break;
                case TTY_TYPE:
                        if (!strncmp(step->name, bp->ut_line, UT_LINESIZE))
                        break;
                case TTY_TYPE:
                        if (!strncmp(step->name, bp->ut_line, UT_LINESIZE))
-                               return(YES);
+                               return (YES);
                        break;
                case USER_TYPE:
                        if (!strncmp(step->name, bp->ut_name, UT_NAMESIZE))
                        break;
                case USER_TYPE:
                        if (!strncmp(step->name, bp->ut_name, UT_NAMESIZE))
-                               return(YES);
+                               return (YES);
                        break;
        }
                        break;
        }
-       return(NO);
+       return (NO);
 }
 
 /*
 }
 
 /*
@@ -291,12 +317,10 @@ addarg(type, arg)
        int type;
        char *arg;
 {
        int type;
        char *arg;
 {
-       register ARG *cur;
+       ARG *cur;
 
 
-       if (!(cur = (ARG *)malloc((u_int)sizeof(ARG)))) {
-               fputs("last: malloc failure.\n", stderr);
-               exit(1);
-       }
+       if (!(cur = (ARG *)malloc((u_int)sizeof(ARG))))
+               err(1, "malloc failure");
        cur->next = arglist;
        cur->type = type;
        cur->name = arg;
        cur->next = arglist;
        cur->type = type;
        cur->name = arg;
@@ -311,16 +335,14 @@ TTY *
 addtty(ttyname)
        char *ttyname;
 {
 addtty(ttyname)
        char *ttyname;
 {
-       register TTY *cur;
+       TTY *cur;
 
 
-       if (!(cur = (TTY *)malloc((u_int)sizeof(TTY)))) {
-               fputs("last: malloc failure.\n", stderr);
-               exit(1);
-       }
+       if (!(cur = (TTY *)malloc((u_int)sizeof(TTY))))
+               err(1, "malloc failure");
        cur->next = ttylist;
        cur->logout = currentout;
        cur->next = ttylist;
        cur->logout = currentout;
-       bcopy(ttyname, cur->tty, UT_LINESIZE);
-       return(ttylist = cur);
+       memmove(cur->tty, ttyname, UT_LINESIZE);
+       return (ttylist = cur);
 }
 
 /*
 }
 
 /*
@@ -337,13 +359,13 @@ hostconv(arg)
        static char *hostdot, name[MAXHOSTNAMELEN];
        char *argdot;
 
        static char *hostdot, name[MAXHOSTNAMELEN];
        char *argdot;
 
-       if (!(argdot = index(arg, '.')))
+       if (!(argdot = strchr(arg, '.')))
                return;
        if (first) {
                first = 0;
                if (gethostname(name, sizeof(name)))
                        err(1, "gethostname");
                return;
        if (first) {
                first = 0;
                if (gethostname(name, sizeof(name)))
                        err(1, "gethostname");
-               hostdot = index(name, '.');
+               hostdot = strchr(name, '.');
        }
        if (hostdot && !strcasecmp(hostdot, argdot))
                *argdot = '\0';
        }
        if (hostdot && !strcasecmp(hostdot, argdot))
                *argdot = '\0';
@@ -365,21 +387,19 @@ ttyconv(arg)
         */
        if (strlen(arg) == 2) {
                /* either 6 for "ttyxx" or 8 for "console" */
         */
        if (strlen(arg) == 2) {
                /* either 6 for "ttyxx" or 8 for "console" */
-               if (!(mval = malloc((u_int)8))) {
-                       fputs("last: malloc failure.\n", stderr);
-                       exit(1);
-               }
+               if (!(mval = malloc((u_int)8)))
+                       err(1, "malloc failure");
                if (!strcmp(arg, "co"))
                        (void)strcpy(mval, "console");
                else {
                        (void)strcpy(mval, "tty");
                        (void)strcpy(mval + 3, arg);
                }
                if (!strcmp(arg, "co"))
                        (void)strcpy(mval, "console");
                else {
                        (void)strcpy(mval, "tty");
                        (void)strcpy(mval + 3, arg);
                }
-               return(mval);
+               return (mval);
        }
        if (!strncmp(arg, _PATH_DEV, sizeof(_PATH_DEV) - 1))
        }
        if (!strncmp(arg, _PATH_DEV, sizeof(_PATH_DEV) - 1))
-               return(arg + 5);
-       return(arg);
+               return (arg + 5);
+       return (arg);
 }
 
 /*
 }
 
 /*