clearerr_sclearerr_s

重置流的错误指示符。Resets the error indicator for a stream. 这是 clearerr 版本,具有 CRT 中的安全功能中所述的安全增强功能。This is a version of clearerr with security enhancements as described in Security Features in the CRT.

语法Syntax

errno_t clearerr_s(  
   FILE *stream   
);  

参数Parameters

stream
指向 FILE 结构的指针Pointer to FILE structure

返回值Return Value

如果成功,则返回零;如果 stream 为 NULL,则返回 EINVALZero if successful; EINVAL if stream is NULL.

备注Remarks

clearerr_s 函数为 stream 重置错误指示符和文件尾指示符。The clearerr_s function resets the error indicator and end-of-file indicator for stream. 不会自动清除错误指示符;设置指定流的错误指示符后,在调用 clearerr_sclearerrfseekfsetposrewind 前,将继续在该流上执行操作以返回错误值。Error indicators are not automatically cleared; once the error indicator for a specified stream is set, operations on that stream continue to return an error value until clearerr_s, clearerr, fseek, fsetpos, or rewind is called.

如果 stream 为 NULL,则调用无效的参数处理程序,如参数验证中所述。If stream is NULL, the invalid parameter handler is invoked, as described in Parameter Validation. 如果允许执行继续,则该函数将 errno 设置为 EINVAL 并返回 EINVALIf execution is allowed to continue, this function sets errno to EINVAL and returns EINVAL.

惠?Requirements

例程所返回的值Routine 必需的标头Required header
clearerr_s <stdio.h><stdio.h>

有关其他兼容性信息,请参见“简介”中的 兼容性For additional compatibility information, see Compatibility in the Introduction.

示例Example

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

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

请参阅See Also

错误处理 Error Handling
流 I/O Stream I/O
clearerr clearerr
_eof _eof
feof feof
ferror ferror
perror、_wperrorperror, _wperror