valloc.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* Allocate memory on a page boundary.
  2. Copyright (C) 1991, 1992, 1993, 1994 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.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with this library; see the file COPYING.LIB. If
  13. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  14. Cambridge, MA 02139, USA.
  15. The author may be reached (Email) at the address mike@ai.mit.edu,
  16. or (US mail) as Mike Haertel c/o Free Software Foundation. */
  17. #if defined (__GNU_LIBRARY__) || defined (_LIBC)
  18. #include <stddef.h>
  19. #include <sys/cdefs.h>
  20. extern size_t __getpagesize __P ((void));
  21. #else
  22. #include "getpagesize.h"
  23. #define __getpagesize() getpagesize()
  24. #endif
  25. #ifndef _MALLOC_INTERNAL
  26. #define _MALLOC_INTERNAL
  27. #include <malloc.h>
  28. #endif
  29. static __malloc_size_t pagesize;
  30. __ptr_t
  31. valloc (size)
  32. __malloc_size_t size;
  33. {
  34. if (pagesize == 0)
  35. pagesize = __getpagesize ();
  36. return memalign (pagesize, size);
  37. }