Salloc.c 785 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /* $Id$ */
  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 *Salloc(str, n) : allocate n bytes, initialized with the string
  9. str
  10. */
  11. #if __STDC__
  12. #include <stdlib.h>
  13. #else
  14. extern char *malloc();
  15. #endif
  16. #include "alloc.h"
  17. char *
  18. Salloc(str, sz)
  19. register char *str;
  20. register unsigned int sz;
  21. {
  22. /* Salloc() is not a primitive function: it just allocates a
  23. piece of storage and copies a given string into it.
  24. */
  25. char *res = malloc(sz);
  26. register char *m = res;
  27. if (sz && m == 0) No_Mem();
  28. while (sz--)
  29. *m++ = *str++;
  30. return res;
  31. }