home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1992 / 06 / dflt12 / dfalloc.c < prev    next >
Text File  |  1992-03-26  |  1KB  |  73 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.         wnd = Focus.FirstWindow;
  25.         while (wnd != NULL)    {
  26.             if (GetClass(wnd) == APPLICATION)    {
  27.                 SendMessage(wnd, CLOSE_WINDOW, 0, 0);
  28.                 break;
  29.             }
  30.             wnd = NextWindow(wnd);
  31.         }
  32.         getvideo(rc, savbuf);
  33.         for (x = 0; x < 18; x++)    {
  34.             for (y = 0; y < 3; y++)        {
  35.                 int c = (255 & (*(*(ErrMsg+y)+x))) | 0x7000;
  36.                 PutVideoChar(x+rc.lf, y+rc.tp, c);
  37.             }
  38.         }
  39.         getkey();
  40.         storevideo(rc, savbuf);
  41.         if (AllocTesting)
  42.             longjmp(AllocError, 1);
  43.     }
  44. }
  45.  
  46. void *DFcalloc(size_t nitems, size_t size)
  47. {
  48.     void *rtn = calloc(nitems, size);
  49.     if (size && rtn == NULL)
  50.         AllocationError();
  51.     return rtn;
  52. }
  53.  
  54. void *DFmalloc(size_t size)
  55. {
  56.     void far * rtn = malloc(size);
  57.     if (size && rtn == NULL)
  58.         AllocationError();
  59.     return rtn;
  60. }
  61.  
  62. void *DFrealloc(void far *block, size_t size)
  63. {
  64.     void far * rtn = realloc(block, size);
  65.     if (size && rtn == NULL)
  66.         AllocationError();
  67.     return rtn;
  68. }
  69.  
  70.  
  71.  
  72.  
  73.