Why is wtmp so big?

Edwin R. Carp erc at khijol.UUCP
Thu Dec 7 02:17:51 AEST 1989


In article <413 at tabbs.UUCP> aris at tabbs.UUCP (Aris Stathakis) writes:
>From article <1226 at ispi.UUCP>, by jbayer at ispi.UUCP (Jonathan Bayer):
>
>Since it is a binary file, this is no trivial task.

As Jean-Luc Picard would say, "Oh, come now!".  Of course it's trivial;
here's a piece of trivial code to do it:

#define WTMP "/etc/wtmp"
#define TRUNC 100L /* save how many entries? */
struct utmp utmp; /* fast and easy, but rather confusing! */
int in, out;
#define SCRATCH "/tmp/whatever"

if((in=open(WTMP,O_RDONLY);
... (perror code goes here)
if((out=open(SCRATCH,O_WRONLY);
... (perror code goes here)
/* point to the end of the file - TRUNC entries */
lseek(in, (long)((long)sizeof(struct utmp)*TRUNC*-1L), 2);
/* now copy from in to out */
for(i=0; i<(int)TRUNC; i++) copy(in, out); /* copy from WTMP to SCRATCH */
close(in);
rewind(out);
in=open(WTMP, O_WRONLY);
for(i=0; i<(int)TRUNC; i++) copy(out, in); /* copy from SCRATCH to WTMP */
close(out);
close(in);

This is not fleshed out, of course, but you get the idea.  The lseek() is
the key to doing the binary stuff.  We're lucky that it's all fixed length
records, though - if they were variable length, this wouldn't work.

--------------------------- discard all after this line ------------------------
Ed Carp	N7EKG/5 (28.3-28.5) ...!attctc!puzzle!khijol!erc   (home) (512) 445-2044
Snail Mail:  1800 E. Stassney  #1205 Austin, Tx  78744

"You may think you're smart, Pierce, but you're STUPID!  But, you've met your
 match in ME!"  - Col. Flagg
"Good tea.  Nice house."  -- Worf



More information about the Comp.unix.xenix mailing list