Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android似乎不支持syscall,open()_Android_Linux_Android Ndk_Linux Kernel - Fatal编程技术网

android似乎不支持syscall,open()

android似乎不支持syscall,open(),android,linux,android-ndk,linux-kernel,Android,Linux,Android Ndk,Linux Kernel,android是一种linux,它必须支持posix。 以下是测试代码,我通过NDK编译: #include <unistd.h> #include <stdio.h> #include<sys/types.h> #include<sys/stat.h> #include<fcntl.h> void main(){ int fd; char pathname[128] = "/data/pwrite.txt";

android是一种linux,它必须支持posix。 以下是测试代码,我通过NDK编译:

#include <unistd.h>
#include <stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>

void main(){
    int fd;
    char pathname[128] = "/data/pwrite.txt";
    fd = open(pathname, O_WRONLY);
    if(fd==-1){
        printf("open fail.\n");

    }
    perror("/data/pwrite.txt");
}

我认为问题不在于
syscall open()
,而在于您试图访问
/data
。此文件夹仅可用于根移动设备或在emulator中访问。您是否尝试将文件放入
/sdcard
文件夹?

我认为问题在于标志-您只使用
O\u WRONLY
。但是如果文件不存在,您也应该使用
O_create
标志创建它。因此,如果文件不存在,则应调用:

fd = open(pathname, O_WRONLY | O_CREAT);

不要只打印“打开失败”,而是打印实际错误。您可以通过打印出
errno
strerror
返回的字符串,或使用
perror
函数来执行此操作。kaiwii@ubuntu:~$adb shell/data/pwrite/test1打开失败/data/pwrite.txt:没有此类文件或directory@JoachimPileborg我使用perror打印错误,上面是它提示的内容。但是,我感到困惑的是,为什么不使用open()创建文件呢。thx您访问过吗@实际上,我的问题似乎有点不同。
fd = open(pathname, O_WRONLY | O_CREAT);