How to bridge C __flexarray?

I'm attempting to write a Swift wrapper for inotify, and I need to read the name out of a struct which is defined like so:

/* Structure describing an inotify event. */

struct inotify_event
    int wd;
    uint32_t mask;
    uint32_t cookie;
    uint32_t len;
    char name __flexarr;

The problem is, when I try to access this name field from Swift, it does not appear to exist in the Swift view of this struct:

error: value of type 'inotify_event' has no member 'name'
        print("\t \(String(cString:")

How can I access it?

If the clang importer isn’t bringing it in, the easiest thing to do is to write a C shim layer that can give you access to it. This could involve a function that returns a pointer, for example.

I built a swift library wrapper around inotify, I havent done much with it the past few years other than make sure it compiles under new swift releases but it might be able to at least point you in a direction that can help you out.

This is great, thank you!

1 Like

This worked, thanks!

1 Like