Malloc.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* $Header$ */
  2. /*
  3. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. * See the copyright notice in the ACK home directory, in the file "Copyright".
  5. */
  6. /* M E M O R Y A L L O C A T I O N R O U T I N E S */
  7. /* The memory allocation routines offered in this file are:
  8. char *Malloc(n) : allocate n bytes
  9. char *Srealloc(ptr, n) : reallocate buffer to n bytes
  10. char *Salloc(str, n) : allocate n bytes, initialized with the string
  11. str
  12. This file imports routines from "system".
  13. */
  14. #include <system.h>
  15. #include "in_all.h"
  16. #include "alloc.h"
  17. EXPORT char *
  18. Malloc(sz)
  19. unsigned int sz;
  20. {
  21. char *res = malloc(sz);
  22. if (res == 0) No_Mem();
  23. return res;
  24. }
  25. EXPORT char *
  26. Salloc(str, sz)
  27. register char str[];
  28. register unsigned int sz;
  29. {
  30. /* Salloc() is not a primitive function: it just allocates a
  31. piece of storage and copies a given string into it.
  32. */
  33. char *res = malloc(sz);
  34. register char *m = res;
  35. if (m == 0) No_Mem();
  36. while (sz--)
  37. *m++ = *str++;
  38. return res;
  39. }
  40. EXPORT char *
  41. Srealloc(str, sz)
  42. char str[];
  43. unsigned int sz;
  44. {
  45. str = realloc(str, sz);
  46. if (str == 0) No_Mem();
  47. return str;
  48. }