| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 #include <errno.h> | 6 #include <errno.h> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 | 9 |
| 10 /* Newlib currently does not have posix_memalign in its headers, though | |
| 11 * the malloc implementation (dlmalloc) does support it. | |
| 12 * http://code.google.com/p/nativeclient/issues/detail?id=2505 | |
| 13 */ | |
| 14 #if defined(NEWLIB) | |
| 15 extern int posix_memalign(void **memptr, size_t alignment, size_t size); | |
| 16 #endif | |
| 17 | |
| 18 int main(int argc, char* argv[]) { | 10 int main(int argc, char* argv[]) { |
| 19 char *outp; | 11 char *outp; |
| 20 /* Try a few alignments, some of them might be the standard malloc align. | 12 /* Try a few alignments, some of them might be the standard malloc align. |
| 21 * They should all be powers of 2 and be a multiple of sizeof(void*). | 13 * They should all be powers of 2 and be a multiple of sizeof(void*). |
| 22 */ | 14 */ |
| 23 size_t align_to_test[] = {4, 8, 16, 32, 64, 128, 256, 512, 1024, 0}; | 15 size_t align_to_test[] = {4, 8, 16, 32, 64, 128, 256, 512, 1024, 0}; |
| 24 size_t sizes_to_test[] = {1, 2, 4, 8, 10, 16, 32, 64, 128, 256, 512, 1024, 0}; | 16 size_t sizes_to_test[] = {1, 2, 4, 8, 10, 16, 32, 64, 128, 256, 512, 1024, 0}; |
| 25 int i = 0; | 17 int i = 0; |
| 26 int j = 0; | 18 int j = 0; |
| 27 | 19 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 58 | 50 |
| 59 /* Check that smaller than sizeof(void*) alignment fails. */ | 51 /* Check that smaller than sizeof(void*) alignment fails. */ |
| 60 if (posix_memalign((void**)&outp, sizeof(void*) - 1, | 52 if (posix_memalign((void**)&outp, sizeof(void*) - 1, |
| 61 20 * sizeof(char)) != EINVAL) { | 53 20 * sizeof(char)) != EINVAL) { |
| 62 fprintf(stderr, "posix_memaligned failed to return EINVAL for non-pow2!\n"); | 54 fprintf(stderr, "posix_memaligned failed to return EINVAL for non-pow2!\n"); |
| 63 return 1; | 55 return 1; |
| 64 } | 56 } |
| 65 | 57 |
| 66 return 0; | 58 return 0; |
| 67 } | 59 } |
| OLD | NEW |