LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 831|回复: 8

定义了*ptr,为什么check说没有定义?

[复制链接]
发表于 2003-12-20 15:45:06 | 显示全部楼层 |阅读模式
#include <sys/types.h>
#include <sys/stat.h>
#include "ourhdr.h"
int main( int argc,char *argv[] )
{
int     i;
struct stat buf;
char   *ptr;
     for (i=1 ; i<argc ; i++) {
         printf ("%s: ",argv);
             if(lstat(argv, &buf) <0) {
              fprintf(stderr,"lstat error\n");
              continue;
         }
              if      (S_ISREG(buf.st_mode))  ptr= "regular file";
              else if (S_ISDIR(buf.st_mode))  ptr= "directory file";
              else if (S_ISCHR(buf.st_mode))  ptr= "character file";
              else if (S_ISBLK(buf.st_mode))  ptr= "block special";
              else if (S_ISFIFO(buf.st_mode)) prt= "fifo file";
              else if (S_ISLNK(buf.st_mode))  ptr= "symbolic link";
              else if (S_ISSOCK(buf,st_mode))  ptr= "socket";
              else                          ptr= "unknown mode";
              printf("%s\n", ptr);
   }
exit (0);
}

这是check的结果:
# gcc -c print_file_type_cp.c
print_file_type_cp.c: In function `main':
print_file_type_cp.c:19: `prt' undeclared (first use in this function)
print_file_type_cp.c:19: (Each undeclared identifier is reported only once
print_file_type_cp.c:19: for each function it appears in.)
print_file_type_cp.c:21:44: macro "S_ISSOCK" passed 2 arguments, but takes just 1
print_file_type_cp.c:21: `S_ISSOCK' undeclared (first use in this function)

请帮指出错误,先谢了!!好奇怪:confused:
发表于 2003-12-20 17:42:44 | 显示全部楼层
一个ptr,一个是prt,你太粗心了
 楼主| 发表于 2003-12-20 18:04:03 | 显示全部楼层
谢谢~~~我太粗心了。

好象不能定义S_ISSOCK.

# gcc -c print_file_type_cp.c
print_file_type_cp.c:21:44: macro "S_ISSOCK" passed 2 arguments, but takes just 1
print_file_type_cp.c: In function `main':
print_file_type_cp.c:21: `S_ISSOCK' undeclared (first use in this function)
print_file_type_cp.c:21: (Each undeclared identifier is reported only once
print_file_type_cp.c:21: for each function it appears in.)

发现有这个宏:
# cat stat.h|grep S_ISSOCK
#  define S_ISSOCK(mode) __S_ISTYPE((mode), __S_IFSOCK)
发表于 2003-12-20 18:54:22 | 显示全部楼层
这个宏是受限的:

#ifdef        __USE_BSD
# ifndef __S_IFLNK
#  define S_ISLNK(mode)  0
# endif
# ifdef __S_IFSOCK
#  define S_ISSOCK(mode) __S_ISTYPE((mode), __S_IFSOCK)
# endif
#endif
 楼主| 发表于 2003-12-20 21:38:49 | 显示全部楼层
谢谢你~~~你说的受限的宏,就是功能测试宏吗?

但书上说所有的功能测试宏都是以_开头,上面的# define S_ISSOCK(mode) __S_ISTYPE((mode), __S_IFSOCK)

S_ISSOCK不是以_开头阿:ask:ask

我怎么能通过?不好意思阿。问了这么多。。。
发表于 2003-12-20 22:22:12 | 显示全部楼层
??
 楼主| 发表于 2003-12-20 22:40:30 | 显示全部楼层
不明白“受限的宏”是什么意思?
同时对功能测试宏的理解不够?
发表于 2003-12-21 00:33:00 | 显示全部楼层
它外层有ifdef __USE_BSD
也就是说如果__USE_BSD被定义,S_ISSOCK才被定义.
 楼主| 发表于 2003-12-21 13:42:17 | 显示全部楼层
谢谢~~~我弄懂
#ifdef  
# ifndef
#  
# endif
# ifdef
#  
# endif
#endif
的意思了。

经别人提醒:原来是这里的,号错了。
S_ISSOCK(buf,st_mode)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表