Seconda parte della risistemazione delle dichiarazioni di inclusione.
[gapil.git] / sources / FortuneClient.c
index caf3002d7ee7c06532418e21a2cc57068395af50..5d8ba0af50d8c340e9d311cdb9cdaac58273d373 100644 (file)
  */
 #include <sys/types.h>   /* primitive system data types */
 #include <unistd.h>      /* unix standard library */
-#include <arpa/inet.h>   /* IP addresses conversion utiliites */
 #include <stdio.h>      /* standard I/O library */
-#include <errno.h>>      /* error definitions and routines */
+#include <stdlib.h>     /* C standard library */
+#include <errno.h>       /* error definitions and routines */
 #include <fcntl.h>       /* file control functions */
+#include <string.h>     /* C strings library */
+#include <limits.h>      /* 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);
 }