File: dfalloc.c

package info (click to toggle)
dosemu-freedos 1%3A0.0.b9r5a%2Betch.1-0etch1
  • links: PTS
  • area: contrib
  • in suites: etch
  • size: 19,744 kB
  • ctags: 23,279
  • sloc: ansic: 143,864; asm: 20,397; makefile: 3,868; perl: 1,106; yacc: 690; sh: 553; pascal: 297; xml: 150; cpp: 67
file content (75 lines) | stat: -rw-r--r-- 1,458 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* ---------- dfalloc.c ---------- */

#include "dflat.h"

static void AllocationError(void)
{
    static BOOL OnceIn=FALSE;
    extern jmp_buf AllocError;
    extern BOOL AllocTesting;
    static char *ErrMsg[]={
        "Ŀ",
        " Out of Memory! ",
        ""};
    int x,y;
    char savbuf[108];
    RECT rc={30,11,47,13};

    if (!OnceIn)
        {
        OnceIn=TRUE;

        /* Close all windows */
        SendMessage(ApplicationWindow, CLOSE_WINDOW, 0, 0);
        getvideo(rc, savbuf);
        for (x=0;x<18;x++)
            {
            for (y=0;y<3;y++)
                {
                int c=(255 & (*(*(ErrMsg+y)+x))) | 0x7000;
                PutVideoChar(x+rc.lf, y+rc.tp, c);
                }

            }

        getkey();
        storevideo(rc, savbuf);
        if (AllocTesting)
            longjmp(AllocError, 1);

        }

}

void *DFcalloc(size_t nitems, size_t size)
{
    void *rtn=calloc(nitems, size);

    if (size && rtn == NULL)
        AllocationError();

    return rtn;

}

void *DFmalloc(size_t size)
{
    void *rtn=malloc(size);

    if (size && rtn == NULL)
        AllocationError();

    return rtn;

}

void *DFrealloc(void *block, size_t size)
{
    void *rtn=(block == NULL) ? malloc(size) : realloc(block,size);

    if (size && rtn == NULL)
        AllocationError();

    return rtn;

}