dfmbuf_init: Initializing a z/TPFDF multiple LREC buffer
Use this function to initialize a storage area to be used as a z/TPFDF multiple LREC buffer.
Last updated
- Changed for PUT11.
- Added for PUT09.
Format
#include <cdf.h>
int dfmbuf_init(dft_buf *buf_ptr, dft_bufs buf_len);
int dfmbuf_init_v2(dft_buf *buf_ptr, dft_bufs buf_len); - buf_ptr
- is the pointer to the storage area to be used as a z/TPFDF multiple LREC buffer.
- buf_len
- specifies the size of the z/TPFDF multiple LREC buffer. The size must be greater than 256 for the dfmbuf_init function and greater than 512 for the For dfmbuf_init_v2 function. The size must include the space needed for the z/TPFDF multiple LREC buffer header and the LREC containers.
Entry requirements
The z/TPFDF multiple LREC buffer referenced by the buf_ptr parameter must be allocated before calling the dfmbuf_init function.
The z/TPFDF multiple LREC buffer referenced by the buf_ptr parameter must be allocated before calling the dfmbuf_init or dfmbuf_init_v2 function.
Return conditions
A value of 0 indicates successful completion.
Error return
A nonzero value is returned if an error occurred. For information about how to check the error indicators, see Identifying return indicators and errors.
Programming considerations
- After you completed processing all LRECs in a z/TPFDF multiple LREC buffer, if you want to remove the LREC containers and use the buffer again, you must call the dfmbuf_init or dfmbuf_init_v2 function to initialize the buffer again.
- This function results in the generation of inline code.
- When a buffer is initialized with header version 1 by using the dfmbuf_init function,
only the following z/TPFDF multiple LREC buffer functions
are supported to work with this buffer and you cannot work with storage
above 2 GB except where specifically noted in a parameter's description:
- dfmbuf_append
- dfmbuf_copy
- dfmbuf_getinfo
- dfmbuf_resize
- dfadd_multi
- dfred_multi
- When a buffer is initialized with header version 2 by using the dfmbuf_init_v2 function, all z/TPFDF multiple LREC buffer APIs are supported to work with this buffer and you can work with storage above 2 GB.
Examples
The following example reads matching
LRECs (using the active keys) from the input subfile into the z/TPFDF multiple LREC buffer.
As many LRECs as fits in the buffer are read. These LRECs are then
added from the buffer into the output subfile. This process is repeated
until all LRECs are processed.
/*----------------------------------------------------------------*
* Allocate DF MULTI BUFFER and initialize it *
*----------------------------------------------------------------*/
buffer_len = 5000; /* buffer length */
buffer_ptr = (dft_buf *)malloc(buffer_len); /* allocate buffer */
if (!buffer_ptr) {
wtopc_text("MALLOC ERROR");
exit(0);
}
if (dfmbuf_init_v2(buffer_ptr, buffer_len) != 0) {
wtopc_text("ERROR INITIALIZING DF MULTI BUFFER");
// (...) Free buffer and exit
}
// (...) Open the input subfile with the access parameters.
// (...) Set up and activate selection keys.
/*-----------------------------------------------------------------*
* Read as many LRECs as fits from the input subfile into the buffer*
*------------------------------------------------------------------*/
dfred_multi(input_sw_ptr, 0, buffer_ptr);
if (DFMULTI_NOTHING_READ(input_sw_ptr)){
wtopc_text("NO LRECS READ INTO BUFFER");
// (...) Free buffer and exit
}
while (DFMULTI_INCOMPLETE(input_sw_ptr)) {
/*----------------------------------------------------------------*
* Add the LRECs in the buffer to the output subfile *
*----------------------------------------------------------------*/
dfadd_multi(output_sw_ptr, 0, buffer_ptr);
if (DF_ER(output_sw_ptr)) { /* serious error occurred */
wtopc_text("SERIOUS TPFDF ERROR");
// (...) Free buffer, close all subfiles and exit
}
if (dfmbuf_init_v2(buffer_ptr, buffer_len) != 0) {
wtopc_text("BUFFER WAS NOT RE-INITIALIZED");
// (...) Free buffer, close all subfiles and exit
}
} /* end while loop */
/*-----------------------------------------------------------------*
* Add either the remaining or all the LRECs from the input subfile *
* in the buffer to the output subfile *
*-----------------------------------------------------------------*/
dfadd_multi(output_sw_ptr, 0, buffer_ptr);
free(buffer_ptr);
exit(0);Related information
- See the following functions for more information:
- For information about how to check the error indicators, see Identifying return indicators and errors.