FreeBSD regtest: remove test for version 13+ syscalls
[valgrind.git] / memcheck / tests / freebsd / linkat.c
blob79b6ee377fe70e46c657d15f32d02c5988e11ac8
1 /*
2 * Test this family of functions
3 * linkat, unlinkat, symlinkat
5 * and whilst we have an open filehandle, gratuitously test
6 * fdatasync
7 */
9 #include <unistd.h>
10 #include <dirent.h>
11 #include <string.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include "../../../config.h"
16 int main(void)
18 char buff[64];
19 char tmpfromfile[] = "/tmp/testlinkat1.XXXXXX";
20 char tmptolink[] = "/tmp/testlinkat2.XXXXXX";
21 char tmptosymlink[] = "/tmp/testlinkat3.XXXXXX";
22 int tmpfd = mkstemp(tmpfromfile);
23 mktemp(tmptolink);
25 memset(buff, 0, sizeof(buff));
26 sprintf(buff, "some data");
27 write(tmpfd, buff, strlen(buff)+1);
28 #if defined(HAVE_FDATASYNC)
29 fdatasync(tmpfd);
30 #endif
31 close (tmpfd);
33 DIR* tmpdir = opendir("/tmp");
34 if (tmpdir) {
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);
53 // now some errors
54 char* badstring = strdup(from);
55 free(badstring);
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);
62 free(badstring);
63 linkat(tmpdirfd, from, tmpdirfd, badstring, 0);
64 unlinkat(tmpdirfd, badstring, 0);
66 badstring = strdup(tosym);
67 free(badstring);
68 symlinkat(from, tmpdirfd, badstring);
69 unlinkat(tmpdirfd, badstring, 0);
71 int uninit;
72 linkat(uninit, from, uninit, to, uninit);
73 symlinkat(from, uninit, tosym);
74 unlinkat(uninit, "dontcare", uninit);
76 closedir(tmpdir);
79 unlink(tmpfromfile);
80 int badint;
81 #if defined(HAVE_FDATASYNC)
82 fdatasync(badint);
83 #endif