root/cat.c

/* [<][>][^][v][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)
   9 {
  10   int n;
  11 
  12   while((n = read(fd, buf, sizeof(buf))) > 0)
  13     write(1, buf, n);
  14   if(n < 0){
  15     printf(1, "cat: read error\n");
  16     exit();
  17   }
  18 }
  19 
  20 int
  21 main(int argc, char *argv[])
  22 {
  23   int fd, i;
  24 
  25   if(argc <= 1){
  26     cat(0);
  27     exit();
  28   }
  29 
  30   for(i = 1; i < argc; i++){
  31     if((fd = open(argv[i], 0)) < 0){
  32       printf(1, "cat: cannot open %s\n", argv[i]);
  33       exit();
  34     }
  35     cat(fd);
  36     close(fd);
  37   }
  38   exit();
  39 }

/* [<][>][^][v][top][bottom][index][help] */