-
-
Save etehtsea/12584ea05174f2f41a8cd850c9e03135 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import jnr.ffi.Runtime; | |
import jnr.ffi.Memory; | |
import jnr.ffi.StructLayout; | |
import jnr.ffi.LibraryLoader; | |
import jnr.ffi.Pointer; | |
import jnr.ffi.annotations.Out; | |
import jnr.ffi.annotations.Transient; | |
public class HelloWorld { | |
public static interface LibC { | |
int puts(String s); | |
int __xstat64(int statVersion, CharSequence path, @Out @Transient SB stat); | |
} | |
public static final class SB extends StructLayout { | |
public SB(jnr.ffi.Runtime runtime) { | |
super(runtime); | |
} | |
public final dev_t st_dev = new dev_t(); | |
public final ino_t st_ino = new ino_t(); | |
public final mode_t st_mode = new mode_t(); | |
public final nlink_t st_nlink = new nlink_t(); | |
public final uid_t st_uid = new uid_t(); | |
public final gid_t st_gid = new gid_t(); | |
public final dev_t st_rdev = new dev_t(); | |
public final size_t st_size = new size_t(); | |
public final blksize_t st_blksize = new blksize_t(); | |
public final blkcnt_t st_blocks = new blkcnt_t(); | |
public final time_t st_atime = new time_t(); // Time of last access | |
public final SignedLong st_atimensec = new SignedLong(); // Time of last access (nanoseconds) | |
public final time_t st_mtime = new time_t(); // Last data modification time | |
public final SignedLong st_mtimensec = new SignedLong(); // Last data modification time (nanoseconds) | |
public final time_t st_ctime = new time_t(); // Time of last status change | |
public final SignedLong st_ctimensec = new SignedLong(); // Time of last status change (nanoseconds) | |
public final Signed64 __unused4 = new Signed64(); | |
} | |
public static void main(String[] args) throws Throwable { | |
LibC libc = LibraryLoader.create(LibC.class).load("c"); | |
File f = File.createTempFile("stat", null).getParentFile(); | |
//jnr.ffi.Runtime runtime = Runtime.getRuntime(libc); | |
//SB stat = new SB(runtime); | |
//Pointer memory = Memory.allocate(runtime, stat.size()); | |
//System.out.println("Struct size: " + stat.size()); | |
try { | |
System.out.println(f.getAbsolutePath()); | |
// int ret = libc.__xstat64(0, f.getAbsolutePath(), stat); | |
//System.out.println("Finished with: " + ret); | |
//System.out.println("\tdev: " + stat.st_dev.get(memory)); | |
//System.out.println("\tinode: " + stat.st_ino.get(memory)); | |
//System.out.println("\tmode: " + stat.st_mode.get(memory)); | |
//System.out.println("\tlinks: " + stat.st_nlink.get(memory)); | |
//System.out.println("\towner: " + stat.st_uid.get(memory)); | |
//System.out.println("\tgroup: " + stat.st_gid.get(memory)); | |
//System.out.println("\trdev: " + stat.st_rdev.get(memory)); | |
//System.out.println("\tsize: " + stat.st_size.get(memory)); | |
//System.out.println("\tblksize: " + stat.st_blksize.get(memory)); | |
//System.out.println("\tblkcnt: " + stat.st_blocks.get(memory)); | |
} finally { | |
f.delete(); | |
} | |
libc.puts("Hello, World"); | |
} | |
} |
Author
etehtsea
commented
May 11, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment