package SYS::lastlog; @ISA = qw(Exporter); @EXPORT = qw(last); use Carp; use Struct; $LASTLOG_T = 'L A8 A16'; $LASTLOG_S = length(pack($LASTLOG_T, ())); # struct lastlog { # time_t ll_time; # char ll_line[8]; # char ll_host[16]; /* same as in utmp */ # }; struct SYS::lastlog qw{ time line host }; sub read { my $class = shift; local($fh) = shift; croak "usage: lastlog::read FH" unless defined fileno($fh) && @_ == 0; my $buff; return sysread($fh, $buff, $LASTLOG_S) == $LASTLOG_S ? new SYS::lastlog unpack($LASTLOG_T, $buff) : undef; } sub open { return open (FH, '/usr/adm/lastlog') ? *FH : undef; } sub new { croak "usage: lastlog::new list" if @_ == 0; my $class = shift; # these are created so they can be imported ($time, $line, $host) = @_; bless [ @_ ]; }; 1;