clearerr_s

ストリームのエラー インジケーターをリセットします。 この関数は、「CRTclearerrセキュリティ機能」の説明に従って、セキュリティが強化されたバージョンです。

構文

errno_t clearerr_s(
   FILE *stream
);

パラメーター

stream
FILE 構造体へのポインター

戻り値

成功した場合は 0。 EINVAL if stream is NULL.

解説

clearerr_s 関数は、stream のエラー インジケーターとファイルの終わりインジケーターをリセットします。 エラー インジケーターは自動的にクリアされません。指定したストリームのエラー インジケーターが設定されると、そのストリームに対する操作は、呼び出されるまでclearerr_sエラー値をfsetposclearerrfseekrewind返し続けます。

有効な場合streamNULL、「パラメーターの検証」の説明に従って、無効なパラメーター ハンドラーが呼び出されます。 実行の継続が許可された場合、この関数は errnoEINVAL に設定し、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();
      }
   }
}

Input

n

出力

Write error: Bad file descriptor
Will input cause an error? n

関連項目

エラー処理
ストリーム入出力
clearerr
_eof
feof
ferror
perror, _wperror