I keep writing up little notes to self and then forgetting to post 'em. This was from my first pass over "last". (Not a huge amount of cleanup, most of it was research.)
Currently, toys.h includes utmpx.h but not utmp.h. The reason is that utmpx.h is in posix-2008, and utmp.h isn't: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/utmpx.h.html It turns out, utmp.h is deprecated, replaced by utmpx.h: http://lists.freebsd.org/pipermail/freebsd-current/2010-January/014893.html And there's example code on how to use the new posix interface in the programming book written by Michael Kerrisk (the man page maintainer), ala: http://man7.org/tlpi/code/online/dist/loginacct/dump_utmpx.c.html It _also_ turns out that in Linux, struct utmp and utmpx are the same thing. So the accessor functions changed, but the actual file format didn't. Odd. Let's gloss over that for the moment, and focus on cleaning up the code that's there. First problem, my netbook doesn't list any logged in users: $ last wtmp begins Thu May 1 04:52:20 2014 Hmmm... how about if I do a fresh login: $ last root tty4 Fri May 9 05:32 still logged in root tty4 Fri May 9 05:32 - 05:32 (00:00) wtmp begins Fri May 9 05:32:02 2014 Ok, I can work with that. Going through main(): GLOBALS start zeroed so we don't need to assign NULL to TT.list. &tm[1] is just tm+1. Special-casing an empty file seems unnecessary. Also, instead of having an lseek before the loop and another at the end of the loop, let's have just one at the start of the loop. Between the two of those, the need for stat goes away. Well, the other thing the stat was doing was giving a timestamp for an empty log. Let's just use current time in that case. _______________________________________________ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net