Add /none/tests/use_after_close to .gitignore
[valgrind.git] / memcheck / tests / freebsd / setproctitle.c
blob44e7514a2ef3ae99beb18541602047e1aa235c6e
1 #include <sys/types.h>
2 #include <sys/sysctl.h>
3 #include <sys/elf_common.h>
4 #include <sys/auxv.h>
5 #include <unistd.h>
6 #include <stdarg.h>
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include "../../../config.h"
11 int main(void)
13 #if defined(KERN_PS_STRINGS) && defined(AT_PS_STRINGS)
14 unsigned long ul_ps_strings;
15 struct ps_strings* v1;
16 struct ps_strings* v2;
17 struct ps_strings* v3;
18 int name[] = {CTL_KERN, KERN_PS_STRINGS};
20 size_t struct_len = sizeof(ul_ps_strings);
22 if (sysctlbyname("kern.ps_strings", &ul_ps_strings, &struct_len, NULL, 0) < 0) {
23 perror("sysctlbyname failed:");
24 exit(-1);
26 v1 = (struct ps_strings*)ul_ps_strings;
28 (void)elf_aux_info(AT_PS_STRINGS, &v2, sizeof(v2));
30 if (sysctl(name, 2, &ul_ps_strings, &struct_len, NULL, 0) < 0) {
31 perror("sysctl failed:");
32 exit(-1);
34 v3 = (struct ps_strings*)ul_ps_strings;
36 if (v1 == v2 && v1 == v2) {
37 printf("OK\n");
38 } else {
39 printf("FAIL ps_strings different\n");
40 printf("v1 %p v2 %p v3 %p\n", v1, v2, v3);
42 #else
43 printf("OK\n");
44 #endif
46 setproctitle("foo %s %d", "bar", 42);