BPX1FCT (fcntl) example
The code for the first example duplicates the standard error file descriptor to a file descriptor greater than or equal to FILEDES2.
The code for the second example sets a shared byte
range lock. For the callable service, see fcntl (BPX1FCT, BPX4FCT) — Control open file descriptors.
For the data structure, see BPXYFCTL — Command values and flags for fcntl, BPXYBRLK — Map byte range lock request for fcntl, and BPXYOPNF — Map flag values for open.
AMODE 64 callers use BPX4FCT (fcntl) example.
* for 2nd parm F_DUPFD, F_DUPFD2 3rd parm file desc no..
* for 2nd parm F_GETFD, F_GETFL 3rd parm 0
* for 2nd parm F_SETFD 3rd parm BPXYFCTL
* for 2nd parm F_GETLK, F_SETLK, F_SETLKW 3rd parm BPXYBRLK
* for 2nd parm F_SETFL 3rd parm BPXYOPNF
SPACE ,
* Example 1 - duplicate file descriptor
MVC FILEDES2,=F'20' Get free file descriptor >= 20
SPACE ,
CALL BPX1FCT, General purpose file control +
(=A(STDERR_FILENO), Input: File descriptor +
=A(F_DUPFD), Input: Action, BPXYFCTL +
FILEDES2, Input: Argument #/0/FCTL/BRLK/OPNF+
RETVAL, Return value: 0, -1 or action +
RETCODE, Return code +
RSNCODE), Reason code +
VL,MF=(E,PLIST) ----------------------------------
SPACE ,
* Example 2 - duplicate file descriptor
MVC FILEDES2,=F'20' Get next higher file descriptor
LA R15,BRLK
ST R15,BRLKA
XC BRLK(BRLK#LENGTH),BRLK Null out BRLK
MVC L_TYPE,=AL2(F_RDLCK) Lock type = shared
MVC L_WHENCE,=AL2(SEEK_CUR) Whence = from current cursor
SPACE ,
CALL BPX1FCT, General purpose file control +
(=A(STDERR_FILENO), Input: File descriptor +
=A(F_SETLK), Input: Action, BPXYFCTL +
BRLKA, Input: Argument #/0/FCTL/BRLK/OPNF+
RETVAL, Return value: 0, -1 or action +
RETCODE, Return code +
RSNCODE), Reason code +
VL,MF=(E,PLIST) ----------------------------------