_Rreadd() — Read a Record by Relative Record Number

Format

#include <recio.h>

_RIOFB_T *_Rreadd (_RFILE *fp, void *buf, size_t size,
                            int opts, long rrn);

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 _Rreadd() function reads the record that is specified by rrn in the arrival sequence access path for the file that is associated with fp. If the file is opened for updating, the _Rreadd() function locks the record specified by the rrn unless __NO_LOCK is specified. If the file is a keyed file, the keyed access path is ignored. Up to size number of bytes are copied from the record into buf (move mode only).End of change

The following parameters are valid for the _Rreadd() 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.
rrn
The relative record number of the record to be read.
opts
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 is locked for update. The previously locked record will no longer be locked.
__NO_LOCK
Does not lock the record being positioned to.

The _Rreadd() function is valid for database, DDM and display (subfiles) files.

Return Value

The _Rreadd() function returns a pointer to the _RIOFB_T structure associated with fp. If the _Rreadd() 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). If blkrcd=Y and riofb=Y are specified, the blk_count and the blk_filled_by fields of the _RIOFB_T structure are updated. The key and rrn fields are also updated. If the file associated with fp is a display file, the sysparm field is updated. If it is unsuccessful, the num_bytes field is set to a value less than size and errno will be 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 _Rreadd()

#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 second record.                                        */
    _Rreadd ( fp, NULL, 20, __DFT, 2 );
    printf ( "Second record: %10.10s\n", *(fp->in_buf) );
 
    _Rclose ( fp );
}

Related Information



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