peter-lawrey/Java-Thread-Affinity — Issue #4: Fix JNA errno support
Author: jbellis
Created: 2011-12-29 22:11:42+00:00
State: open

The modern way to handle errno from JNA is to declare your native methods as "throws LastErrorException." Then you can access getErrorCode on a caught LEE. For example, https://github.com/ryanking/apache-cassandra/blob/trunk/src/java/org/apache/cassandra/utils/CLibrary.java (which has some instanceof dancing that you may not care about if you only support versions of JNA new enough to define LEE).

Calling errno directly is problematic (it's often a macro), and even Native.getLastError (JNA's old way to expose it semi-portably) doesn't always work (apparently it can itself trigger syscalls that reset errno...). LastErrorException does work reliably and is the recommended way to handle errno now.