home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / tmp9 / p_omalloc.c < prev    next >
C/C++ Source or Header  |  2002-01-20  |  2KB  |  91 lines

  1. /*****************************************************************************/
  2. /*                                                                           */
  3. /*              Copyright (c) 1995 by Oy Online Solutions Ltd.               */
  4. /*                                                                           */
  5. /*   Distribution of this source code is strictly forbbidden. Use of this    */
  6. /*   source code is granted to the University of Columbia C-Kermit project   */
  7. /*   to be distributed in binary format only. Please familiarize yourself    */
  8. /*   with the accompanying LICENSE.P file.                                   */
  9. /*                                                                           */
  10. /*****************************************************************************/
  11.  
  12. /* More friendlier interface to OS/2's DosAllocMem and DosFreeMem API calls */
  13.  
  14. #include "ckcdeb.h"
  15. #ifndef NOXFER
  16.  
  17. #ifdef OS2
  18. #ifdef NT
  19. #include <windows.h>
  20. #else /* NT */
  21. #define INCL_DOSMEMMGR
  22. #include <os2.h>
  23. #undef COMMENT
  24. #endif /* NT */
  25. #else /* OS2 */
  26. #include <stdlib.h>
  27. #endif /* OS2 */
  28.  
  29.  
  30. #include "p.h"
  31. #include "p_type.h"
  32. #include "p_error.h"
  33.  
  34. VOID
  35. #ifdef CK_ANSIC
  36. p_omalloc(void **buf, U32 size, U32 module, U32 line)
  37. #else
  38. p_omalloc(buf,size,module,line)
  39.      void **buf; U32 size; U32 module; U32 line;
  40. #endif
  41. {
  42.   APIRET rc=0;
  43.  
  44.   if ( buf == NULL )
  45.       return;
  46.  
  47. #ifdef OS2
  48. #ifdef NT
  49.    *buf = GlobalAlloc( 0, size ) ;
  50.    if ( !buf ) rc = GetLastError() ;
  51. #else /* NT */
  52.    rc = DosAllocMem(buf, size, PAG_COMMIT | PAG_WRITE | PAG_READ);
  53. #endif /* NT */
  54. #else /* OS2 */
  55.    *buf = malloc(size);
  56.    if ( !*buf ) rc = 1 ;
  57. #endif /* OS2 */
  58.  
  59.   if (rc)
  60.     os2_error(P_ERROR_DOSALLOCMEM, rc, module, line, NULL);
  61. }
  62.  
  63. VOID
  64. #ifdef CK_ANSIC
  65. p_ofree(void **buf, U32 module, U32 line)
  66. #else
  67. p_ofree(buf, module,line)
  68.      void **buf; U32 module; U32 line;
  69. #endif
  70. {
  71.     APIRET rc=0;
  72.  
  73.     if ( *buf == NULL )
  74.         return;
  75.  
  76. #ifdef OS2
  77. #ifdef NT
  78.    if ( GlobalFree(*buf) )
  79.       rc = GetLastError() ;
  80. #else /* NT */
  81.    rc = DosFreeMem(*buf);
  82. #endif /* NT */
  83. #else /* OS2 */
  84.     rc = free(*buf);
  85. #endif /* OS2 */
  86.   if (rc)
  87.     os2_error(P_ERROR_DOSFREEMEM, rc, module, line, 0);
  88.   *buf = NULL;
  89. }
  90. #endif /* NOXFER */
  91.