Module inotify

inotify support for working with inotify objects.

Examples

use rustix::fs::inotify;
use rustix::io;
use std::mem::MaybeUninit;

# fn test() -> io::Result<()> {
// Create an inotify object. In this example, we use `NONBLOCK` so that the
// reader fails with `WOULDBLOCK` when no events are ready. Otherwise it
// will block until at least one event is ready.
let inotify = inotify::init(inotify::CreateFlags::NONBLOCK)?;

// Add a directory to watch.
inotify::add_watch(
    &inotify,
    "/path/to/some/directory/to/watch",
    inotify::WatchFlags::ALL_EVENTS,
)?;

// Generate some events in the watched directory…

// Loop over pending events.
let mut buf = [MaybeUninit::uninit(); 512];
let mut iter = inotify::Reader::new(inotify, &mut buf);
loop {
    let entry = match iter.next() {
        // Stop iterating if there are no more events for now.
        Err(io::Errno::WOULDBLOCK) => break,
        Err(e) => return Err(e),
        Ok(entry) => entry,
    };

    // Use `entry`…
}

# Ok(())
# }

Structs

Functions