2006-08-23 03:09:24 +02:00
|
|
|
#include "types.h"
|
|
|
|
#include "stat.h"
|
2006-08-08 21:58:06 +02:00
|
|
|
#include "user.h"
|
|
|
|
|
|
|
|
char buf[513];
|
|
|
|
|
2006-08-23 03:09:24 +02:00
|
|
|
void
|
|
|
|
rfile(int fd)
|
2006-08-08 21:58:06 +02:00
|
|
|
{
|
2006-08-23 03:09:24 +02:00
|
|
|
int cc;
|
2006-08-08 21:58:06 +02:00
|
|
|
|
2006-08-23 03:09:24 +02:00
|
|
|
while((cc = read(fd, buf, sizeof(buf) - 1)) > 0){
|
|
|
|
buf[cc] = '\0';
|
|
|
|
puts(buf);
|
|
|
|
}
|
|
|
|
if(cc < 0){
|
|
|
|
puts("cat: read error\n");
|
2006-08-08 21:58:06 +02:00
|
|
|
exit();
|
|
|
|
}
|
2006-08-23 03:09:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int fd, i;
|
2006-08-08 21:58:06 +02:00
|
|
|
|
2006-09-06 19:27:19 +02:00
|
|
|
if(argc <= 1) {
|
2006-08-23 03:09:24 +02:00
|
|
|
rfile(0);
|
|
|
|
} else {
|
2006-09-06 17:32:21 +02:00
|
|
|
for(i = 1; i < argc; i++){
|
|
|
|
fd = open(argv[i], 0);
|
|
|
|
if(fd < 0){
|
2006-09-06 19:04:06 +02:00
|
|
|
puts("cat: cannot open ");
|
|
|
|
puts(argv[i]);
|
|
|
|
puts("\n");
|
|
|
|
exit();
|
2006-09-06 17:32:21 +02:00
|
|
|
}
|
|
|
|
rfile(fd);
|
|
|
|
close(fd);
|
2006-08-08 21:58:06 +02:00
|
|
|
}
|
2006-08-23 03:09:24 +02:00
|
|
|
}
|
2006-08-08 21:58:06 +02:00
|
|
|
|
|
|
|
exit();
|
|
|
|
}
|