aboutsummaryrefslogtreecommitdiff
path: root/semestr-5/so/lista0/lista_0/3_cat.c
blob: 45f41065b800a460b8a00899511930912071a7f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "apue.h"
#include <stdio.h>
#include <fcntl.h>

#define BUFFSIZE 4096

int main(int argc, char **argv) {
  int n;
  char buf[BUFFSIZE];

  if (argc != 2) {
    printf("Usage: %s <file to output>", argv[0]);
    exit(1);
  }

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

  while ((n = read(fd, buf, BUFFSIZE)) > 0)
    if (write(STDOUT_FILENO, buf, n) != n)
      err_sys("write error");

  if (n < 0)
    err_sys("read error");

  exit(0);
}