文章目录

  • man 3 perror
  • man 3posix perror
  • 20220723 C语言 | perror函数使用详解

man 3 perror

PERROR(3)                                                            Linux Programmer's Manual                                                           PERROR(3)NAMEperror - print a system error message //打印系统错误信息SYNOPSIS#include <stdio.h>void perror(const char *s);#include <errno.h>const char * const sys_errlist[];int sys_nerr;int errno;       /* Not really declared this way; see errno(3) */Feature Test Macro Requirements for glibc (see feature_test_macros(7)):sys_errlist, sys_nerr: _BSD_SOURCEDESCRIPTIONThe perror() function produces a message on standard error describing the last error encountered during a call to a system or library function.//perror() 函数在标准错误上生成一条消息,描述在调用系统或库函数期间遇到的最后一个错误。First (if s is not NULL and *s is not a null byte ('\0')), the argument string s is printed, followed by a colon and a blank.  Then an error message corre‐sponding to the current value of errno and a new-line.//首先(如果 s 不是 NULL 并且 *s 不是空字节 ('\0')),则打印参数字符串 s,后跟一个冒号和一个空格。 //然后是与 errno 的当前值相对应的错误消息和换行符。To be of most use, the argument string should include the name of the function that incurred the error.//最常用的是,参数字符串应该包含导致错误的函数的名称。The global error list sys_errlist[], which can be indexed by errno, can be used to obtain the error message without the newline.  The largest message  num‐ber  provided in the table is sys_nerr-1.  Be careful when directly accessing this list, because new error values may not have been added to sys_errlist[].The use of sys_errlist[] is nowadays deprecated.//可以通过errno索引的全局错误列表sys_errlist[],可以用来获取不带换行符的错误信息。 //表中提供的最大消息编号是 sys_nerr-1。 //直接访问此列表时要小心,因为新的错误值可能尚未添加到 sys_errlist[]。//现在不推荐使用 sys_errlist[] 。When a system call fails, it usually returns -1 and sets the variable errno to a value  describing  what  went  wrong.   (These  values  can  be  found  in<errno.h>.)   Many  library functions do likewise.  The function perror() serves to translate this error code into human-readable form.  Note that errno isundefined after a successful sysme call or library function call: this call may well change this variable, even though it succeeds, for example because  itinternally  used  some  other  library function that failed.  Thus, if a failing call is not immediately followed by a call to perror(), the value of errnoshould be saved.//当系统调用失败时,它通常会返回 -1 并将变量 errno 设置为描述错误原因的值。 //(这些值可以在 <errno.h> 中找到。)许多库函数也是如此。 //函数 perror() 用于将此错误代码转换为人类可读的形式。 //请注意,在成功的系统调用或库函数调用之后,errno 是未定义的:此调用很可能会更改此变量,即使它成功,例如因为它在内部使用了其他失败的库函数。 //因此,如果调用失败后没有立即调用 perror(),则应保存 errno 的值。ATTRIBUTESFor an explanation of the terms used in this section, see attributes(7).┌──────────┬───────────────┬─────────────────────┐│Interface │ Attribute     │ Value               │├──────────┼───────────────┼─────────────────────┤│perror()  │ Thread safety │ MT-Safe race:stderr │└──────────┴───────────────┴─────────────────────┘CONFORMING TOperror(), errno: POSIX.1-2001, POSIX.1-2008, C89, C99, 4.3BSD.The externals sys_nerr and sys_errlist derive from BSD, but are not specified in POSIX.1.NOTESThe externals sys_nerr and sys_errlist are defined by glibc, but in <stdio.h>.SEE ALSOerr(3), errno(3), error(3), strerror(3)COLOPHONThis page is part of release 4.04 of the Linux man-pages project.  A description of the project, information about reporting bugs, and the  latest  versionof this page, can be found at http://www.kernel.org/doc/man-pages/.2015-07-23                                                                   PERROR(3)Manual page perror(3) line 22/63 (END) (press h for help or q to quit)

man 3posix perror

PERROR(3POSIX)                                                       POSIX Programmer's Manual                                                      PERROR(3POSIX)PROLOGThis  manual  page is part of the POSIX Programmer's Manual.  The Linux implementation of this interface may differ (consult the corresponding Linux manualpage for details of Linux behavior), or the interface may not be implemented on Linux.//本手册页是 POSIX 程序员手册的一部分。 //此接口的 Linux 实现可能不同(有关 Linux 行为的详细信息,请参阅相应的 Linux 手册页),或者该接口可能未在 Linux 上实现。NAMEperror — write error messages to standard error   //将错误消息写入标准错误SYNOPSIS#include <stdio.h>void perror(const char *s);DESCRIPTIONThe functionality described on this reference page is aligned with the ISO C standard. Any conflict between the requirements described here and  the  ISO Cstandard is unintentional. This volume of POSIX.1‐2008 defers to the ISO C standard.//本参考页上描述的功能符合 ISO C 标准。 //此处描述的要求与 ISO C 标准之间的任何冲突都是无意的。 //本卷 POSIX.1-2008 遵循 ISO C 标准。The  perror()  function  shall  map the error number accessed through the symbol errno to a language-dependent error message, which shall be written to thestandard error stream as follows://perror() 函数应将通过符号 errno 访问的错误号映射到与语言相关的错误消息,//该错误消息应写入标准错误流,如下所示:*  First (if s is not a null pointer and the character pointed to by s is not the null byte), the string pointed to by s  followed  by  a  <colon>  and  a<space>.//首先(如果 s 不是空指针并且 s 指向的字符不是空字节),//s 指向的字符串后跟 <colon> 和 <space>。(接冒号和空格(": "))*  Then an error message string followed by a <newline>.//然后是一个错误消息字符串,后跟一个 <换行符>。The contents of the error message strings shall be the same as those returned by strerror() with argument errno.//错误消息字符串的内容应与带参数 errno 的 strerror() 返回的内容相同。The  perror()  function  shall  mark  for update the last data modification and last file status change timestamps of the file associated with the standarderror stream at some time between its successful completion and exit(), abort(), or the completion of fflush() or fclose() on stderr.//perror() 函数应在其成功完成和 exit()、abort() 或 fflush( ) 或 stderr 上的 fclose()。The perror() function shall not change the orientation of the standard error stream.//perror() 函数不应改变标准错误流的方向。On error, perror() shall set the error indicator for the stream to which stderr points, and shall set errno to indicate the error.//发生错误时,perror() 应为 stderr 指向的流设置错误指示符,并应设置 errno 以指示错误。Since no value is returned, an application wishing to check for error situations should  call  clearerr(stderr)  before  calling  perror(),  then  if  fer‐ror(stderr) returns non-zero, the value of errno indicates which error occurred.//由于没有返回值,因此希望检查错误情况的应用程序应在调用 perror() 之前调用 clearerr(stderr),然后如果 fer-ror(stderr) 返回非零,则 errno 的值指示发生了哪个错误。RETURN VALUEThe perror() function shall not return a value.//perror() 函数不应返回值。ERRORSRefer to fputc().The following sections are informative.EXAMPLESPrinting an Error Message for a FunctionThe  following example replaces bufptr with a buffer that is the necessary size. If an error occurs, the perror() function prints a message and the programexits.//以下示例将 bufptr 替换为必要大小的缓冲区。 //如果发生错误,perror() 函数会打印一条消息并退出程序。#include <stdio.h>#include <stdlib.h>...char *bufptr;size_t szbuf;...if ((bufptr = malloc(szbuf)) == NULL) {perror("malloc"); exit(2);}...APPLICATION USAGEApplication writers may prefer to use alternative interfaces instead of perror(), such as strerror_r() in combination with fprintf().//应用程序编写者可能更喜欢使用替代接口而不是 perror(),例如 strerror_r() 与 fprintf() 的组合。RATIONALENone.FUTURE DIRECTIONSNone.SEE ALSOfprintf(), fputc(), psiginfo(), strerror()The Base Definitions volume of POSIX.1‐2008, <stdio.h>COPYRIGHTPortions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology  --  PortableOperating  System  Interface  (POSIX),  The Open Group Base Specifications Issue 7, Copyright (C) 2013 by the Institute of Electrical and Electronics Engi‐neers, Inc and The Open Group.  (This is POSI

参考文章1:C 库函数 - perror()

参考文章2:perror()函数的使用

20220723 C语言 | perror函数使用详解

参考文章:C语言 | perror函数使用详解

linux C语言perror()函数(将错误消息写入标准错误)(把一个描述性错误消息输出到标准错误 stderr。首先输出自定义字符串 str,后跟一个冒号,然后是一个空格)相关推荐

  1. linux下 C语言perror函数的作用

    头文件 #include<stdio.h> #include<stdlib.h>// 注意 不可以掉了这个头文件,perror是包含在这个文件里的//编辑本段perror表头文 ...

  2. linux c语言 select函数用法

    原文地址:点击打开链接 linux c语言 select函数用法 Select在Socket编程中还是比较重要的,可是对于初学Socket的人来说都不太爱用Select写程序,他们只是习惯写诸如 co ...

  3. linux C语言access()函数(检查用户对文件的权限)(判断文件是否存在)

    文章目录 man 2 access 20220601 不知道上面所说的pathname的符号链接取消引用是什么意思 man 2 access ACCESS(2) Linux Programmer's ...

  4. linux c语言内核函数手册,Linux C函数实例速查手册

    函数学习目录: 第1章 初级I/O函数 1.1 close函数:关闭已经打开的文件 1.2 creat函数:创建一个文件 1.3 dup函数:复制文件描述符 1.4 dup2函数:复制文件描述符到指定 ...

  5. linux C语言 常用函数(系统调用等) 持续更新

    文章目录 系统调用是什么 Linux C语言 文件部分系统调用 1.open()打开文件 2.close()关闭文件 3.mkdir()创建目录 4.access()判断路径是否存在 5.fcntl( ...

  6. C语言 | perror函数使用详解

    1024G 嵌入式资源大放送!包括但不限于C/C++.单片机.Linux等.关注微信公众号[嵌入式大杂烩],回复1024,即可免费获取! 我们大多都使用printf来打印一些信息,其它的接口都比较少用 ...

  7. linux下perror函数,Linux学习 之 perror函数,strerror函数,errno

    #include // void perror(const char *msg); #include // char *strerror(int errnum); #include //errno e ...

  8. linux c语言sleep函数的头文件,C语言中的pause()函数和alarm()函数以及sleep()函数

    C语言pause()函数:让进程暂停直到信号出现头文件: #include 定义函数: int pause(void); 函数说明:pause()会令目前的进程暂停(进入睡眠状态), 直到被信号(si ...

  9. linux C语言mkfifo()函数 mkfifoat()函数(制作一个 FIFO 特殊文件(命名管道))

    文章目录 man 3 mkfifo 20220605 示例 man 3 mkfifo MKFIFO(3) Linux Programmer's Manual MKFIFO(3)NAMEmkfifo, ...

最新文章

  1. python文件流习题解析
  2. iOS12系统应用发送普通邮实现发送
  3. hadoop 9000端口的服务未启动_IDEA 微服务单项目多端口启动
  4. mysql集群从节点无法启动_一次galera cluster集群故障节点无法启动问题排查
  5. 如何通过自动增加索引,实现数据库查询耗时降低50%?
  6. 谷歌浏览器怎么打开flash Chrome启用flash插件技巧分享
  7. 劳务费计算用matlab实现
  8. [原创]python MySQLdb在windows环境下的安装、出错问题以及解决办法
  9. Linux网络编程-TCPUDP测试工具下载和使用
  10. Spring开发指南_夏昕 问题总结
  11. golang快速入门[6.2]-集成开发环境-emacs详解
  12. 内外网隔离--网络准入控制系统有什么功能
  13. IDEA使用破解补丁永久激活
  14. linux u识别,基于uCLinux的纸币识别器底层系统研究和实现
  15. InvalidKeyException: Illegal key size异常解决方案
  16. Android Studio DeviceFileExplorer 看不到文件列表问题
  17. vue设置浏览器自动打开网址为 http://0.0.0.0:8080/ 的网页可能暂时无法连接,或者它已永久性地移动到了新网址。
  18. 数据安全技术研究国外
  19. 综合案例注册(register)
  20. 神经网络应用_我们为应用选择了神经变态,这就是我们的做法

热门文章

  1. 整理2年多的沉思录-人生说
  2. github在浏览器直接阅读代码技巧(直接在github后面加上1s)
  3. 情人节程序员表白代码合集
  4. SpringBoot配置文件分类
  5. 华南师范大学图书馆《乡村振兴战略下传统村落文化旅游设计》新宝藏 ​​​
  6. css 实现带弧度的三角
  7. 生产车间管理制度:优化生产流程,提高效率和安全性
  8. db2 日期英式写法_英文日期格式的正确写法
  9. Cordova 插件的介绍及安装使用
  10. 在iOS工程中用Cordova加载远程网页