ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Linux-Inotify2/Inotify2.xs
Revision: 1.4
Committed: Fri Sep 29 14:41:33 2006 UTC (17 years, 8 months ago) by root
Branch: MAIN
CVS Tags: rel-1_1
Changes since 1.3: +3 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.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 root 1.3 #include <fcntl.h>
9 root 1.1
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 root 1.2 newCONSTSUB (stash, "IN_MOVE_SELF" , newSViv (IN_MOVE_SELF));
33 root 1.1 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 root 1.4 newCONSTSUB (stash, "IN_ONLYDIR" , newSViv (IN_ONLYDIR));
39     newCONSTSUB (stash, "IN_DONT_FOLLOW" , newSViv (IN_DONT_FOLLOW));
40     newCONSTSUB (stash, "IN_MASK_ADD" , newSViv (IN_MASK_ADD));
41 root 1.1 newCONSTSUB (stash, "IN_ISDIR" , newSViv (IN_ISDIR));
42     newCONSTSUB (stash, "IN_ONESHOT" , newSViv (IN_ONESHOT));
43     newCONSTSUB (stash, "IN_ALL_EVENTS" , newSViv (IN_ALL_EVENTS));
44     }
45    
46     int
47     inotify_init ()
48    
49     void
50     inotify_close (int fd)
51     CODE:
52     close (fd);
53    
54     int
55     inotify_add_watch (int fd, char *name, U32 mask)
56    
57     int
58     inotify_rm_watch (int fd, U32 wd)
59    
60 root 1.3 int
61     inotify_blocking (int fd, I32 blocking)
62     CODE:
63     fcntl (fd, F_SETFL, blocking ? 0 : O_NONBLOCK);
64    
65 root 1.1 void
66     inotify_read (int fd, int size = 8192)
67     PPCODE:
68     {
69     char buf [size], *cur, *end;
70     int got = read (fd, buf, size);
71    
72     if (got < 0)
73 root 1.3 if (errno != EAGAIN && errno != EINTR)
74     croak ("Linux::Inotify2: read error while reading events");
75     else
76     XSRETURN_EMPTY;
77 root 1.1
78     cur = buf;
79     end = buf + got;
80    
81     while (cur < end)
82     {
83     struct inotify_event *ev = (struct inotify_event *)cur;
84     cur += sizeof (struct inotify_event) + ev->len;
85    
86     while (ev->len > 0 && !ev->name [ev->len - 1])
87     --ev->len;
88    
89     HV *hv = newHV ();
90     hv_store (hv, "wd", sizeof ("wd") - 1, newSViv (ev->wd), 0);
91     hv_store (hv, "mask", sizeof ("mask") - 1, newSViv (ev->mask), 0);
92     hv_store (hv, "cookie", sizeof ("cookie") - 1, newSViv (ev->cookie), 0);
93     hv_store (hv, "name", sizeof ("name") - 1, newSVpvn (ev->name, ev->len), 0);
94    
95 root 1.3 XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv)));
96 root 1.1 }
97     }
98    
99