打开文件失败(-1),不同标志设置 [英] open file fail(-1) with different flag settings

查看:144
本文介绍了打开文件失败(-1),不同标志设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于使用open()与原生的Andr​​oid不同的标志问题。

由于我想打开一个文件,而忽略缓存和放大器;缓冲液,在奥得直接访问硬件(SD卡)。
如果该标志设置为
O_CREAT | O_RDWR | O_NDELAY,S_IRUSR | S_IWUSR | O_DIRECT | O_SYNC
。我能有一个积极的文件描述符(FD)。

但是,如果我更改设置为
  O_CREAT | O_RDWR | S_IRUSR | S_IWUSR | O_DIRECT | O_SYNC
其结果是失败(-1)。


解决方案

  

如果标志设置O_CREAT | O_RDWR | O_NDELAY,S_IRUSR | S_IWUSR | O_DIRECT | O_SYNC。我能有一个积极的文件描述符(FD)。


这不是形式完全正确的用法

  INT开放(常量字符*路径,诠释标志,mode_t模式);


  

但是,如果我更改设置为O_CREAT | O_RDWR | S_IRUSR | S_IWUSR | O_DIRECT | O_SYNC结果是失败(-1)。


你所谓的设置的就是标记模式符号无效的混合物。此外,由于O_CREAT已标志被指定,在模式参数必须提供,它不是。结果
尝试从标记分隔的模式取值

 打开(路径,O_CREAT | O_RDWR | O_DIRECT | O_SYNC,S_IRUSR | S_IWUSR);

I have a question about using open() with different flags in Native android.

Because i want to open a file and ignore the cache& buffer, in oder to access the hardware(SD card) directly. If the flag setting is O_CREAT | O_RDWR | O_NDELAY, S_IRUSR | S_IWUSR| O_DIRECT | O_SYNC . I can got a positive file descriptor(fd).

But if I change the setting to O_CREAT | O_RDWR | S_IRUSR | S_IWUSR| O_DIRECT | O_SYNC the result is fail(-1).

解决方案

If the flag setting is O_CREAT | O_RDWR | O_NDELAY, S_IRUSR | S_IWUSR| O_DIRECT | O_SYNC . I can got a positive file descriptor(fd).

That is not quite correct usage of the form

int open(const char *pathname, int flags, mode_t mode);

But if I change the setting to O_CREAT | O_RDWR | S_IRUSR | S_IWUSR| O_DIRECT | O_SYNC the result is fail(-1).

What you call "setting" is an invalid mixture of flags and mode symbols. Also, since O_CREAT has been specified in flags, the mode argument must be supplied and it is not.
Try separating the modes from the flags:

open(pathname, O_CREAT | O_RDWR | O_DIRECT | O_SYNC, S_IRUSR | S_IWUSR);

这篇关于打开文件失败(-1),不同标志设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆