home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / cprog / dflt14.zip / DFALLOC.C < prev    next >
Text File  |  1992-08-12  |  1KB  |  61 lines

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