Updated cwho.c for Chat system
    San Barr hanging out @ The Beach 
    slb at bnl.UUCP
       
    Fri Feb 15 09:15:50 AEST 1985
    
    
  
	I've updated the small cwho utility for the Chat system so
it notifies the user "No users logged into Chat" if no-one is logged in
insted of sitting there, rather dumb, and not printing any messages.
	Please send all updates and improvments to slb at bnl.ARPA
----------------CUT HERE----------------
#include <stdio.h>
#include <sys/types.h>
#include <stat.h>
#include "chat.h"
struct	stat	sbuf;
struct	logs	lbuf;
main()		/* Show who's logged into chat */
{
	int	lfile;
	if (stat(LOGFILE) == EOF) {
		puts("No users logged into Chat.");
		exit(1);
	}
	if (sbuf.st_size == 0) {
		puts("No users logged into Chat.");
		exit(1);
	}
	if ((lfile=open(LOGFILE, 0)) == EOF)
		exit(1);
	puts("Users In Chat        Tty    When");
	while (read(lfile, (char *) &lbuf, sizeof(lbuf))==sizeof(lbuf)) {
		if (lbuf.l_line[0]=='\0' || lbuf.l_name[0]=='\0')
			continue;	/* Skip blankies */
	printf("%-20.20s %-5.5s  %7.7s\n",lbuf.l_name,
					  	   lbuf.l_line,lbuf.l_time);
	}
	if (close(lfile) == EOF) {
		perror(LOGFILE);
		exit(1);
	}
}
-- 
                        Sanford L. Barr
           Famous designer of the Write Only Memory.
                       --             --
		..!decvax!philabs!sbcs!bnl!slb
    
    
More information about the Comp.sources.unix
mailing list