FreeBSD regtest: add fakes for older versions in scalar
[valgrind.git] / memcheck / tests / freebsd / extattr.c
blobf5d99b1a5ddfb301e82fa0e7bd0766a3c31548ee
1 /*
2 * Test this family of functions
3 * extattr_get_fd, extattr_set_fd, extattr_delete_fd, extattr_list_fd,
4 * extattr_get_file, extattr_set_file, extattr_delete_file,
5 * extattr_list_file, extattr_get_link, extattr_set_link,
6 * extattr_delete_link, extattr_list_link - system calls to manipulate VFS
7 */
9 #include <sys/types.h>
10 #include <sys/extattr.h>
11 #include <string.h>
12 #include <stdlib.h>
13 #include <unistd.h>
14 #include <stdio.h>
15 #include "../../memcheck.h"
17 int main()
19 ssize_t n;
20 char buff[64];
21 char tmpfile[] = "test1.XXXXXX";
22 int tmpfd = mkstemp(tmpfile);
23 memset(buff, 0, sizeof(buff));
24 sprintf(buff, "some data");
26 // valid calls even though "test1" does not exist
27 n = extattr_get_file("test1", EXTATTR_NAMESPACE_USER, "bar", NULL, 0);
28 (void)extattr_get_file("test1", EXTATTR_NAMESPACE_USER, "bar", buff, sizeof(buff));
29 (void)extattr_get_link("test1", EXTATTR_NAMESPACE_USER, "bar", buff, sizeof(buff));
30 (void)extattr_list_file("test1", EXTATTR_NAMESPACE_USER, buff, sizeof(buff));
31 (void)extattr_list_link("test1", EXTATTR_NAMESPACE_USER, buff, sizeof(buff));
33 n = extattr_get_fd(tmpfd, EXTATTR_NAMESPACE_USER, "bar", NULL, 0);
34 (void)extattr_get_fd(tmpfd, EXTATTR_NAMESPACE_USER, "bar", buff, sizeof(buff));
35 (void)extattr_list_fd(tmpfd, EXTATTR_NAMESPACE_USER, buff, sizeof(buff));
37 n = extattr_set_file("test1", EXTATTR_NAMESPACE_USER, "bar", NULL, 0);
38 (void)extattr_set_file("test1", EXTATTR_NAMESPACE_USER, "bar", buff, sizeof(buff));
39 (void)extattr_set_link("test1", EXTATTR_NAMESPACE_USER, "bar", buff, sizeof(buff));
41 n = extattr_set_fd(tmpfd, EXTATTR_NAMESPACE_USER, "bar", NULL, 0);
42 (void)extattr_set_fd(tmpfd, EXTATTR_NAMESPACE_USER, "bar", buff, sizeof(buff));
44 (void)extattr_delete_file("test1", EXTATTR_NAMESPACE_USER, "foo");
45 (void)extattr_delete_link("test1", EXTATTR_NAMESPACE_USER, "foo");
46 (void)extattr_delete_fd(tmpfd, EXTATTR_NAMESPACE_USER, "foo");
48 // now some invalid calls
49 int uninit;
50 (void)extattr_get_file("test1", uninit, "bar", buff, sizeof(buff));
51 (void)extattr_get_link("test1", uninit, "bar", buff, sizeof(buff));
52 (void)extattr_get_fd(tmpfd, uninit, "bar", buff, sizeof(buff));
53 (void)extattr_list_file("test1", uninit, buff, sizeof(buff));
54 (void)extattr_list_link("test1", uninit, buff, sizeof(buff));
55 (void)extattr_list_fd(tmpfd, uninit, buff, sizeof(buff));
56 (void)extattr_delete_file("test1", uninit, "foo");
57 (void)extattr_delete_link("test1", uninit, "foo");
58 (void)extattr_delete_fd(tmpfd, uninit, "foo");
60 char* badbuff = malloc(64);
61 free(badbuff);
62 (void)extattr_get_file("test1", EXTATTR_NAMESPACE_USER, "bar", badbuff, 64);
63 (void)extattr_get_link("test1", EXTATTR_NAMESPACE_USER, "bar", badbuff, 64);
64 (void)extattr_get_fd(tmpfd, EXTATTR_NAMESPACE_USER, "bar", badbuff, 64);
65 badbuff = malloc(64);
66 free(badbuff);
67 (void)extattr_list_file("test1", EXTATTR_NAMESPACE_USER, badbuff, 64);
68 (void)extattr_list_link("test1", EXTATTR_NAMESPACE_USER, badbuff, 64);
69 (void)extattr_list_fd(tmpfd, EXTATTR_NAMESPACE_USER, badbuff, 64);
71 char* badstring = strdup("test2");
72 free(badstring);
73 (void)extattr_get_file(badstring, EXTATTR_NAMESPACE_USER, "bar", buff, sizeof(buff));
74 (void)extattr_get_link(badstring, EXTATTR_NAMESPACE_USER, "bar", buff, sizeof(buff));
75 (void)extattr_get_file("test1", EXTATTR_NAMESPACE_USER, badstring, buff, sizeof(buff));
76 (void)extattr_get_link("test1", EXTATTR_NAMESPACE_USER, badstring, buff, sizeof(buff));
77 (void)extattr_list_file(badstring, EXTATTR_NAMESPACE_USER, buff, sizeof(buff));
78 (void)extattr_delete_file(badstring, EXTATTR_NAMESPACE_USER, "foo");
79 (void)extattr_delete_link(badstring, EXTATTR_NAMESPACE_USER, "foo");
81 int badfd = tmpfd;
82 VALGRIND_MAKE_MEM_UNDEFINED(&badfd, sizeof(int));
83 (void)extattr_get_fd(badfd, EXTATTR_NAMESPACE_USER, "bar", buff, sizeof(buff));
84 (void)extattr_list_fd(badfd, EXTATTR_NAMESPACE_USER, buff, sizeof(buff));
85 (void)extattr_delete_fd(badfd, EXTATTR_NAMESPACE_USER, "foo");
87 int badsize = sizeof(buff);
88 VALGRIND_MAKE_MEM_UNDEFINED(&badsize, sizeof(int));
89 extattr_get_file("test1", EXTATTR_NAMESPACE_USER, "bar", buff, badsize);
90 extattr_get_link("test1", EXTATTR_NAMESPACE_USER, "bar", buff, badsize);
91 extattr_get_fd(tmpfd, EXTATTR_NAMESPACE_USER, "bar", buff, badsize);
92 extattr_list_file("test1", EXTATTR_NAMESPACE_USER, buff, badsize);
93 extattr_list_link("test1", EXTATTR_NAMESPACE_USER, buff, badsize);
94 extattr_list_fd(tmpfd, EXTATTR_NAMESPACE_USER, buff, badsize);
96 close (tmpfd);
97 unlink(tmpfile);