summaryrefslogtreecommitdiff
path: root/cat.c
diff options
context:
space:
mode:
authorkaashoek <kaashoek>2006-08-23 01:09:24 +0000
committerkaashoek <kaashoek>2006-08-23 01:09:24 +0000
commit8b58e81077abf4e843873f16c03077e2fafce52d (patch)
tree9613a801fc9b3421ee79725782e3ef9bb4650574 /cat.c
parentf18ab5c04e5380e0fb27f63e8335e5d621315c1d (diff)
downloadxv6-labs-8b58e81077abf4e843873f16c03077e2fafce52d.tar.gz
xv6-labs-8b58e81077abf4e843873f16c03077e2fafce52d.tar.bz2
xv6-labs-8b58e81077abf4e843873f16c03077e2fafce52d.zip
i/o redirection in sh
better parsing of sh commands (copied from jos sh) cat: read from 1 if no args sbrk system call, but untested getpid system call moved locks in keyboard intr, but why do we get intr w. null characters from keyboard?
Diffstat (limited to 'cat.c')
-rw-r--r--cat.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/cat.c b/cat.c
index 8154ae2..631bd09 100644
--- a/cat.c
+++ b/cat.c
@@ -1,17 +1,32 @@
+#include "types.h"
+#include "stat.h"
#include "user.h"
char buf[513];
-int
-main(int argc, char *argv[])
+void
+rfile(int fd)
{
- int fd, i, cc;
+ int cc;
- if(argc < 2){
- puts("Usage: cat files...\n");
+ while((cc = read(fd, buf, sizeof(buf) - 1)) > 0){
+ buf[cc] = '\0';
+ puts(buf);
+ }
+ if(cc < 0){
+ puts("cat: read error\n");
exit();
}
+}
+
+int
+main(int argc, char *argv[])
+{
+ int fd, i;
+ if (argc <= 1) {
+ rfile(0);
+ } else {
for(i = 1; i < argc; i++){
fd = open(argv[i], 0);
if(fd < 0){
@@ -20,16 +35,10 @@ main(int argc, char *argv[])
puts("\n");
exit();
}
- while((cc = read(fd, buf, sizeof(buf) - 1)) > 0){
- buf[cc] = '\0';
- puts(buf);
- }
- if(cc < 0){
- puts("cat: read error\n");
- exit();
- }
+ rfile(fd);
close(fd);
}
+ }
exit();
}