Ticket #19062: foo.c

File foo.c, 736 bytes (added by bhaible, 2 weeks ago)

test case foo.c

Line 
1#include <errno.h>
2#include <fcntl.h>
3#include <unistd.h>
4#include <sys/stat.h>
5#include <stdio.h>
6#include <string.h>
7#include <assert.h>
8#ifndef O_BINARY
9# define O_BINARY 0
10#endif
11
12int
13main ()
14{
15 const char *linkname = "link4";
16 struct stat statbuf;
17 unlink (linkname);
18 assert (symlink ("/nonexistent/test8237/24715863701440", linkname) >= 0);
19 assert (stat (linkname, &statbuf) < 0);
20
21 int ret = open (linkname, O_RDWR | O_BINARY | O_TRUNC | O_CREAT, 0666);
22
23 if (ret >= 0)
24 printf ("ret = %d\n", ret);
25 else if (errno == ENOENT)
26 printf ("ret = %d, errno == ENOENT\n", ret);
27 else
28 printf ("ret = %d, errno == %s\n", ret, strerror (errno));
29
30 assert (ret < 0);
31 assert (errno == ENOENT);
32
33 printf ("OK\n");
34}