Archived
1
0
Fork 0
This repository has been archived on 2026-05-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
archived/src/inotify-watch.c
Henrik Hautakoski f46ae1970b Change indentation to follow the updated standard.
Alot of mixed indentation. use 4 chars wide soft tabs.
2011-03-19 12:28:48 +02:00

75 lines
1.7 KiB
C

#include <stdio.h>
#include <string.h>
#include "xalloc.h"
#include "path.h"
#include "inotify-watch.h"
struct watch* inotify_watch_new(int wd, const char *path) {
struct watch *w = xmallocz(sizeof(struct watch));
w->wd = wd;
w->path = path;
return w;
}
static void watch_free(struct tree *tree, void *data) {
void (*fn)(struct watch *) = data;
if (fn)
fn((struct watch*)tree);
xfree(tree);
}
void inotify_watch_destroy(struct watch *watch, void (*fn)(struct watch *)) {
if (watch) {
struct tree *tree = (struct tree*) watch;
if (!tree_is_root(tree))
tree_detach(tree);
tree_traverse(tree, watch_free, fn);
}
}
struct watch* inotify_watch_add(struct watch *parent, struct watch *watch) {
if (parent->tree.child) {
struct watch *it = (struct watch*)parent->tree.child;
/* move nodes that are children of this watch alongside watch */
while(it) {
if (path_isparent(it->path, watch->path)) {
struct watch *next = (struct watch*)it->tree.next;
tree_move(&watch->tree, &it->tree);
it = next;
} else {
it = (struct watch*)it->tree.next;
}
}
}
return (struct watch*)tree_link(&parent->tree, &watch->tree);
}
void inotify_watch_rm(struct watch *watch) {
tree_unlink(&watch->tree);
}
struct watch* inotify_watch_find_child(struct watch *watch, const char *path) {
if (watch->tree.child) {
struct watch *it = (struct watch *) watch->tree.child;
while(it) {
if (!strcmp(watch->path, it->path))
return it;
it = (struct watch*) it->tree.next;
}
}
return NULL;
}