Handle not bound allow-remote-paths in file-remote-p
[sxemacs] / lib-src / yow.c
index 8f7df31..934f976 100644 (file)
@@ -1,9 +1,9 @@
 /*
  * yow.c
- * 
+ *
  * Print a quotation from Zippy the Pinhead.
  * Qux <Kaufman-David@Yale> March 6, 1986
- * 
+ *
  * With dynamic memory allocation.
  */
 
@@ -12,6 +12,7 @@
 #define DONT_ENCAPSULATE
 #include <config.h>
 
+#include <assert.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <../src/sxe-paths.h>  /* For PATH_DATA.  */
 #define YOW_FILE "yow.lines"
 #endif
 
-void yow(FILE * fp);
-void setup_yow(FILE * fp);
+static void yow(FILE * fp);
+static void setup_yow(FILE * fp);
 
-int main(int argc, char *argv[])
+#define xstrncpy(d_,s_,l_)                     \
+       do {                                    \
+               char* dst_=d_;                  \
+               dst_[0]='\0';                   \
+               strncat((dst_),(s_),(l_)-1);    \
+       } while(0)
+
+
+int
+main(int argc, char *argv[])
 {
        FILE *fp;
        char file[BUFSIZ];
 
        if (argc > 2 && !strcmp(argv[1], "-f")) {
-               strncpy(file, argv[2], sizeof(file)-1);
-               file[sizeof(file)-1]='\0';
-       } else
+               assert(argv[2] != NULL);
+               xstrncpy(file, argv[2], sizeof(file));
+       } else {
 #ifdef PATH_DATA
 #ifdef vms
                int sz = snprintf(file, sizeof(file), "%s%s", PATH_DATA, YOW_FILE);
 #else
-               int sz = snprintf(file, sizeof(file), "%s/%s", PATH_DATA, YOW_FILE);
+               int sz = snprintf(file, sizeof(file), "%s/%s", PATH_DATA, YOW_FILE);
 #endif
                assert(sz>=0 && sz<sizeof(file));
 #else                          /* !PATH_DATA */
-       {
                fprintf(stderr,
                        "%s: the location of the \"%s\" file was not supplied at compile-time.\n\
 You must supply it with the -f command-line option.\n",
                        argv[0], YOW_FILE);
                exit(1);
-       }
 #endif
+       }
 
        if ((fp = fopen(file, "r")) == NULL) {
                perror(file);
@@ -79,7 +88,8 @@ static long header_len;
 #define AVG_LEN 40             /* average length of a quotation */
 
 /* Sets len and header_len */
-void setup_yow(FILE * fp)
+static void
+setup_yow(FILE * fp)
 {
        int c;
 
@@ -105,7 +115,8 @@ void setup_yow(FILE * fp)
 }
 
 /* go to a random place in the file and print the quotation there */
-void yow(FILE * fp)
+static void
+yow(FILE * fp)
 {
        long offset;
        int c, i = 0;
@@ -158,4 +169,5 @@ void yow(FILE * fp)
        }
        buf[i++] = 0;
        printf("%s\n", buf);
+       free(buf);
 }