【发布时间】:2012-03-11 22:43:50
【问题描述】:
我正在使用 open 函数创建文件并使用 O_CREAT | O_EXCEL 。我已将模式传递为 "0666" 。但是通过屏蔽最终分配给它的权限是 -rw-r--r-- 而不是 -rw-rw-rw-。有人告诉我我可以使用 umask (011) 然后再次重置原始掩码。 但我不知道如何在 c++ 程序中传递它。这是我在做什么的小sn-p。
# include <iostream>
# include <stdio.h>
# include <conio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
using namespace std;
int main()
{
int fd = open("C:\\Users\\Ritesh\\Music\\music.txt", O_CREAT | O_EXCL, 0666);
getch();
return 0;
}
创建文件C:\Users\Ritesh\Music\music.txt with permission -rw-r--r-- . 我希望它是-rw-rw-rw-
【问题讨论】:
-
我很困惑。您如何拥有具有 Unix 权限位和 DOS 路径名的文件系统?什么O/S同时提供
<sys/stat.h>和<conio.h>? -
@Rob 别担心我只是在寻找要打开的头文件时复制了它。我只是在我的 Windows 系统上使用 DEV c++。实际上我在工作场所使用 solaris。很抱歉,如果它让您感到困惑。
-
那么,您要问的是哪个系统? Windows 还是 Solaris?