/*  Dave's neato wtmp program  
 *	wzap.c  
 *	NOTE:  	reads 'wtmp' from current directory and writes
 *			'wtmp.out' in cuurent directory...
 */

#include	<utmp.h>
#include	<stdio.h>
#include	<time.h>
#include	<sys/time.h>

FILE *Wfile, *Wout;

struct utmp myutmp;

main(argc,argv) 
int argc;
char *argv[];
{
	char username[20];
	char yesorno[5];
	long thetime, posi;

	if (argc<2) {
		printf("\n\n");
		printf("Enter username to zap from the wtmp: ");
		scanf("%s",username);
	} else strcpy(username,argv[1]);

	printf("\nopening file...\n");
	if ((Wfile = fopen("wtmp","r"))==NULL)
		{ printf("no open file\n"); exit(0); }
	printf("\opening output file...\n");
	if ((Wout = fopen("wtmp.out","wr"))==NULL)
		{ printf("no open output file...\n"); exit(0); }

	printf("working...\n");
	while(!feof(Wfile)) {
		fread(&myutmp,sizeof(myutmp),1,Wfile);
		if (strncmp(myutmp.ut_name,username,8))
			fwrite(&myutmp,sizeof(myutmp),1,Wout); 
	}
	fclose(Wfile);
	fclose(Wout);
}
