_eof
更新 : 2007 年 11 月
ファイルの終端 (EOF) をチェックします。
int _eof(
int fd
);
パラメータ
- fd
開いているファイルを参照するファイル記述子。
戻り値
_eof は、現在の位置がファイルの終端の場合に 1 を返します。それ以外の場合には 0 を返します。戻り値 –1 はエラーを示します。この場合、「パラメータの検証」に説明されているように、無効なパラメータ ハンドラが呼び出されます。実行の継続が許可された場合、errno が EBADF に設定されます。これは、無効なファイル記述子を示します。
解説
_eof 関数は、fd に関連付けられたファイルの終端に到達しているかどうかを判別します。
必要条件
関数 |
必須ヘッダー |
オプション ヘッダー |
---|---|---|
_eof |
<io.h> |
<errno.h> |
互換性の詳細については、「C ランタイム ライブラリ」の「互換性」を参照してください。
使用例
// crt_eof.c
// This program reads data from a file
// ten bytes at a time until the end of the
// file is reached or an error is encountered.
//
#include <io.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <share.h>
int main( void )
{
int fh, count, total = 0;
char buf[10];
if( _sopen_s( &fh, "crt_eof.txt", _O_RDONLY, _SH_DENYNO, 0 ) )
{
perror( "Open failed");
exit( 1 );
}
// Cycle until end of file reached:
while( !_eof( fh ) )
{
// Attempt to read in 10 bytes:
if( (count = _read( fh, buf, 10 )) == -1 )
{
perror( "Read error" );
break;
}
// Total actual bytes read
total += count;
}
printf( "Number of bytes read = %d\n", total );
_close( fh );
}
入力 : crt_eof.txt
This file contains some text.
出力
Number of bytes read = 29
.NET Framework の相当するアイテム
適用できません。標準 C 関数を呼び出すには、PInvoke を使用します。詳細については、「プラットフォーム呼び出しの例」を参照してください。