如何在C中更改/显示权限

spe*_*d17 7 c linux chmod

我是C编程的新手,我想在dir和subdir的文件上实现chmod命令.如何使用C代码更改/显示权限?有人可以帮忙举个例子吗?如果有人能为我提供代码,我将不胜感激.

Cas*_*bel 12

有一个chmod功能.从man 3p chmod:

SYNOPSIS
   #include <sys/stat.h>

   int chmod(const char *path, mode_t mode);

...
Run Code Online (Sandbox Code Playgroud)

如果要读取权限,则使用stat.来自man 3p stat:

SYNOPSIS
   #include <sys/stat.h>

   int stat(const char *restrict path, struct stat *restrict buf);

...
Run Code Online (Sandbox Code Playgroud)

如果你想像你提到的那样递归地执行它,你将不得不循环结束readdir自己的结果.