home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / OAKALLOC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-10  |  2.0 KB  |  107 lines

  1. /*
  2.     oakalloc.c  
  3.  
  4.     % 'oakland' insulated alloc functions
  5.  
  6.     OWL 1.2
  7.     Copyright (c) 1986, 1987, 1988 by Oakland Group, Inc.
  8.     ALL RIGHTS RESERVED.
  9.  
  10.     Revision History:
  11.     -----------------
  12.      3/28/90 jmd    ansi-fied
  13.      5/03/90 jmd    added fix for Turbo/Rational realloc bug
  14.     10/10/90 ted    added support for TCP Turbo C++ flag.
  15. */
  16.  
  17. #include "oakhead.h"
  18. /* -------------------------------------------------------------------------- */
  19.  
  20. VOID *omalloc(int tag, SIZE_T size)
  21. /*
  22.     Call malloc with the given size.
  23.     Return the result.
  24.     If malloc fails, sets oak_errno to tag
  25. */
  26. {
  27.     VOID *m;
  28.  
  29.     if ((m = (VOID *)malloc(size)) == NULL) {
  30.         oak_SetErrno(tag);
  31.     }
  32.  
  33.     return(m);
  34. }
  35. /* -------------------------------------------------------------------------- */
  36.  
  37. VOID *ocalloc(int tag, SIZE_T n, SIZE_T size)
  38. /*
  39.     Call calloc with the given size.
  40.     Return the result.
  41.     If calloc fails, sets oak_errno to tag
  42. */
  43. {
  44.     VOID *m;
  45.  
  46.     if ((m = (VOID *)calloc(n, size)) == NULL) {
  47.         oak_SetErrno(tag);
  48.     }
  49.  
  50.     return(m);
  51. }
  52. /* -------------------------------------------------------------------------- */
  53.  
  54. VOID *orealloc(int tag, VOID *buffer, SIZE_T size)
  55. /*
  56.     Call realloc with the given size and buffer.
  57.     Return the result.
  58.     If realloc fails, sets oak_errno to tag
  59. */
  60. {
  61.     VOID *m;
  62.  
  63. #ifdef OAK_RATIONAL
  64. #    ifdef TC
  65. #        define REALLOC_BUG
  66. #    endif
  67. #    ifdef TCP
  68. #        define REALLOC_BUG
  69. #    endif
  70. #endif
  71.  
  72. #ifdef REALLOC_BUG
  73.  
  74.     /* compensate for Turbo/Rational realloc bug */
  75.  
  76.     if ((m = (VOID *)malloc(size)) == NULL) {
  77.         oak_SetErrno(tag);
  78.     }
  79.     else {
  80.         memcpy(m, buffer, size);
  81.         free(buffer);
  82.     }
  83.  
  84. #else
  85.  
  86.     if ((m = (VOID *)realloc(buffer, size)) == NULL) {
  87.         oak_SetErrno(tag);
  88.     }
  89.  
  90. #endif
  91.  
  92.     return(m);
  93. }
  94. /* -------------------------------------------------------------------------- */
  95.  
  96. void ofree(int tag, VOID *buffer)
  97. /*
  98.     Call free with the given buffer.
  99.     Return the result.
  100. */
  101. {
  102.     free(buffer);
  103.     /* tag not used in this version */    oak_notused(tag);
  104. }
  105. /* -------------------------------------------------------------------------- */
  106.  
  107.