如果系统调用函数失败,我们通常使用perror输出错误消息。我想使用fprintf输出perror字符串,请问如何实现这样的功能: fprintf(stderr, perror output string here);
fprintf(stderr, "LeakTracer: timer_settime 失败,无法设置计时器 (timer_trackStartTime): %s \n",strerror(errno);
- RajSanpuiperror(“fopen”)
。这将导致“fopen:<错误描述>”。在使用fprintf(stderr,“%s \ n”,strerror(errno))
的情况下,您应该给出:<error_description>,因此如果您需要完全相同,请使用:fprintf(stderr,“fopen:%s \ n”,strerror(errno))
。当然,您应该将“fopen”替换为您的函数名称 - maverik