Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检查C程序中的文件属性_C_Unix - Fatal编程技术网

检查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

全部,

AFAIK,chmod函数更改c程序中的文件属性

c中是否有任何函数可以让您检查或比较文件属性


在我的程序中,我想要的是在执行文件之前测试它是否具有用于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_模式以查找文件权限位