valloc.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* Allocate memory on a page boundary.
  2. 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.
  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. #include <stdlib.h>
  18. #include "malloc.h"
  19. #ifdef emacs
  20. #include "config.h"
  21. #endif
  22. #ifdef __GNU_LIBRARY__
  23. extern size_t __getpagesize __P ((void));
  24. #else
  25. #ifndef USG
  26. extern size_t getpagesize __P ((void));
  27. #define __getpagesize() getpagesize()
  28. #else
  29. #include <sys/param.h>
  30. #ifdef EXEC_PAGESIZE
  31. #define __getpagesize() EXEC_PAGESIZE
  32. #else /* No EXEC_PAGESIZE. */
  33. #ifdef NBPG
  34. #ifndef CLSIZE
  35. #define CLSIZE 1
  36. #endif /* No CLSIZE. */
  37. #define __getpagesize() (NBPG * CLSIZE)
  38. #else /* No NBPG. */
  39. #define __getpagesize() NBPC
  40. #endif /* NBPG. */
  41. #endif /* EXEC_PAGESIZE. */
  42. #endif /* USG. */
  43. #endif
  44. static size_t pagesize;
  45. __ptr_t
  46. valloc (size)
  47. size_t size;
  48. {
  49. if (pagesize == 0)
  50. pagesize = __getpagesize ();
  51. return memalign (pagesize, size);
  52. }