_Rwrread () -写入和读取记录 (单独的缓冲区)

格式

#include <recio.h>

_RIOFB_T *_Rwrread(_RFILE *fp, void *in_buf, size_t in_buf_size,
                   void *out_buf, size_t out_buf_size);

语言级别

ILE C 扩展

线程安全

False

描述

_Rwrread() 函数对 fp指定的文件执行写操作,然后执行读操作。 可以为输入和输出数据指定单独的缓冲区。 当前记录格式的最小大小和长度决定了要在系统缓冲区和缓冲区之间为操作的写和读部分复制的数据量。 如果 out_buf_size 大于当前格式的记录长度,那么会在操作的写部分将 errno 设置为 ETRUNC。 如果 in_buf_size 小于当前记录格式的长度,那么在操作的读部分将 errno 设置为 ETRUNC。

_Rwrread() 函数对显示和 ICF 文件有效。

返回值

_Rwrread() 函数返回指向与 fp关联的 _RIOFB_T 结构的指针。 如果 _Rwrread() 操作成功,那么 num_bytes 字段将设置为在操作的读取部分 (移动方式) 或文件的记录长度 (定位方式) 中从系统缓冲区传输到 in_buf 的字节数。

errno 的值可以设置为:
含义
ENOTUPD
文件未打开,无法执行更新操作。
ETRUNC
在 I/O 操作上发生截断。
EIOERROR
发生了不可恢复的I/O错误。
EIORECERR
发生了可恢复的I/O错误。
请参阅 表 1表 1 以获取 errno 设置。

示例

#include <stdio.h>
#include <recio.h>
#include <string.h>
#include <stdlib.h>
 
typedef struct {
    char name[20];
    char address[25];
} format1 ;
 
typedef struct {
    char name[8];
    char password[10];
} format2 ;
 
typedef union {
    format1 fmt1;
    format2 fmt2;
} formats ;
 
int main(void)
{
    _RFILE   *fp; /* File pointer                                     */
    _RIOFB_T *rfb; /*Pointer to the file's feedback structure         */
    formats  buf, in_buf, out_buf; /* Buffers to hold data            */
 
    /* Open the device file.                                          */
    if (( fp = _Ropen ( "MYLIB/T1677RD2", "ar+" )) == NULL )
    {
        printf ( "Could not open file\n" );
        exit ( 1 );
    }
 
    _Rpgmdev ( fp,"DEVICE2" );/* Change the default program device.   */
                              /* Replace with actual device name.     */
 
    _Rformat ( fp,"FORMAT2" );   /* Set the record format for the     */
                                 /* display file.                     */
 
    rfb = _Rwrite ( fp, "", 0 );   /* Set up the display.             */
    rfb = _Rwriterd ( fp, &buf, sizeof(buf) );
 
    rfb = _Rwrread ( fp, &in_buf, sizeof(in_buf), &out_buf,
                     sizeof(out_buf ));
 
    /* Continue processing.                                           */
 
    _Rclose ( fp );
}

相关信息