summaryrefslogtreecommitdiff
path: root/examples/c/csv/code.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/c/csv/code.c')
-rw-r--r--examples/c/csv/code.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/examples/c/csv/code.c b/examples/c/csv/code.c
index 24aaac81..85c6c792 100644
--- a/examples/c/csv/code.c
+++ b/examples/c/csv/code.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2005, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
@@ -26,7 +26,8 @@ int usage(void);
* Globals
*/
FILE *cfp; /* C source file */
-FILE *hfp; /* C source file */
+FILE *ffp; /* CSV file */
+FILE *hfp; /* C header file */
char *progname; /* Program name */
int verbose; /* Verbose flag */
@@ -45,6 +46,8 @@ main(int argc, char *argv[])
else
++progname;
+ ffp = NULL;
+
/* Initialize arguments. */
cfile = "csv_local.c"; /* Default header/source files */
hfile = "csv_local.h";
@@ -55,8 +58,8 @@ main(int argc, char *argv[])
case 'c':
cfile = optarg;
break;
- case 'f':
- if (freopen(optarg, "r", stdin) == NULL) {
+ case 'f': /* Required argument */
+ if ((ffp = freopen(optarg, "r", stdin)) == NULL) {
fprintf(stderr,
"%s: %s\n", optarg, strerror(errno));
return (EXIT_FAILURE);
@@ -75,7 +78,7 @@ main(int argc, char *argv[])
argc -= optind;
argv += optind;
- if (*argv != NULL)
+ if (*argv != NULL || ffp == NULL)
return (usage());
/* Load records from the input file. */