[ create a new paste ] login | about

Link: http://codepad.org/rik8bxkY    [ raw code | fork ]

C, pasted on May 16:
#include <stdio.h> 
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
  int fd;
  char buf[256];
  int len;

  if (argc != 2) {
    printf("usage:./mycat [filename]\n");
    return (1);
  }

  fd = open(argv[1], O_RDONLY);

  if (fd == -1) {
    perror("open");
    return (1);
 }

  while (1) {
    len = read(fd,buf,sizeof(buf));

    if (len > 0){
      write (1, buf, len);
    } else if (len == 0){
      break;
    } else { 
    perror("read");
    return (1);
    }
  }
  close(fd);
  return (0);
}


Create a new paste based on this one


Comments: