root/cat.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. cat
  2. main

   1 #include "types.h"
   2 #include "stat.h"
   3 #include "user.h"
   4 
   5 char buf[512];
   6 
   7 void
   8 cat(int fd)
     /* [previous][next][first][last][top][bottom][index][help]  */
   9 {
  10   int n;
  11 
  12   while((n = read(fd, buf, sizeof(buf))) > 0) {
  13     if (write(1, buf, n) != n) {
  14       printf(1, "cat: write error\n");
  15       exit();
  16     }
  17   }
  18   if(n < 0){
  19     printf(1, "cat: read error\n");
  20     exit();
  21   }
  22 }
  23 
  24 int
  25 main(int argc, char *argv[])
     /* [previous][next][first][last][top][bottom][index][help]  */
  26 {
  27   int fd, i;
  28 
  29   if(argc <= 1){
  30     cat(0);
  31     exit();
  32   }
  33 
  34   for(i = 1; i < argc; i++){
  35     if((fd = open(argv[i], 0)) < 0){
  36       printf(1, "cat: cannot open %s\n", argv[i]);
  37       exit();
  38     }
  39     cat(fd);
  40     close(fd);
  41   }
  42   exit();
  43 }

/* [previous][next][first][last][top][bottom][index][help]  */