Bug 480126 - Build failure on Raspberry Pi 5 / OS 6.1.0-rpi7-rpi-v8
[valgrind.git] / memcheck / tests / posix_memalign.c
blob6000c42ddabfc03fd284342950f404d60c584ffc
2 // These #defines attempt to ensure that posix_memalign() is declared, and
3 // so no spurious warning is given about using it.
5 // Advertise compliance of the code to the XSI (a POSIX superset that
6 // defines what a system must be like to be called "UNIX")
7 #undef _XOPEN_SOURCE
8 #define _XOPEN_SOURCE 600
10 // Advertise compliance to POSIX
11 #undef _POSIX_C_SOURCE
12 #define _POSIX_C_SOURCE 200112L
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <assert.h>
17 #include "tests/malloc.h"
18 #include <errno.h>
19 #include "../../config.h"
21 int main ( void )
23 # if !defined(VGO_darwin) || (DARWIN_VERS >= DARWIN_10_6)
24 // Nb: assuming VG_MIN_MALLOC_SZB is 8 or more...
25 int* p;
26 int res;
27 assert(sizeof(long int) == sizeof(void*));
29 # define PM(a,b,c) posix_memalign((void**)a, b, c)
31 // test for size 0
32 res = PM(&p, 64, 0);
33 #if defined(VGO_solaris)
34 assert(NULL == p);
35 #else
36 assert(0 == res && p && 0 == (long)p % 64);
37 free(p);
38 #endif
40 res = PM(&p, -1,100);
41 assert(EINVAL == res);
42 res = PM(&p, 0, 100);
43 assert(EINVAL == res);
44 res = PM(&p, 1, 100);
45 assert(EINVAL == res);
46 res = PM(&p, 2, 100);
47 assert(EINVAL == res);
48 res = PM(&p, 3, 100);
49 assert(EINVAL == res);
50 res = PM(&p, sizeof(void*), 100);
51 assert(0 == res && p && 0 == (long)p % sizeof(void*));
52 free(p);
53 res = PM(&p, 31, 100);
54 assert(EINVAL == res);
55 res = PM(&p, 32, 100);
56 assert(0 == res && p && 0 == (long)p % 32);
57 free(p);
58 res = PM(&p, 33, 100);
59 assert(EINVAL == res);
60 res = PM(&p, 4095, 100);
61 assert(EINVAL == res);
62 res = PM(&p, 4096, 100);
63 assert(0 == res && p && 0 == (long)p % 4096);
64 free(p);
65 res = PM(&p, 4097, 100);
66 assert(EINVAL == res);
67 res = PM(&p, 4 * 1024 * 1024, 100);
68 assert(0 == res && p && 0 == (long)p % (4 * 1024 * 1024));
69 free(p);
70 res = PM(&p, 16 * 1024 * 1024, 100);
71 assert(0 == res && p && 0 == (long)p % (16 * 1024 * 1024));
72 free(p);
73 #endif