Skip to content

Instantly share code, notes, and snippets.

@ayosec
Created December 24, 2011 01:41
Show Gist options
  • Save ayosec/1515892 to your computer and use it in GitHub Desktop.
Save ayosec/1515892 to your computer and use it in GitHub Desktop.
LibC binding with JNA
package com.ayosec.misc;
import com.sun.jna.*;
public class LibC {
public interface Handle extends Library {
Handle module = (Handle) Native.loadLibrary("c", Handle.class);
int getpid();
int getppid();
int kill(int pid, int signal);
int readlink(String path, byte[] buffer, int size);
}
public static String readlink(String path) throws java.io.FileNotFoundException {
byte[] buffer = new byte[300];
int size = LibC.Handle.module.readlink(path, buffer, 300);
if(size > 0)
return new String(buffer, 0, size);
else
throw new java.io.FileNotFoundException(path);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment