/* yet another test program. */
  #include <string.h>
       #include <stdlib.h>
       #include <pwd.h>
       #include <unistd.h>
       #include <utmp.h>
 
       int main(int argc, char *argv[])
       {
         struct utmp entry;

	 FILE *wtmpf = fopen ("/home/jeremy/code/jdmchat/this.wtmp", "a");
 
         system("echo before adding entry:;last -f ./this.wtmp");
 
         entry.ut_type=USER_PROCESS;
         entry.ut_pid=getpid();
         strcpy(entry.ut_line, "jmchat");
         /* only correct for ptys named /dev/tty[pqr][0-9a-z] */
         strcpy(entry.ut_id,ttyname(0)+strlen("/dev/tty"));
         time(&entry.ut_time);
         strcpy(entry.ut_user,getpwuid(getuid())->pw_name);
         memset(entry.ut_host,0,UT_HOSTSIZE);
         entry.ut_addr=0;

	 fwrite ( &entry, sizeof(entry), 1, wtmpf );
	 fclose (wtmpf);
         system("echo after adding entry:;last -f ./this.wtmp");
 
	 wtmpf = fopen ("/home/jeremy/code/jdmchat/this.wtmp", "a");
         entry.ut_type=USER_PROCESS;
	 entry.ut_time++;
         memset(entry.ut_user,0,UT_NAMESIZE);
	 fwrite (&entry, sizeof(entry), 1, wtmpf );
	 fclose (wtmpf);
         system("echo after adding logout entry:;last -f ./this.wtmp");
 
         return 0;
       }
