1.
#include <stdio.h>
#include <unistd.h>
void main(){
link("foo", "bar");
unlink("foo");
if(open("bar", 1) < 0)
printf("open error\n");
else
printf("open succeeded\n");
}
2.
#include <stdio.h>
#include <unistd.h>
void main(){
symlink("foo", "bar");
unlink("foo");
if(open("bar", 1) < 0)
printf("open error\n");
else
printf("open succeeded\n");
}
the result from first code is "open succeeded".
and the file "foo" is deleted. only remains "bar" whose contents is same with the file "foo".
the reslut frome second code is "open error". and also only remains "bar".
why these results are generated?
1. especially, although each the hardlink and the symbolic link("bar") points the file "foo", the file "foo" was deleted.
2. why "bar" is not deletd, after unlink("foo"). unlink function means that it removes the link, which points the specified file.(this case, "foo")
3. why result from first code and second code is different?