1 /* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
3 This library is free software; you can redistribute it and/or
4 modify it under the terms of the GNU Library General Public License as
5 published by the Free Software Foundation; either version 2 of the
6 License, or (at your option) any later version.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public
14 License along with this library; see the file COPYING.LIB. If
15 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
16 Cambridge, MA 02139, USA. */
18 #ifndef _MALLOC_INTERNAL
19 #define _MALLOC_INTERNAL
24 memalign (alignment
, size
)
29 unsigned long int adj
;
31 size
= ((size
+ alignment
- 1) / alignment
) * alignment
;
33 result
= malloc (size
);
36 adj
= (unsigned long int) ((unsigned long int) ((char *) result
-
37 (char *) NULL
)) % alignment
;
41 for (l
= _aligned_blocks
; l
!= NULL
; l
= l
->next
)
42 if (l
->aligned
== NULL
)
43 /* This slot is free. Use it. */
47 l
= (struct alignlist
*) malloc (sizeof (struct alignlist
));
55 result
= l
->aligned
= (char *) result
+ alignment
- adj
;
56 l
->next
= _aligned_blocks
;