clearerr_s

重置流的错误指示符。 此函数的版本是 clearerr,具有 CRT 中的安全功能中所述的安全增强功能。

语法

errno_t clearerr_s(
   FILE *stream
);

参数

stream
指向 FILE 结构的指针

返回值

如果成功,则返回零;如果 streamNULL,则返回 EINVAL

注解

clearerr_s 函数为 stream 重置错误指示符和文件尾指示符。 错误指示符不会自动清除;设置指定流的错误指示符后,在调用 clearerr_sclearerrfseekfsetposrewind 前,将继续在该流上执行操作以返回错误值。

如果 streamNULL,则会调用无效的参数处理程序,如参数验证中所述。 如果允许执行继续,则该函数将 errno 设置为 EINVAL 并返回 EINVAL

默认情况下,此函数的全局状态范围限定为应用程序。 若要更改此行为,请参阅 CRT 中的全局状态

要求

例程 必需的标头
clearerr_s <stdio.h>

有关兼容性的详细信息,请参阅 兼容性

示例

// 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

另请参阅

错误处理
流 I/O
clearerr
_eof
feof
ferror
perror_wperror