检查C程序中的文件属性
全部, AFAIK,chmod函数更改c程序中的文件属性 c中是否有任何函数可以让您检查或比较文件属性检查C程序中的文件属性,c,unix,C,Unix,全部, AFAIK,chmod函数更改c程序中的文件属性 c中是否有任何函数可以让您检查或比较文件属性 在我的程序中,我想要的是在执行文件之前测试它是否具有用于u和g用户和组的正确x,您可以使用它来查找权限。您要查找的是将返回给定路径上的信息的文件 例如: #include <stdlib.h> #include <stdio.h> #include <errno.h> #include <string.h> #include <sys/t
在我的程序中,我想要的是在执行文件之前测试它是否具有用于u和g用户和组的正确x,您可以使用它来查找权限。您要查找的是将返回给定路径上的信息的文件 例如:
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
int main ( int argc, char *argv[])
{
struct stat FileAttrib;
if(argc <= 1)
{
printf("Argument missing!\n");
exit(10);
}
if (stat(argv[(argc - 1)], &FileAttrib) < 0)
printf("File Error Message = %s\n", strerror(errno));
else
printf( "Permissions: %d\n", FileAttrib.st_mode );
return 0;
}
是-尝试统计-
这将检索详细信息以及您需要的更多信息调用int stat const char*filename、struct stat*pStat和pass stat structure。
您可以检查pStat->st_模式以查找文件权限位