java - JNA causes UnsatisfiedLinkException with Unix Stat -


so, i'm attempting call linux c - stat function.

my jna code:

    public int stat(bap path, bap statdump); 

the bap class:

public static class bap extends structure {      public byte[] array;      public bap(int size) {         array = new byte[size];     }      @override     protected list getfieldorder() {         return arrays.aslist(new string[]{"array"});     }  } 

which, while nasty, performs byte array pointer many other functions successfully. think problem is, here: int stat(const char *restrict path, struct stat *restrict buf);, defined http://linux.die.net/man/3/stat

how pass constant char array, , *restrict mean? attempted google, don't think liked * in search query, nothing relevant.

edit: full exception

exception in thread "main" java.lang.reflect.invocationtargetexception     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:      43)     @ java.lang.reflect.method.invoke(method.java:497)     @ org.eclipse.jdt.internal.jarinjarloader.jarrsrcloader.main(jarrsrcloader.java:58) caused by: java.lang.unsatisfiedlinkerror: error looking function 'stat': java: undefined       symbol: stat     @ com.sun.jna.function.<init>(function.java:208)     @ com.sun.jna.nativelibrary.getfunction(nativelibrary.java:536)     @ com.sun.jna.nativelibrary.getfunction(nativelibrary.java:513)     @ com.sun.jna.nativelibrary.getfunction(nativelibrary.java:499)     @ com.sun.jna.library$handler.invoke(library.java:199)     @ com.sun.proxy.$proxy0.stat(unknown source) 

have looked @ sys/stat.h see if there's actual declaration stat() or if it's c preprocessor macro?

in link above, stat stat64 if __use_file_offset64 defined.

to see if problem, change function name stat stat64.

as more permanent solution supply function mapper library load.

the following example first looks base label, tries again after appending "64":

functionmapper mapper = new functionmapper() {     public string getfunctionname(nativelibrary library, java.lang.reflect.method method) {         string name = method.getname();         try {             library.getfunction(name);         } catch(unsatisfiedlinkerror e) {             try {                 library.getfunction(name + "64");                 return name + "64";             } catch(unsatisfiedlinkerror e) {                  // if neither variant worked, report failure on base label             }         }         return name;     } }; map options = new hashmap() {     { put(library.option_function_mapper, mapper); } }; library = native.loadlibrary("c", options); 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -