-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiles.c
More file actions
39 lines (31 loc) · 771 Bytes
/
files.c
File metadata and controls
39 lines (31 loc) · 771 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
int main() {
char buff[10];
int fd = open("files.c", O_RDONLY);
if (fd == -1) {
printf("error\n");
}
int result;
while ((result = read(fd, buff, 10)) > 0) {
int written = 0;
while (written < result) {
int w_result = write(STDOUT_FILENO, buff + written,
result - written);
if (w_result == -1) {
printf("error\n");
return -1;
}
written += w_result;
}
}
if (result == -1) {
printf("error\n");
}
if (close(fd) == -1) {
printf("error\n");
}
}