Merge branch 'master' of ssh://gapil.gnulinux.it/srv/git/gapil
[gapil.git] / sources / FortuneClient.c
index 37aaef4238ee8b21a468542799327c805b11f379..99af385be0e9ae9eb5ef1880b7c6e033d096be17 100644 (file)
  *
  * Usage: fortune -h give all info
  *
- * $Id: FortuneClient.c,v 1.2 2002/08/19 17:34:23 piccardi Exp $
- *
  ****************************************************************/
 /* 
  * Include needed headers
  */
-#include <sys/types.h>   /* predefined types */
-#include <unistd.h>      /* include unix standard library */
-#include <arpa/inet.h>   /* IP addresses conversion utiliites */
-#include <stdio.h>      /* include standard I/O library */
-#include <errno.h>
-#include <fcntl.h>
+#include <sys/types.h>   /* primitive system data types */
+#include <unistd.h>      /* unix standard library */
+#include <stdio.h>      /* standard I/O library */
+#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 <sys/stat.h>
 
 #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);
 }