Class Clib
java.lang.Object
com.ibm.dtfj.corereaders.zos.util.Clib
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
Modifier and TypeFieldDescriptionstatic final int
fseek whence argument to indicate that offset is from the current position of the file pointerstatic final int
fseek whence argument to indicate that offset is from the end of the filestatic final int
fseek whence argument to indicate that offset is from the beginning of the file -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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
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
Friendlier version of the native perror call that accepts a String parameter.
-
Field Details
-
SEEK_SET
public static final int SEEK_SETfseek whence argument to indicate that offset is from the beginning of the file- See Also:
-
SEEK_CUR
public static final int SEEK_CURfseek whence argument to indicate that offset is from the current position of the file pointer- See Also:
-
SEEK_END
public static final int SEEK_ENDfseek whence argument to indicate that offset is from the end of the file- See Also:
-
-
Constructor Details
-
Clib
public Clib()
-
-
Method Details
-
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 arraymode
- 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
-
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 fopenpos
- 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 fopenpos
- 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 fopenoffset
- the offset to seek towhence
- 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 datasize
- the size of each elementcount
- the number of elements to readfp
- 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
Friendlier version of the native perror call that accepts a String parameter.
-