FreeBSD/usr.bin/last/last.c
/*
 * wtmp --
 *	read through the utx.log file
 */
wtmp
read through the utx.log file
wtmp read through the utx . log file
static void
wtmp(void)
{
	struct utmpx *buf = NULL;
	struct utmpx *ut;
	static unsigned int amount = 0;
	time_t t;
	char ct[80];
	struct tm *tm;
	SLIST_INIT(&idlist);
	(void)time(&t);
	if (setutxdb(UTXDB_LOG, file) != 0)
		err(1, "%s", file);
	while ((ut = getutxent()) != NULL) {
		if (amount % 128 == 0) {
			buf = realloc(buf, (amount + 128) * sizeof *ut);
			if (buf == NULL)
				err(1, "realloc");
		}
		memcpy(&buf[amount++], ut, sizeof *ut);
		if (t > ut->ut_tv.tv_sec)
			t = ut->ut_tv.tv_sec;
	}
	endutxent();
	while (amount > 0)
		doentry(&buf[--amount]);
	tm = localtime(&t);
	(void) strftime(ct, sizeof(ct), "%+", tm);
	printf("\n%s begins %s\n", ((file == NULL) ? "utx.log" : file), ct);
}
static void wtmp ( void ) { struct utmpx * buf = NULL ; struct utmpx * ut ; static unsigned int amount = 0 ; time_t t ; char ct [ 80 ] ; struct tm * tm ; SLIST_INIT ( & idlist ) ; ( void ) time ( & t ) ; if ( setutxdb ( UTXDB_LOG , file ) != 0 ) err ( 1 , " " , file ) ; while ( ( ut = getutxent ( ) ) != NULL ) { if ( amount % 128 == 0 ) { buf = realloc ( buf , ( amount + 128 ) * sizeof * ut ) ; if ( buf == NULL ) err ( 1 , " " ) ; } memcpy ( & buf [ amount ++ ] , ut , sizeof * ut ) ; if ( t > ut -> ut_tv . tv_sec ) t = ut -> ut_tv . tv_sec ; } endutxent ( ) ; while ( amount > 0 ) doentry ( & buf [ -- amount ] ) ; tm = localtime ( & t ) ; ( void ) strftime ( ct , sizeof ( ct ) , " " , tm ) ; printf ( " \n \n " , ( ( file == NULL ) ? " " : file ) , ct ) ; }
wtmp
      read through the utx.log file
wtmp read through the utx . log file
/* Load the last entries from the file. */ /* Display them in reverse order. */