]> 4ch.mooo.com Git - 16.git/blob - src/lib/16_hc.c
farcoreleft() is now flexible <3 going to code later like a few days from now later
[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 test stuff\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\r
56 #ifdef __BORLANDC__\r
57  *\r
58 #endif\r
59 #ifdef __WATCOMC__\r
60  __near*\r
61 #endif\r
62 HC_LargestFreeBlock(size_t* Size)\r
63 {\r
64         size_t s0, s1;\r
65 #ifdef __BORLANDC__\r
66         void * p;\r
67 #endif\r
68 #ifdef __WATCOMC__\r
69         void __near* p;\r
70 #endif\r
71 \r
72         s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);\r
73 #ifdef __BORLANDC__\r
74         while (s0 && (p = malloc(s0)) == NULL)\r
75 #endif\r
76 #ifdef __WATCOMC__\r
77         while (s0 && (p = _nmalloc(s0)) == NULL)\r
78 #endif\r
79                 s0 >>= 1;\r
80 \r
81         if (p)\r
82 #ifdef __BORLANDC__\r
83                 free(p);\r
84 #endif\r
85 #ifdef __WATCOMC__\r
86                 _nfree(p);\r
87 #endif\r
88 \r
89         s1 = s0 >> 1;\r
90         while (s1)\r
91         {\r
92 #ifdef __BORLANDC__\r
93                 if ((p = malloc(s0 + s1)) != NULL)\r
94 #endif\r
95 #ifdef __WATCOMC__\r
96                 if ((p = _nmalloc(s0 + s1)) != NULL)\r
97 #endif\r
98                 {\r
99                         s0 += s1;\r
100 #ifdef __BORLANDC__\r
101                         free(p);\r
102 #endif\r
103 #ifdef __WATCOMC__\r
104                         _nfree(p);\r
105 #endif\r
106                 }\r
107         s1 >>= 1;\r
108         }\r
109 #ifdef __BORLANDC__\r
110         while (s0 && (p = malloc(s0)) == NULL)\r
111 #endif\r
112 #ifdef __WATCOMC__\r
113         while (s0 && (p = _nmalloc(s0)) == NULL)\r
114 #endif\r
115                 s0 ^= s0 & -s0;\r
116 \r
117         *Size = s0;\r
118         return p;\r
119 }\r
120 \r
121 //from: https://stackoverflow.com/questions/14386856/c-check-available-ram\r
122 size_t HC_coreleft(void)\r
123 {\r
124         size_t total = 0;\r
125         void __near* pFirst = NULL;\r
126         void __near* pLast = NULL;\r
127         for(;;)\r
128         {\r
129                 size_t largest;\r
130                 void __near* p = (void __near *)HC_LargestFreeBlock(&largest);\r
131                 if (largest < sizeof(void __near*))\r
132                 {\r
133                         if (p != NULL)\r
134 #ifdef __BORLANDC__\r
135                         free(p);\r
136 #endif\r
137 #ifdef __WATCOMC__\r
138                         _nfree(p);\r
139 #endif\r
140                         break;\r
141                 }\r
142                 *(void __near* __near*)p = NULL;\r
143                 total += largest;\r
144                 if (pFirst == NULL)\r
145                         pFirst = p;\r
146 \r
147                 if (pLast != NULL)\r
148                         *(void __near* __near*)pLast = p;\r
149                 pLast = p;\r
150         }\r
151 \r
152         while (pFirst != NULL)\r
153         {\r
154                 void __near* p = *(void __near* __near*)pFirst;\r
155 #ifdef __BORLANDC__\r
156                 free(pFirst);\r
157 #endif\r
158 #ifdef __WATCOMC__\r
159                 _nfree(pFirst);\r
160 #endif\r
161                 pFirst = p;\r
162         }\r
163         return total;\r
164 }\r
165 \r
166 //far version of above\r
167 void far* HC_LargestFarFreeBlock(unsigned long* Size)\r
168 {\r
169         unsigned long s0, s1;\r
170         void far* p;\r
171 \r
172         s0 = ~(unsigned long)0 ^ (~(unsigned long)0 >> 1);\r
173         while (s0 && (p = _fmalloc(s0)) == NULL)\r
174                 s0 >>= 1;\r
175 \r
176         if (p)\r
177                 _ffree(p);\r
178 \r
179         s1 = s0 >> 1;\r
180         while (s1)\r
181         {\r
182                 if ((p = _fmalloc(s0 + s1)) != NULL)\r
183                 {\r
184                         s0 += s1;\r
185                         _ffree(p);\r
186                 }\r
187         s1 >>= 1;\r
188         }\r
189         while (s0 && (p = _fmalloc(s0)) == NULL)\r
190                 s0 ^= s0 & -s0;\r
191 \r
192         *Size = s0;\r
193         return p;\r
194 }\r
195 \r
196 //far version of above\r
197 unsigned long HC_farcoreleft(void)\r
198 {\r
199         unsigned long total = 0UL;\r
200         void far* pFirst = NULL;\r
201         void far* pLast = NULL;\r
202         for(;;)\r
203         {\r
204                 unsigned long largest;\r
205                 void far* p = HC_LargestFarFreeBlock(&largest);\r
206                 if (largest < sizeof(void far*))\r
207                 {\r
208                         if (p != NULL)\r
209                         _ffree(p);\r
210                         break;\r
211                 }\r
212                 *(void far* far*)p = NULL;\r
213                 total += largest;\r
214                 if (pFirst == NULL)\r
215                         pFirst = p;\r
216 \r
217                 if (pLast != NULL)\r
218                         *(void far* far*)pLast = p;\r
219                 pLast = p;\r
220         }\r
221 \r
222         while (pFirst != NULL)\r
223         {\r
224                 void far* p = *(void far* far*)pFirst;\r
225                 _ffree(pFirst);\r
226                 pFirst = p;\r
227         }\r
228         return total;\r
229 }\r
230 \r
231 #ifdef __WATCOMC__\r
232 /*void huge* LargestHugeFreeBlock(size_t* Size)\r
233 {\r
234         size_t s0, s1;\r
235         void huge* p;\r
236 \r
237         s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);\r
238         while (s0 && (p = halloc((dword)s0, 1)) == NULL)\r
239                 s0 >>= 1;\r
240 \r
241         if (p)\r
242                 hfree(p);\r
243 \r
244         s1 = s0 >> 1;\r
245         while (s1)\r
246         {\r
247                 if ((p = halloc((dword)(s0 + s1), 1)) != NULL)\r
248                 {\r
249                         s0 += s1;\r
250                         hfree(p);\r
251                 }\r
252         s1 >>= 1;\r
253         }\r
254         while (s0 && (p = halloc((dword)s0, 1)) == NULL)\r
255                 s0 ^= s0 & -s0;\r
256 \r
257         *Size = s0;\r
258         return p;\r
259 }\r
260 \r
261 size_t _hugecoreleft(void)\r
262 {\r
263         size_t total = 0;\r
264         void huge* pFirst = NULL;\r
265         void huge* pLast = NULL;\r
266         for(;;)\r
267         {\r
268                 size_t largest;\r
269                 void huge* p = LargestHugeFreeBlock(&largest);\r
270                 if (largest < sizeof(void huge*))\r
271                 {\r
272                         if (p != NULL)\r
273                         hfree(p);\r
274                         break;\r
275                 }\r
276                 *(void huge* huge*)p = NULL;\r
277                 total += largest;\r
278                 if (pFirst == NULL)\r
279                         pFirst = p;\r
280 \r
281                 if (pLast != NULL)\r
282                         *(void huge* huge*)pLast = p;\r
283                 pLast = p;\r
284         }\r
285 \r
286         while (pFirst != NULL)\r
287         {\r
288                 void huge* p = *(void huge* huge*)pFirst;\r
289                 hfree(pFirst);\r
290                 pFirst = p;\r
291         }\r
292         return total;\r
293 }\r
294 \r
295 void __based(__self)* LargestBasedFreeBlock(size_t* Size)\r
296 {\r
297         __segment segu;\r
298         size_t s0, s1;\r
299         void __based(__self)* p;\r
300 \r
301         s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);\r
302         while (s0 && (p = _bmalloc(segu, s0)) == NULL)\r
303                 s0 >>= 1;\r
304 \r
305         if (p)\r
306                 _ffree(p);\r
307 \r
308         s1 = s0 >> 1;\r
309         while (s1)\r
310         {\r
311                 if ((p = _bmalloc(segu, s0 + s1)) != NULL)\r
312                 {\r
313                         s0 += s1;\r
314                         _ffree(p);\r
315                 }\r
316         s1 >>= 1;\r
317         }\r
318         while (s0 && (p = _bmalloc(segu, s0)) == NULL)\r
319                 s0 ^= s0 & -s0;\r
320 \r
321         *Size = s0;\r
322         return p;\r
323 }\r
324 \r
325 size_t _basedcoreleft(void)\r
326 {\r
327         __segment segu;\r
328         size_t total = 0;\r
329         void __based(segu)* pFirst = NULL;\r
330         void __based(segu)* pLast = NULL;\r
331         // allocate based heap\r
332         segu = _bHC_heapseg( 1024 );\r
333         if( segu == _NULLSEG ) {\r
334                 printf( "Unable to allocate based heap\n" );\r
335                 return 0;\r
336 \r
337         }\r
338         else\r
339 \r
340         for(;;)\r
341         {\r
342                 size_t largest;\r
343                 void __based(segu)* p = LargestBasedFreeBlock(&largest);\r
344                 if (largest < sizeof(void far*))\r
345                 {\r
346                         if (p != NULL)\r
347                         _ffree(p);\r
348                         break;\r
349                 }\r
350                 *(void far* far*)p = NULL;\r
351                 total += largest;\r
352                 if (pFirst == NULL)\r
353                         pFirst = p;\r
354 \r
355                 if (pLast != NULL)\r
356                         *(void far* far*)pLast = p;\r
357                 pLast = p;\r
358         }\r
359 \r
360         while (pFirst != NULL)\r
361         {\r
362                 void far* p = *(void far* far*)pFirst;\r
363                 _ffree(pFirst);\r
364                 pFirst = p;\r
365         }\r
366         return total;\r
367 }*/\r
368 #if 0\r
369 size_t HC_GetFreeSize(void)\r
370 {\r
371         struct _heapinfo h_info;\r
372         int heap_status;\r
373         size_t h_free=0, h_total=0, h_used=0;\r
374 \r
375         h_info._pentry = NULL;\r
376         for(;;) {\r
377                 heap_status = _heapwalk( &h_info );\r
378                 if( heap_status != _HEAPOK ) break;\r
379                 if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") h_free += h_info._size;\r
380                 if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") h_used += h_info._size;\r
381                 h_total += h_info._size;\r
382         }\r
383         HCL_heapstat0(heap_status);\r
384         return h_free;\r
385 }\r
386 #endif\r
387 \r
388 unsigned long HC_GetFarFreeSize(void)\r
389 {\r
390         struct _heapinfo fh_info;\r
391         int heap_status;\r
392         unsigned long fh_free=0, fh_total=0, fh_used=0;\r
393 \r
394         fh_info._pentry = NULL;\r
395         for(;;) {\r
396                 heap_status = _fheapwalk( &fh_info );\r
397                 if( heap_status != _HEAPOK ) break;\r
398                 if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") fh_free += fh_info._size;\r
399                 if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") fh_used += fh_info._size;\r
400                 fh_total += fh_info._size;\r
401         }\r
402         HCL_heapstat0(heap_status);\r
403         return fh_free;\r
404 }\r
405 \r
406 size_t HC_GetNearFreeSize(void)\r
407 {\r
408         struct _heapinfo nh_info;\r
409         int heap_status;\r
410         size_t nh_free=0, nh_total=0, nh_used=0;\r
411 \r
412         nh_info._pentry = NULL;\r
413         for(;;) {\r
414                 heap_status = _nheapwalk( &nh_info );\r
415                 if( heap_status != _HEAPOK ) break;\r
416                 if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") nh_free += nh_info._size;\r
417                 if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") nh_used += nh_info._size;\r
418                 nh_total += nh_info._size;\r
419         }\r
420         HCL_heapstat0(heap_status);\r
421         return nh_free;\r
422 }\r
423 \r
424 void HC_heapdump(global_game_variables_t *gvar)\r
425 {\r
426         struct _heapinfo fh_info, nh_info;//, h_info;\r
427         int heap_status;\r
428         size_t nh_free, fh_free, nh_total, fh_total, nh_used, fh_used;//,       h_free, h_total, h_used;\r
429         byte    scratch[1024],str[16];\r
430 \r
431         HC_OpenDebug(gvar);\r
432 \r
433 #if 0\r
434         strcpy(scratch,"\n      == default ==\n\n");\r
435         write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
436         h_info._pentry = NULL;\r
437         h_free=0; h_total=0; h_used=0;\r
438         for(;;) {\r
439                 heap_status = _heapwalk( &h_info );\r
440                 if( heap_status != _HEAPOK ) break;\r
441                 strcpy(scratch,"  "); strcat(scratch,(h_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at ");\r
442                 sprintf(str, "%Fp", h_info._pentry); //ultoa((dword)h_info._pentry,str,16);\r
443                         strcat(scratch,str); strcat(scratch," of size "); ultoa(h_info._size,str,10); strcat(scratch,str); strcat(scratch,"\n");\r
444                 if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") h_free += h_info._size;\r
445                 if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") h_used += h_info._size;\r
446                 h_total += h_info._size;\r
447                 write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
448         }\r
449         HCL_heapstat(gvar, heap_status, &scratch);\r
450 #endif\r
451 \r
452         //near\r
453         strcpy(scratch,"\n      == near ==\n\n");\r
454         write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
455         nh_info._pentry = NULL;\r
456         nh_free=0; nh_total=0; nh_used=0;\r
457         for(;;) {\r
458                 heap_status = _nheapwalk( &nh_info );\r
459                 if( heap_status != _HEAPOK ) break;\r
460                 strcpy(scratch,"  "); strcat(scratch,(nh_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at ");\r
461                 sprintf(str, "%Fp", nh_info._pentry); //ultoa((dword)nh_info._pentry,str,16);\r
462                         strcat(scratch,str); strcat(scratch," of size "); ultoa(nh_info._size,str,10); strcat(scratch,str); strcat(scratch,"\n");\r
463 /*              printf( "  %s block at %Fp of size %4.4X\n",\r
464 (nh_info._useflag == _USEDENTRY ? "USED" : "FREE"),\r
465 nh_info._pentry, nh_info._size );*/\r
466                 if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") nh_free += nh_info._size;\r
467                 if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") nh_used += nh_info._size;\r
468                 nh_total += nh_info._size;\r
469                 write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
470         }\r
471         HCL_heapstat(gvar, heap_status, &scratch);\r
472 \r
473         //far\r
474         strcpy(scratch,"\n      == far ==\n\n");\r
475         write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
476         fh_info._pentry = NULL;\r
477         fh_free=0; fh_total=0; fh_used=0;\r
478         for(;;) {\r
479                 heap_status = _fheapwalk( &fh_info );\r
480                 if( heap_status != _HEAPOK ) break;\r
481                 strcpy(scratch,"  "); strcat(scratch,(fh_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at ");\r
482                 sprintf(str, "%Fp", fh_info._pentry); //ultoa((dword)fh_info._pentry,str,16);\r
483                         strcat(scratch,str); strcat(scratch," of size "); ultoa(fh_info._size,str,10); strcat(scratch,str); strcat(scratch,"\n");\r
484                 /*printf( "  %s block at %Fp of size %4.4X\n",\r
485 (fh_info._useflag == _USEDENTRY ? "USED" : "FREE"),\r
486 fh_info._pentry, fh_info._size );*/\r
487                 if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") fh_free += fh_info._size;\r
488                 if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") fh_used += fh_info._size;\r
489                 fh_total += fh_info._size;\r
490                 write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
491         }\r
492         HCL_heapstat(gvar, heap_status, &scratch);\r
493 \r
494         strcpy(scratch,"\n");\r
495         strcat(scratch,kittengets(2,0,"Memory Type         Total      Used       Free\n"));\r
496         strcat(scratch,"----------------  --------   --------   --------\n");\r
497 //      printmeminfoline(&scratch, "Default", h_total, h_used, h_free);\r
498         printmeminfoline(&scratch, "Near", nh_total, nh_used, nh_free);\r
499         printmeminfoline(&scratch, "Far", fh_total, fh_used, fh_free);\r
500         strcat(scratch,"----------------  --------   --------   --------\n");\r
501         strcat(scratch,"HC_coreleft = ");                       ultoa((dword)HC_coreleft(),str,10);                     strcat(scratch,str);    strcat(scratch,"\n");\r
502         strcat(scratch,"HC_farcoreleft = ");                    ultoa((dword)HC_farcoreleft(),str,10);          strcat(scratch,str);    strcat(scratch,"\n");\r
503 //      strcat(scratch,"HC_Newfarcoreleft = ");         ultoa((dword)HC_Newfarcoreleft(),str,10);               strcat(scratch,str);    strcat(scratch,"\n");\r
504 //      strcat(scratch,"HC_GetFreeSize = ");            ultoa((dword)HC_GetFreeSize(),str,10);          strcat(scratch,str);    strcat(scratch,"\n");\r
505         strcat(scratch,"HC_GetNearFreeSize = ");        ultoa((dword)HC_GetNearFreeSize(),str,10);      strcat(scratch,str);    strcat(scratch,"\n");\r
506         strcat(scratch,"HC_GetFarFreeSize = ");         ultoa((dword)HC_GetFarFreeSize(),str,10);       strcat(scratch,str);    strcat(scratch,"\n");\r
507         strcat(scratch,"coreleft = ");                          ultoa((dword)coreleft(),str,10);                                strcat(scratch,str);    strcat(scratch,"\n");\r
508         strcat(scratch,"farcoreleft = ");                       ultoa((dword)farcoreleft(),str,10);                     strcat(scratch,str);    strcat(scratch,"\n");\r
509         strcat(scratch,"stackavail = ");                        ultoa((dword)stackavail(),str,10);                      strcat(scratch,str);    strcat(scratch,"\n");\r
510         write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
511         HC_CloseDebug(gvar);\r
512 }\r
513 \r
514 void HCL_heapstat(global_game_variables_t *gvar, int heap_status, byte *str)\r
515 {\r
516         switch( heap_status ) {\r
517                 case _HEAPEND:\r
518                         strcpy((str),"OK - end of heap\n");\r
519                 break;\r
520                 case _HEAPEMPTY:\r
521                         strcpy((str),"OK - heap is empty\n");\r
522 \r
523                 break;\r
524                 case _HEAPBADBEGIN:\r
525                         strcpy((str),"ERROR - heap is damaged\n");\r
526                 break;\r
527                 case _HEAPBADPTR:\r
528                         strcpy((str),"ERROR - bad pointer to heap\n");\r
529                 break;\r
530                 case _HEAPBADNODE:\r
531                         strcpy((str),"ERROR - bad node in heap\n");\r
532         }\r
533         write(gvar->handle.heaphandle,(str),strlen((str)));\r
534 }\r
535 \r
536 void HCL_heapstat0(int heap_status)\r
537 {\r
538         switch( heap_status ) {\r
539                 case _HEAPEND:\r
540                         //printf("OK - end of heap\n");\r
541                 break;\r
542                 case _HEAPEMPTY:\r
543                         //printf("OK - heap is empty\n");\r
544                 break;\r
545                 case _HEAPBADBEGIN:\r
546                         printf("ERROR - heap is damaged\n");\r
547                 break;\r
548                 case _HEAPBADPTR:\r
549                         printf("ERROR - bad pointer to heap\n");\r
550                 break;\r
551                 case _HEAPBADNODE:\r
552                         printf("ERROR - bad node in heap\n");\r
553         }\r
554 }\r
555 \r
556 unsigned long farcoreleft()\r
557 {\r
558 //----  _fheapgrow();\r
559         return HC_farcoreleft();\r
560 //stack overflows       return HC_GetFarFreeSize();\r
561 }\r
562 \r
563 unsigned long coreleft()\r
564 {\r
565         _nheapgrow();\r
566         return _memavl();\r
567 //      return HC_GetNearFreeSize();\r
568 }\r
569 #endif\r
570 \r
571 /*\r
572 ============================\r
573 =\r
574 = HC_OpenDebug / HC_CloseDebug\r
575 =\r
576 = Opens a binary file with the handle "heaphandle"\r
577 =\r
578 ============================\r
579 */\r
580 void HC_OpenDebug(global_game_variables_t *gvar)\r
581 {\r
582 #ifdef __BORLANDC__\r
583         unlink("heap.16b");\r
584         gvar->handle.heaphandle = open(gvar->handle.heapdumpfilename, O_CREAT | O_WRONLY | O_TEXT);\r
585 #endif\r
586 #ifdef __WATCOMC__\r
587         unlink("heap.16w");\r
588         gvar->handle.heaphandle = open(gvar->handle.heapdumpfilename, O_CREAT | O_WRONLY | O_TEXT);\r
589 #endif\r
590 }\r
591 \r
592 void HC_CloseDebug(global_game_variables_t *gvar)\r
593 {\r
594         close(gvar->handle.heaphandle);\r
595 \r
596 #ifdef __BORLANDC__\r
597         strcpy(gvar->handle.heapdumpfilename, "heap.16b");\r
598 #endif\r
599 #ifdef __WATCOMC__\r
600         strcpy(gvar->handle.heapdumpfilename, "heap.16w");\r
601 #endif\r
602 }\r