_Rwrited() — Write a Record Directly

Format

#include <recio.h>

_RIOFB_T *_Rwrited(_RFILE *fp, void *buf, size_t size, unsigned 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

The _Rwrited() function writes a record to the file associated with fp at the position specified by rrn. The _Rwrited() function will only write over deleted records. The number of bytes 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 if the operation is successful.

The _Rwrited() function has no effect on the position of the file for a read operation.

The _Rwrited() function is valid for database, DDM and subfiles.

Return Value

The _Rwrited() function returns a pointer to the _RIOFB_T structure associated with fp. If the _Rwrited() operation is successful the num_bytes field is set to the number of bytes transferred from the user's buffer to the system buffer (move mode) or the record length of the file (locate mode). The rrn field is updated. If 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 specified (move mode) or zero (locate mode) and errno is changed.

The value of errno may be set to:

Value
Meaning
ENOTWRITE
The file is not open for write 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 _Rwrited()

#include <stdio.h>
#include <stdlib.h>
#include <recio.h>
#define LEN          10
#define NUM_RECS     20
#define SUBFILENAME  "MYLIB/T1677RD6"
#define PFILENAME    "MYLIB/T1677RDB"
typedef struct  {
    char name[LEN];
    char phone[LEN];
} pf_t;
#define RECLEN sizeof(pf_t)
void init_subfile(_RFILE *, _RFILE *);
int main(void)
{
    _RFILE           *pf;
    _RFILE           *subf;
 /* Open the subfile and the physical file.       */
    if ((pf = _Ropen(PFILENAME, "rr")) == NULL)  {
        printf("can't open file %s\n", PFILENAME);
        exit(1);
    }
    if ((subf = _Ropen(SUBFILENAME, "ar+")) == NULL)  {
        printf("can't open file %s\n", SUBFILENAME);
        exit(2);
    }
 /* Initialize the subfile with records           *
  * from the physical file.                       */
    init_subfile(pf, subf);
 /* Write the subfile to the display by writing   *
  * a record to the subfile control format.       */
     _Rformat(subf, "SFLCTL");
     _Rwrite(subf, "", 0);
     _Rreadnc(subf, "", 0);
 /* Close the physical file and the subfile.      */
    _Rclose(pf);
    _Rclose(subf);
}
void init_subfile(_RFILE *pf, _RFILE *subf)
    {
        _RIOFB_T      *fb;
        int           i;
        pf_t          record;
 /* Select the subfile record format.             */
        _Rformat(subf, "SFL");
        for (i = 1; i <= NUM_RECS; i++)  {
            fb = _Rreadn(pf, &record, RECLEN, __DFT);
            if (fb->num_bytes != RECLEN)  {
            printf("%d\n", fb->num_bytes);
            printf("%d\n", RECLEN);
                printf("error occurred during read\n");
                exit(3);
            }
            fb = _Rwrited(subf, &record, RECLEN, i);
            if (fb->num_bytes != RECLEN)  {
                printf("error occurred during write\n");
                exit(4);
            }
        }
    }

Related Information



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