X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2FFortuneClient.c;h=5d8ba0af50d8c340e9d311cdb9cdaac58273d373;hp=caf3002d7ee7c06532418e21a2cc57068395af50;hb=d451ac30382ae398b9a2242a4f82b3438affc8a7;hpb=31f55ec58bee8b2c4993633849b7da4e30cab222 diff --git a/sources/FortuneClient.c b/sources/FortuneClient.c index caf3002..5d8ba0a 100644 --- a/sources/FortuneClient.c +++ b/sources/FortuneClient.c @@ -32,10 +32,12 @@ */ #include /* primitive system data types */ #include /* unix standard library */ -#include /* IP addresses conversion utiliites */ #include /* standard I/O library */ -#include > /* error definitions and routines */ +#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 "macros.h" @@ -85,39 +87,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); }