_Rreads() — Read the Same Record

Format

#include <recio.h>

_RIOFB_T *_Rreads(_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

Start of changeThe _Rreads() function reads the current 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 _Rreads() function locks the record positioned to unless __NO_LOCK is specified.End of change

If the current position in the file that is associated with fp has no record associated with it, the _Rreads() function will fail.

The _Rreads() function is not valid when the file is open for record blocking.

The following are valid parameters for the _Rreads() function.

buf
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
Specifies the number of bytes that are to be read and stored in buf. If locate mode is used, this parameter is ignored.
opts
Specifies the processing options for the file. Possible values are:
__DFT
If the file is opened for updating, then the record being read or positioned to is locked. The previously locked record will no longer be locked.
__NO_LOCK
Do not lock the record being positioned to.

The _Rreads() function is valid for database and DDM files.

Return Value

The _Rreads() function returns a pointer to the _RIOFB_T structure that is associated with fp. If the _Rreads() 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 also updated. If it is unsuccessful, the num_bytes field is set to a value less than size, and errno is changed.

The value of errno may be set to:

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.

See Table 12 and Table 14 for errno settings.

Example that uses _Rreads()

#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 last record.                                          */
    _Rreadl ( fp, NULL, 20, __DFT );
    printf ( "Last record: %10.10s\n", *(fp->in_buf) );
 
    /* Get the same record without locking it.                       */
    _Rreads ( fp, NULL, 20, __NO_LOCK);
    printf ( "Same record: %10.10s\n", *(fp->in_buf) );
 
    _Rclose ( fp );
}

Related Information



[ Top of Page | Previous Page | Next Page | Contents | Index ]