[syslinux:master] cat.c32: handle multiple files, use argv[0], copy 4K at a time
syslinux-bot for H. Peter Anvin
hpa at zytor.com
Thu May 20 20:33:11 PDT 2010
Commit-ID: eedb9638d8534bbd39bfa657b932554c92ac55d6
Gitweb: http://syslinux.zytor.com/commit/eedb9638d8534bbd39bfa657b932554c92ac55d6
Author: H. Peter Anvin <hpa at zytor.com>
AuthorDate: Thu, 20 May 2010 20:12:44 -0700
Committer: H. Peter Anvin <hpa at zytor.com>
CommitDate: Thu, 20 May 2010 20:12:44 -0700
cat.c32: handle multiple files, use argv[0], copy 4K at a time
Loop over multiple files, use argv[0] for the program name, and copy
4K at a time.
Signed-off-by: H. Peter Anvin <hpa at zytor.com>
---
com32/modules/cat.c | 25 ++++++++++++++-----------
1 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/com32/modules/cat.c b/com32/modules/cat.c
index 8df4767..0a9514c 100644
--- a/com32/modules/cat.c
+++ b/com32/modules/cat.c
@@ -5,26 +5,29 @@
int main(int argc, char *argv[])
{
FILE *f;
- int ch;
int i;
+ int len;
+ char buf[4096];
openconsole(&dev_stdcon_r, &dev_stdcon_w);
if (argc < 2) {
- fprintf(stderr, "Usage: cat.c32 filename\n");
+ fprintf(stderr, "Usage: %s filename...\n", argv[0]);
return 1;
}
- f = fopen(argv[1], "r");
- if (!f) {
- fprintf(stderr, "File \"%s\" does not exist.\n", argv[1]);
- return 1;
- }
+ for (i = 1; i < argc; i++) {
+ f = fopen(argv[i], "r");
+ if (!f) {
+ fprintf(stderr, "%s: %s: file not found\n", argv[0], argv[i]);
+ return 1;
+ }
- while ((ch = getc(f)) != EOF)
- putchar(ch);
-
- fclose(f);
+ while ((len = fread(buf, 1, sizeof buf, f)) > 0)
+ fwrite(buf, 1, len, stdout);
+
+ fclose(f);
+ }
return 0;
}
More information about the Syslinux-commits
mailing list