2006-08-23 01:09:24 +00:00
|
|
|
#include "types.h"
|
|
|
|
#include "stat.h"
|
2006-08-08 19:58:06 +00:00
|
|
|
#include "user.h"
|
|
|
|
|
2007-08-24 20:03:40 +00:00
|
|
|
char buf[512];
|
2006-08-08 19:58:06 +00:00
|
|
|
|
2006-08-23 01:09:24 +00:00
|
|
|
void
|
|
|
|
rfile(int fd)
|
2006-08-08 19:58:06 +00:00
|
|
|
{
|
2007-08-24 20:03:40 +00:00
|
|
|
int n;
|
2006-08-08 19:58:06 +00:00
|
|
|
|
2007-08-24 20:03:40 +00:00
|
|
|
while((n = read(fd, buf, sizeof(buf))) > 0)
|
|
|
|
write(1, buf, n);
|
|
|
|
if(n < 0){
|
|
|
|
printf(1, "cat: read error\n");
|
2006-08-08 19:58:06 +00:00
|
|
|
exit();
|
|
|
|
}
|
2006-08-23 01:09:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int fd, i;
|
2006-08-08 19:58:06 +00:00
|
|
|
|
2006-09-06 17:27:19 +00:00
|
|
|
if(argc <= 1) {
|
2006-08-23 01:09:24 +00:00
|
|
|
rfile(0);
|
2007-08-24 20:03:40 +00:00
|
|
|
exit();
|
2006-08-23 01:09:24 +00:00
|
|
|
}
|
2006-08-08 19:58:06 +00:00
|
|
|
|
2007-08-24 20:03:40 +00:00
|
|
|
for(i = 1; i < argc; i++){
|
|
|
|
if((fd = open(argv[i], 0)) < 0){
|
|
|
|
printf(1, "cat: cannot open %s\n", argv[i]);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
rfile(fd);
|
|
|
|
close(fd);
|
|
|
|
}
|
2006-08-08 19:58:06 +00:00
|
|
|
exit();
|
|
|
|
}
|