lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* posix_memalign for uClibc |
| 3 | * |
| 4 | * Copyright (C) 1996-2002, 2003, 2004, 2005 Free Software Foundation, Inc. |
| 5 | * Copyright (C) 2005 by Erik Andersen <andersen@uclibc.org> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU Library General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or (at your |
| 10 | * option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License |
| 15 | * for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Library General Public License |
| 18 | * along with this program; if not, write to the Free Software Foundation, |
| 19 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <stdlib.h> |
| 24 | #include <malloc.h> |
| 25 | #include <sys/types.h> |
| 26 | #include <errno.h> |
| 27 | #include <sys/param.h> |
| 28 | |
| 29 | int posix_memalign(void **memptr, size_t alignment, size_t size) |
| 30 | { |
| 31 | /* Make sure alignment is correct. */ |
| 32 | if (alignment % sizeof(void *) != 0) |
| 33 | /* Skip these checks because the memalign() func does them for us |
| 34 | || !powerof2(alignment / sizeof(void *)) != 0 |
| 35 | || alignment == 0 |
| 36 | */ |
| 37 | return EINVAL; |
| 38 | |
| 39 | *memptr = memalign(alignment, size); |
| 40 | |
| 41 | return (*memptr != NULL ? 0 : ENOMEM); |
| 42 | } |