home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / window / dflat / dfalloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-28  |  1.2 KB  |  66 lines

  1. /* ---------- dfalloc.c ---------- */
  2.  
  3. #include "dflat.h"
  4.  
  5.  
  6. static void AllocationError(void)
  7. {
  8.     WINDOW wnd;
  9.     static BOOL OnceIn = FALSE;
  10.     extern jmp_buf AllocError;
  11.     extern BOOL AllocTesting;
  12.     static char *ErrMsg[] = {
  13.         "┌────────────────┐",
  14.         "│ Out of Memory! │",
  15.         "└────────────────┘"
  16.     };
  17.     int x, y;
  18.     char savbuf[108];
  19.     RECT rc = {30,11,47,13};
  20.  
  21.     if (!OnceIn)    {
  22.         OnceIn = TRUE;
  23.         /* ------ close all windows ------ */
  24.         SendMessage(ApplicationWindow, CLOSE_WINDOW, 0, 0);
  25.         getvideo(rc, savbuf);
  26.         for (x = 0; x < 18; x++)    {
  27.             for (y = 0; y < 3; y++)        {
  28.                 int c = (255 & (*(*(ErrMsg+y)+x))) | 0x7000;
  29.                 PutVideoChar(x+rc.lf, y+rc.tp, c);
  30.             }
  31.         }
  32.         getkey();
  33.         storevideo(rc, savbuf);
  34.         if (AllocTesting)
  35.             longjmp(AllocError, 1);
  36.     }
  37. }
  38.  
  39. void *DFcalloc(size_t nitems, size_t size)
  40. {
  41.     void *rtn = calloc(nitems, size);
  42.     if (size && rtn == NULL)
  43.         AllocationError();
  44.     return rtn;
  45. }
  46.  
  47. void *DFmalloc(size_t size)
  48. {
  49.     void far * rtn = malloc(size);
  50.     if (size && rtn == NULL)
  51.         AllocationError();
  52.     return rtn;
  53. }
  54.  
  55. void *DFrealloc(void far *block, size_t size)
  56. {
  57.     void far * rtn = realloc(block, size);
  58.     if (size && rtn == NULL)
  59.         AllocationError();
  60.     return rtn;
  61. }
  62.  
  63.  
  64.  
  65.  
  66.