_Rreadf() — Read the First Record
Format
#include <recio.h>
_RIOFB_T *_Rreadf (_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 _Rreadf()
function reads the first record in the access path that is currently being used for the file specified by fp. The access path may be keyed sequence or arrival sequence. If the file is opened for updating, the _Rreadf()
function locks the first record unless __NO_LOCK is specified. Up to size number of bytes are copied from the record into buf (move mode only).
_Rreadf()
function. - buf
- This parameter points to the buffer where the data that is read is to be stored. If locate mode is used, this parameter must be set to NULL.
- size
- This parameter specifies the number of bytes that are to be read and stored in buf. If locate mode is used, this parameter is ignored.
- opts
- This parameter specifies the processing and access options for the file. The possible options are:
- __DFT
- If the file is opened for updating, then the record being read or positioned to is locked for update. The previously locked record will no longer be locked.
- __NO_LOCK
- Does not lock the record being positioned to.
The _Rreadf()
function is valid for database and DDM files.
Return Value
The _Rreadf()
function returns a pointer to the _RIOFB_T structure that is specified by fp. If the _Rreadf()
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 record blocking is taking place, the blk_count and blk_filled_by fields are updated. The num_bytes field is set to EOF if the file is empty. If it is unsuccessful, the num_bytes field is set to a value less than size, and errno is changed.
- Value
- Meaning
- ENOTREAD
- The file is not open for read 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 <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 first record. */
_Rdelete ( fp );
_Rclose ( fp );
}
Related Information
- _Rreadd() — Read a Record by Relative Record Number
- _Rreadindv() — Read from an Invited Device
- _Rreadk() — Read a Record by Key
- _Rreadl() — Read the Last Record
- _Rreadn() — Read the Next Record
- _Rreadnc() — Read the Next Changed Record in a Subfile
- _Rreadp() — Read the Previous Record
- _Rreads() — Read the Same Record