我在 Linux 中创建文件时遇到问题,它使我的文件受到写保护,我不知道为什么会这样。
void fileOperation::openFileWrite(char x, off_t s)
{
int fd;
char c[2] = {x};
fd = open("/home/stud/txtFile", O_CREAT | O_WRONLY); //open file
if(fd == -1)
cout << "can't open file" << endl;
else
{
lseek(fd, s, SEEK_SET);//seek at first byte
write(fd, (void*)&c, 2);//write to file
}
syncfs(fd);
::close(fd);
}