ストリームのエラー インジケーターをリセットします。 この関数は、「CRT のセキュリティ機能説明されているように、セキュリティが強化されたclearerrのバージョン。
構文
errno_t clearerr_s(
FILE *stream
);
パラメーター
stream
FILE 構造体へのポインター
戻り値
成功した場合は 0。streamがNULLされているかどうかをEINVALします。
解説
clearerr_s 関数は、stream のエラー インジケーターとファイルの終わりインジケーターをリセットします。 エラー インジケーターは自動的にクリアされません。指定したストリームのエラー インジケーターが設定されると、そのストリームに対する操作は、 clearerr_s、 clearerr、 fseek、 fsetpos、または rewind が呼び出されるまでエラー値を返し続けます。
stream が NULL の場合は、「パラメーターの検証」で説明されているように、無効なパラメーター ハンドラーが呼び出されます。 実行の継続が許可された場合、この関数は errno を EINVAL に設定し、EINVAL を返します。
既定では、この関数のグローバル状態の適用対象は、アプリケーションになります。 この動作を変更するには、「CRT でのグローバル状態」を参照してください。
要件
| ルーチンによって返される値 | 必須ヘッダー |
|---|---|
clearerr_s |
<stdio.h> |
互換性の詳細については、「 Compatibility」を参照してください。
例
// crt_clearerr_s.c
// This program creates an error
// on the standard input stream, then clears
// it so that future reads won't fail.
#include <stdio.h>
int main( void )
{
int c;
errno_t err;
// Create an error by writing to standard input.
putc( 'c', stdin );
if( ferror( stdin ) )
{
perror( "Write error" );
err = clearerr_s( stdin );
if (err != 0)
{
abort();
}
}
// See if read causes an error.
printf( "Will input cause an error? " );
c = getc( stdin );
if( ferror( stdin ) )
{
perror( "Read error" );
err = clearerr_s( stdin );
if (err != 0)
{
abort();
}
}
}
入力
n
出力
Write error: Bad file descriptor
Will input cause an error? n