summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2015-09-03 13:49:22 -0600
committerLuke Shumaker <lukeshu@sbcglobal.net>2015-09-03 13:49:22 -0600
commitb67e5f77e7d1ea35fa2d69242ddb6ece0c390f35 (patch)
tree6f408ac16b4864a7cd90c2b370eafba59f6b4fa8
parent1ebfc2d1ded91c4390378a1952534c4d8b35390b (diff)
Fix issues in inotify bindings
-rw-r--r--inotify/inotify.go27
1 files changed, 15 insertions, 12 deletions
diff --git a/inotify/inotify.go b/inotify/inotify.go
index 976bdae..8c99a28 100644
--- a/inotify/inotify.go
+++ b/inotify/inotify.go
@@ -29,7 +29,7 @@ func InotifyInit() (*Inotify, error) {
fd: Cint(fd),
isClosed: false,
}
- o.buff = o.fullbuff[:]
+ o.buff = o.fullbuff[:0]
return &o, err
}
@@ -39,7 +39,7 @@ func InotifyInit1(flags Cint) (*Inotify, error) {
fd: Cint(fd),
isClosed: false,
}
- o.buff = o.fullbuff[:]
+ o.buff = o.fullbuff[:0]
return &o, err
}
@@ -65,30 +65,33 @@ func (o *Inotify) Close() error {
return sysclose(o.fd)
}
-func (o *Inotify) Read() (*Event, error) {
+func (o *Inotify) Read() (Event, error) {
if len(o.buff) == 0 {
if o.isClosed {
- return nil, InotifyAlreadyClosedError
+ return Event{Wd: -1}, InotifyAlreadyClosedError
}
+
len, err := sysread(o.fd, o.buff)
if len == 0 {
- return nil, o.Close()
+ return Event{Wd: -1}, o.Close()
} else if len <= 0 {
- return nil, err
+ return Event{Wd: -1}, err
}
o.buff = o.fullbuff[0:len]
}
+
raw := (*syscall.InotifyEvent)(unsafe.Pointer(&o.buff[0]))
- var ret Event
- ret.Wd = Cint(raw.Wd)
- ret.Mask = Mask(raw.Mask)
- ret.Cookie = raw.Cookie
- ret.Name = nil
+ ret := Event{
+ Wd: Cint(raw.Wd),
+ Mask: Mask(raw.Mask),
+ Cookie: raw.Cookie,
+ Name: nil,
+ }
if raw.Len > 0 {
bytes := (*[syscall.NAME_MAX]byte)(unsafe.Pointer(&o.buff[syscall.SizeofInotifyEvent]))
name := string(bytes[:raw.Len-1])
ret.Name = &name
}
o.buff = o.buff[0 : syscall.SizeofInotifyEvent+raw.Len]
- return &ret, nil
+ return ret, nil
}