文件渗透并在C中将char与int比较

时间:2019-05-28 17:14:08

标签: c file-permissions

我在octal2中具有以参数形式给出的八进制文件权限。例如:777 Statchmod应该具有作为参数指定的文件“ file_name”的文件许可权。

我有一个具有777许可权的文件,但Stachmod却获得了448,但我不知道为什么。 我也不知道如何在If语句中将octal2与Stachmod进行比较

char octal2[7];

    read(fd2[0], octal2, 7);

        // verify the octal permission of the file and give the result on the answear

        struct stat buf;  
    stat(file_name, &buf);
    int statchmod = buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
    printf("The statchmod is %d\n", statchmod);

    if (statchmod ==  octal2[0])
     {
        char answear[]="Totul e OK!"; //OK
        printf("The answear is %s\n", answear);
     }
    else
     {

        chmod(file_name, S_IRWXU);

        char answear[]="Drepturile au fost modificate"; //not OK

        printf("The answear is %s\n", answear);
     }

0 个答案:

没有答案
相关问题