summaryrefslogtreecommitdiff
path: root/common/inotify_helpers.h
blob: a0d884aa22a9728bf08bf619d4a721832526004a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* inotify_helper.h - Simple iteration for inotify events
 *
 * Copyright (C) 2014 Luke Shumaker
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _INOTIFY_HELPER_H
#define _INOTIFY_HELPER_H

#include <sys/inotify.h>	/* for 'struct inotify_event' */
#include <sys/types.h>	/* for ssize_t, uint32_t */
#include <limits.h>	/* for NAME_MAX */

char *inotify_mask2str(uint32_t mask);
int inotify_print_event(struct inotify_event *event);

struct inotify_buffer {
	ssize_t len;
	ssize_t pos;
	char dat[sizeof(struct inotify_event)+NAME_MAX+1];
};

struct inotify_event *inotify_next_event_r(int fd, struct inotify_buffer *buf);
struct inotify_event *inotify_next_event(int fd);

#define INOTIFY_ITERATOR(FD, EVENT) \
	struct inotify_event *EVENT = inotify_next_event(FD); \
	EVENT != NULL; \
	EVENT = inotify_next_event(FD)

#define INOTIFY_ITERATOR_R(FD, EVENT, BUF) \
	struct inotify_event *EVENT = inotify_next_event_r(FD, BUF); \
	EVENT != NULL; \
	EVENT = inotify_next_event_r(FD, BUF)

#endif