strerror

自测之Lesson5:标准I/O

ぐ巨炮叔叔 提交于 2020-03-05 23:07:24
题目:使用perror函数和strerror函数编写一个程序。 程序代码: #include <stdio.h> #include <errno.h> #include <string.h> int main() { FILE *fp = fopen("file.txt", "r"); if (fp == NULL) { perror("ERROR"); // 返回上一个系统调用的错误原因,此原因依照全局变量errno的值来决定要输出的字符串 printf("strerror:%s\n", strerror(errno)); return -1; } fclose(fp); return 0; } 题目:编写带可变参数的WriteLog函数。 程序代码: #include <stdio.h> #include <unistd.h> #include <string.h> #include <stdarg.h> int WriteLog(char *pFmt, ...) { va_list args; char szBuf[256]; va_start(args, pFmt); vsnprintf(szBuf, 255, pFmt, args); va_end(args); FILE *pf = fopen("test", "w"); if (pf == NULL) { perror

Maximum size of message for strerror_r on VxWorks

荒凉一梦 提交于 2019-12-11 01:24:44
问题 VxWorks provides a version of strerror_r that only takes two parameters. STATUS strerror_r ( int errcode, /* error number */ char *buffer /* string buffer */ ) cURL mentions MAXERRSTR_SIZE . The vxworks-style strerror_r() does use the buffer we pass to the function. The buffer size should be at least MAXERRSTR_SIZE (150) defined in rtsold.h But I can't seem to find the file rtsold.h anywhere in the distribution. What is the maximum size of the message copied into the buffer? Is there a

pointer/integer type mismatch in conditional expression

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: gcc 4.7.2 c89 Hello, I am getting the following warning: pointer/integer type mismatch in conditional expression I am compiling with the following CFLAGS -Wall -Wextra fprintf(stderr, "'Failed to open file' Error [ %s ]\n", (errno == 0) ? "None" : strerror(errno)); The program runs ok, but I can't see that the warning is all about. Both "None" and strerror(errno) return a string and not Integer value. And I am comparing errno number to zero. Many thanks for any suggestions, 回答1: Check whether you have included <string.h> header. If not, the

How to get POSIX strerror_r instead of GNU version?

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How do I get the POSIX strerror_r instead of GNU version? I'm compiling with g++ on Ubuntu 8.04 with glibc version 2.7 ( based on what's in ). Edit On the above man page it says: Feature Test Macro Requirements for glibc (see feature_test_macros(7)): The XSI-compliant version of strerror_r() is provided if: (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE Otherwise, the GNU-specific version is provided. It then says in feature_test_macros(7) : If no feature test macros are explicitly defined, then the following feature