ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Linux-Inotify2/Inotify2.xs
Revision: 1.3
Committed: Mon Dec 19 16:50:27 2005 UTC (18 years, 5 months ago) by root
Branch: MAIN
CVS Tags: rel-1_0, rel-1_01
Changes since 1.2: +11 -2 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 #include <fcntl.h>
9
10 #include "inotify.h"
11 #include "inotify-syscalls.h"
12
13 MODULE = Linux::Inotify2 PACKAGE = Linux::Inotify2
14
15 PROTOTYPES: ENABLE
16
17 BOOT:
18 {
19 HV *stash = gv_stashpv ("Linux::Inotify2", 0);
20
21 newCONSTSUB (stash, "IN_ACCESS" , newSViv (IN_ACCESS));
22 newCONSTSUB (stash, "IN_MODIFY" , newSViv (IN_MODIFY));
23 newCONSTSUB (stash, "IN_ATTRIB" , newSViv (IN_ATTRIB));
24 newCONSTSUB (stash, "IN_CLOSE_WRITE" , newSViv (IN_CLOSE_WRITE ));
25 newCONSTSUB (stash, "IN_CLOSE_NOWRITE", newSViv (IN_CLOSE_NOWRITE));
26 newCONSTSUB (stash, "IN_OPEN" , newSViv (IN_OPEN));
27 newCONSTSUB (stash, "IN_MOVED_FROM" , newSViv (IN_MOVED_FROM));
28 newCONSTSUB (stash, "IN_MOVED_TO" , newSViv (IN_MOVED_TO));
29 newCONSTSUB (stash, "IN_CREATE" , newSViv (IN_CREATE));
30 newCONSTSUB (stash, "IN_DELETE" , newSViv (IN_DELETE));
31 newCONSTSUB (stash, "IN_DELETE_SELF" , newSViv (IN_DELETE_SELF));
32 newCONSTSUB (stash, "IN_MOVE_SELF" , newSViv (IN_MOVE_SELF));
33 newCONSTSUB (stash, "IN_UNMOUNT" , newSViv (IN_UNMOUNT));
34 newCONSTSUB (stash, "IN_Q_OVERFLOW" , newSViv (IN_Q_OVERFLOW));
35 newCONSTSUB (stash, "IN_IGNORED" , newSViv (IN_IGNORED));
36 newCONSTSUB (stash, "IN_CLOSE" , newSViv (IN_CLOSE));
37 newCONSTSUB (stash, "IN_MOVE" , newSViv (IN_MOVE));
38 newCONSTSUB (stash, "IN_ISDIR" , newSViv (IN_ISDIR));
39 newCONSTSUB (stash, "IN_ONESHOT" , newSViv (IN_ONESHOT));
40 newCONSTSUB (stash, "IN_ALL_EVENTS" , newSViv (IN_ALL_EVENTS));
41 }
42
43 int
44 inotify_init ()
45
46 void
47 inotify_close (int fd)
48 CODE:
49 close (fd);
50
51 int
52 inotify_add_watch (int fd, char *name, U32 mask)
53
54 int
55 inotify_rm_watch (int fd, U32 wd)
56
57 int
58 inotify_blocking (int fd, I32 blocking)
59 CODE:
60 fcntl (fd, F_SETFL, blocking ? 0 : O_NONBLOCK);
61
62 void
63 inotify_read (int fd, int size = 8192)
64 PPCODE:
65 {
66 char buf [size], *cur, *end;
67 int got = read (fd, buf, size);
68
69 if (got < 0)
70 if (errno != EAGAIN && errno != EINTR)
71 croak ("Linux::Inotify2: read error while reading events");
72 else
73 XSRETURN_EMPTY;
74
75 cur = buf;
76 end = buf + got;
77
78 while (cur < end)
79 {
80 struct inotify_event *ev = (struct inotify_event *)cur;
81 cur += sizeof (struct inotify_event) + ev->len;
82
83 while (ev->len > 0 && !ev->name [ev->len - 1])
84 --ev->len;
85
86 HV *hv = newHV ();
87 hv_store (hv, "wd", sizeof ("wd") - 1, newSViv (ev->wd), 0);
88 hv_store (hv, "mask", sizeof ("mask") - 1, newSViv (ev->mask), 0);
89 hv_store (hv, "cookie", sizeof ("cookie") - 1, newSViv (ev->cookie), 0);
90 hv_store (hv, "name", sizeof ("name") - 1, newSVpvn (ev->name, ev->len), 0);
91
92 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
93 }
94 }
95
96