aboutsummaryrefslogtreecommitdiff
path: root/semestr-5/so/lista0/lista_0/3_cat.c
diff options
context:
space:
mode:
Diffstat (limited to 'semestr-5/so/lista0/lista_0/3_cat.c')
-rw-r--r--semestr-5/so/lista0/lista_0/3_cat.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/semestr-5/so/lista0/lista_0/3_cat.c b/semestr-5/so/lista0/lista_0/3_cat.c
new file mode 100644
index 0000000..45f4106
--- /dev/null
+++ b/semestr-5/so/lista0/lista_0/3_cat.c
@@ -0,0 +1,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);
+}