xref: /netbsd-src/external/gpl2/libmalloc/dist/valloc.c (revision 181254a7b1bdde6873432bffef2d2decc4b5c22f)
1 /*	$NetBSD: valloc.c,v 1.2 2016/01/13 21:56:38 christos Exp $	*/
2 
3 /* Allocate memory on a page boundary.
4    Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
5 
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
10 
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 Library General Public License for more details.
15 
16 You should have received a copy of the GNU Library General Public
17 License along with this library; see the file COPYING.LIB.  If
18 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
19 Cambridge, MA 02139, USA.
20 
21    The author may be reached (Email) at the address mike@ai.mit.edu,
22    or (US mail) as Mike Haertel c/o Free Software Foundation.  */
23 
24 #if defined (__GNU_LIBRARY__) || defined (_LIBC)
25 #include <stddef.h>
26 #include <unistd.h>
27 #include <sys/cdefs.h>
28 extern size_t __getpagesize __P ((void));
29 #else
30 #include "getpagesize.h"
31 #define	 __getpagesize()	getpagesize()
32 #endif
33 
34 #ifndef	_MALLOC_INTERNAL
35 #define	_MALLOC_INTERNAL
36 #include <malloc.h>
37 #endif
38 
39 static __malloc_size_t pagesize;
40 
41 __ptr_t
42 valloc (size)
43      __malloc_size_t size;
44 {
45   if (pagesize == 0)
46     pagesize = __getpagesize ();
47 
48   return memalign (pagesize, size);
49 }
50