Handle not bound allow-remote-paths in file-remote-p
[sxemacs] / lib-src / yow.c
index a644f07..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.  */
 static void yow(FILE * fp);
 static void setup_yow(FILE * fp);
 
+#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[])
 {
@@ -40,25 +49,24 @@ main(int argc, char *argv[])
        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);
@@ -161,4 +169,5 @@ yow(FILE * fp)
        }
        buf[i++] = 0;
        printf("%s\n", buf);
+       free(buf);
 }