我可以使用perror()或strerror()打印属于a的"人类可读"错误消息errno,但是如果我还要打印符号名称(例如" EAGAIN")的话errno呢?
任何方便的功能或宏来做到这一点?
更新:附上我最终编写的代码,基于下面接受的答案及其评论的想法:
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
int get_errno_name(char *buf, int buf_size) {
// Using the linux-only gawk instead of awk, because of the convenient
// match() functionality. For Posix portability, use a different recipe...
char cmd[] = "e= && " // errno to be inserted here (max digits = 6)
"echo '#include <errno.h>' | "
"gcc -dM -E - | " // optionally, use …Run Code Online (Sandbox Code Playgroud) 我读了《Linux 编程接口 29-2 线程》和 errno下一个:
在 Linux 上,线程特定的 errno 的实现方式与大多数其他 UNIX 实现类似:errno 被定义为一个宏,该宏扩展为函数调用,返回每个线程不同的可修改左值。
我想知道函数如何返回可修改的左值。