/*
* yow.c
- *
+ *
* Print a quotation from Zippy the Pinhead.
* Qux <Kaufman-David@Yale> March 6, 1986
- *
+ *
* With dynamic memory allocation.
*/
#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[])
{
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);
}
buf[i++] = 0;
printf("%s\n", buf);
+ free(buf);
}