Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/137.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++/Linux如何为其他用户获取读取权限统计? 我正在编写一个简单的C++ WebServer赋值,我想检查这个文件是否可以被其他用户读取。否则,服务器将发回403禁止_C++_Linux_Permissions - Fatal编程技术网

C++/Linux如何为其他用户获取读取权限统计? 我正在编写一个简单的C++ WebServer赋值,我想检查这个文件是否可以被其他用户读取。否则,服务器将发回403禁止

C++/Linux如何为其他用户获取读取权限统计? 我正在编写一个简单的C++ WebServer赋值,我想检查这个文件是否可以被其他用户读取。否则,服务器将发回403禁止,c++,linux,permissions,C++,Linux,Permissions,我已经有了一个使用stat(FILE,&statbuf)的statbuf.st_模式,但我不知道如何检索其他用户的读取权限。我知道有“S_IROTH”,但我不知道如何使用它。我尝试使用cout将其打印到终端。您需要根据S\u IROTH屏蔽文件的模式。此外,您错误地传递了statbuf(您应该得到警告)。正确的代码应该如下所示: int result = stat(path, &statbuf); if (result != 0) { return NOT_FOUND; } if

我已经有了一个使用
stat(FILE,&statbuf)
statbuf.st_模式
,但我不知道如何检索其他用户的读取权限。我知道有“S_IROTH”,但我不知道如何使用它。我尝试使用
cout将其打印到终端。您需要根据
S\u IROTH
屏蔽文件的模式。此外,您错误地传递了
statbuf
(您应该得到警告)。正确的代码应该如下所示:

int result = stat(path, &statbuf);
if (result != 0) {
    return NOT_FOUND;
}
if (!(statbuf.st_mode & S_IROTH)) {
    return FORBIDDEN;
}
... success, continue ...

这是一个打字错误,因为我没有复制粘贴我的代码…我已经更正了它。您的代码正在运行,非常感谢!