Example:
import std/inotify when defined(linux): let inoty: FileHandle = inotify_init() ## Create 1 Inotify. doAssert inoty >= 0 ## Check for errors (FileHandle is alias to cint). let watchdoge: cint = inotify_add_watch(inoty, ".", IN_ALL_EVENTS) ## Add directory to watchdog. doAssert watchdoge >= 0 ## Check for errors. doAssert inotify_rm_watch(inoty, watchdoge) >= 0 ## Remove directory from the watchdog
Types
InotifyEvent {.pure, final, importc: "struct inotify_event", header: "<sys/inotify.h>".} = object wd* {.importc: "wd".}: FileHandle ## Watch descriptor. mask* {.importc: "mask".}: uint32 ## Watch mask. cookie* {.importc: "cookie".}: uint32 ## Cookie to synchronize two events. len* {.importc: "len".}: uint32 ## Length (including NULs) of name. name* {.importc: "name".}: char ## Name.
- An Inotify event. Source Edit
Procs
proc inotify_init(): FileHandle {.cdecl, importc: "inotify_init", header: "<sys/inotify.h>", ...raises: [], tags: [], forbids: [].}
- Create and initialize inotify instance. Source Edit
proc inotify_init1(flags: cint): FileHandle {.cdecl, importc: "inotify_init1", header: "<sys/inotify.h>", ...raises: [], tags: [], forbids: [].}
- Create and initialize inotify instance. Source Edit
Iterators
iterator inotify_events(evs: pointer; n: int): ptr InotifyEvent {....raises: [], tags: [], forbids: [].}
-
Abstract the packed buffer interface to yield event object pointers.
var evs = newSeq[byte](8192) # Already did inotify_init+add_watch while (let n = read(fd, evs[0].addr, 8192); n) > 0: # read forever for e in inotify_events(evs[0].addr, n): echo e[].len # echo name lens
Source Edit