Module openj9.dtfj

Class Clib


  • public class Clib
    extends Object
    This class provides a low level interface to some of the z/OS C library. This approach was inspired by the SWT design in that we have a one-to-one mapping between JNI calls and C library calls: no extra work is done in the native functions. This is much easier to maintain because this library should rarely need recompiling.

    Please refer to the C library documentation for more details about arguments to these calls.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int SEEK_CUR
      fseek whence argument to indicate that offset is from the current position of the file pointer
      static int SEEK_END
      fseek whence argument to indicate that offset is from the end of the file
      static int SEEK_SET
      fseek whence argument to indicate that offset is from the beginning of the file
    • Constructor Summary

      Constructors 
      Constructor Description
      Clib()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int fgetpos​(long fp, int[] pos)
      This method is a wrapper around fgetpos.
      static long fopen​(byte[] filename, byte[] mode)
      This method is a wrapper around fopen.
      static long fopen​(String filename, String mode)
      This method is a slightly friendlier version of the native fopen call (the parameters are Strings rather than byte arrays otherwise everything is the same).
      static int fread​(byte[] buf, int size, int count, long fp)
      This method is a wrapper around fread.
      static int fseek​(long fp, long offset, int whence)
      This method is a wrapper around fseek.
      static int fsetpos​(long fp, int[] pos)
      This method is a wrapper around fsetpos.
      static void perror​(byte[] prefix)
      This method is a wrapper around perror.
      static void perror​(String prefix)
      Friendlier version of the native perror call that accepts a String parameter.
    • Field Detail

      • SEEK_SET

        public static final int SEEK_SET
        fseek whence argument to indicate that offset is from the beginning of the file
        See Also:
        Constant Field Values
      • SEEK_CUR

        public static final int SEEK_CUR
        fseek whence argument to indicate that offset is from the current position of the file pointer
        See Also:
        Constant Field Values
      • SEEK_END

        public static final int SEEK_END
        fseek whence argument to indicate that offset is from the end of the file
        See Also:
        Constant Field Values
    • Constructor Detail

      • Clib

        public Clib()
    • Method Detail

      • fopen

        public static long fopen​(byte[] filename,
                                 byte[] mode)
        This method is a wrapper around fopen.
        Parameters:
        filename - the name of the file to open as a null-terminated ebcdic byte array
        mode - the open mode which must be a null-terminated ebcdic byte array. See the C library fopen documentation for more details
        Returns:
        the FILE stream pointer from fopen cast to a long
      • fopen

        public static long fopen​(String filename,
                                 String mode)
        This method is a slightly friendlier version of the native fopen call (the parameters are Strings rather than byte arrays otherwise everything is the same).
      • fgetpos

        public static int fgetpos​(long fp,
                                  int[] pos)
        This method is a wrapper around fgetpos. Here we make use of the knowledge that a C fpos_t on z/OS is actually an array of 8 ints.
        Parameters:
        fp - the stream obtained from an earlier call to fopen
        pos - this must be an array of 8 ints. The position indicator is stored in this array. The same array contents may be passed to a subsequent fsetpos call.
        Returns:
        the return code from the fgetpos call (zero if successful)
      • fsetpos

        public static int fsetpos​(long fp,
                                  int[] pos)
        This method is a wrapper around fsetpos.
        Parameters:
        fp - the stream obtained from an earlier call to fopen
        pos - this must be an array of 8 ints whose contents were obtained in a previous call to fgetpos.
        Returns:
        the return code from the fsetpos call (zero if successful)
      • fseek

        public static int fseek​(long fp,
                                long offset,
                                int whence)
        This method is a wrapper around fseek. (Note: this hasn't been tested for seeks over 2GB yet).
        Parameters:
        fp - the stream obtained from an earlier call to fopen
        offset - the offset to seek to
        whence - specifies where to seek from
        Returns:
        the return code from the fseek call (zero if successful)
      • fread

        public static int fread​(byte[] buf,
                                int size,
                                int count,
                                long fp)
        This method is a wrapper around fread.
        Parameters:
        buf - the buffer to contain the read data
        size - the size of each element
        count - the number of elements to read
        fp - the stream obtained from an earlier call to fopen
        Returns:
        the number of elements read
      • perror

        public static void perror​(byte[] prefix)
        This method is a wrapper around perror.
        Parameters:
        prefix - the message prefix as a null-terminated ebcdic byte array
      • perror

        public static void perror​(String prefix)
        Friendlier version of the native perror call that accepts a String parameter.