Format
#include <recio.h>
_RIOFB_T *_Rreadn (_RFILE *fp, void *buf, size_t size, int opts);
Language Level: ILE C Extension
Threadsafe: Yes. However, if the file pointer is passed among threads, the I/O feedback area is shared among those threads.
Description
The _Rreadn() function reads the next record in the access path that is currently being used for the file that is associated with fp. The access path may be keyed sequence or arrival sequence. Up to size number of bytes are copied from the record into buf (move mode only). If the file is opened for updating, the _Rreadn() function locks the record positioned to unless __NO_LOCK is specified.
If the file associated with fp is opened for sequential member processing and the current record position is the last record of any member in the file except the last, _Rreadn() will read the first record in the next member of the file.
If an _Rlocate() operation positioned to a record specifying the __PRIOR option, _Rreadn() will read the record positioned to by the _Rlocate() operation.
If the file is open for record blocking and a call to _Rreadp() has filled the block, the _Rreadn() function is not valid if there are records remaining in the block. You can check the blk_count in _RIOFB_T to see if there are any remaining records.
The following are valid parameters for the _Rreadn() function.
The _Rreadn() function is valid for all types of files except printer files.
Return Value
The _Rreadn() function returns a pointer to the _RIOFB_T structure that is associated with fp. If the _Rreadn() operation is successful the num_bytes field is set to the number of bytes transferred from the system buffer to the user's buffer (move mode) or the record length of the file (locate mode). The key and rrn fields are updated. If the file that is associated with fp is a display file, the sysparm field is also updated. If record blocking is taking place, the blk_count and the blk_filled_by fields of the _RIOFB_T structure are updated. If attempts are made to read beyond the last record in the file, the num_bytes field is set to EOF. If it is unsuccessful, the num_bytes field is set to a value less than size, and errno is changed. If you are using device files and specify zero as the size, check errno to determine if the function was successful.
The value of errno may be set to:
See Table 12 and Table 14 for errno settings.
Example that uses _Rreadn()
#include <stdio.h>
#include <stdlib.h>
#include <recio.h>
int main(void)
{
_RFILE *fp;
_XXOPFB_T *opfb;
/* Open the file for processing in arrival sequence. */
if (( fp = _Ropen ( "MYLIB/T1677RD1", "rr+, arrseq=Y" )) == NULL )
{
printf ( "Open failed\n" );
exit ( 1 );
}
/* Get the library and file names of the file opened. */
opfb = _Ropnfbk ( fp );
printf ( "Library: %10.10s\nFile: %10.10s\n",
opfb->library_name,
opfb->file_name);
/* Get the first record. */
_Rreadf ( fp, NULL, 20, __DFT );
printf ( "First record: %10.10s\n", *(fp->in_buf) );
/* Delete the second record. */
_Rreadn ( fp, NULL, 20, __DFT );
_Rdelete ( fp );
_Rclose ( fp );
}
Related Information