_Rupdate() — Update a Record

Format

#include <recio.h>

_RIOFB_T *_Rupdate(_RFILE *fp, void *buf, size_t size);

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 _Rupdate() function updates the record that is currently locked for update in the file that is specified by fp. The file must be open for update. A record is locked for update by reading or locating to it unless __NO_LOCK is specified on the read or locate operation. If the __NO_POSITION option is specified on a locate operation the record updated may not be the record currently positioned to. After the update operation, the updated record is no longer locked.

The number of bytes that are copied from buf to the record is the minimum of size and the record length of the file (move mode only). If size is greater than the record length, the data is truncated, and errno is set to ETRUNC. One complete record is always written to the file. If the size is less than the record length of the file, the remaining data in the record will be the original data that was read into the system buffer by the read that locked the record. If a locate operation locked the record, the remaining data will be what was in the system input buffer prior to the locate.

The _Rupdate() function can be used to update deleted records and key fields. A deleted record that is updated will no longer be marked as a deleted record. In both of these cases any keyed access paths defined for fp will be changed.

Note:
If locate mode is being used, _Rupdate() works on the data in the file's input buffer.

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

Return Value

The _Rupdate() function returns a pointer to the _RIOFB_T structure associated with fp. If the _Rupdate() function 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 fp is a display file, the sysparm field is updated. If the _Rupdate() function is unsuccessful, the num_bytes field is set to a value less than the size specified (move mode) or zero (locate mode). The errno value will also be changed.

The value of errno may be set to:

Value
Meaning
ENOTUPD
The file is not open for update operations.
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 _Rupdate()

#include <stdio.h>
#include <stdlib.h>
#include <recio.h>
 
int main(void)
{
    _RFILE   *in;
    char     new_purchase[21] = "PEAR      1002022244";
 
    /* Open the file for processing in keyed sequence.              */
 
    if ( (in = _Ropen("MYLIB/T1677RD4", "rr+, arrseq=N")) == NULL )
    {
        printf("Open failed\n");
        exit(1);
    };
 
    /* Update the first record in the keyed sequence.               */
 
    _Rlocate(in, NULL, 0, __FIRST);
    _Rupdate(in, new_purchase, 20);
 
    /* Force the end of data.                                       */
 
    _Rfeod(in);
 
    _Rclose(in);
}

Related Information



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