我想在linux中使用c++创建一个具有特定文件权限的文件(1644).I知道我可以用chmod来实现这一点,但我想通过c++编程来实现。
这可能吗?请帮帮忙。
谢谢。
发布于 2014-07-08 09:03:21
发布于 2014-07-08 09:02:03
您需要在sys/stat.h中使用struct stat
man 2统计以查看各种st_mode字段值。
发布于 2014-07-08 09:15:03
您可以使用sys/stat.h中的chmod函数:
int chmod(const char *path, mode_t mode);
所以就像这样:
#include <sys/stat.h>
...
if (!chmod("/tmp/testfile",
S_ISVTX | // Sticky bit
S_IRUSR | // User read
S_IWUSR | // User write
S_IRGRP | // Group read
S_IROTH // Other read
))
{
// Handle error case
}
https://stackoverflow.com/questions/24627583
复制相似问题