android是一种linux,它必须支持posix.But,当它似乎不支持syscall时,open()。 下面是测试代码,而我通过NDK编译:android似乎不支持系统调用,打开()
#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");
}
及以下是来自Android的提示:
[email protected]:~$ adb shell /data/pwrite/test1
open fail.
/data/pwrite.txt: No such file or directory
而不是仅仅打印“打开失败”,而是打印实际的错误。你可以通过打印'errno'或'strerror'返回的字符串,或者使用'perror'函数来做到这一点。 –
kaiwii @ ubuntu:〜$ adb shell/data/pwrite/test1 打开失败。 /data/pwrite.txt:没有这样的文件或目录 –
@Joachim Pileborg我使用perror打印错误,上面是它提示。但是,我感到困惑,为什么不open()创建文件.thx –