iv_inotify(3)

✨ iv_inotify β€” the ivykis inotify(7) wrapper, bestie edition ✨

okay so you want to watch files like a little hawk πŸ¦… and you're using ivykis? say less. this is from the ivykis programmer's manual, and it's giving "inotify but make it event-loop-friendly." no cap. πŸ’…


πŸŽ€ NAME πŸŽ€

IV_INOTIFY_INIT, iv_inotify_register, iv_inotify_unregister, IV_INOTIFY_WATCH_INIT, iv_inotify_watch_register, iv_inotify_watch_unregister β€” literally the whole ivykis inotify(7) wrapper, one iconique family of functions. πŸ‘‘


🌸 SYNOPSIS 🌸

like, here's the whole cast, verbatim, no edits, periodt:

#include <iv_inotify.h>

struct iv_inotify {
};

void IV_INOTIFY_INIT(struct iv_inotify *inotify);
int iv_inotify_register(struct iv_inotify *inotify);
void iv_inotify_unregister(struct iv_inotify *inotify);

struct iv_inotify_watch {
        struct iv_inotify       *inotify;
        const char              *pathname;
        uint32_t                mask;
        void                    *cookie;
        void                    (*handler)(void *, struct inotify_event *);
};

void IV_INOTIFY_WATCH_INIT(struct iv_inotify_watch *watch);
int iv_inotify_watch_register(struct iv_inotify_watch *watch);
int iv_inotify_watch_unregister(struct iv_inotify_watch *watch);

πŸ’– DESCRIPTION πŸ’–

so here's the tea, bestie β˜• β€” let's go function by function because the way that each one has a job is so satisfying.

πŸ¦‹ the instance functions

iv_inotify_register β€” this one registers an iv_inotify instance with the iv_inotify(3) module. the inotify parameter is a pointer to the iv_inotify structure you want to register. that's it, that's the whole vibe.

iv_inotify_unregister β€” the reverse, the breakup arc 😭. it unregisters an iv_inotify instance from the iv_inotify(3) module. the inotify parameter is a pointer to the iv_inotify structure you're unregistering.

🌈 the watch functions

iv_inotify_watch_register β€” adds a watch to the registered iv_inotify instance that's specified by the ->inotify member. like, it's matching them up. main character energy fr fr. πŸ’ž

iv_inotify_watch_unregister β€” removes a watch from the iv_inotify instance specified by the ->inotify member. goodbye watch πŸ‘‹

πŸ“ the struct deets (iykyk)

in the iv_inotify_watch structure used by these functions:

  • ->pathname and ->mask correspond to the members of struct inotify_watch as described in inotify(7). yes, same names, same meaning, we are not inventing anything here.
  • ->handler is the event handler that gets called when this watch triggers. ✨
  • the arguments to that handler function are (1) the pointer stored in the ->cookie member of the iv_inotify_watch structure, and (2) a pointer to an inotify_event structure as described in inotify(7). so your cookie comes back to you, like a lil boomerang πŸͺƒπŸͺ.

⭐ RETURN VALUE ⭐

  • iv_inotify_register and iv_inotify_watch_register return zero on success. slay. βœ…
  • on error, -1 is returned, and errno is set appropriately. that's the "it's not giving" signal πŸ’€.

πŸ’€ ERRORS πŸ’€

ngl, the error handling is honestly just passing the buck in the cutest way: iv_inotify will return errors returned by inotify_init(3) and inotify_add_watch(3). so whatever those two say, that's what you get. 🫢


πŸ”₯ SEE ALSO πŸ”₯

go read these, bestie, they're the extended universe:


and that's the whole page!! πŸ’– this came to you from the ivykis girlies, dated 2009-02-07, filed under iv_inotify(3). obsessed with you for reading the whole thing, mwah πŸŽ€βœ¨