/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999-2016 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
- *
+ *
* "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
* Reserved. This file contains Original Code and/or Modifications of
* Original Code as defined in and that are subject to the Apple Public
* except in compliance with the License. Please obtain a copy of the
* License at http://www.apple.com/publicsource and read it before using
* this file.
- *
+ *
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License."
- *
+ *
* @APPLE_LICENSE_HEADER_END@
*/
/*
* Copyright (c) 1994 Christopher G. Demetriou.
* @(#)Copyright (c) 1994, Simon J. Gerraty.
- *
+ *
* This is free software. It comes with NO WARRANTY.
- * Permission to use, modify and distribute this source code
+ * Permission to use, modify and distribute this source code
* is granted subject to the following conditions.
- * 1/ that the above copyright notice and this notice
- * are preserved in all copies and that due credit be given
- * to the author.
- * 2/ that any changes to this code are clearly commented
- * as such so that the author does not get blamed for bugs
+ * 1/ that the above copyright notice and this notice
+ * are preserved in all copies and that due credit be given
+ * to the author.
+ * 2/ that any changes to this code are clearly commented
+ * as such so that the author does not get blamed for bugs
* other than his own.
*/
* globals - yes yuk
*/
#ifdef CONSOLE_TTY
-static char *Console = CONSOLE_TTY;
+static char *Console = CONSOLE_TTY;
#endif
static time_t Total = 0;
static time_t FirstTime = 0;
void usage __P((void));
struct tty_list *
-add_tty(name)
- char *name;
+add_tty(char *name)
{
struct tty_list *tp;
register char *rcp;
Flags |= AC_T;
-
+
if ((tp = NEW(struct tty_list)) == NULL)
err(1, "malloc");
tp->len = 0; /* full match */
* should we process the named tty?
*/
int
-do_tty(name)
- char *name;
+do_tty(char *name)
{
struct tty_list *tp;
int def_ret = 0;
-
+
for (tp = Ttys; tp != NULL; tp = tp->next) {
if (tp->ret == 0) /* specific don't */
def_ret = 1; /* default do */
* is someone logged in on Console?
*/
int
-on_console(head)
- struct utmp_list *head;
+on_console(struct utmp_list *head)
{
struct utmp_list *up;
* update user's login time
*/
struct user_list *
-update_user(head, name, secs)
- struct user_list *head;
- char *name;
- time_t secs;
+update_user(struct user_list *head, char *name, time_t secs)
{
struct user_list *up;
*/
if (Flags & AC_U)
return head;
-
+
if ((up = NEW(struct user_list)) == NULL)
err(1, "malloc");
up->next = head;
}
int
-main(argc, argv)
- int argc;
- char **argv;
+main(int argc, char **argv)
{
FILE *fp;
int c;
if (Flags & AC_D)
Flags &= ~AC_P;
ac();
-
+
return 0;
}
* print login time in decimal hours
*/
void
-show(name, secs)
- char *name;
- time_t secs;
+show(char *name, time_t secs)
{
(void)printf("\t%-*s %8.2f\n", UT_NAMESIZE, name,
((double)secs / 3600));
}
void
-show_users(list)
- struct user_list *list;
+show_users(struct user_list *list)
{
struct user_list *lp;
* print total login time for 24hr period in decimal hours
*/
void
-show_today(users, logins, secs)
- struct user_list *users;
- struct utmp_list *logins;
- time_t secs;
+show_today(struct user_list *users, struct utmp_list *logins, time_t secs)
{
struct user_list *up;
struct utmp_list *lp;
/* restore the missing second */
yesterday++;
-
+
for (lp = logins; lp != NULL; lp = lp->next) {
secs = yesterday - lp->usr.ut_tv.tv_sec;
Users = update_user(Users, lp->usr.ut_user, secs);
secs += up->secs;
up->secs = 0; /* for next day */
}
- if (secs)
+ if (secs)
(void)printf("%s %11.2f\n", date, ((double)secs / 3600));
}
* been shut down.
*/
struct utmp_list *
-log_out(head, up)
- struct utmp_list *head;
- struct utmpx *up;
+log_out(struct utmp_list *head, struct utmpx *up)
{
struct utmp_list *lp, *lp2, *tlp;
time_t secs;
-
+
for (lp = head, lp2 = NULL; lp != NULL; )
if (up->ut_type == BOOT_TIME || up->ut_type == SHUTDOWN_TIME || strncmp(lp->usr.ut_line, up->ut_line,
sizeof (up->ut_line)) == 0) {
* if do_tty says ok, login a user
*/
struct utmp_list *
-log_in(head, up)
- struct utmp_list *head;
- struct utmpx *up;
+log_in(struct utmp_list *head, struct utmpx *up)
{
struct utmp_list *lp;
if (up->ut_host[0] == ':') {
/*
* SunOS 4.0.2 does not treat ":0.0" as special but we
- * do.
+ * do.
*/
if (on_console(head))
return head;
/*
* ok, no recorded login, so they were here when wtmp
- * started! Adjust ut_tv.tv_sec!
+ * started! Adjust ut_tv.tv_sec!
*/
up->ut_tv.tv_sec = FirstTime;
/*
}
int
-ac()
+ac(void)
{
struct utmp_list *lp, *head = NULL;
struct utmpx *u, end;
struct tm *ltm;
time_t secs = 0;
int day = -1;
-
+
setutxent_wtmp(1); /* read in forward direction */
while ((u = getutxent_wtmp()) != NULL) {
if (!FirstTime)
bzero(&end, sizeof(end));
end.ut_tv.tv_sec = time((time_t *)0);
end.ut_type = SHUTDOWN_TIME;
-
+
if (Flags & AC_D) {
ltm = localtime(&end.ut_tv.tv_sec);
if (day >= 0 && day != ltm->tm_yday) {
}
void
-usage()
+usage(void)
{
(void)fprintf(stderr,
#ifdef CONSOLE_TTY