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 f76f15c

Browse files
committed
Add inotify skeleton code
1 parent 9f39957 commit f76f15c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

‎inotify/inotify_exam.c‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
11
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include <errno.h>
25
#include <sys/inotify.h>
36

7+
#define INOTIFY_PATH "/tmp/"
8+
49
int main(int argc, char *argv[])
510
{
11+
int ret;
612
int fd;
13+
int wd;
714

815
fd = inotify_init();
16+
if (fd < 0) {
17+
perror("inotify_init");
18+
exit(EXIT_FAILURE);
19+
}
20+
21+
wd = inotify_add_watch(fd, INOTIFY_PATH, IN_MODIFY | IN_CREATE | IN_DELETE);
22+
if (wd < 0) {
23+
fprintf(stderr, "Failed to add watch [%s] [%s]", INOTIFY_PATH, strerror(errno));
24+
perror("inotify_add_watch");
25+
exit(EXIT_FAILURE);
26+
}
27+
28+
ret = inotify_rm_watch(fd, wd);
29+
if (ret < 0) {
30+
fprintf(stderr, "Failed to rm watch [fd : %d] [wd : %d] [%s]", fd, wd, strerror(errno));
31+
perror("inotify_rm_watch");
32+
exit(EXIT_FAILURE);
33+
}
934

1035
return 0;
1136
}

0 commit comments

Comments
(0)

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