ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Linux-Inotify2/Inotify2.xs
Revision: 1.1
Committed: Mon Aug 22 09:51:38 2005 UTC (18 years, 9 months ago) by root
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# Content
1 #define PERL_NO_GET_CONTEXT
2
3 #include "EXTERN.h"
4 #include "perl.h"
5 #include "XSUB.h"
6
7 #include <unistd.h>
8
9 #include "inotify.h"
10 #include "inotify-syscalls.h"
11
12 MODULE = Linux::Inotify2 PACKAGE = Linux::Inotify2
13
14 PROTOTYPES: ENABLE
15
16 BOOT:
17 {
18 HV *stash = gv_stashpv ("Linux::Inotify2", 0);
19
20 newCONSTSUB (stash, "IN_ACCESS" , newSViv (IN_ACCESS));
21 newCONSTSUB (stash, "IN_MODIFY" , newSViv (IN_MODIFY));
22 newCONSTSUB (stash, "IN_ATTRIB" , newSViv (IN_ATTRIB));
23 newCONSTSUB (stash, "IN_CLOSE_WRITE" , newSViv (IN_CLOSE_WRITE ));
24 newCONSTSUB (stash, "IN_CLOSE_NOWRITE", newSViv (IN_CLOSE_NOWRITE));
25 newCONSTSUB (stash, "IN_OPEN" , newSViv (IN_OPEN));
26 newCONSTSUB (stash, "IN_MOVED_FROM" , newSViv (IN_MOVED_FROM));
27 newCONSTSUB (stash, "IN_MOVED_TO" , newSViv (IN_MOVED_TO));
28 newCONSTSUB (stash, "IN_CREATE" , newSViv (IN_CREATE));
29 newCONSTSUB (stash, "IN_DELETE" , newSViv (IN_DELETE));
30 newCONSTSUB (stash, "IN_DELETE_SELF" , newSViv (IN_DELETE_SELF));
31 newCONSTSUB (stash, "IN_UNMOUNT" , newSViv (IN_UNMOUNT));
32 newCONSTSUB (stash, "IN_Q_OVERFLOW" , newSViv (IN_Q_OVERFLOW));
33 newCONSTSUB (stash, "IN_IGNORED" , newSViv (IN_IGNORED));
34 newCONSTSUB (stash, "IN_CLOSE" , newSViv (IN_CLOSE));
35 newCONSTSUB (stash, "IN_MOVE" , newSViv (IN_MOVE));
36 newCONSTSUB (stash, "IN_ISDIR" , newSViv (IN_ISDIR));
37 newCONSTSUB (stash, "IN_ONESHOT" , newSViv (IN_ONESHOT));
38 newCONSTSUB (stash, "IN_ALL_EVENTS" , newSViv (IN_ALL_EVENTS));
39 }
40
41 int
42 inotify_init ()
43
44 void
45 inotify_close (int fd)
46 CODE:
47 close (fd);
48
49 int
50 inotify_add_watch (int fd, char *name, U32 mask)
51
52 int
53 inotify_rm_watch (int fd, U32 wd)
54
55 void
56 inotify_read (int fd, int size = 8192)
57 PPCODE:
58 {
59 char buf [size], *cur, *end;
60 int got = read (fd, buf, size);
61
62 if (got < 0)
63 croak ("Linux::Inotify2: read error while reading events");
64
65 cur = buf;
66 end = buf + got;
67
68 while (cur < end)
69 {
70 struct inotify_event *ev = (struct inotify_event *)cur;
71 cur += sizeof (struct inotify_event) + ev->len;
72
73 while (ev->len > 0 && !ev->name [ev->len - 1])
74 --ev->len;
75
76 HV *hv = newHV ();
77 hv_store (hv, "wd", sizeof ("wd") - 1, newSViv (ev->wd), 0);
78 hv_store (hv, "mask", sizeof ("mask") - 1, newSViv (ev->mask), 0);
79 hv_store (hv, "cookie", sizeof ("cookie") - 1, newSViv (ev->cookie), 0);
80 hv_store (hv, "name", sizeof ("name") - 1, newSVpvn (ev->name, ev->len), 0);
81
82 XPUSHs (newRV_noinc ((SV *)hv));
83 }
84 }
85
86