_Rreadindv () -从受邀设备读取

格式

#include <recio.h>

_RIOFB_T *_Rreadindv(_RFILE *fp, void *buf, size_t size, int opts);

语言级别

ILE C 扩展

线程安全

False

描述

_Rreadindv() 函数从受邀设备读取数据。

以下是 _Rreadindv() 函数的有效参数。
buf
指向要存储所读取数据的缓冲区。 如果使用了定位方式,那么此参数必须设置为 NULL。
大小
指定要读取并存储在 buf中的字节数。 如果使用了定位方式,那么将忽略此参数。
选项
指定文件的处理选项。 可能的值包括:
__DFT
如果打开文件以进行更新,那么将锁定正在读取或定位到的记录。 否则,将忽略该选项。

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

返回值

_Rreadindv() 函数返回指向与 fp关联的 _RIOFB_T 结构的指针。 如果 _Rreadindv() 函数成功,那么 num_bytes 字段将设置为从系统缓冲区传输到用户缓冲区的字节数 (移动方式) 或文件的记录长度 (定位方式)。 还会更新 sysparm 和 rrn (用于子文件) 字段。 如果文件为空,那么 num_bytes 字段设置为 EOF。 如果 _Rreadindv() 函数不成功,那么 num_bytes 字段将设置为小于 size 值的值,并且将更改 errno。

errno 的值可以设置为:
含义
阅读
未打开该文件以执行读操作。
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 */
    _XXIOFB_T *iofb;      /* Pointer to the file's feedback area      */
    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 );
    }
    _Racquire ( fp,"DEVICE1" );    /* Acquire another device. Replace */
                                   /* with actual device name.        */
    _Rformat ( fp,"FORMAT1" );     /* Set the record format for the   */
                                   /* display file.                   */
    rfb = _Rwrite ( fp, "", 0 );   /* Set up the display.             */
    _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 ));
    _Rreadindv ( fp, &buf, sizeof(buf), __DFT );
                                  /* Read from the first device that  */
                                  /* enters data - device becomes     */
                                  /* default program device.          */
    /* Determine which terminal responded first.                      */
    iofb = _Riofbk ( fp );
    if ( !strncmp ( "FORMAT1  ", iofb -> rec_format, 10 ))
    {
        _Rrelease ( fp, "DEVICE1" );
    }
    else
    {
        _Rrelease(fp, "DEVICE2" );
    }
    /* Continue processing.                                           */
    printf ( "Data displayed is %45.45s\n", &buf);
    _Rclose ( fp );
}

相关信息