summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2015-09-18 17:45:34 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2015-09-18 17:45:34 -0400
commit5d29d4c39d1c082535410510be6c54e349e1e3a7 (patch)
treef3d90d2641cbe9e109a087cb462bdb855001612e
parentbb61a2624631616f2954e6a9063dcabd58847831 (diff)
Massive documentation and copyright clean-up.
-rw-r--r--dl/dl_gnu.go91
-rw-r--r--dl/dlfcn.go62
-rw-r--r--dl/dlsym_reserved.go63
-rw-r--r--getgr/getgr.go18
-rw-r--r--inotify/bits.go67
-rw-r--r--inotify/inotify.go47
-rw-r--r--inotify/inutil/inotify_util.go32
-rw-r--r--inotify/syscall.go42
8 files changed, 330 insertions, 92 deletions
diff --git a/dl/dl_gnu.go b/dl/dl_gnu.go
index c7c409b..99ec32c 100644
--- a/dl/dl_gnu.go
+++ b/dl/dl_gnu.go
@@ -1,44 +1,69 @@
-package dl
+// The code in this file is trivial, and not eligable for copyright.
+//
+// The documentation in this file is taken from the Linux Programmer's
+// Manual page for dlopen(3).
+//
+// Copyright 1995 Yggdrasil Computing, Incorporated.
+// written by Adam J. Richter (adam@yggdrasil.com),
+// with typesetting help from Daniel Quinlan (quinlan@yggdrasil.com).
+// and Copyright 2003, 2015 Michael Kerrisk (mtk.manpages@gmail.com).
+//
+// This is free documentation; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of
+// the License, or (at your option) any later version.
+//
+// The GNU General Public License's references to "object code"
+// and "executables" are to be interpreted as the output of any
+// document formatting or typesetting system, including
+// intermediate and printed output.
+//
+// This manual is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public
+// License along with this manual; if not, see
+// <http://www.gnu.org/licenses/>.
+//
+// Modified by David A. Wheeler <dwheeler@dwheeler.com> 2000-11-28.
+// Applied patch by Terran Melconian, aeb, 2001-12-14.
+// Modified by Hacksaw <hacksaw@hacksaw.org> 2003-03-13.
+// Modified by Matt Domsch, 2003-04-09: _init and _fini obsolete
+// Modified by Michael Kerrisk <mtk.manpages@gmail.com> 2003-05-16.
+// Modified by Walter Harms: dladdr, dlvsym
+// Modified by Petr Baudis <pasky@suse.cz>, 2008-12-04: dladdr caveat
-import "unsafe"
+package dl
//#define _GNU_SOURCE
-//#include <stdlib.h>
-//#include <stdint.h>
//#include <dlfcn.h>
-//const uintptr_t rtld_next = (uintptr_t)RTLD_NEXT;
-//const uintptr_t rtld_default = (uintptr_t)RTLD_DEFAULT;
import "C"
+// These flags to Open() are GNU libc extensions.
const (
- RTLD_NOLOAD Flag = C.RTLD_NOLOAD
- RTLD_NODELETE Flag = C.RTLD_NODELETE
- RTLD_DEEPBIND Flag = C.RTLD_DEEPBIND
-)
+ // Do not unload the shared object during Close().
+ // Consequently, the object's static variables are not
+ // reinitialized if the object is reloaded with Open() at a
+ // later time.
+ RTLD_NODELETE Flag = C.RTLD_NODELETE // (since glibc 2.2, also present on Solaris)
-// These are kinda weird in that they aren't required by the standard,
-// but they are reserved by the standard (see the documentation for
-// `dlsym(3)`). On glibc, it takes _GNU_SOURCE to get them.
-//
-// There are two special pseudo-handles that may be specified
-// in handle:
-var (
- RTLD_DEFAULT Handle = Handle{unsafe.Pointer(uintptr(C.rtld_default))}
- // Find the first occurrence of the desired symbol using
- // the default shared object search order. The search will
- // include global symbols in the executable and its
- // dependencies, as well as symbols in shared objects that
- // were dynamically loaded with the RTLD_GLOBAL flag.
- RTLD_NEXT Handle = Handle{unsafe.Pointer(uintptr(C.rtld_next))}
- // Find the next occurrence of the desired symbol in the
- // search order after the current object. This allows one
- // to provide a wrapper around a function in another shared
- // object, so that, for example, the definition of a
- // function in a preloaded shared object (see LD_PRELOAD in
- // ld.so(8)) can find and invoke the "real" function
- // provided in another shared object (or for that matter,
- // the "next" definition of the function in cases where
- // there are multiple layers of preloading).
+ // Don't load the shared object. This can be used to test if
+ // the object is already resident (Open() returns nil if it
+ // is not, or the object's handle if it is resident). This
+ // flag can also be used to promote the flags on a shared
+ // object that is already loaded. For example, a shared
+ // object that was previously loaded with RTLD_LOCAL can be
+ // reopened with RTLD_NOLOAD | RTLD_GLOBAL.
+ RTLD_NOLOAD Flag = C.RTLD_NOLOAD // (since glibc 2.2, also present on Solaris)
+
+ // Place the lookup scope of the symbols in this shared object
+ // ahead of the global scope. This means that a
+ // self-contained object will use its own symbols in
+ // preference to global symbols with the same name contained
+ // in objects that have already been loaded.
+ RTLD_DEEPBIND Flag = C.RTLD_DEEPBIND // (since glibc 2.3.4)
)
// TODO: dlmopen
diff --git a/dl/dlfcn.go b/dl/dlfcn.go
index d5467f3..3ab5abb 100644
--- a/dl/dlfcn.go
+++ b/dl/dlfcn.go
@@ -1,3 +1,25 @@
+// Copyright 2015 Luke Shumaker <lukeshu@sbcglobal.net>.
+//
+// This is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of
+// the License, or (at your option) any later version.
+//
+// The GNU General Public License's references to "object code" and
+// "executables" are to be interpreted to also include the output of
+// any document formatting or typesetting system, including
+// intermediate and printed output.
+//
+// This software is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public
+// License along with this manual; if not, see
+// <http://www.gnu.org/licenses/>.
+
+// Package dl provides an interface to the POSIX runtime linker.
package dl
import (
@@ -12,26 +34,39 @@ import "C"
type Flag int
+// POSIX specifies these four flags to Open().
const (
- RTLD_LAZY Flag = C.RTLD_LAZY // Relocations are performed at an
- // implementation-defined time.
- RTLD_NOW Flag = C.RTLD_NOW // Relocations are performed when the
- // object is loaded.
- RTLD_GLOBAL Flag = C.RTLD_GLOBAL // All symbols are available for
- // relocation processing of other
- // modules.
- RTLD_LOCAL Flag = C.RTLD_LOCAL // All symbols are not made available
- // for relocation processing by other
- // modules.
+ // Relocations are performed at an implementation-defined
+ // time.
+ RTLD_LAZY Flag = C.RTLD_LAZY
+
+ // Relocations are performed when the object is loaded.
+ RTLD_NOW Flag = C.RTLD_NOW
+
+ // All symbols are available for relocation processing of
+ // other modules.
+ RTLD_GLOBAL Flag = C.RTLD_GLOBAL
+
+ // All symbols are not made available for relocation
+ // processing by other modules.
+ RTLD_LOCAL Flag = C.RTLD_LOCAL
)
type Handle struct {
c unsafe.Pointer
}
+// Open a shared object file, returning a Handle to it, or an error.
+// If name is an empty string, then the returned handle is the global
+// symbol table for the current process; if the name contains a slash,
+// then it is interpretted as a pathname; otherwise, it is
+// interpretted in an implementation-defined manner.
func Open(name string, flags Flag) (Handle, error) {
nameC := C.CString(name)
defer C.free(unsafe.Pointer(nameC))
+ if name == "" {
+ nameC = nil
+ }
dlerror()
ptr := C.dlopen(nameC, C.int(flags))
@@ -41,8 +76,10 @@ func Open(name string, flags Flag) (Handle, error) {
return Handle{ptr}, nil
}
+// Look up a symbol, and return a pointer to it.
+//
// This returns uintptr instead of unsafe.Pointer so that code using
-// reflect cannot obtain unsafe.Pointers without importing the unsafe
+// dl cannot obtain unsafe.Pointers without importing the unsafe
// package explicitly.
func (h Handle) Sym(symbol string) (uintptr, error) {
symbolC := C.CString(symbol)
@@ -56,6 +93,9 @@ func (h Handle) Sym(symbol string) (uintptr, error) {
return uintptr(ptr), nil
}
+// Close this handle on a shared object; decrementint the reference
+// count; if the reference count drops below 0, then the object is
+// unloaded.
func (h Handle) Close() error {
dlerror()
r := C.dlclose(h.c)
diff --git a/dl/dlsym_reserved.go b/dl/dlsym_reserved.go
new file mode 100644
index 0000000..081e012
--- /dev/null
+++ b/dl/dlsym_reserved.go
@@ -0,0 +1,63 @@
+// The documentation for RTLD_DEFAULT and RTLD_NEXT is taken from the
+// Linux Programmer's Manual page for dlsym(3).
+//
+// Copyright 1995 Yggdrasil Computing, Incorporated.
+// Copyright 2003, 2015 Michael Kerrisk <mtk.manpages@gmail.com>.
+// Copyright 2015 Luke Shumaker <lukeshu@sbcglobal.net>.
+//
+// This is free documentation; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of
+// the License, or (at your option) any later version.
+//
+// The GNU General Public License's references to "object code"
+// and "executables" are to be interpreted as the output of any
+// document formatting or typesetting system, including
+// intermediate and printed output.
+//
+// This manual is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public
+// License along with this manual; if not, see
+// <http://www.gnu.org/licenses/>.
+
+package dl
+
+import "unsafe"
+
+//#define _GNU_SOURCE
+//#include <stdint.h>
+//#include <dlfcn.h>
+//const uintptr_t rtld_next = (uintptr_t)RTLD_NEXT;
+//const uintptr_t rtld_default = (uintptr_t)RTLD_DEFAULT;
+import "C"
+
+// These constant values for Handles are reserved by POSIX for future
+// use with these meanings. They are available in GNU libdl if
+// _GNU_SOURCE is defined.
+var (
+ // This Handle represents the default default shared object
+ // search order. The search will include global symbols in
+ // the executable and its dependencies, as well as symbols in
+ // shared objects that were dynamically loaded with the
+ // RTLD_GLOBAL flag.
+ RTLD_DEFAULT Handle
+
+ // This Handle represents the shared object search order after
+ // the current object. This allows one to provide a wrapper
+ // around a function in another shared object, so that, for
+ // example, the definition of a function in a preloaded shared
+ // object (see LD_PRELOAD in ld.so(8)) can find and invoke the
+ // "real" function provided in another shared object (or for
+ // that matter, the "next" definition of the function in cases
+ // where there are multiple layers of preloading).
+ RTLD_NEXT Handle
+)
+
+func init() {
+ RTLD_DEFAULT = Handle{c: unsafe.Pointer(uintptr(C.rtld_default)), o: 2}
+ RTLD_DEFAULT = Handle{c: unsafe.Pointer(uintptr(C.rtld_next)), o: 2}
+}
diff --git a/getgr/getgr.go b/getgr/getgr.go
index 5470b2c..5e32826 100644
--- a/getgr/getgr.go
+++ b/getgr/getgr.go
@@ -1,3 +1,21 @@
+// Copyright 2015 Luke Shumaker <lukeshu@sbcglobal.net>.
+//
+// This is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License as
+// published by the Free Software Foundation; either version 2.1 of the
+// License, or (at your option) any later version.
+//
+// This software is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this manual; if not, see
+// <http://www.gnu.org/licenses/>.
+
+// Package getgr provides an interface to query the POSIX group
+// database.
package getgr
import (
diff --git a/inotify/bits.go b/inotify/bits.go
index eb0270f..18d8566 100644
--- a/inotify/bits.go
+++ b/inotify/bits.go
@@ -1,3 +1,24 @@
+// Copyright (C) 2015 Luke Shumaker
+//
+// Many of the comments in this file are taken from the GNU libc
+// header file <sys/inotify.h>
+//
+// Copyright (C) 2005-2015 Free Software Foundation, Inc.
+//
+// The GNU C Library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// The GNU C Library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with the GNU C Library; if not, see
+// <http://www.gnu.org/licenses/>.
+
package inotify
const (
@@ -7,39 +28,39 @@ const (
IN_NONBLOCK int = 00004000
)
-type Fd int
-type Wd int
+type file int // File Descriptor
+type Wd int // Watch Descriptor
type Mask uint32
const (
// Supported events suitable for the `mask` parameter of Inotify.AddWatch().
- IN_ACCESS Mask = (1<< 0) // File was accessed.
- IN_MODIFY Mask = (1<< 1) // File was modified.
- IN_ATTRIB Mask = (1<< 2) // Metadata changed.
- IN_CLOSE_WRITE Mask = (1<< 3) // Writtable file was closed.
- IN_CLOSE_NOWRITE Mask = (1<< 4) // Unwrittable file closed.
- IN_OPEN Mask = (1<< 5) // File was opened.
- IN_MOVED_FROM Mask = (1<< 6) // File was moved from X.
- IN_MOVED_TO Mask = (1<< 7) // File was moved to Y.
- IN_CREATE Mask = (1<< 8) // Subfile was created.
- IN_DELETE Mask = (1<< 9) // Subfile was deleted.
- IN_DELETE_SELF Mask = (1<<10) // Self was deleted.
- IN_MOVE_SELF Mask = (1<<11) // Self was moved.
+ IN_ACCESS Mask = (1 << 0) // File was accessed.
+ IN_MODIFY Mask = (1 << 1) // File was modified.
+ IN_ATTRIB Mask = (1 << 2) // Metadata changed.
+ IN_CLOSE_WRITE Mask = (1 << 3) // Writtable file was closed.
+ IN_CLOSE_NOWRITE Mask = (1 << 4) // Unwrittable file closed.
+ IN_OPEN Mask = (1 << 5) // File was opened.
+ IN_MOVED_FROM Mask = (1 << 6) // File was moved from X.
+ IN_MOVED_TO Mask = (1 << 7) // File was moved to Y.
+ IN_CREATE Mask = (1 << 8) // Subfile was created.
+ IN_DELETE Mask = (1 << 9) // Subfile was deleted.
+ IN_DELETE_SELF Mask = (1 << 10) // Self was deleted.
+ IN_MOVE_SELF Mask = (1 << 11) // Self was moved.
// Events that appear in output without subscribing to them.
- IN_UNMOUNT Mask = (1<<13) // Backing fs was unmounted.
- IN_Q_OVERFLOW Mask = (1<<14) // Event queued overflowed.
- IN_IGNORED Mask = (1<<15) // File was ignored (expect no more events).
+ IN_UNMOUNT Mask = (1 << 13) // Backing fs was unmounted.
+ IN_Q_OVERFLOW Mask = (1 << 14) // Event queued overflowed.
+ IN_IGNORED Mask = (1 << 15) // File was ignored (expect no more events).
// Special flags that you may pass to Inotify.AddWatch()...
// except for IN_ISDIR, which is a flag that is set on output events.
- IN_ONLYDIR Mask = (1<<24) // Only watch the path if it is a directory.
- IN_DONT_FOLLOW Mask = (1<<25) // Do not follow a sym link.
- IN_EXCL_UNLINK Mask = (1<<26) // Exclude events on unlinked objects.
- IN_MASK_ADD Mask = (1<<29) // Add to the mask of an already existing watch.
- IN_ISDIR Mask = (1<<30) // Event occurred against dir.
- IN_ONESHOT Mask = (1<<31) // Only send event once.
+ IN_ONLYDIR Mask = (1 << 24) // Only watch the path if it is a directory.
+ IN_DONT_FOLLOW Mask = (1 << 25) // Do not follow a sym link.
+ IN_EXCL_UNLINK Mask = (1 << 26) // Exclude events on unlinked objects.
+ IN_MASK_ADD Mask = (1 << 29) // Add to the mask of an already existing watch.
+ IN_ISDIR Mask = (1 << 30) // Event occurred against dir.
+ IN_ONESHOT Mask = (1 << 31) // Only send event once.
// Convenience macros */
IN_CLOSE Mask = (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) // Close.
diff --git a/inotify/inotify.go b/inotify/inotify.go
index 0d67b44..2fd3a83 100644
--- a/inotify/inotify.go
+++ b/inotify/inotify.go
@@ -1,3 +1,21 @@
+// Copyright 2015 Luke Shumaker <lukeshu@sbcglobal.net>.
+//
+// This is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License as
+// published by the Free Software Foundation; either version 2.1 of the
+// License, or (at your option) any later version.
+//
+// This software is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this manual; if not, see
+// <http://www.gnu.org/licenses/>.
+
+// Package inotify provides an interface to the Linux inotify system.
+// The inotify system is a mechanism for monitoring filesystem events.
package inotify
import (
@@ -7,7 +25,7 @@ import (
)
type Inotify struct {
- fd Fd
+ fd file
fdLock sync.RWMutex
buffFull [4096]byte
buff []byte
@@ -15,12 +33,14 @@ type Inotify struct {
}
type Event struct {
- Wd Wd /* Watch descriptor */
- Mask Mask /* Mask describing event */
- Cookie uint32 /* Unique cookie associating related events (for rename(2)) */
- Name *string /* Optional name */
+ Wd Wd // Watch descriptor
+ Mask Mask // Mask describing event
+ Cookie uint32 // Unique cookie associating related events (for rename(2))
+ Name *string // Optional name
}
+// Create an inotify instance. The variant InotifyInit1() allows
+// flags to access extra functionality.
func InotifyInit() (*Inotify, error) {
fd, err := inotify_init()
o := Inotify{
@@ -30,6 +50,8 @@ func InotifyInit() (*Inotify, error) {
return &o, err
}
+// Create an inotify instance, with flags specifying extra
+// functionality.
func InotifyInit1(flags int) (*Inotify, error) {
fd, err := inotify_init1(flags)
o := Inotify{
@@ -39,18 +61,29 @@ func InotifyInit1(flags int) (*Inotify, error) {
return &o, err
}
+// Add a watch to the inotify instance, or modifies an existing watch
+// item.
func (o *Inotify) AddWatch(path string, mask Mask) (Wd, error) {
o.fdLock.RLock()
defer o.fdLock.RUnlock()
return inotify_add_watch(o.fd, path, mask)
}
+// Remove a watch from the inotify instance.
func (o *Inotify) RmWatch(wd Wd) error {
o.fdLock.RLock()
defer o.fdLock.RUnlock()
return inotify_rm_watch(o.fd, wd)
}
+// Close the inotify instance; further calls to this object will
+// error.
+//
+// Events recieved before Close() is called may still be Read() after
+// the call to Close().
+//
+// Beware that if Close() is called while waiting on Read(), it will
+// block until events are read.
func (o *Inotify) Close() error {
o.fdLock.Lock()
defer o.fdLock.Unlock()
@@ -58,6 +91,10 @@ func (o *Inotify) Close() error {
return sysclose(o.fd)
}
+// Read an event from the inotify instance.
+//
+// Events recieved before Close() is called may still be Read() after
+// the call to Close().
func (o *Inotify) Read() (Event, error) {
o.buffLock.Lock()
defer o.buffLock.Unlock()
diff --git a/inotify/inutil/inotify_util.go b/inotify/inutil/inotify_util.go
index 3a5eed5..c643e59 100644
--- a/inotify/inutil/inotify_util.go
+++ b/inotify/inutil/inotify_util.go
@@ -1,3 +1,20 @@
+// Copyright 2015 Luke Shumaker <lukeshu@sbcglobal.net>.
+//
+// This is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License as
+// published by the Free Software Foundation; either version 2.1 of
+// the License, or (at your option) any later version.
+//
+// This software is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this manual; if not, see
+// <http://www.gnu.org/licenses/>.
+
+// Package inutil provides a channel-based interface to inotify.
package inutil
import (
@@ -6,25 +23,21 @@ import (
"syscall"
)
-const (
- // Flags for the parameter of InotifyInit1().
- // These, oddly, appear to be 24-bit numbers.
- IN_CLOEXEC = inotify.IN_CLOEXEC
-)
-
type Watcher struct {
Events <-chan inotify.Event
- events chan<- inotify.Event
Errors <-chan error
+ events chan<- inotify.Event
errors chan<- error
in *inotify.Inotify
}
+// Wraps inotify.InotifyInit()
func WatcherInit() (*Watcher, error) {
in, err := inotify.InotifyInit()
return newWatcher(in, err)
}
+// Wraps inotify.InotifyInit1()
func WatcherInit1(flags int) (*Watcher, error) {
in, err := inotify.InotifyInit1(flags &^ inotify.IN_NONBLOCK)
return newWatcher(in, err)
@@ -44,14 +57,19 @@ func newWatcher(in *inotify.Inotify, err error) (*Watcher, error) {
return o, err
}
+// Wraps inotify.Inotify.AddWatch(); adds or modifies a watch.
func (o *Watcher) AddWatch(path string, mask inotify.Mask) (inotify.Wd, error) {
return o.in.AddWatch(path, mask)
}
+// Wraps inotify.Inotify.RmWatch(); removes a watch.
func (o *Watcher) RmWatch(wd inotify.Wd) error {
return o.in.RmWatch(wd)
}
+// Wraps inotify.Inotify.Close(). Unlike inotify.Inotify.Close(),
+// this cannot block. Also unlike inotify.Inotify.Close(), nothing
+// may be received from the channel after this is called.
func (o *Watcher) Close() {
func() {
defer recover()
diff --git a/inotify/syscall.go b/inotify/syscall.go
index 721a10a..d1b5140 100644
--- a/inotify/syscall.go
+++ b/inotify/syscall.go
@@ -1,3 +1,19 @@
+// Copyright 2015 Luke Shumaker <lukeshu@sbcglobal.net>.
+//
+// This is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License as
+// published by the Free Software Foundation; either version 2.1 of
+// the License, or (at your option) any later version.
+//
+// This software is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this manual; if not, see
+// <http://www.gnu.org/licenses/>.
+
package inotify
import (
@@ -12,27 +28,27 @@ func newPathError(op string, path string, err error) error {
return &os.PathError{Op: op, Path: path, Err: err}
}
-/* Create and initialize inotify instance. */
-func inotify_init() (Fd, error) {
+// Create and initialize inotify instance.
+func inotify_init() (file, error) {
fd, errno := syscall.InotifyInit()
- return Fd(fd), os.NewSyscallError("inotify_init", errno)
+ return file(fd), os.NewSyscallError("inotify_init", errno)
}
-/* Create and initialize inotify instance. */
-func inotify_init1(flags int) (Fd, error) {
+// Create and initialize inotify instance.
+func inotify_init1(flags int) (file, error) {
fd, errno := syscall.InotifyInit1(flags)
- return Fd(fd), os.NewSyscallError("inotify_init1", errno)
+ return file(fd), os.NewSyscallError("inotify_init1", errno)
}
-/* Add watch of object NAME to inotify instance FD. Notify about
- events specified by MASK. */
-func inotify_add_watch(fd Fd, name string, mask Mask) (Wd, error) {
+// Add watch of object NAME to inotify instance FD. Notify about
+// events specified by MASK.
+func inotify_add_watch(fd file, name string, mask Mask) (Wd, error) {
wd, errno := syscall.InotifyAddWatch(int(fd), name, uint32(mask))
return Wd(wd), newPathError("inotify_add_watch", name, errno)
}
-/* Remove the watch specified by WD from the inotify instance FD. */
-func inotify_rm_watch(fd Fd, wd Wd) error {
+// Remove the watch specified by WD from the inotify instance FD.
+func inotify_rm_watch(fd file, wd Wd) error {
success, errno := syscall.InotifyRmWatch(int(fd), uint32(wd))
switch success {
case -1:
@@ -49,11 +65,11 @@ func inotify_rm_watch(fd Fd, wd Wd) error {
panic("should never happen")
}
-func sysclose(fd Fd) error {
+func sysclose(fd file) error {
return os.NewSyscallError("close", syscall.Close(int(fd)))
}
-func sysread(fd Fd, p []byte) (int, error) {
+func sysread(fd file, p []byte) (int, error) {
n, err := syscall.Read(int(fd), p)
return n, os.NewSyscallError("read", err)
}