summaryrefslogtreecommitdiff
path: root/src/inotify/inotify.go
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
commit959055420845d7c63148fd5be8f9cf4285e2446b (patch)
treed0a64e601f458feae6873e982f87b56a0ad33923 /src/inotify/inotify.go
parent9463f76baa6012fe6abb6f8ce229caa6d54c1216 (diff)
Fix issues in inotify bindings
Diffstat (limited to 'src/inotify/inotify.go')
-rw-r--r--src/inotify/inotify.go27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/inotify/inotify.go b/src/inotify/inotify.go
index 976bdae..8c99a28 100644
--- a/src/inotify/inotify.go
+++ b/src/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
}