2 * Test this family of functions
3 * linkat, unlinkat, symlinkat
5 * and whilst we have an open filehandle, gratuitously test
14 #include "../../../config.h"
19 char tmpfromfile
[] = "/tmp/testlinkat1.XXXXXX";
20 char tmptolink
[] = "/tmp/testlinkat2.XXXXXX";
21 char tmptosymlink
[] = "/tmp/testlinkat3.XXXXXX";
22 int tmpfd
= mkstemp(tmpfromfile
);
25 memset(buff
, 0, sizeof(buff
));
26 sprintf(buff
, "some data");
27 write(tmpfd
, buff
, strlen(buff
)+1);
28 #if defined(HAVE_FDATASYNC)
33 DIR* tmpdir
= opendir("/tmp");
35 int tmpdirfd
= dirfd(tmpdir
);
37 const char* from
= tmpfromfile
+5;
38 const char* to
= tmptolink
+5;
39 const char* tosym
= tmptosymlink
+5;
41 if (-1 == linkat(tmpdirfd
, from
, tmpdirfd
, to
, 0)) {
42 perror("linkat failed");
45 unlinkat(tmpdirfd
, to
, 0);
47 if (-1 == symlinkat(from
, tmpdirfd
, tosym
)) {
48 perror("symlinkat failed");
51 unlinkat(tmpdirfd
, tosym
, 0);
54 char* badstring
= strdup(from
);
56 linkat(tmpdirfd
, badstring
, tmpdirfd
, to
, 0);
57 symlinkat(badstring
, tmpdirfd
, tosym
);
58 unlinkat(tmpdirfd
, to
, 0);
59 unlinkat(tmpdirfd
, tosym
, 0);
61 badstring
= strdup(to
);
63 linkat(tmpdirfd
, from
, tmpdirfd
, badstring
, 0);
64 unlinkat(tmpdirfd
, badstring
, 0);
66 badstring
= strdup(tosym
);
68 symlinkat(from
, tmpdirfd
, badstring
);
69 unlinkat(tmpdirfd
, badstring
, 0);
72 linkat(uninit
, from
, uninit
, to
, uninit
);
73 symlinkat(from
, uninit
, tosym
);
74 unlinkat(uninit
, "dontcare", uninit
);
81 #if defined(HAVE_FDATASYNC)