_Rwrread() — Write and Read a Record (separate buffers)
Format
#include <recio.h>
_RIOFB_T *_Rwrread(_RFILE *fp, void *in_buf, size_t in_buf_size,
void *out_buf, size_t out_buf_size);
Language Level
ILE C Extension
Threadsafe
No
Description
The _Rwrread()
function
performs a write and then a read operation on the file that is specified
by fp. Separate buffers may be specified
for the input and output data. The minimum of size and the length
of the current record format determines the amount of data to be copied
between the system buffer and the buffers for both the write and read
parts of the operation. If out_buf_size is
greater than the record length of the current format, errno is set
to ETRUNC on the write part of the operation. If in_buf_size is
less than the length of the current record format, errno is set to
ETRUNC on the read part of the operation.
The _Rwrread()
function
is valid for display and ICF files.
Return Value
The _Rwrread()
function
returns a pointer to the _RIOFB_T structure that is associated with fp.
If the _Rwrread()
operation
is successful, the num_bytes field is set to the number of bytes transferred
from the system buffer to in_buf in the
read part of the operation (move mode) or the record length of the
file (locate mode).
- Value
- Meaning
- ENOTUPD
- The file is not open for update operations.
- ETRUNC
- Truncation occurred on an I/O operation.
- EIOERROR
- A non-recoverable I/O error occurred.
- EIORECERR
- A recoverable I/O error occurred.
Example
#include <stdio.h>
#include <recio.h>
#include <string.h>
#include <stdlib.h>
typedef struct {
char name[20];
char address[25];
} format1 ;
typedef struct {
char name[8];
char password[10];
} format2 ;
typedef union {
format1 fmt1;
format2 fmt2;
} formats ;
int main(void)
{
_RFILE *fp; /* File pointer */
_RIOFB_T *rfb; /*Pointer to the file's feedback structure */
formats buf, in_buf, out_buf; /* Buffers to hold data */
/* Open the device file. */
if (( fp = _Ropen ( "MYLIB/T1677RD2", "ar+" )) == NULL )
{
printf ( "Could not open file\n" );
exit ( 1 );
}
_Rpgmdev ( fp,"DEVICE2" );/* Change the default program device. */
/* Replace with actual device name. */
_Rformat ( fp,"FORMAT2" ); /* Set the record format for the */
/* display file. */
rfb = _Rwrite ( fp, "", 0 ); /* Set up the display. */
rfb = _Rwriterd ( fp, &buf, sizeof(buf) );
rfb = _Rwrread ( fp, &in_buf, sizeof(in_buf), &out_buf,
sizeof(out_buf ));
/* Continue processing. */
_Rclose ( fp );
}