liblinux++

Log | Files | Refs

cat.c (412B)


      1 #include "linux.h"
      2 
      3 static void cat(int fd)
      4 {
      5 	static char buf[0x1000];
      6 
      7 	for (;;)
      8 	{
      9 		int n = read(fd, buf, sizeof(buf));
     10 		if (get_errno(n))
     11 			exit(2);
     12 		if (n == 0)
     13 			return;
     14 		if (write(1, buf, n) != n)
     15 			exit(3);
     16 	}
     17 }
     18 
     19 int main(int argc, char* argv[])
     20 {
     21 	for (int i = 1; i < argc; ++i)
     22 	{
     23 		int fd = openat(AT_FDCWD, argv[i], 0, O_RDONLY);
     24 		if (get_errno(fd))
     25 			return 1;
     26 		cat(fd);
     27 		close(fd);
     28 	}
     29 }