Program output when scanning the directory with ls -l:
file system events = 0x40000020
DirMon-1 @ WORK got 'F5' from OS
'/tmp/test/': opened
file system events = 0x40000001
DirMon-1 @ WORK got 'F0' from OS
'/tmp/test/': accessed
file system events = 0x40000010
DirMon-1 @ WORK got 'F4' from OS
'/tmp/test/': closed (read)
Program output when touching a file with touch /tmp/test/a-file:
file system events = 0x00000100
DirMon-1 @ WORK got 'F8' from OS
'a-file': created
file system events = 0x00000020
DirMon-1 @ WORK got 'F5' from OS
'a-file': opened
file system events = 0x00000004
DirMon-1 @ WORK got 'F2' from OS
'a-file': metadata changed
file system events = 0x00000008
DirMon-1 @ WORK got 'F3' from OS
'a-file': closed (write)
Program output when deleting the directory being monitored:
DirMon-1 @ WORK got 'F10' from OS
'/tmp/test/': deleted
file system events = 0x00008000
DirMon-1 @ WORK got 'F15' from OS
'/tmp/test/': ignored
DirMon-1 @ WORK got 'S1' from OS
got signal #15 from PID 110187
Bye!
I made (eventually successful) attempt to redesign this example in such a way that it does not use heap allocation (as an exercize). And I must confess that was not very easy adventure for me. It seems I am more comfortable with heap allocation rather than stack one with my current understanding of Zig
Also I’ve made a couple of things along the way:
generic (fixed sized) ring buffer (I tried to implement it before but at that time something went wrong)
the code related to event sources (signals and so on) was completely refactored, now it is more OOP-fashioned:
No, I am not a big fan of OOP languages, but sometimes inheritance/polymorphism are convenient things and what is good that in C/Zig they are explicit.
The sources are here. I am using @fieldParentPtr() hard (event sources and machines themselves code), because I just like to do this way, it is an analog of well-known magic container_of() C macro.