X-Git-Url: https://gapil.gnulinux.it/gitweb/?a=blobdiff_plain;f=sources%2FFortuneClient.c;h=caf3002d7ee7c06532418e21a2cc57068395af50;hb=31f55ec58bee8b2c4993633849b7da4e30cab222;hp=9d5c54624aa6f223c442eaa0b80a75f32b738654;hpb=198add70c8604fe7ffb05689aa693d782102917e;p=gapil.git diff --git a/sources/FortuneClient.c b/sources/FortuneClient.c index 9d5c546..caf3002 100644 --- a/sources/FortuneClient.c +++ b/sources/FortuneClient.c @@ -26,18 +26,16 @@ * * Usage: fortune -h give all info * - * $Id: FortuneClient.c,v 1.1 2002/08/18 10:34:09 piccardi Exp $ - * ****************************************************************/ /* * Include needed headers */ -#include /* predefined types */ -#include /* include unix standard library */ +#include /* primitive system data types */ +#include /* unix standard library */ #include /* IP addresses conversion utiliites */ -#include /* include standard I/O library */ -#include -#include +#include /* standard I/O library */ +#include > /* error definitions and routines */ +#include /* file control functions */ #include "macros.h" @@ -87,31 +85,30 @@ int main(int argc, char *argv[]) * Main code beginning * * ***********************************************************/ - snprintf(fifoname, 80, "/tmp/fortune.%d", getpid()); - if (mkfifo(fifoname, 0622)) { + snprintf(fifoname, 80, "/tmp/fortune.%d", getpid()); /* compose name */ + if (mkfifo(fifoname, 0622)) { /* open client fifo */ if (errno!=EEXIST) { perror("Cannot create well known fifo"); exit(-1); } } - fifo_server = open(fortunefilename, O_WRONLY); + fifo_server = open(fortunefilename, O_WRONLY); /* open server fifo */ if (fifo_server < 0) { perror("Cannot open well known fifo"); exit(-1); } debug("%s\n", fifoname); - nread = write(fifo_server, fifoname, strlen(fifoname)+1); - close(fifo_server); - fifo_client = open(fifoname, O_RDONLY); + nread = write(fifo_server, fifoname, strlen(fifoname)+1); /* write name */ + close(fifo_server); /* close server fifo */ + fifo_client = open(fifoname, O_RDONLY); /* open client fifo */ if (fifo_client < 0) { perror("Cannot open well known fifo"); exit(-1); } - nread = read(fifo_client, buffer, sizeof(buffer)); - printf("%s", buffer); - close(fifo_client); - close(fifo_server); - unlink(fifoname); + nread = read(fifo_client, buffer, sizeof(buffer)); /* read answer */ + printf("%s", buffer); /* print fortune */ + close(fifo_client); /* close client */ + unlink(fifoname); /* remove client fifo */ } /* * routine to print usage info and exit