FreeBSD regtest: add fakes for older versions in scalar
[valgrind.git] / memcheck / tests / freebsd / chmod_chown.c
blob1fe40f4145520ecbbce401573a1fb9d01994a8d2
1 /*
2 * Test this family of functions
3 * lchmod chownat lchownat
4 */
6 #include <unistd.h>
7 #include <dirent.h>
8 #include <string.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <sys/stat.h>
13 int main(void)
15 char buff[64];
16 char tmpfile[] = "/tmp/test_chmod_chown.XXXXXX";
17 char tmplink[] = "/tmp/test_chx_link.XXXXXX";
18 int tmpfd = mkstemp(tmpfile);
19 mktemp(tmplink);
21 memset(buff, 0, sizeof(buff));
22 sprintf(buff, "some data");
23 write(tmpfd, buff, strlen(buff)+1);
24 close (tmpfd);
26 DIR* tmpdir = opendir("/tmp");
27 if (tmpdir) {
28 int tmpdirfd = dirfd(tmpdir);
30 if (-1 == symlinkat(tmpfile+5, tmpdirfd, tmplink+5)) {
31 perror("linkat failed");
34 if (-1 == lchmod(tmplink, S_IRWXU|S_IRWXG|S_IRWXO))
36 perror("lchmod failed:");
39 if (fchmodat(tmpdirfd, tmpfile+5, S_IRWXU|S_IRWXG|S_IRWXO, 0))
41 perror("fchmodat failed:");
44 // no test for failure as not everyone runnning this will be a member of group 921
45 fchownat(tmpdirfd, tmpfile+5, getuid(), 920, 0);
47 closedir(tmpdir);
50 unlink(tmpfile);
51 unlink(tmplink);
53 // error section
54 char* badstring = strdup("foo");
55 free(badstring);
56 int badint1;
57 int badint2;
58 int badint3;
59 int badint4;
61 lchmod(badstring, badint1);
62 fchmodat(badint1, badstring, badint2, badint3);
63 fchownat(badint1, badstring, badint2, badint3, badint4);