/* * Help Access Library * A Library to access the contents of Windows Help files. * * Copyright (C) 1995-2000 Bernd Herd, http://www.herdsoft.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* hlpalloc.c --------------------------------------- * @doc * * @module hlpalloc.c | * Memory allocation procedures for debugging purposes. * * Help Access Library Project. *-----------------------------------------------------*/ #include #include #include #include #include #include "hlpacces.h" #include "top.h" #define DEBUG 0 #if DEBUG static int s=0; void *Hlpmalloc(DWORD size) { int *p=(int *) malloc(size+sizeof(int)); s+=size; *p=size; return (void *)(p+1); } void *Hlpcalloc(int size, int c) { void *p=Hlpmalloc(size*c); memset(p,size*c,0); return p; } void *Hlprealloc(char *blk, int nsize) { void *n=Hlpmalloc(nsize); int o=*(((int *)blk)-1); memcpy(n,blk,o); Hlpfree(blk); return n; } void Hlpfree(void *blk) { int *org=(((int *)blk)-1); s=s-*org; free(org); printf("free:Rest %d\n",s); } char *Hlpstrdup(const char *src) { int len=strlen(src)+1; char *n=Hlpmalloc(len); memcpy(n,src,len); return n; } #else #ifdef __FLAT__ void *Hlpmalloc(DWORD size) { return malloc(size); } #else void *Hlpmalloc(DWORD size) { if (HIWORD(size)) { MessageBox(NULL,"Table exceeds 64 KByte and cannot be handled by 16-Bit Version", "Help Access Library", MB_SYSTEMMODAL); exit(5); } return malloc(LOWORD(size)); } #endif #ifdef __FLAT__ void *Hlpcalloc(int size, int c) { return calloc(size,c); } #else void *Hlpcalloc(int size, int c) { if (HIWORD(size*(DWORD)c)) { MessageBox(NULL,"Table exceeds 64 KByte and cannot be handled by 16-Bit Version", "Help Access Library", MB_SYSTEMMODAL); exit(5); } return calloc(size,c); } #endif void *Hlprealloc(void *blk, int nsize) { return realloc(blk, nsize); } void Hlpfree(void *blk) { free(blk); } char *Hlpstrdup(const char *src) { return strdup(src); } #endif