summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2010-05-20 20:12:44 -0700
committerH. Peter Anvin <hpa@zytor.com>2010-05-20 20:12:44 -0700
commiteedb9638d8534bbd39bfa657b932554c92ac55d6 (patch)
treed28a7e69d04bf20147c119a8b4cbe56ac7f4fe1c
parentfe4a9d5de55bfc168986ae44bed97b641092e88f (diff)
downloadsyslinux-eedb9638d8534bbd39bfa657b932554c92ac55d6.tar.gz
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@zytor.com>
-rw-r--r--com32/modules/cat.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/com32/modules/cat.c b/com32/modules/cat.c
index 8df47675..0a9514c4 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;
}