Tag: strerror

VxWorks上strerror_r的最大消息大小

VxWorks提供了一个只有两个参数的strerror_r版本。 STATUS strerror_r ( int errcode, /* error number */ char *buffer /* string buffer */ ) cURL提到MAXERRSTR_SIZE 。 vxworks样式的strerror_r()确实使用我们传递给函数的缓冲区。 缓冲区大小至少应为rtsold.h中定义的MAXERRSTR_SIZE(150) 但我似乎无法在发行版的任何地方找到文件rtsold.h。 复制到缓冲区的消息的最大大小是多少? 是否在某处定义了#define或整数常量?

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

我可以使用perror()或strerror()来打印属于errno的“人类可读”错误消息,但是如果我还要打印errno的符号名称(例如“ EAGAIN ”)该怎么办? 任何方便的function或宏来做到这一点? 更新:附上我最终编写的代码,基于下面接受的答案及其评论的想法: #include #include #include 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 ‘ […]