我正在尝试使用系统调用打开二进制文件,但无法使用函数(fopen 等)
if ((fd2 = open("RandomStruct.bin",O_RDWR|O_CREAT)) == -1)
err_sys("Failed to open binary\n");
这行代码不正确吗?谢谢! 顺便说一句,我得到“:错误 0”O.o
最佳答案
不,这是不正确的。如果指定 O_CREAT 标志,则 open() 需要另一个参数,即新文件的权限位。例如
open("RandomStruct.bin",O_RDWR|O_CREAT, 0755);
关于c - 尝试打开文件 c 系统调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14641610/