Interface LibC

  • All Superinterfaces:
    com.sun.jna.Library

    public interface LibC
    extends com.sun.jna.Library
    Minimal interface to the standard "C" library.
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface com.sun.jna.Library

        com.sun.jna.Library.Handler
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static LibC INSTANCE
      Native library instance.
      • Fields inherited from interface com.sun.jna.Library

        OPTION_ALLOW_OBJECTS, OPTION_CALLING_CONVENTION, OPTION_CLASSLOADER, OPTION_FUNCTION_MAPPER, OPTION_INVOCATION_MAPPER, OPTION_OPEN_FLAGS, OPTION_STRING_ENCODING, OPTION_STRUCTURE_ALIGNMENT, OPTION_TYPE_MAPPER
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      int _putenv​(String envstring)
      Closest Windows equivalent to setenv(String, String, int).
      int getpid()
      Get the current process id.
      int mlock​(com.sun.jna.Pointer addr, com.sun.jna.NativeLong length)
      Locks (pins) parts of virtual address space into RAM so it can not be swapped out.
      int munlock​(com.sun.jna.Pointer addr, com.sun.jna.NativeLong length)
      Unlock previously locked memory.
      int setenv​(String name, String value, int overwrite)
      Change or add an evironment variable.
      int unsetenv​(String name)
      Unset an environment variable.
      int vsnprintf​(ByteBuffer str, int size, String format, com.sun.jna.Pointer args)
      Format a string with a variable arguments list into a fixed size buffer.
    • Field Detail

      • INSTANCE

        static final LibC INSTANCE
        Native library instance.
    • Method Detail

      • vsnprintf

        int vsnprintf​(ByteBuffer str,
                      int size,
                      String format,
                      com.sun.jna.Pointer args)
        Format a string with a variable arguments list into a fixed size buffer.

        The resultant string will be truncated to the size of the buffer if it would otherwise exceed it.

        For example, if the buffer has a capacity of 10 this is a maximum of 9 characters plus a null terminator for a total capacity of 10. This means if 10 characters are required, the buffer capacity must be 11 to accommodate the null terminator.

        Parameters:
        str - buffer
        size - capacity of the buffer, including space for a null terminator
        format - format string
        args - format arguments
        Returns:
        length of the formatted string, which may exceed the capacity of the buffer, or less than zero on error
      • mlock

        int mlock​(com.sun.jna.Pointer addr,
                  com.sun.jna.NativeLong length)
        Locks (pins) parts of virtual address space into RAM so it can not be swapped out.
        Parameters:
        addr - address pointer
        length - length
        Returns:
        0 if successful; -1 if not, setting errno to an error code
      • munlock

        int munlock​(com.sun.jna.Pointer addr,
                    com.sun.jna.NativeLong length)
        Unlock previously locked memory.
        Parameters:
        addr - address pointer
        length - length
        Returns:
        0 if successful; -1 if not, setting errno to an error code
      • setenv

        int setenv​(String name,
                   String value,
                   int overwrite)
        Change or add an evironment variable.

        The value strings are copied (natively).

        Not available on Windows.

        Parameters:
        name - name of environment variable
        value - value of the environment variable
        overwrite - non-zero to replace any existing value
        Returns:
        0 if successful; -1 if not, setting errno to an error code
      • unsetenv

        int unsetenv​(String name)
        Unset an environment variable.

        Not available on Windows.

        Parameters:
        name - name of environment variable
        Returns:
        0 if successful; -1 if not, setting errno to an error code
      • getpid

        int getpid()
        Get the current process id.

        Not available on Windows.

        Returns:
        process id
      • _putenv

        int _putenv​(String envstring)
        Closest Windows equivalent to setenv(String, String, int).

        Note that after setting an environment variable, it will not show up via System#getenv even if it was successfully set.

        Use with case, it is not guaranteed to be thread-safe.

        Only available on Windows.

        Parameters:
        envstring - variable and value to set, in the format "variable=value", without quotes.
        Returns:
        zero on success, non-zero on error