On Friday, 27 December 2013 at 10:56:55 UTC, Artur Skawina wrote:

You probably meant

   read(inotfd, event, (*event).sizeof);

but in this case the inotify_event structure contains an optional
trailing buffer, so it should be

   read(inotfd, event, bufsiz);

artur

Yes, thanks for the correction.

I had trouble getting the file name from the event. I think it's because the inotify module has name defined as char[0]. So I did this, which prints the name by using the extra data beyond the inotify_event struct itself:


    void* buf = GC.malloc(bufsiz);

    /* wait for an event to occur */
    size_t readlen = read(inotfd, buf, bufsiz);
    inotify_event* event = cast(inotify_event*) (buf);

    /* process event struct here */
    writeln("Received inotify event:");
    writeln("Bytes read: ", readlen);
    writeln("Length: ", event.len);
    writeln("Name:", cast(char[])(buf[event.len..readlen]));

Reply via email to