#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
int
main()
{
unlink("link4");
unlink("file4");
int ret = symlink("file4", "link4");
printf("symlink -> %d\n", ret);
ret = open("link4", O_RDWR | O_TRUNC | O_CREAT, 0666);
if (ret < 0) {
perror("open");
return ret;
} else {
printf("ret -> %d\n", ret);
}
const char *linkname = "link4";
struct stat statbuf;
unlink(linkname);
assert(symlink ("/nonexistent/test8237/24715863701440", linkname) >= 0);
assert(stat(linkname, &statbuf) < 0);
ret = open(linkname, O_RDWR | O_TRUNC | O_CREAT, 0666);
if (ret >= 0)
printf("ret = %d\n", ret);
else if (errno == ENOENT)
printf("ret = %d, errno == ENOENT\n", ret);
else
printf("ret = %d, errno == %s\n", ret, strerror (errno));
assert(ret < 0);
assert(errno == ENOENT);
printf("OK\n");
return 0;
}