1

Is there a way for jnr to construct a struct for me in order to access a returned call using jnr.

for example, if I wanted to use

int statvfs(const char *path, struct statvfs *buf);

where struct statvfs is:

struct statvfs {
    unsigned long  f_bsize;    /* file system block size */
    unsigned long  f_frsize;   /* fragment size */
    fsblkcnt_t     f_blocks;   /* size of fs in f_frsize units */
    fsblkcnt_t     f_bfree;    /* # free blocks */
    fsblkcnt_t     f_bavail;   /* # free blocks for unprivileged users */
    fsfilcnt_t     f_files;    /* # inodes */
    fsfilcnt_t     f_ffree;    /* # free inodes */
    fsfilcnt_t     f_favail;   /* # free inodes for unprivileged users */
    unsigned long  f_fsid;     /* file system ID */
    unsigned long  f_flag;     /* mount flags */
    unsigned long  f_namemax;  /* maximum filename length */
};

how would I be able to access this?

zcaudate
  • 13,998
  • 7
  • 64
  • 124

1 Answers1

1

To use C++ struct, you should define class that extends jnr.ffi.Struct . Each field should have one of the java-types, defined in jnr.ffi.Struct class or extended from one of it.

For example short field from *.h file should be defined as jnr.ffi.Struct.Signed16 in struct class.

If you need to have an array field, you must initialize it using static method Struct.array(Struct.Signed8[] array) as following:

public final Signed8[] byteArray = array(new Signed8[8])
goto1134
  • 107
  • 11