You don't want to use stat()
for this. You want to use access()
from <unistd.h>
:
char const* name = "file";
if (access(name, R_OK)) {
std::cout << "'" << name << "' is readable\n";
}
if (access(name, W_OK)) {
std::cout << "'" << name << "' is writable\n";
}