1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#define _ISOC11_SOURCE 1
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <myth/myth.h>
#if ! HAVE_DECL_ALIGNED_ALLOC
void * aligned_alloc(size_t al, size_t sz);
#endif
int main(int argc, char ** argv) {
size_t al = (argc > 1 ? atol(argv[1]) : 32);
size_t sz = (argc > 2 ? atol(argv[2]) : 64);
size_t n = (argc > 3 ? atol(argv[3]) : 3);
size_t i;
for (i = 0; i < n; i++) {
char * a = (char *)aligned_alloc(al, sz);
if (!a) { perror("aligned_alloc"); exit(1); }
if (((long)a) % al) {
fprintf(stderr,
"aligned_alloc(%ld,%ld) returned a pointer %p not aligned as specified\n",
al, sz, a);
exit(1);
}
size_t j;
for (j = 0; j < sz; j++) a[j] = 1;
}
printf("OK\n");
return 0;
}
|