Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e2694ab

Browse files
committed
Arrange line and tab
Signed-off-by: Seungha Son <seungha.son@samsung.com>
1 parent ddff49d commit e2694ab

File tree

1 file changed

+88
-88
lines changed

1 file changed

+88
-88
lines changed

‎io_multiplexing/poll/poll_inotify.c

Lines changed: 88 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -7,114 +7,114 @@
77
#include <unistd.h>
88

99
static void handle_events(int fd, int *wd, int argc, char* argv[]) {
10-
int i;
11-
ssize_t len;
12-
char *ptr;
13-
char buf[4096] __attribute__ ((aligned(__alignof__(struct inotify_event))));
14-
const struct inotify_event *event;
10+
int i;
11+
ssize_t len;
12+
char *ptr;
13+
char buf[4096] __attribute__ ((aligned(__alignof__(struct inotify_event))));
14+
const struct inotify_event *event;
1515

16-
for (;;) {
17-
len = read(fd, buf, sizeof buf);
18-
if (len == -1 && errno != EAGAIN) {
19-
perror("read");
20-
exit(EXIT_FAILURE);
21-
}
16+
for (;;) {
17+
len = read(fd, buf, sizeof buf);
18+
if (len == -1 && errno != EAGAIN) {
19+
perror("read");
20+
exit(EXIT_FAILURE);
21+
}
2222

23-
if (len <= 0)
24-
break;
23+
if (len <= 0)
24+
break;
2525

26-
for (ptr = buf; ptr < buf + len; ptr += sizeof(struct inotify_event) + event->len) {
27-
event = (const struct inotify_event *) ptr;
26+
for (ptr = buf; ptr < buf + len; ptr += sizeof(struct inotify_event) + event->len) {
27+
event = (const struct inotify_event *) ptr;
2828

2929
for (i = 1; i < argc; ++i) {
30-
if (wd[i] == event->wd) {
31-
printf("%s ", argv[i]);
32-
break;
33-
}
34-
}
35-
36-
if (event->mask & IN_OPEN)
37-
printf("IN_OPEN");
38-
if (event->mask & IN_CLOSE_NOWRITE)
39-
printf("IN_CLOSE_NOWRITE");
40-
if (event->mask & IN_CLOSE_WRITE)
41-
printf("IN_CLOSE_WRITE");
30+
if (wd[i] == event->wd) {
31+
printf("%s ", argv[i]);
32+
break;
33+
}
34+
}
35+
36+
if (event->mask & IN_OPEN)
37+
printf("IN_OPEN");
38+
if (event->mask & IN_CLOSE_NOWRITE)
39+
printf("IN_CLOSE_NOWRITE");
40+
if (event->mask & IN_CLOSE_WRITE)
41+
printf("IN_CLOSE_WRITE");
4242
if (event->mask & IN_MODIFY)
4343
printf("IN_MODIFY");
4444
if (event->mask & IN_CLOSE_WRITE)
4545
printf("IN_CLOSE_WRITE");
4646
if (event->mask & IN_IGNORED)
4747
printf("IN_IGNORED");
4848
printf("\n");
49-
}
50-
}
49+
}
50+
}
5151
}
5252

5353
int main(int argc, char* argv[]) {
54-
char buf[100];
55-
int fd, i, poll_num;
56-
int *wd;
57-
nfds_t nfds;
58-
struct pollfd fds[2];
59-
60-
if (argc < 2) {
61-
printf("Usage: %s PATH [PATH ...]\n", argv[0]);
62-
exit(EXIT_FAILURE);
63-
}
64-
65-
fd = inotify_init1(IN_NONBLOCK);
66-
if (fd == -1) {
67-
perror("inotify_init1");
68-
exit(EXIT_FAILURE);
69-
}
70-
71-
wd = calloc(argc, sizeof(int));
72-
if (wd == NULL) {
73-
perror("calloc");
74-
exit(EXIT_FAILURE);
75-
}
76-
77-
for (i = 1; i < argc; i++) {
78-
wd[i] = inotify_add_watch(fd, argv[i], IN_OPEN | IN_CLOSE | IN_CLOSE_WRITE | IN_MODIFY | IN_IGNORED);
79-
if (wd[i] == -1) {
80-
fprintf(stderr, "Cannot watch '%s'\n", argv[i]);
81-
perror("inotify_add_watch");
82-
exit(EXIT_FAILURE);
83-
}
84-
}
85-
86-
nfds = 2;
87-
88-
fds[0].fd = STDIN_FILENO;
89-
fds[0].events = POLLIN;
90-
91-
fds[1].fd = fd;
92-
fds[1].events = POLLIN;
93-
94-
while (1) {
95-
poll_num = poll(fds, nfds, -1);
96-
if (poll_num == -1) {
97-
if (errno == EINTR)
98-
continue;
99-
perror("poll");
100-
exit(EXIT_FAILURE);
101-
}
102-
103-
if (poll_num > 0) {
104-
if (fds[0].revents & POLLIN) {
54+
char buf[100];
55+
int fd, i, poll_num;
56+
int *wd;
57+
nfds_t nfds;
58+
struct pollfd fds[2];
59+
60+
if (argc < 2) {
61+
printf("Usage: %s PATH [PATH ...]\n", argv[0]);
62+
exit(EXIT_FAILURE);
63+
}
64+
65+
fd = inotify_init1(IN_NONBLOCK);
66+
if (fd == -1) {
67+
perror("inotify_init1");
68+
exit(EXIT_FAILURE);
69+
}
70+
71+
wd = calloc(argc, sizeof(int));
72+
if (wd == NULL) {
73+
perror("calloc");
74+
exit(EXIT_FAILURE);
75+
}
76+
77+
for (i = 1; i < argc; i++) {
78+
wd[i] = inotify_add_watch(fd, argv[i], IN_OPEN | IN_CLOSE | IN_CLOSE_WRITE | IN_MODIFY | IN_IGNORED);
79+
if (wd[i] == -1) {
80+
fprintf(stderr, "Cannot watch '%s'\n", argv[i]);
81+
perror("inotify_add_watch");
82+
exit(EXIT_FAILURE);
83+
}
84+
}
85+
86+
nfds = 2;
87+
88+
fds[0].fd = STDIN_FILENO;
89+
fds[0].events = POLLIN;
90+
91+
fds[1].fd = fd;
92+
fds[1].events = POLLIN;
93+
94+
while (1) {
95+
poll_num = poll(fds, nfds, -1);
96+
if (poll_num == -1) {
97+
if (errno == EINTR)
98+
continue;
99+
perror("poll");
100+
exit(EXIT_FAILURE);
101+
}
102+
103+
if (poll_num > 0) {
104+
if (fds[0].revents & POLLIN) {
105105
if (read(STDIN_FILENO, &buf, 100) > 0) {
106106
printf("%s\n", buf);
107107
memset(buf, 0, 100);
108108
}
109109
}
110-
if (fds[1].revents & POLLIN) {
111-
handle_events(fd, wd, argc, argv);
112-
}
113-
}
114-
}
115-
116-
close(fd);
117-
free(wd);
110+
if (fds[1].revents & POLLIN) {
111+
handle_events(fd, wd, argc, argv);
112+
}
113+
}
114+
}
115+
116+
close(fd);
117+
free(wd);
118118

119119
return 0;
120120
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /