Code:int fd = open(fname, O_RDWR|O_CREAT, 0777);
unlink(fname);
write(fd,"abcd",4);
Printable View
Code:int fd = open(fname, O_RDWR|O_CREAT, 0777);
unlink(fname);
write(fd,"abcd",4);
What kind of question is it?
this is not C++ - plain C
unlink is not a standard function - so it should be on specific forum
You do not explain your problem
You think all people here are mind readers or what?
Suppose unlink() did actually refuse to delete the file, how would you know? You are not checking the return value.
--
Mats
Yes, I completely agree - there is a reference count [1] on the number of processes holding the file open. When the last process closes the file, it goes away.
I was just trying to point out that if unlink DIDN'T work because a file is open (which is the more likely scenario than the fact that write fails in any way when the file is already opened - unlink should not CLOSE an open file if it can't delete an opened file - it should fail to delete the file).
[1] I beleive it's actually the inode of the file that has a reference count. But I may be wrong.
--
Mats