Interface PosixCLibrary

All Superinterfaces:
NativeLibrary

public non-sealed interface PosixCLibrary extends NativeLibrary
PosixCLibrary relies on preview features of the Java platform:
  • PosixCLibrary refers to one or more preview APIs: MemorySegment.
Programs can only use PosixCLibrary when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
Provides access to methods in libc.so available on POSIX systems.
  • Field Details

  • Method Details

    • geteuid

      int geteuid()
      Gets the effective userid of the current process.
      Returns:
      the effective user id
      See Also:
    • newRLimit

      Create a new RLimit struct for use by getrlimit.
    • getrlimit

      int getrlimit(int resource, PosixCLibrary.RLimit rlimit)
      Retrieve the current rlimit values for the given resource.
      Returns:
      0 on success, -1 on failure with errno set
      See Also:
    • setrlimit

      int setrlimit(int resource, PosixCLibrary.RLimit rlimit)
    • mlockall

      int mlockall(int flags)
      Lock all the current process's virtual address space into RAM.
      Parameters:
      flags - flags determining how memory will be locked
      Returns:
      0 on success, -1 on failure with errno set
      See Also:
    • madvise

      int madvise(MemorySegmentPREVIEW segment, long offset, long length, int advice)
      Provides advice to the operating system about how a region of memory will be accessed, allowing the kernel to optimize memory management.

      This method is a thin wrapper around the POSIX madvise(2) system call. The call is advisory only and does not guarantee any specific behavior.

      Requirements:

      Parameters:
      segment - the starting memory segment of the region to be advised; must refer to native memory and be page-size aligned
      length - the length in bytes of the memory region starting at segment
      advice - the access pattern advice (for example MADV_WILLNEED, MADV_DONTNEED, MADV_SEQUENTIAL, etc.)
      Returns:
      0 on success, or -1 on failure with errno set to indicate the error
      Throws:
      IllegalArgumentException - if segment does not represent native memory
      See Also:
    • getPageSize

      int getPageSize()
      Returns native page size.
    • newStat64

      PosixCLibrary.Stat64 newStat64(int sizeof, int stSizeOffset, int stBlocksOffset)
    • open

      int open(String pathname, int flags, int mode)
    • open

      int open(String pathname, int flags)
    • fstat64

      int fstat64(int fd, PosixCLibrary.Stat64 stats)
    • ftruncate

      int ftruncate(int fd, long length)
    • newFStore

    • fcntl

      int fcntl(int fd, int cmd, PosixCLibrary.FStore fst)
    • socket

      int socket(int domain, int type, int protocol)
      Open a file descriptor to connect to a socket.
      Parameters:
      domain - The socket protocol family, eg AF_UNIX
      type - The socket type, eg SOCK_DGRAM
      protocol - The protocol for the given protocl family, normally 0
      Returns:
      an open file descriptor, or -1 on failure with errno set
      See Also:
    • newUnixSockAddr

      PosixCLibrary.SockAddr newUnixSockAddr(String path)
      Create a sockaddr for the AF_UNIX family.
    • connect

      int connect(int sockfd, PosixCLibrary.SockAddr addr)
      Connect a socket to an address.
      Parameters:
      sockfd - An open socket file descriptor
      addr - The address to connect to
      Returns:
      0 on success, -1 on failure with errno set
    • send

      long send(int sockfd, CloseableByteBuffer buffer, int flags)
      Send a message to a socket.
      Parameters:
      sockfd - The open socket file descriptor
      buffer - The message bytes to send
      flags - Flags that may adjust how the message is sent
      Returns:
      The number of bytes sent, or -1 on failure with errno set
      See Also:
    • close

      int close(int fd)
      Close a file descriptor
      Parameters:
      fd - The file descriptor to close
      Returns:
      0 on success, -1 on failure with errno set
      See Also:
    • strerror

      String strerror(int errno)
      Return a string description for an error.
      Parameters:
      errno - The error number
      Returns:
      a String description for the error
      See Also:
    • errno

      int errno()
      Return the error number from the last failed C library call.
      See Also: