Подайте разрешение и сравните char с int в C - PullRequest
0 голосов
/ 28 мая 2019

У меня есть в octal2 разрешение на доступ к файлу в восьмеричном виде в качестве параметра.Например: 777 Statchmod должен иметь разрешение File из файла "имя_файла", указанное в качестве параметра.

У меня есть файл с разрешением 777, но Stachmod получает 448, и я не знаю почему.Также я не знаю, как сравнить octal2 с Stachmod в операторе If

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);
     }
...