Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!natinst!rpp386!puzzle!khijol!erc From: erc@khijol.UUCP (Edwin R. Carp) Newsgroups: comp.unix.xenix Subject: Re: Why is wtmp so big? Message-ID: <436@khijol.UUCP> Date: 6 Dec 89 15:17:51 GMT References: <1226@ispi.UUCP> <413@tabbs.UUCP> Reply-To: erc@khijol.UUCP (Edwin R. Carp) Organization: Deadly Force, Inc., aka Clint Eastwood School of Diplomacy Lines: 40 In article <413@tabbs.UUCP> aris@tabbs.UUCP (Aris Stathakis) writes: >From article <1226@ispi.UUCP>, by jbayer@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