问题
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).
回答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);
来源:https://stackoverflow.com/questions/28165493/open-file-fail-1-with-different-flag-settings