error: call to '__creat_missing_mode' declared with attribute error

int fd;
fd=open("/data/data/tmp.txt", O_WRONLY|O_CREAT);
write(fd, prop_name, sizeof(prop_name));
close(fd);


ERROR:

In file included from hardware/libhardware/hardware.c:29:0:
In function 'open',
    inlined from 'hw_get_module_by_class' at hardware/libhardware/hardware.c:175:3:
bionic/libc/include/fcntl.h:100:13: error: call to '__creat_missing_mode' declared with attribute error: called with O_CREAT, but missing mode
             __creat_missing_mode();  // compile time error

SOLUTION:

fd=open("/data/data/tmp.txt", O_WRONLY|O_CREAT, 0666);


使用open函数时,如果在第二个参数中使用了 O_CREAT,就必须添加第三个参数:创建文件时赋予的初始权限。


原文地址:https://www.cnblogs.com/ztguang/p/12645193.html