XCode C++ missing sperm()

前端 未结 3 2122
谎友^
谎友^ 2021-02-20 07:56

I\'m using C++ and XCode to create a cmd line app to save file permissions, however I can\'t get the sperm() method to be identified, the error is

\'Use

3条回答
  •  独厮守ぢ
    2021-02-20 08:10

    This might make me look like a pervert, but I searched google for 'sperm' (ofcourse only for .h and .cpp files). The bad news is I can't find any references to it (except on the stat function page itself).

    The good news is I found this piece of code which defines it's own 'sperm' function:

    char const * sperm(__mode_t mode) {
        static char local_buff[16] = {0};
        int i = 0;
        // user permissions
        if ((mode & S_IRUSR) == S_IRUSR) local_buff[i] = 'r';
        else local_buff[i] = '-';
        i++;
        if ((mode & S_IWUSR) == S_IWUSR) local_buff[i] = 'w';
        else local_buff[i] = '-';
        i++;
        if ((mode & S_IXUSR) == S_IXUSR) local_buff[i] = 'x';
        else local_buff[i] = '-';
        i++;
        // group permissions
        if ((mode & S_IRGRP) == S_IRGRP) local_buff[i] = 'r';
        else local_buff[i] = '-';
        i++;
        if ((mode & S_IWGRP) == S_IWGRP) local_buff[i] = 'w';
        else local_buff[i] = '-';
        i++;
        if ((mode & S_IXGRP) == S_IXGRP) local_buff[i] = 'x';
        else local_buff[i] = '-';
        i++;
        // other permissions
        if ((mode & S_IROTH) == S_IROTH) local_buff[i] = 'r';
        else local_buff[i] = '-';
        i++;
        if ((mode & S_IWOTH) == S_IWOTH) local_buff[i] = 'w';
        else local_buff[i] = '-';
        i++;
        if ((mode & S_IXOTH) == S_IXOTH) local_buff[i] = 'x';
        else local_buff[i] = '-';
        return local_buff;
    }
    

    usage is simple:

    #include 
    #include 
    #include 
    
    int main(int argc, char ** argv)
    {
        std::cout<

    output on ideone:

    r-x-w-r--
    r--------
    r--r--rw-
    

提交回复
热议问题