免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2638 | 回复: 7
打印 上一主题 下一主题

请问:错误代码的宏在哪里定义??? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-12-29 15:37 |只看该作者 |倒序浏览
我有个程序,如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <error.h>

extern int errno;

int main(int argc,char ** argv[])
{
    struct stat filestat;
    int i_ret;

    i_ret = stat("/tmp/aa.txt",&filestat);
    if (i_ret != 0 && errno == ENOENT)
    {
        printf("文件不存在!\n");
        return(1);
    }
    return(0);
}

用cc编译时提示如下:
bb.c: In function `main':
bb.c:17: `ENOENT' undeclared (first use in this function)
bb.c:17: (Each undeclared identifier is reported only once
bb.c:17: for each function it appears in.)
请问,宏ENOENT在哪里定义???
man 2 stat中有以下内容:
ERRORS
       EBADF  filedes is bad.

       ENOENT A component of the path file_name does not exist, or the path is an empty string.

       ENOTDIR
              A component of the path is not a directory.

       ELOOP  Too many symbolic links encountered while traversing the path.

       EFAULT Bad address.

       EACCES Permission denied.

       ENOMEM Out of memory (i.e. kernel memory).

       ENAMETOOLONG
              File name too long.
有哪位大虾知道呢???

论坛徽章:
0
2 [报告]
发表于 2006-12-29 15:49 |只看该作者
extern int errno; 这一句没有必要

一般在/usr/include和/usr/include/sys下都有errno.h头文件

论坛徽章:
0
3 [报告]
发表于 2006-12-29 15:56 |只看该作者
<errno.h>

errno: ERRor No.,错误号

论坛徽章:
0
4 [报告]
发表于 2006-12-29 15:58 |只看该作者
#include <error.h>
晕,没有看到,应该是#include <errno.h>

论坛徽章:
0
5 [报告]
发表于 2006-12-29 17:33 |只看该作者
将extern int error;去掉后,编译提示error没有定义,我是在SUSE LINUX下编译的。

论坛徽章:
0
6 [报告]
发表于 2006-12-30 14:56 |只看该作者
有人知道吗?

论坛徽章:
0
7 [报告]
发表于 2007-01-06 12:51 |只看该作者
有人可以帮助解决吗?

论坛徽章:
0
8 [报告]
发表于 2007-01-06 12:58 |只看该作者
2 楼、3 楼和 4 楼均已经给出答案了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP