_Rreadnc () -读取子文件中的下一个已更改记录

格式

#include <recio.h>

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

语言级别

ILE C 扩展

线程安全

False

描述

_Rreadnc() 函数从与 fp关联的子文件中的当前位置读取下一个已更改的记录。 从屏幕读取的数据的最小 大小 将从系统缓冲区复制到 buf

以下是 _Rreadnc() 函数的有效参数。
buf
指向要存储所读取数据的缓冲区。 如果使用了定位方式,那么此参数必须设置为 NULL。
大小
指定要读取并存储在 buf中的字节数。

_Rreadnc() 函数对子文件有效。

返回值

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

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

示例

#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);
}

相关信息