Created
December 24, 2011 01:41
-
-
Save ayosec/1515892 to your computer and use it in GitHub Desktop.
LibC binding with JNA
This file contains hidden or 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
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