linux下输出标准错误的方法

来源:互联网 发布:ipad怎么清除缓存数据 编辑:程序博客网 时间:2024/06/05 20:52
GNU glibc提供一个对printf的扩展,直接printf("%m"),可以输出标准的错误信息,例如下面:
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
int main()
{
        if (open("/usr/test",0) < 0)
        {
                printf("%m /n");
                printf("%s /n",strerror(errno));
        }
        return 0;
}
输出为 :
No such file or directory 
No such file or directory 
原创粉丝点击