aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/core/cat.c
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2021-12-05 15:17:44 -0800
committerNicholas Noll <nbnoll@eml.cc>2021-12-05 15:17:44 -0800
commitb48327d357e0818d1a6ae2a064cfa7d1567e1242 (patch)
tree4677f228a9846937a7ec71c72a1ab63ab69d68ab /src/cmd/core/cat.c
parentc200dd832789afa298ba45e0b9efdec96c0e92cc (diff)
feat(huge): huge refactor (in progress).
Commented out libc includes to uncover all explicit dependencies. A large fraction has now been ported over (no testing). I did not port over the command line tools, such as the rc shell. These will be done independently - as of now I just want the library to stand independent. Compilation currently fails due to the lack of math functions.
Diffstat (limited to 'src/cmd/core/cat.c')
-rw-r--r--src/cmd/core/cat.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/cmd/core/cat.c b/src/cmd/core/cat.c
index e9b770b..aeed1be 100644
--- a/src/cmd/core/cat.c
+++ b/src/cmd/core/cat.c
@@ -11,15 +11,15 @@ usage(void)
static void
cat(int fd, char *s)
{
- long n;
+ intptr nr, nw;
char buf[8192];
- while((n=read(fd, buf, sizeof(buf)))>0){
- if(write(1, buf, n) != n)
+ while(!(sys·read(fd, buf, sizeof(buf), &nr))){
+ if(sys·write(1, buf, nr, &nw) || nr != nw)
fmt·panic("write error copying %s: %r", s);
}
- if(n<0)
+ if(nr<0)
fmt·panic("error reading %s: %r", s);
}
@@ -40,12 +40,14 @@ main(int argc, char *argv[])
}
while(argc-- > 0){
- if((fd = open(*argv, O_RDONLY))<0)
+ if(sys·open(*argv, sys·ORead, 0, &fd))
fmt·panic("can't open %s: %r", *argv);
cat(fd, *argv);
- close(fd);
+ sys·close(fd);
argv++;
}
+
+ return 0;
}