summaryrefslogtreecommitdiff
path: root/sh.c
diff options
context:
space:
mode:
authorkaashoek <kaashoek>2006-09-06 01:25:41 +0000
committerkaashoek <kaashoek>2006-09-06 01:25:41 +0000
commitd49a2d53867b2b3a7d627be217c12b3a95676766 (patch)
tree1fb2120c6edc1c3900962963dd9399a35528153e /sh.c
parent56ac0d72fc2c6c3535e06f26140700b4dc096a00 (diff)
downloadxv6-labs-d49a2d53867b2b3a7d627be217c12b3a95676766.tar.gz
xv6-labs-d49a2d53867b2b3a7d627be217c12b3a95676766.tar.bz2
xv6-labs-d49a2d53867b2b3a7d627be217c12b3a95676766.zip
nits
Diffstat (limited to 'sh.c')
-rw-r--r--sh.c21
1 files changed, 4 insertions, 17 deletions
diff --git a/sh.c b/sh.c
index 5da556e..b2905e7 100644
--- a/sh.c
+++ b/sh.c
@@ -162,37 +162,24 @@ ioredirection(void)
for (i = 0; i < nextnode; i++) {
switch (list[i].token) {
case '<':
+ if (close(0) < 0)
+ printf(2, "close 0 failed\n");
if ((fd = open(list[i].s, O_RDONLY)) < 0) {
printf(2, "failed to open %s for read: %d", list[i].s, fd);
return -1;
}
-
if (debug)
printf(2, "redirect 0 from %s\n", list[i].s);
-
- close(0);
- if ((dfd = dup(fd)) < 0)
- printf(2, "dup failed\n");
- if (debug)
- printf(2, "dup returns %d\n", dfd);
- close(fd);
break;
case '>':
+ if (close(1) < 0)
+ printf(2, "close 1 failed\n");
if ((fd = open(list[i].s, O_WRONLY|O_CREATE)) < 0) {
printf(2, "failed to open %s for write: %d", list[i].s, fd);
exit();
}
-
if (debug)
printf(2, "redirect 1 to %s\n", list[i].s);
-
- if (close(1) < 0)
- printf(2, "close 1 failed\n");
- if ((dfd = dup(fd)) < 0)
- printf(2, "dup failed\n");
- if (debug)
- printf(2, "dup returns %d\n", dfd);
- close(fd);
break;
}
}