X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2FFortuneClient.c;h=99af385be0e9ae9eb5ef1880b7c6e033d096be17;hp=37aaef4238ee8b21a468542799327c805b11f379;hb=26f7a8bb19c6cb198c213757a97b6ac79e40db4b;hpb=c1b22636d04ef04d31842b40878c83fa63ebe739 diff --git a/sources/FortuneClient.c b/sources/FortuneClient.c index 37aaef4..99af385 100644 --- a/sources/FortuneClient.c +++ b/sources/FortuneClient.c @@ -26,18 +26,19 @@ * * Usage: fortune -h give all info * - * $Id: FortuneClient.c,v 1.2 2002/08/19 17:34:23 piccardi Exp $ - * ****************************************************************/ /* * Include needed headers */ -#include /* predefined types */ -#include /* include unix standard library */ -#include /* IP addresses conversion utiliites */ -#include /* include standard I/O library */ -#include -#include +#include /* primitive system data types */ +#include /* unix standard library */ +#include /* standard I/O library */ +#include /* C standard library */ +#include /* error definitions and routines */ +#include /* file control functions */ +#include /* C strings library */ +#include /* system limits constants, types and functions */ +#include #include "macros.h" @@ -87,39 +88,38 @@ int main(int argc, char *argv[]) * Main code beginning * * ***********************************************************/ - snprintf(fifoname, 80, "/tmp/fortune.%d", getpid()); /* compose name */ - if (mkfifo(fifoname, 0622)) { /* open client fifo */ + 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); /* open server fifo */ + 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); /* write name */ - close(fifo_server); /* close server fifo */ - fifo_client = open(fifoname, O_RDONLY); /* open client fifo */ + 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)); /* read answer */ - printf("%s", buffer); /* print fortune */ - close(fifo_client); /* close client */ + 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 */ void usage(void) { - printf("Elementary fortune server\n"); + printf("Elementary fortune client\n"); printf("Usage:\n"); - printf(" fortune [-h] [-f] \n"); + printf(" fortune [-h] \n"); printf(" -h print this help\n"); - printf(" -f filename set file for fortunes\n"); exit(1); }