相关疑难解决方法(0)

如何在C中打印errno的符号名称?

我可以使用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)

c printf errno strerror

8
推荐指数
2
解决办法
4697
查看次数

c 中函数如何返回左值?

我读了《Linux 编程接口 29-2 线程》和 errno下一个:

在 Linux 上,线程特定的 errno 的实现方式与大多数其他 UNIX 实现类似:errno 被定义为一个宏,该宏扩展为函数调用,返回每个线程不同的可修改左值。

我想知道函数如何返回可修改的左值。

c linux multithreading pthreads

3
推荐指数
1
解决办法
113
查看次数

标签 统计

c ×2

errno ×1

linux ×1

multithreading ×1

printf ×1

pthreads ×1

strerror ×1