| 1 |
#pragma once |
| 2 |
|
| 3 |
/* |
| 4 |
* Directory Watch |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <c-stdaux.h> |
| 8 |
#include <stdlib.h> |
| 9 |
|
| 10 |
typedef struct Dirwatch Dirwatch; |
| 11 |
|
| 12 |
enum { |
| 13 |
_DIRWATCH_E_SUCCESS, |
| 14 |
|
| 15 |
DIRWATCH_E_TRIGGERED, |
| 16 |
}; |
| 17 |
|
| 18 |
struct Dirwatch { |
| 19 |
int inotify_fd; |
| 20 |
}; |
| 21 |
|
| 22 |
#define DIRWATCH_NULL(_x) { \ |
| 23 |
.inotify_fd = -1, \ |
| 24 |
} |
| 25 |
|
| 26 |
/* dirwatch */ |
| 27 |
|
| 28 |
int dirwatch_new(Dirwatch **dwp); |
| 29 |
Dirwatch *dirwatch_free(Dirwatch *dw); |
| 30 |
|
| 31 |
int dirwatch_get_fd(Dirwatch *dw); |
| 32 |
int dirwatch_dispatch(Dirwatch *dw); |
| 33 |
int dirwatch_add(Dirwatch *dw, const char *path); |
| 34 |
|
| 35 |
/* inline helpers */ |
| 36 |
|
| 37 |
static inline void dirwatch_freep(Dirwatch **dw) { |
| 38 |
if (*dw) |
| 39 |
dirwatch_free(*dw); |
| 40 |
} |