aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGert Hulselmans <gerth@zytor.com>2010-05-03 17:07:43 -0700
committerH. Peter Anvin <hpa@zytor.com>2010-05-11 16:06:56 -0700
commit4d6d5f91c3e6c69dc22cd51225f1a3e87fa19468 (patch)
treec49d51adbf60016b3b0343cba7a0f259e3519ec4
parent3e635bedf730d0cd1d29d332fe608842c244a152 (diff)
downloadcontrib-4d6d5f91c3e6c69dc22cd51225f1a3e87fa19468.tar.gz
contrib-4d6d5f91c3e6c69dc22cd51225f1a3e87fa19468.tar.xz
contrib-4d6d5f91c3e6c69dc22cd51225f1a3e87fa19468.zip
cat.c32: check if filename exists
Don't crash if the file doesn't exist. Signed-off-by: Gert Hulselmans <gerth@zytor.com> Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--com32/samples/cat.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/com32/samples/cat.c b/com32/samples/cat.c
index 16380b0e..3930f744 100644
--- a/com32/samples/cat.c
+++ b/com32/samples/cat.c
@@ -15,13 +15,18 @@ int main(int argc, char *argv[])
printf("argv[%d] = %p = \"%s\"\n", i, argv[i], argv[i]);
if (argc < 2) {
- fprintf(stderr, "Missing file name!\n");
- exit(1);
+ fprintf(stderr, "Usage: cat.c32 filename\n");
+ return 1;
}
printf("File = %s\n", argv[1]);
f = fopen(argv[1], "r");
+ if (!f) {
+ fprintf(stderr, "File name \"%s\" does not exist.\n", argv[1]);
+ return 1;
+ }
+
while ((ch = getc(f)) != EOF)
putchar(ch);