Archived
1
0
Fork 0

inotify-watch: Adding inotify watch datastructure.

This commit is contained in:
Henrik Hautakoski 2011-02-15 16:33:51 +01:00
parent 9e9321dc65
commit 3b68160892
4 changed files with 146 additions and 0 deletions

View file

@ -20,6 +20,7 @@ path : unit.c $(ROOT)src/path.o $(addprefix $(ROOT),$(obj-strbuf))
fscrawl : $(ROOT)src/fscrawl.o $(addprefix $(ROOT),$(obj-fscrawl))
notify : $(addprefix $(ROOT),$(obj-notify))
inotify-map : $(addprefix $(ROOT),$(obj-inotify-map))
inotify-watch : $(addprefix $(ROOT), $(obj-xalloc)) $(addprefix $(ROOT), $(obj-path)) $(ROOT)src/tree.o ../src/inotify-watch.o
log : $(addprefix $(ROOT),$(obj-log))
tree : $(addprefix $(ROOT),$(obj-xalloc)) $(ROOT)src/tree.o
str-list : unit.c $(addprefix $(ROOT),$(obj-str-list))

49
test/t_inotify-watch.c Normal file
View file

@ -0,0 +1,49 @@
#include <assert.h>
#include <stdio.h>
#include "../src/inotify-watch.h"
void print_node(struct tree *n, void *data) {
size_t c = tree_parent_count(n);
while(c--)
printf("");
if (n->next == NULL && n->parent)
printf("└──");
else
printf("│──");
printf(" %s\n", ((struct watch *)n)->path);
}
int main() {
struct watch *root = inotify_watch_new(0, "/");
struct watch *ch1 = inotify_watch_new(1, "/var/");
struct watch *ch2 = inotify_watch_new(2, "/mnt/");
inotify_watch_add(root, ch1);
inotify_watch_add(root, ch2);
inotify_watch_add(ch1, inotify_watch_new(11, "/var/a/"));
inotify_watch_add(ch1, inotify_watch_new(12, "/var/b/"));
inotify_watch_add(ch2, inotify_watch_new(21, "/mnt/c/"));
inotify_watch_add((struct watch*)ch2->tree.child, inotify_watch_new(234, "/mnt/c/a/"));
tree_traverse((struct tree*)root, print_node, NULL);
inotify_watch_rm(ch1);
printf("---\n");
tree_traverse((struct tree*)root, print_node, NULL);
inotify_watch_add(root, ch1);
printf("---\n");
tree_traverse((struct tree*)root, print_node, NULL);
inotify_watch_destroy(root, NULL);
return 0;
}