ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Linux-Inotify2/Inotify2.xs
Revision: 1.2
Committed: Tue Aug 23 02:45:23 2005 UTC (18 years, 9 months ago) by root
Branch: MAIN
CVS Tags: rel-0_8
Changes since 1.1: +1 -0 lines
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_MOVE_SELF" , newSViv (IN_MOVE_SELF));
32 newCONSTSUB (stash, "IN_UNMOUNT" , newSViv (IN_UNMOUNT));
33 newCONSTSUB (stash, "IN_Q_OVERFLOW" , newSViv (IN_Q_OVERFLOW));
34 newCONSTSUB (stash, "IN_IGNORED" , newSViv (IN_IGNORED));
35 newCONSTSUB (stash, "IN_CLOSE" , newSViv (IN_CLOSE));
36 newCONSTSUB (stash, "IN_MOVE" , newSViv (IN_MOVE));
37 newCONSTSUB (stash, "IN_ISDIR" , newSViv (IN_ISDIR));
38 newCONSTSUB (stash, "IN_ONESHOT" , newSViv (IN_ONESHOT));
39 newCONSTSUB (stash, "IN_ALL_EVENTS" , newSViv (IN_ALL_EVENTS));
40 }
41
42 int
43 inotify_init ()
44
45 void
46 inotify_close (int fd)
47 CODE:
48 close (fd);
49
50 int
51 inotify_add_watch (int fd, char *name, U32 mask)
52
53 int
54 inotify_rm_watch (int fd, U32 wd)
55
56 void
57 inotify_read (int fd, int size = 8192)
58 PPCODE:
59 {
60 char buf [size], *cur, *end;
61 int got = read (fd, buf, size);
62
63 if (got < 0)
64 croak ("Linux::Inotify2: read error while reading events");
65
66 cur = buf;
67 end = buf + got;
68
69 while (cur < end)
70 {
71 struct inotify_event *ev = (struct inotify_event *)cur;
72 cur += sizeof (struct inotify_event) + ev->len;
73
74 while (ev->len > 0 && !ev->name [ev->len - 1])
75 --ev->len;
76
77 HV *hv = newHV ();
78 hv_store (hv, "wd", sizeof ("wd") - 1, newSViv (ev->wd), 0);
79 hv_store (hv, "mask", sizeof ("mask") - 1, newSViv (ev->mask), 0);
80 hv_store (hv, "cookie", sizeof ("cookie") - 1, newSViv (ev->cookie), 0);
81 hv_store (hv, "name", sizeof ("name") - 1, newSVpvn (ev->name, ev->len), 0);
82
83 XPUSHs (newRV_noinc ((SV *)hv));
84 }
85 }
86
87