home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c500 / 4.ddi / EDIT.WEX / EMEM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-28  |  2.0 KB  |  82 lines

  1. /*
  2.  *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3.  *%                                       %
  4.  *%    Copyright (C) 1991, by WATCOM Systems Inc. All rights reserved.    %
  5.  *%                                       %
  6.  *%     Permission is granted to anyone to use this example program for       %
  7.  *%     any purpose on any computer system, subject to the following       %
  8.  *%    restrictions:                               %
  9.  *%                                       %
  10.  *%     1. This example is provided on an "as is" basis, without warranty. %
  11.  *%       You indemnify, hold harmless and defend WATCOM from and against %
  12.  *%       any claims or lawsuits, including attorney's, that arise or       %
  13.  *%       result from the use or distribution of this example, or any     %
  14.  *%       modification thereof.                       %
  15.  *%                                       %
  16.  *%     2. You may not remove, alter or suppress this notice from this       %
  17.  *%        example program or any modification thereof.               %
  18.  *%                                       %
  19.  *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  20.  *
  21.  * EMEM.C
  22.  *
  23.  * Windows edit program : memory allocation routines
  24.  *
  25.  */
  26. #include <windows.h>
  27. #include <malloc.h>
  28. #include <string.h>
  29. #include <stdlib.h>
  30. #include "edit.h"
  31.  
  32. #ifdef __WINDOWS_386__
  33. #define amalloc malloc
  34. #define arealloc realloc
  35. #define afree free
  36. #define amemset memset
  37. #else
  38. #define amalloc _fmalloc
  39. #define arealloc _frealloc
  40. #define afree _ffree
  41. #define amemset _fmemset
  42. #endif
  43.  
  44.  
  45. /*
  46.  * MemAlloc - get some memory
  47.  */
  48. ALLOCPTR MemAlloc( unsigned size )
  49. {
  50. ALLOCPTR    ptr;
  51.  
  52.     if( size == 0 ) return( NULL );
  53.     ptr = amalloc( size );
  54.     if( ptr != NULL ) {
  55.         amemset( ptr, 0, size );
  56.     } else {
  57.         MessageBox( NULL, "Out Of Memory!", EditTitle,
  58.                 MB_SYSTEMMODAL | MB_OK );
  59.         exit( -1 );        /* panic situation */
  60.     }
  61.     return( ptr );
  62.  
  63. } /* MemAlloc */
  64.  
  65. /*
  66.  * MemRealloc - reallocate a block
  67.  */
  68. ALLOCPTR MemRealloc( ALLOCPTR ptr, unsigned newsize )
  69. {
  70.     return( arealloc( ptr, newsize ) );
  71.  
  72. } /* MemRealloc */
  73.  
  74. /*
  75.  * MemFree - free some memory
  76.  */
  77. void MemFree( ALLOCPTR ptr )
  78. {
  79.     afree( ptr );
  80.  
  81. } /* MemFree */
  82.