perror.c

来自「标准c库代码,可以应用于各个系统提供了大量的基本函数」· C语言 代码 · 共 81 行

C
81
字号
/*FUNCTION<<perror>>---print an error message on standard errorINDEX	perrorINDEX	_perror_rANSI_SYNOPSIS	#include <stdio.h>	void perror(char *<[prefix]>);	void _perror_r(void *<[reent]>, char *<[prefix]>);TRAD_SYNOPSIS	#include <stdio.h>	void perror(<[prefix]>)	char *<[prefix]>;	void _perror_r(<[reent]>, <[prefix]>)	char *<[reent]>;	char *<[prefix]>;DESCRIPTIONUse <<perror>> to print (on standard error) an error messagecorresponding to the current value of the global variable <<errno>>.Unless you use <<NULL>> as the value of the argument <[prefix]>, theerror message will begin with the string at <[prefix]>, followed by acolon and a space (<<: >>). The remainder of the error message is oneof the strings described for <<strerror>>.The alternate function <<_perror_r>> is a reentrant version.  Theextra argument <[reent]> is a pointer to a reentrancy structure.RETURNS<<perror>> returns no result.PORTABILITYANSI C requires <<perror>>, but the strings issued vary from oneimplementation to another.Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,<<lseek>>, <<read>>, <<sbrk>>, <<write>>.*/#include <stddef.h>#include <stdio.h>#include <string.h>void_DEFUN (_perror_r, (ptr, s),	struct _reent *ptr _AND	_CONST char *s){  char *error;  if (s != NULL && *s != '\0')    {      fputs (s, _stderr_r (ptr));      fputs (": ", _stderr_r (ptr));    }  if ((error = strerror (ptr->_errno)) != NULL)    fputs (error, _stderr_r (ptr));  fputc ('\n', _stderr_r (ptr));}#ifndef _REENT_ONLYvoid_DEFUN (perror, (s),	_CONST char *s){  _perror_r (_REENT, s);}#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?