- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我创建了这个文件
char *output = "big";
creat(output, O_RDWR);
当我尝试读取文件时
cat big
我的权限被拒绝了。我的代码有什么问题?如何创建具有读写权限模式的文件?
用ls -l,big的权限是这样的
----------
这是什么意思?
最佳答案
您误解了模式参数。从手册页:
mode specifies the permissions to use in case a new file is cre‐
ated. This argument must be supplied when O_CREAT is specified
in flags; if O_CREAT is not specified, then mode is ignored.
The effective permissions are modified by the process's umask in
the usual way: The permissions of the created file are
(mode & ~umask). Note that this mode only applies to future
accesses of the newly created file; the open() call that creates
a read-only file may well return a read/write file descriptor.
还有
creat() is equivalent to open() with flags equal to
O_CREAT|O_WRONLY|O_TRUNC.
因此,更合适的调用可能如下所示:
int fd = creat(output, 0644); /*-rw-r--r-- */
如果你想打开它O_RDWR
,那么只需使用open()
:
int fd = open(output, O_CREAT|O_RDWR|O_TRUNC, 0644);
关于c - O_RDWR 权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15013107/
我使用的是更新和升级的 ubuntu 14.0.4LTS。 我写了一个串口通信的代码。 #include #include #include #include #include
我创建了这个文件 char *output = "big"; creat(output, O_RDWR); 当我尝试读取文件时 cat big 我的权限被拒绝了。我的代码有什么问题?如何创建具有读写
我开始对 C 中的文件描述符感兴趣,我编写了以下代码: int main (void) { int fd1, fd2, sz; char *buf = "hello world !!!
我找不到关于如何锁定文件以进行读写的答案。 lock.l_type = F_WRLCK //for write. lock.l_type = F_RDLCK //for read lock.l_typ
在我的 C 代码中,我使用 open() 和选项 O_CREAT|O_RDWR 写入文件,然后是 write(): readfd = open("ak.bin", O_CREAT|O_RDWR
我想读取一个文件并更改其内容并将其写回文件。 我使用 open 读取文件如下: bfd = open(m_file_name.c_str(), O_RDWR) 但是当我写的时候,它有点像附加到旧的。我
我编写了一个从闪存 Nand(没有文件系统)读取数据的代码。 fd = open("/dev/mtd0", O_RDONLY) 它有效,然后我想尝试读写它..所以我将代码更改为: fd = open(
在我的简单程序中: #include #include #include #include using namespace std; int main(int argc, char *argv
使用函数 Open() 或 OpenFile(path, os.O_RDONLY) 后我可以读取文件,但之后无法删除文件。所以我尝试使用写标志 os.RDWR 打开文件,如下面的代码,看看我是否可以删
我想将触摸屏事件写入‘/dev/input/event1’,但它运行‘open("/dev/input/event1", O_RDWR);'权限被拒绝。我的手机已经 Root ,我用代码获得了根: S
我知道 open 提供了这些互斥的标志:O_RDONLY、O_WRONLY 和 O_RDWR。 我想知道:如果文件以 O_RDWR 和 打开,是否存在任何性能问题(即使只是几分之一毫秒)或处理文件的不
我正在尝试使用 打开一个临时文件 fd = open("/tmp", O_RDWR | O_TMPFILE, 0); if (fd == -1) { perror("open()");
我正在尝试注册为 Symfony 2 项目的新用户,我一直在努力。这是突然冒出来的。它昨天在办公室工作,我在家里设置了类似的设置。我得到了: Warning: session_start(): ope
当我将 index.php 文件更改为 index.html 文件然后再次更改回其原始 index.php 文件时出现此错误 谁能告诉我如何避免这个错误? Warning: session_start
我的应用程序有一个小问题。 首先我安装 i2c-tools 包, 我向所有用户授予 dev/i2c* 文件的所有权限。 之后,在 etc/modules 文件中添加行 i2c-dev i2c 设备存在
我正在尝试为结构构造函数编写单元测试,如果在 file.Open 期间发生错误,它也可能返回 nil。我不知道如何使用标志测试/模拟文件错误:os.O_RDWR|os.O_CREATE|os.O_AP
我正在将一些代码从 Win32 移植到使用锁定文件的 Linux。我用 open 为 Linux 做了一个实现,但我不确定如果文件在 Samba 共享上它是否会工作。我试过了,它似乎可以正常工作,但我
我是一名优秀的程序员,十分优秀!