#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

main(int argc, char * argv[])
{
   int fd;
   time_t now;
   char * message;
   if(argc!=2)
   {
	printf("errror usage!\nusage: server filename\n");
	exit(1);
   }
   if((fd=open(argv[1],O_CREAT|O_WRONLY|O_TRUNC,0644))==-1)
   {
	perror("open");
	exit(1);
   }
   while(1)
   {
	time(&now);
	message=ctime(&now);
	if((lseek(fd,0,SEEK_SET))==-1)
	{
	   perror("lseek");
	   exit(1);
	}
	if(write(fd,message,strlen(message))==-1)
	{
	   perror("write");
	   exit(1);
	}
	sleep(1);
   }
}
