home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / misc / 39 / alloc.c next >
Encoding:
C/C++ Source or Header  |  1986-07-17  |  1.0 KB  |  60 lines

  1. /* alloc.c - version 1.0.2 */
  2. #ifdef LINT
  3.  
  4. /*
  5.    a ridiculous definition, suppressing
  6.     "possible pointer alignment problem" for (long *) malloc()
  7.     "enlarg defined but never used"
  8.     "ftell defined (in <stdio.h>) but never used"
  9.    from lint
  10. */
  11. #include <stdio.h>
  12. long *
  13. alloc(n) unsigned n; {
  14. long dummy = ftell(stderr);
  15.     if(n) dummy = 0;    /* make sure arg is used */
  16.     return(&dummy);
  17. }
  18.  
  19. #else
  20.  
  21. extern char *malloc();
  22. #ifndef TOS
  23. extern char *realloc();
  24. #endif
  25.  
  26. long *
  27. alloc(lth)
  28. register unsigned lth;
  29. {
  30.     register char *ptr;
  31.  
  32.     if(!(ptr = malloc(lth)))
  33.         panic("Cannot get %d bytes", lth);
  34.     return((long *) ptr);
  35. }
  36.  
  37. #ifdef TOS
  38. long *
  39. enlarge(ptr,lth)
  40. char *ptr;
  41. unsigned lth;
  42. {
  43.     if (!free(ptr)) panic("Cannot free a memory block");
  44.     else return (alloc(lth));
  45. }
  46. #else
  47. long *
  48. enlarge(ptr,lth)
  49. register char *ptr;
  50. register unsigned lth;
  51. {
  52.     register char *nptr;
  53.  
  54.     if(!(nptr = realloc(ptr,lth)))
  55.         panic("Cannot reallocate %d bytes", lth);
  56.     return((long *) nptr);
  57. }
  58. #end
  59. #endif LINT
  60.