]> 4ch.mooo.com Git - 16.git/blob - src/lib/16_hc.c
16_ca needs huge amounts of work and I should remember what needs to be done soon...
[16.git] / src / lib / 16_hc.c
1 /* Project 16 Source Code~\r
2  * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
3  *\r
4  * This file is part of Project 16.\r
5  *\r
6  * Project 16 is free software; you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation; either version 3 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * Project 16 is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or\r
18  * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
19  * Fifth Floor, Boston, MA 02110-1301 USA.\r
20  *\r
21  */\r
22 /*\r
23         heap check\r
24 */\r
25 \r
26 #include "src/lib/16_hc.h"\r
27 #include <malloc.h>\r
28 \r
29 //from ftp://213.85.246.177/pub/FreeBSD/ports/archivers/arj/work/arj-3.10.22/environ.c\r
30 #if 0\r
31 //#ifdef __WATCOMC__\r
32 long HC_Newfarcoreleft()\r
33 {\r
34         void __huge *hp;                static long rc=736L;    long s_rc;\r
35 \r
36         s_rc=rc;        rc+=2L;\r
37         do\r
38                 hp=halloc(rc-=2L, 1024);\r
39         while(hp==NULL&&rc>0L);\r
40         if(hp!=NULL)\r
41                 hfree(hp);\r
42         if(rc<s_rc)\r
43                 return(rc*1024L);\r
44         do\r
45         {\r
46                 hp=halloc(rc+=16L, 1024);\r
47                 if(hp!=NULL)\r
48                         hfree(hp);\r
49         } while(hp!=NULL);\r
50         return((rc-16L)*1024L);\r
51 }\r
52 #endif\r
53 \r
54 //from: https://stackoverflow.com/questions/14386856/c-check-available-ram\r
55 void __near* HC_LargestFreeBlock(size_t* Size)\r
56 {\r
57         size_t s0, s1;\r
58         void __near* p;\r
59 \r
60         s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);\r
61         while (s0 && (p = _nmalloc(s0)) == NULL)\r
62                 s0 >>= 1;\r
63 \r
64         if (p)\r
65                 _nfree(p);\r
66 \r
67         s1 = s0 >> 1;\r
68         while (s1)\r
69         {\r
70                 if ((p = _nmalloc(s0 + s1)) != NULL)\r
71                 {\r
72                         s0 += s1;\r
73                         _nfree(p);\r
74                 }\r
75         s1 >>= 1;\r
76         }\r
77         while (s0 && (p = _nmalloc(s0)) == NULL)\r
78                 s0 ^= s0 & -s0;\r
79 \r
80         *Size = s0;\r
81         return p;\r
82 }\r
83 \r
84 //from: https://stackoverflow.com/questions/14386856/c-check-available-ram\r
85 size_t HC_coreleft(void)\r
86 {\r
87         size_t total = 0;\r
88         void __near* pFirst = NULL;\r
89         void __near* pLast = NULL;\r
90         for(;;)\r
91         {\r
92                 size_t largest;\r
93                 void __near* p = (void __near *)HC_LargestFreeBlock(&largest);\r
94                 if (largest < sizeof(void __near*))\r
95                 {\r
96                         if (p != NULL)\r
97                         _nfree(p);\r
98                         break;\r
99                 }\r
100                 *(void __near* __near*)p = NULL;\r
101                 total += largest;\r
102                 if (pFirst == NULL)\r
103                         pFirst = p;\r
104 \r
105                 if (pLast != NULL)\r
106                         *(void __near* __near*)pLast = p;\r
107                 pLast = p;\r
108         }\r
109 \r
110         while (pFirst != NULL)\r
111         {\r
112                 void __near* p = *(void __near* __near*)pFirst;\r
113                 _nfree(pFirst);\r
114                 pFirst = p;\r
115         }\r
116         return total;\r
117 }\r
118 \r
119 //far version of above\r
120 void far* HC_LargestFarFreeBlock(unsigned long* Size)\r
121 {\r
122         unsigned long s0, s1;\r
123         void far* p;\r
124 \r
125         s0 = ~(unsigned long)0 ^ (~(unsigned long)0 >> 1);\r
126         while (s0 && (p = _fmalloc(s0)) == NULL)\r
127                 s0 >>= 1;\r
128 \r
129         if (p)\r
130                 _ffree(p);\r
131 \r
132         s1 = s0 >> 1;\r
133         while (s1)\r
134         {\r
135                 if ((p = _fmalloc(s0 + s1)) != NULL)\r
136                 {\r
137                         s0 += s1;\r
138                         _ffree(p);\r
139                 }\r
140         s1 >>= 1;\r
141         }\r
142         while (s0 && (p = _fmalloc(s0)) == NULL)\r
143                 s0 ^= s0 & -s0;\r
144 \r
145         *Size = s0;\r
146         return p;\r
147 }\r
148 \r
149 //far version of above\r
150 unsigned long HC_farcoreleft(void)\r
151 {\r
152         unsigned long total = 0UL;\r
153         void far* pFirst = NULL;\r
154         void far* pLast = NULL;\r
155         for(;;)\r
156         {\r
157                 unsigned long largest;\r
158                 void far* p = HC_LargestFarFreeBlock(&largest);\r
159                 if (largest < sizeof(void far*))\r
160                 {\r
161                         if (p != NULL)\r
162                         _ffree(p);\r
163                         break;\r
164                 }\r
165                 *(void far* far*)p = NULL;\r
166                 total += largest;\r
167                 if (pFirst == NULL)\r
168                         pFirst = p;\r
169 \r
170                 if (pLast != NULL)\r
171                         *(void far* far*)pLast = p;\r
172                 pLast = p;\r
173         }\r
174 \r
175         while (pFirst != NULL)\r
176         {\r
177                 void far* p = *(void far* far*)pFirst;\r
178                 _ffree(pFirst);\r
179                 pFirst = p;\r
180         }\r
181         return total;\r
182 }\r
183 \r
184 //==#ifdef __WATCOMC__\r
185 /*void huge* LargestHugeFreeBlock(size_t* Size)\r
186 {\r
187         size_t s0, s1;\r
188         void huge* p;\r
189 \r
190         s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);\r
191         while (s0 && (p = halloc((dword)s0, 1)) == NULL)\r
192                 s0 >>= 1;\r
193 \r
194         if (p)\r
195                 hfree(p);\r
196 \r
197         s1 = s0 >> 1;\r
198         while (s1)\r
199         {\r
200                 if ((p = halloc((dword)(s0 + s1), 1)) != NULL)\r
201                 {\r
202                         s0 += s1;\r
203                         hfree(p);\r
204                 }\r
205         s1 >>= 1;\r
206         }\r
207         while (s0 && (p = halloc((dword)s0, 1)) == NULL)\r
208                 s0 ^= s0 & -s0;\r
209 \r
210         *Size = s0;\r
211         return p;\r
212 }\r
213 \r
214 size_t _hugecoreleft(void)\r
215 {\r
216         size_t total = 0;\r
217         void huge* pFirst = NULL;\r
218         void huge* pLast = NULL;\r
219         for(;;)\r
220         {\r
221                 size_t largest;\r
222                 void huge* p = LargestHugeFreeBlock(&largest);\r
223                 if (largest < sizeof(void huge*))\r
224                 {\r
225                         if (p != NULL)\r
226                         hfree(p);\r
227                         break;\r
228                 }\r
229                 *(void huge* huge*)p = NULL;\r
230                 total += largest;\r
231                 if (pFirst == NULL)\r
232                         pFirst = p;\r
233 \r
234                 if (pLast != NULL)\r
235                         *(void huge* huge*)pLast = p;\r
236                 pLast = p;\r
237         }\r
238 \r
239         while (pFirst != NULL)\r
240         {\r
241                 void huge* p = *(void huge* huge*)pFirst;\r
242                 hfree(pFirst);\r
243                 pFirst = p;\r
244         }\r
245         return total;\r
246 }\r
247 \r
248 void __based(__self)* LargestBasedFreeBlock(size_t* Size)\r
249 {\r
250         __segment segu;\r
251         size_t s0, s1;\r
252         void __based(__self)* p;\r
253 \r
254         s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);\r
255         while (s0 && (p = _bmalloc(segu, s0)) == NULL)\r
256                 s0 >>= 1;\r
257 \r
258         if (p)\r
259                 _ffree(p);\r
260 \r
261         s1 = s0 >> 1;\r
262         while (s1)\r
263         {\r
264                 if ((p = _bmalloc(segu, s0 + s1)) != NULL)\r
265                 {\r
266                         s0 += s1;\r
267                         _ffree(p);\r
268                 }\r
269         s1 >>= 1;\r
270         }\r
271         while (s0 && (p = _bmalloc(segu, s0)) == NULL)\r
272                 s0 ^= s0 & -s0;\r
273 \r
274         *Size = s0;\r
275         return p;\r
276 }\r
277 \r
278 size_t _basedcoreleft(void)\r
279 {\r
280         __segment segu;\r
281         size_t total = 0;\r
282         void __based(segu)* pFirst = NULL;\r
283         void __based(segu)* pLast = NULL;\r
284         // allocate based heap\r
285         segu = _bHC_heapseg( 1024 );\r
286         if( segu == _NULLSEG ) {\r
287                 printf( "Unable to allocate based heap\n" );\r
288                 return 0;\r
289 \r
290         }\r
291         else\r
292 \r
293         for(;;)\r
294         {\r
295                 size_t largest;\r
296                 void __based(segu)* p = LargestBasedFreeBlock(&largest);\r
297                 if (largest < sizeof(void far*))\r
298                 {\r
299                         if (p != NULL)\r
300                         _ffree(p);\r
301                         break;\r
302                 }\r
303                 *(void far* far*)p = NULL;\r
304                 total += largest;\r
305                 if (pFirst == NULL)\r
306                         pFirst = p;\r
307 \r
308                 if (pLast != NULL)\r
309                         *(void far* far*)pLast = p;\r
310                 pLast = p;\r
311         }\r
312 \r
313         while (pFirst != NULL)\r
314         {\r
315                 void far* p = *(void far* far*)pFirst;\r
316                 _ffree(pFirst);\r
317                 pFirst = p;\r
318         }\r
319         return total;\r
320 }\r
321 \r
322 size_t HC_GetFreeSize(void)\r
323 {\r
324         struct _heapinfo h_info;\r
325         int heap_status;\r
326         size_t h_free=0, h_total=0, h_used=0;\r
327 \r
328         h_info._pentry = NULL;\r
329         for(;;) {\r
330                 heap_status = _heapwalk( &h_info );\r
331                 if( heap_status != _HEAPOK ) break;\r
332                 if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") h_free += h_info._size;\r
333                 if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") h_used += h_info._size;\r
334                 h_total += h_info._size;\r
335         }\r
336         HCL_heapstat(heap_status);\r
337         return h_free;\r
338 }\r
339 */\r
340 \r
341 void HCL_HeapWalking (struct _heapinfo *h_info, hc_use_t *hu, unsigned nearfarswitch)\r
342 {\r
343         hu->h_free=0; hu->h_total=0; hu->h_used=0;\r
344 \r
345         h_info->_pentry = NULL;\r
346         for(;;) {\r
347                 if(nearfarswitch==0) hu->heap_status = _nheapwalk( h_info );\r
348                 else if(nearfarswitch==1) hu->heap_status = _fheapwalk( h_info );\r
349                 if( hu->heap_status != _HEAPOK ) break;\r
350                 if((h_info->_useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") hu->h_free += h_info->_size;\r
351                 if((h_info->_useflag == _USEDENTRY ? "USED" : "FREE")=="USED") hu->h_used += h_info->_size;\r
352                 hu->h_total += h_info->_size;\r
353         }\r
354         HCL_heapstat(hu->heap_status);\r
355 }\r
356 \r
357 unsigned long HC_GetFarFreeSize(void)\r
358 {\r
359         struct _heapinfo h_info;\r
360         hc_use_t hu;\r
361         HCL_HeapWalking (&h_info, &hu, 1);\r
362         return hu.h_free;\r
363 #if 0\r
364         struct _heapinfo fh_info;\r
365         int heap_status;\r
366         unsigned long fh_free=0, fh_total=0, fh_used=0;\r
367 \r
368         fh_info._pentry = NULL;\r
369         for(;;) {\r
370                 heap_status = _fheapwalk( &fh_info );\r
371                 if( heap_status != _HEAPOK ) break;\r
372                 if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") fh_free += fh_info._size;\r
373                 if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") fh_used += fh_info._size;\r
374                 fh_total += fh_info._size;\r
375         }\r
376         HCL_heapstat(heap_status);\r
377         return fh_free;\r
378 #endif\r
379 }\r
380 \r
381 size_t HC_GetNearFreeSize(void)\r
382 {\r
383         struct _heapinfo h_info;\r
384         hc_use_t hu;\r
385         HCL_HeapWalking (&h_info, &hu, 0);\r
386         return hu.h_free;\r
387 #if 0\r
388         struct _heapinfo nh_info;\r
389         int heap_status;\r
390         size_t nh_free=0, nh_total=0, nh_used=0;\r
391 \r
392         nh_info._pentry = NULL;\r
393         for(;;) {\r
394                 heap_status = _nheapwalk( &nh_info );\r
395                 if( heap_status != _HEAPOK ) break;\r
396                 if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") nh_free += nh_info._size;\r
397                 if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") nh_used += nh_info._size;\r
398                 nh_total += nh_info._size;\r
399         }\r
400         HCL_heapstat(heap_status);\r
401         return nh_free;\r
402 #endif\r
403 }\r
404 \r
405 void HC_heapdump(global_game_variables_t *gvar)\r
406 {\r
407         struct _heapinfo fh_info, nh_info;//, h_info;\r
408         int heap_status;\r
409         size_t nh_free, fh_free, nh_total, fh_total, nh_used, fh_used;//,       h_free, h_total, h_used;\r
410         byte    scratch[1024],str[16];\r
411 \r
412         HC_OpenDebug(gvar);\r
413 \r
414 #if 0\r
415         strcpy(scratch,"\n      == default ==\n\n");\r
416         write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
417         h_info._pentry = NULL;\r
418         h_free=0; h_total=0; h_used=0;\r
419         for(;;) {\r
420                 heap_status = _heapwalk( &h_info );\r
421                 if( heap_status != _HEAPOK ) break;\r
422                 strcpy(scratch,"  "); strcat(scratch,(h_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at ");\r
423                 sprintf(str, "%Fp", h_info._pentry); //ultoa((dword)h_info._pentry,str,16);\r
424                         strcat(scratch,str); strcat(scratch," of size "); ultoa(h_info._size,str,10); strcat(scratch,str); strcat(scratch,"\n");\r
425                 if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") h_free += h_info._size;\r
426                 if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") h_used += h_info._size;\r
427                 h_total += h_info._size;\r
428                 write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
429         }\r
430         HCL_heapstatLogWrite(gvar, heap_status, scratch);\r
431 #endif\r
432 \r
433         //near\r
434         strcpy(scratch,"\n      == near ==\n\n");\r
435         write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
436         nh_info._pentry = NULL;\r
437         nh_free=0; nh_total=0; nh_used=0;\r
438         for(;;) {\r
439                 heap_status = _nheapwalk( &nh_info );\r
440                 if( heap_status != _HEAPOK ) break;\r
441                 strcpy(scratch,"  "); strcat(scratch,(nh_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at ");\r
442                 sprintf(str, "%Fp", nh_info._pentry); //ultoa((dword)nh_info._pentry,str,16);\r
443                         strcat(scratch,str); strcat(scratch," of size "); ultoa(nh_info._size,str,10); strcat(scratch,str); strcat(scratch,"\n");\r
444 /*              printf( "  %s block at %Fp of size %4.4X\n",\r
445 (nh_info._useflag == _USEDENTRY ? "USED" : "FREE"),\r
446 nh_info._pentry, nh_info._size );*/\r
447                 if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") nh_free += nh_info._size;\r
448                 if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") nh_used += nh_info._size;\r
449                 nh_total += nh_info._size;\r
450                 write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
451         }\r
452         HCL_heapstatLogWrite(gvar, heap_status, scratch);\r
453 \r
454         //far\r
455         strcpy(scratch,"\n      == far ==\n\n");\r
456         write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
457         fh_info._pentry = NULL;\r
458         fh_free=0; fh_total=0; fh_used=0;\r
459         for(;;) {\r
460                 heap_status = _fheapwalk( &fh_info );\r
461                 if( heap_status != _HEAPOK ) break;\r
462                 strcpy(scratch,"  "); strcat(scratch,(fh_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at ");\r
463                 sprintf(str, "%Fp", fh_info._pentry); //ultoa((dword)fh_info._pentry,str,16);\r
464                         strcat(scratch,str); strcat(scratch," of size "); ultoa(fh_info._size,str,10); strcat(scratch,str); strcat(scratch,"\n");\r
465                 /*printf( "  %s block at %Fp of size %4.4X\n",\r
466 (fh_info._useflag == _USEDENTRY ? "USED" : "FREE"),\r
467 fh_info._pentry, fh_info._size );*/\r
468                 if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") fh_free += fh_info._size;\r
469                 if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") fh_used += fh_info._size;\r
470                 fh_total += fh_info._size;\r
471                 write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
472         }\r
473         HCL_heapstatLogWrite(gvar, heap_status, scratch);\r
474 \r
475         strcpy(scratch,"\n");\r
476         strcat(scratch,kittengets(2,0,"Memory Type         Total      Used       Free\n"));\r
477         strcat(scratch,"----------------  --------   --------   --------\n");\r
478 //      printmeminfoline(&scratch, "Default", h_total, h_used, h_free);\r
479         printmeminfoline(scratch, "Near", nh_total, nh_used, nh_free);\r
480         printmeminfoline(scratch, "Far", fh_total, fh_used, fh_free);\r
481         strcat(scratch,"----------------  --------   --------   --------\n");\r
482         strcat(scratch,"HC_coreleft = ");                       ultoa((dword)HC_coreleft(),str,10);                     strcat(scratch,str);    strcat(scratch,"\n");\r
483         strcat(scratch,"HC_farcoreleft = ");                    ultoa((dword)HC_farcoreleft(),str,10);          strcat(scratch,str);    strcat(scratch,"\n");\r
484 //      strcat(scratch,"HC_Newfarcoreleft = ");         ultoa((dword)HC_Newfarcoreleft(),str,10);               strcat(scratch,str);    strcat(scratch,"\n");\r
485 //      strcat(scratch,"HC_GetFreeSize = ");            ultoa((dword)HC_GetFreeSize(),str,10);          strcat(scratch,str);    strcat(scratch,"\n");\r
486         strcat(scratch,"HC_GetNearFreeSize = ");        ultoa((dword)HC_GetNearFreeSize(),str,10);      strcat(scratch,str);    strcat(scratch,"\n");\r
487         strcat(scratch,"HC_GetFarFreeSize = ");         ultoa((dword)HC_GetFarFreeSize(),str,10);       strcat(scratch,str);    strcat(scratch,"\n");\r
488         strcat(scratch,"coreleft = ");                          ultoa((dword)coreleft(),str,10);                                strcat(scratch,str);    strcat(scratch,"\n");\r
489         strcat(scratch,"farcoreleft = ");                       ultoa((dword)farcoreleft(),str,10);                     strcat(scratch,str);    strcat(scratch,"\n");\r
490         strcat(scratch,"stackavail = ");                        ultoa((dword)stackavail(),str,10);                      strcat(scratch,str);    strcat(scratch,"\n");\r
491         write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
492         HC_CloseDebug(gvar);\r
493 }\r
494 \r
495 void HCL_heapstatLogWrite(global_game_variables_t *gvar, int heap_status, byte *str)\r
496 {\r
497         switch( heap_status ) {\r
498                 case _HEAPEND:\r
499                         strcpy((str),"OK - end of heap\n");\r
500                 break;\r
501                 case _HEAPEMPTY:\r
502                         strcpy((str),"OK - heap is empty\n");\r
503 \r
504                 break;\r
505                 case _HEAPBADBEGIN:\r
506                         strcpy((str),"ERROR - heap is damaged\n");\r
507                 break;\r
508 #ifdef __WATCOMC__\r
509                 case _HEAPBADPTR:\r
510                         strcpy((str),"ERROR - bad pointer to heap\n");\r
511                 break;\r
512 #endif\r
513                 case _HEAPBADNODE:\r
514                         strcpy((str),"ERROR - bad node in heap\n");\r
515         }\r
516         write(gvar->handle.heaphandle,(str),strlen((str)));\r
517 }\r
518 \r
519 void HCL_heapstat(int heap_status)\r
520 {\r
521         switch( heap_status ) {\r
522                 case _HEAPEND:\r
523                         //printf("OK - end of heap\n");\r
524                 break;\r
525                 case _HEAPEMPTY:\r
526                         //printf("OK - heap is empty\n");\r
527                 break;\r
528                 case _HEAPBADBEGIN:\r
529                         printf("ERROR - heap is damaged\n");\r
530                 break;\r
531 #ifdef __WATCOMC__\r
532                 case _HEAPBADPTR:\r
533                         printf("ERROR - bad pointer to heap\n");\r
534                 break;\r
535 #endif\r
536                 case _HEAPBADNODE:\r
537                         printf("ERROR - bad node in heap\n");\r
538         }\r
539 }\r
540 \r
541 //++\r
542 #ifdef __WATCOMC__\r
543 unsigned long farcoreleft()\r
544 {\r
545 //----  _fheapgrow();\r
546         return HC_farcoreleft();\r
547 //stack overflows       return HC_GetFarFreeSize();\r
548 }\r
549 \r
550 unsigned long coreleft()\r
551 {\r
552         _nheapgrow();\r
553         return _memavl();\r
554 //      return HC_GetNearFreeSize();\r
555 }\r
556 #endif\r
557 \r
558 /*\r
559 ============================\r
560 =\r
561 = HC_OpenDebug / HC_CloseDebug\r
562 =\r
563 = Opens a binary file with the handle "heaphandle"\r
564 =\r
565 ============================\r
566 */\r
567 void HC_OpenDebug(global_game_variables_t *gvar)\r
568 {\r
569 #ifdef __BORLANDC__\r
570         unlink("heap.16b");\r
571         gvar->handle.heaphandle = open(gvar->handle.heapdumpfilename, O_CREAT | O_WRONLY | O_TEXT);\r
572 #endif\r
573 #ifdef __WATCOMC__\r
574         unlink("heap.16w");\r
575         gvar->handle.heaphandle = open(gvar->handle.heapdumpfilename, O_CREAT | O_WRONLY | O_TEXT);\r
576 #endif\r
577 }\r
578 \r
579 void HC_CloseDebug(global_game_variables_t *gvar)\r
580 {\r
581         close(gvar->handle.heaphandle);\r
582 \r
583 #ifdef __BORLANDC__\r
584         strcpy(gvar->handle.heapdumpfilename, "heap.16b");\r
585 #endif\r
586 #ifdef __WATCOMC__\r
587         strcpy(gvar->handle.heapdumpfilename, "heap.16w");\r
588 #endif\r
589 }\r