手机版
你好,游客 登录 注册
背景:
阅读新闻

Linux命令:chmod opendir readdir closedir

[日期:2016-11-28] 来源:Linux社区  作者:swjtufq [字体: ]

我们在用shell敲命令的时候有一个chmod,大家都很熟悉了,其实chmod还是一个函数,我们可以在程序中给文件权限:
我们先创建一个hello文件,看一下权限
Linux chmod opendir readdir closedir

然后看代码
Linux chmod opendir readdir closedir

执行,再看hello的权限
Linux chmod opendir readdir closedir

下面我们来看下opendir,readdir closedir

opendir
函数原型
  DIR* opendir (const char * path ); (获取path子目录下的所由文件和目录的列表,如果path是个文件则返回值为NULL)
功能
  打开一个目录,在失败的时候返回一个空的指针。
返回值(DIR)
DIR 结构体的原型为:struct_dirstream
在Linux系统中:
typedef struct __dirstream DIR;
struct __dirstream
{
void __fd; / struct hurd_fd' pointer for descriptor. */
char *__data; /* Directory block. */
int __entry_data; /* Entry number
__data’ corresponds to. */
char __ptr; / Current pointer into the block. */
int __entry_ptr; /* Entry number `__ptr’ corresponds to. */
size_t __allocation; /* Space allocated for the block. */
size_t __size; /* Total valid data in the block. */
__libc_lock_define (, __lock) /* Mutex lock for this structure. */
};

readdir
函数原型
struct dirent* readdir(DIR* dir_handle); (个人理解循环读取dir_handle,目录和文件都读)
功能
读取opendir 返回值的那个列表
返回值
返回dirent结构体指针,dirent结构体成员如下,(文件和目录都行)
struct dirent
  {
  long d_ino; /* inode number 索引节点号 */
  off_t d_off; /* offset to this dirent 在目录文件中的偏移 */
  unsigned short d_reclen; /* length of this d_name 文件名长 */
  unsigned char d_type; /* the type of d_name 文件类型 */
  char d_name [NAME_MAX+1]; /* file name (null-terminated) 文件名,最长255字符 */
  }

下面来看一个例子,把当前目录中的文件打印到shell终端:
Linux chmod opendir readdir closedir

Linux chmod opendir readdir closedir

好了,Linux chmod opendir readdir closedir就总结到这里,如有问题,欢迎指正,谢谢。

本文永久更新链接地址http://www.linuxidc.com/Linux/2016-11/137615.htm

linux
相关资讯       Linux chmod 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款