免费注册 查看新帖 |

Chinaunix

广告
  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 11285 | 回复: 10
打印 上一主题 下一主题

那位牛人解释下宏S_ISDIR()的定义呢? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-10-17 12:59 |只看该作者 |倒序浏览
=======

论坛徽章:
0
2 [报告]
发表于 2005-10-17 13:53 |只看该作者

那位牛人解释下宏S_ISDIR()的定义呢?

判断一个路径是否是目录。


  1. The following symbolic names for the values of type mode_t shall also be defined.

  2. File type:

  3. S_IFMT
  4. Type of file.
  5. S_IFBLK
  6. Block special.
  7. S_IFCHR
  8. Character special.
  9. S_IFIFO
  10. FIFO special.
  11. S_IFREG
  12. Regular.
  13. S_IFDIR
  14. Directory.
  15. S_IFLNK
  16. Symbolic link.
  17. S_IFSOCK
  18. Socket.  
  19. File mode bits:

  20. S_IRWXU
  21. Read, write, execute/search by owner.
  22. S_IRUSR
  23. Read permission, owner.
  24. S_IWUSR
  25. Write permission, owner.
  26. S_IXUSR
  27. Execute/search permission, owner.
  28. S_IRWXG
  29. Read, write, execute/search by group.
  30. S_IRGRP
  31. Read permission, group.
  32. S_IWGRP
  33. Write permission, group.
  34. S_IXGRP
  35. Execute/search permission, group.
  36. S_IRWXO
  37. Read, write, execute/search by others.
  38. S_IROTH
  39. Read permission, others.
  40. S_IWOTH
  41. Write permission, others.
  42. S_IXOTH
  43. Execute/search permission, others.
  44. S_ISUID
  45. Set-user-ID on execution.
  46. S_ISGID
  47. Set-group-ID on execution.
  48. S_ISVTX
  49. [XSI]  On directories, restricted deletion flag.  
  50. The bits defined by S_IRUSR, S_IWUSR, S_IXUSR, S_IRGRP, S_IWGRP, S_IXGRP, S_IROTH, S_IWOTH, S_IXOTH, S_ISUID, S_ISGID, [XSI]   and S_ISVTX   shall be unique.

  51. S_IRWXU is the bitwise-inclusive OR of S_IRUSR, S_IWUSR, and S_IXUSR.

  52. S_IRWXG is the bitwise-inclusive OR of S_IRGRP, S_IWGRP, and S_IXGRP.

  53. S_IRWXO is the bitwise-inclusive OR of S_IROTH, S_IWOTH, and S_IXOTH.

  54. Implementations may OR other implementation-defined bits into S_IRWXU, S_IRWXG, and S_IRWXO, but they shall not overlap any of the other bits defined in this volume of IEEE Std 1003.1-2001. The file permission bits are defined to be those corresponding to the bitwise-inclusive OR of S_IRWXU, S_IRWXG, and S_IRWXO.

  55. The following macros shall be provided to test whether a file is of the specified type. The value m supplied to the macros is the value of st_mode from a stat structure. The macro shall evaluate to a non-zero value if the test is true; 0 if the test is false.

  56. S_ISBLK(m)
  57. Test for a block special file.
  58. S_ISCHR(m)
  59. Test for a character special file.
  60. S_ISDIR(m)
  61. Test for a directory.
  62. S_ISFIFO(m)
  63. Test for a pipe or FIFO special file.
  64. S_ISREG(m)
  65. Test for a regular file.
  66. S_ISLNK(m)
  67. Test for a symbolic link.
  68. S_ISSOCK(m)
  69. Test for a socket.
复制代码


但是这些宏不一定被所有的系统支持。例如sco openserver就不支持S_ISSOCK(m)

论坛徽章:
0
3 [报告]
发表于 2005-10-17 14:00 |只看该作者

那位牛人解释下宏S_ISDIR()的定义呢?

为什么是判断啊?

#  defing  S_ISDIR(MODE)    宏是一个参数啊?

论坛徽章:
0
4 [报告]
发表于 2005-10-17 14:05 |只看该作者

那位牛人解释下宏S_ISDIR()的定义呢?

原帖由 "Com_Net" 发表:
为什么是判断啊?

#  defing  S_ISDIR(MODE)    宏是一个参数啊?


man stat
查看<sys/stat.h>;

论坛徽章:
0
5 [报告]
发表于 2005-10-17 14:07 |只看该作者

那位牛人解释下宏S_ISDIR()的定义呢?

好像是像下面这样定义的,APUE里面说过

#define S_ISDIR(x)  (((x)&STAT_MASK)==STAT_DIR_FLAG)

论坛徽章:
0
6 [报告]
发表于 2005-10-17 14:21 |只看该作者

那位牛人解释下宏S_ISDIR()的定义呢?

楼上:
       可否解释下这个宏啊?

论坛徽章:
0
7 [报告]
发表于 2005-10-17 14:45 |只看该作者

那位牛人解释下宏S_ISDIR()的定义呢?

如果       x ->;           001101010101
STAT_MASK ->;        001000001010
STAT_DIR_FLAG->;  001000000000

那么就返回true阿,估计是这么回事

论坛徽章:
0
8 [报告]
发表于 2005-10-17 14:48 |只看该作者

那位牛人解释下宏S_ISDIR()的定义呢?

谢过楼上各位!

论坛徽章:
0
9 [报告]
发表于 2005-10-17 14:51 |只看该作者

那位牛人解释下宏S_ISDIR()的定义呢?

比如说x是16位,上8位管文件类型,下8位管access权限。
然后有两个mask 一个类型mask是0xff00,另一个权限mask是0x00ff
然后dir_flag 为 0x0100,
      reg_flag为 0x0200,。。。相互不同
     rd_flag     0x0001
     wr_flag     0x0002 。。。也都不同。
这样用不通的mask就同时可以看是什么类型又可以看是什么权限阿

论坛徽章:
0
10 [报告]
发表于 2005-10-18 09:09 |只看该作者

那位牛人解释下宏S_ISDIR()的定义呢?

楼上:
      不大明白,可否详细些啊?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP