File: README.md

package info (click to toggle)
jnr-ffi 2.1.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 2,304 kB
  • sloc: java: 23,671; ansic: 590; xml: 255; sh: 137; makefile: 12
file content (52 lines) | stat: -rw-r--r-- 1,475 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
jnr-ffi [![Build Status](https://travis-ci.org/jnr/jnr-ffi.svg)](https://travis-ci.org/jnr/jnr-ffi)
======

[jnr-ffi](https://github.com/jnr/jnr-ffi) is a java library for loading native libraries without writing JNI code by hand, or using tools such as SWIG.

Example
------

    package helloworld;

    import jnr.ffi.LibraryLoader;

    public class HelloWorld {
        public static interface LibC {
            int puts(String s);
        }

        public static void main(String[] args) {
            LibC libc = LibraryLoader.create(LibC.class).load("c");

            libc.puts("Hello, World");
        }
    }

Supported Types
------

All java primitives are mapped simply to the equivalent C types.

* byte - 8 bit signed integer
* short - 16 bit signed integer
* int - 32 bit signed integer
* long - natural long (i.e. 32 bits wide on 32 bit systems, 64 bit wide on 64bit systems)
* float - 32 bit float
* double - 64 bit float

The width and/or signed-ness of these basic types can be specified using one of the type alias annotations.
 e.g.

    // Use the correct width for the result from getpid(3)
    @pid_t long getpid();

    // read(2) returns a signed long result, and its length parameter is an unsigned long
    @ssize_t long read(int fd, Pointer data, @size_t long len);


In addition, the following java types are mapped to a C pointer

* String - equivalent to "const char *"
* Pointer - equivalent to "void *"
* Buffer - equivalent to "void *"