-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlseek.c
More file actions
42 lines (32 loc) · 757 Bytes
/
Copy pathlseek.c
File metadata and controls
42 lines (32 loc) · 757 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
40
41
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char **argv)
{
int fd;
int ret;
if (argc != 2) {
fprintf(stderr, "<%s> filename\n", argv[0]);
return -1;
}
fd = open(argv[1], O_RDONLY);
if (fd < 0) {
return -1;
}
while (1) {
char bytes[1000];
ret = read(fd, bytes, sizeof(bytes));
if (ret <= 0) {
// reached eof .. set to beginning of the file
lseek(fd, 0, SEEK_SET);
fprintf(stderr, " reached EOF.. setting to the beginning of file\n");
sleep(1);
} else {
write(2, bytes, ret);
}
}
close(fd);
return 0;
}