[syslinux:master] cat.c32: check if filename exists
syslinux-bot for Gert Hulselmans
gerth at zytor.com
Tue May 11 16:09:28 PDT 2010
Commit-ID: 4d6d5f91c3e6c69dc22cd51225f1a3e87fa19468
Gitweb: http://syslinux.zytor.com/commit/4d6d5f91c3e6c69dc22cd51225f1a3e87fa19468
Author: Gert Hulselmans <gerth at zytor.com>
AuthorDate: Mon, 3 May 2010 17:07:43 -0700
Committer: H. Peter Anvin <hpa at zytor.com>
CommitDate: Tue, 11 May 2010 16:06:56 -0700
cat.c32: check if filename exists
Don't crash if the file doesn't exist.
Signed-off-by: Gert Hulselmans <gerth at zytor.com>
Signed-off-by: H. Peter Anvin <hpa at zytor.com>
---
com32/samples/cat.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/com32/samples/cat.c b/com32/samples/cat.c
index 16380b0..3930f74 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);
More information about the Syslinux-commits
mailing list