Commits

Anonymous committed 95ee942

Sort the tree out into into the typical svn representation.

  • Participants
  • Tags secdel-1.2.0

Comments (0)

Files changed (64)

+#ifndef __INC_MYTYPES_H
+#define __INC_MYTYPES_H
+/*-------------------------------------------------------------------------*/
+typedef unsigned int BOOL;
+#define FALSE (0U)
+#define TRUE (1U)
+
+typedef unsigned char BYTE;
+/*-------------------------------------------------------------------------*/
+#endif /*!__INC_MYTPES_H*/
+# Secure Delete, Borland Makefile, written by Overlord David Duncan Ross Palmer
+# overlord@daybologic.co.uk
+# http://daybologic.com/overlord
+# I assume the memory manager is ./dpcrtlmm unless you point me elsewhere
+
+MAKEFILE=Makefile.bor
+DPCRTLMM=.\dpcrtlmm   #only a default
+DLUTILS=.\dlutils
+THISFILE=$(MAKEFILE)
+MYTYPES_H=mytypes.h
+GLOBALS_H=secdel_globals.h
+SVL_H=svl.h
+APPDATA_H=wappdat.h
+
+ERASE=erase
+FILEEXISTS=if exist
+
+HEADERS=$(MYTYPES_H) $(GLOBALS_H) $(SVL_H) $(APPDATA_H)
+
+GLOBALS_C=secdel_globals.c
+SECDEL_C=secdel.c
+SVL_C=svl.c
+APPDATA_C=wappdat.c
+
+SOURCES=$(GLOBALS_C) $(SECDEL_C) $(SVL_C) $(APPDATA_C)
+
+GLOBALS_OBJECT=secdel_globals.obj
+SECDEL_OBJECT=secdel.obj
+SVL_OBJECT=svl.obj
+APPDATA_OBJECT=wappdat.obj
+
+OBJECTS=$(GLOBALS_OBJECT) $(SECDEL_OBJECT) $(SVL_OBJECT) $(APPDATA_OBJECT) $(STRLWR_OBJECT) $(STRICMP_OBJECT) $(STRUPR_OBJECT)
+LIBS=$(DLUTILS)\dlutils.lib $(DPCRTLMM)\dpcrtlmm.lib
+EXEC=secdel.exe
+MASTERDEP=$(THISFILE) $(MYTYPES_H)
+
+# Wow that was nerdy and unnecersary wasn't it :), now to just get on with it
+
+# -O1 = Smallest possible code
+CC=bcc32 -c -O1
+ANSI=-A
+LINK=bcc32 -O1
+IPATH=-I$(DPCRTLMM) -I$(DLUTILS)
+
+$(EXEC) : $(OBJECTS) $(LIBS)
+        echo $(OBJECTS) > linkargs
+        echo $(LIBS) >> linkargs
+        $(LINK) -e$(EXEC) @linkargs
+
+$(GLOBALS_OBJECT) : $(GLOBALS_C) $(MASTERDEP) $(GLOBALS_H)
+        $(CC) $(ANSI) $(IPATH) $(GLOBALS_C)
+
+$(SECDEL_OBJECT) : $(SECDEL_C) $(MASTERDEP) $(GLOBALS_H) $(SVL_H) $(DPCRTLMM_H)
+        $(CC) $(IPATH) $(SECDEL_C)
+
+$(SVL_OBJECT) : $(SVL_C) $(MASTERDEP) $(SVL_H)
+        $(CC) $(ANSI) $(SVL_C)
+
+$(APPDATA_OBJECT) : $(APPDATA_C) $(MASTERDEP) $(APPDATA_H)
+        $(CC) $(ANSI) $(APPDATA_C)
+
+
+clean:
+        -$(FILEEXISTS) $(EXEC) $(ERASE) $(EXEC)
+        -$(FILEEXISTS) $(GLOBALS_OBJECT) $(ERASE) $(GLOBALS_OBJECT)
+        -$(FILEEXISTS) $(SECDEL_OBJECT) $(ERASE) $(SECDEL_OBJECT)
+        -$(FILEEXISTS) $(SVL_OBJECT) $(ERASE) $(SVL_OBJECT)
+        -$(FILEEXISTS) $(APPDATA_OBJECT) $(ERASE) $(APPDATA_OBJECT)
+        -$(FILEEXISTS) DPCRTLMM.LOG $(ERASE) DPCRTLMM.LOG
+        -$(FILEEXISTS) secdel.tds $(ERASE) secdel.tds
+        -$(FILEEXISTS) secdel.map $(ERASE) secdel.map
+        -$(FILEEXISTS) linkargs $(ERASE) linkargs
+        cd $(DPCRTLMM)
+        make -f Makefile.bor clobber
+        cd .. # Now this won't work if libraries move, a better solution is needed
+        cd $(DLUTILS)
+        make -f Makefile.bor clean
+        cd ..
+
+all : $(EXEC) #Compatibilly rule
+
+#----------------------------------------------------------------------------
+# Rules for dependency libraries
+
+$(DLUTILS)\dlutils.lib:
+        cd $(DLUTILS)
+        make -f Makefile.bor all
+        cd ..
+
+$(DPCRTLMM)\dpcrtlmm.lib:
+        cd $(DPCRTLMM)
+        make -f Makefile.bor all
+        cd ..
+# Secure Delete, GNU-type Makefile, written by Overlord David Duncan Ross Palmer
+# overlord@daybologic.co.uk
+# http://daybologic.com/overlord
+#
+# Colelus Ports collection (C) 2000 Daybo Logic, subject to the GNU General
+# public license.
+
+ROOT=../../..
+PUBLIC=$(ROOT)/public
+PRIVATE=$(ROOT)/private
+SDK=$(PUBLIC)/sdk/inc
+THISFILE=Makefile.gnu
+H=.h
+OBJ=.o
+C=.c
+A=.a
+GLOBALS_H=secdel_globals$(H)
+SVL_H=svl$(H)
+APPDATA_H=wappdat$(H)
+BACKUPS=*~
+
+#Libraries
+#---------
+# DPCRTLMM
+DPCRTLMM_PATH=$(PRIVATE)/lib/dpcrtlmm
+DPCRTLMM_H=$(DPCRTLMM_PATH)/dpcrtlmm$(H)
+DPCRTLMM_LIB=$(DPCRTLMM_PATH)/libdpcrtlmm$(A)
+
+# utils
+UTILS_PATH=$(PRIVATE)/lib/utils
+UTILS_H=$(UTILS_PATH)/utils$(H)
+UTILS_LIB=$(UTILS_PATH)/libutils$(A)
+
+LIBRARIES=$(DPCRTLMM_LIB) $(UTILS_LIB)
+HEADERS=$(GLOBALS_H) $(SVL_H) $(APPDATA_H)
+
+GLOBALS_C=secdel_globals$(C)
+SECDEL_C=secdel$(C)
+SVL_C=svl$(C)
+APPDATA_C=wappdat$(C)
+
+SOURCES=$(GLOBALS_C) $(SECDEL_C) $(SVL_C) $(APPDATA_C)
+
+GLOBALS_O=secdel_global$(OBJ)
+SECDEL_O=secdel$(OBJ)
+SVL_O=svl$(OBJ)
+APPDATA_O=wappdat$(OBJ)
+
+OBJECTS=$(GLOBALS_O) $(SECDEL_O) $(SVL_O) $(APPDATA_O)
+EXEC=secdel
+MASTERDEP=$(THISFILE)
+
+
+
+CC=gcc -g -c
+ANSI=-ansi -pedantic -Wall
+LINK=gcc -g
+IPATH=-I$(PUBLIC) -I$(SDK) -I$(DPCRTLMM_PATH) -I$(UTILS_PATH)
+MAKEOUTPUT=-o
+
+$(EXEC) : $(OBJECTS) $(LIBRARIES)
+	$(LINK) $(MAKEOUTPUT) $(EXEC) $(OBJECTS)
+
+$(GLOBALS_O) : $(GLOBALS_C) $(MASTERDEP) $(GLOBALS_H)
+	$(CC) $(ANSI) $(IPATH) $(MAKEOUTPUT) $(GLOBALS_O) $(GLOBALS_C)
+
+$(SECDEL_O) : $(SECDEL_C) $(MASTERDEP) $(GLOBALS_H) $(SVL_H) $(DPCRTLMM_H)
+	$(CC) $(IPATH) $(MAKEOUTPUT)$(SECDEL_O) $(SECDEL_C)
+
+$(SVL_OBJECT) : $(SVL_C) $(MASTERDEP) $(SVL_H)
+	$(CC) $(ANSI) $(MAKEOUTPUT) $(SVL_O) $(SVL_C)
+
+$(APPDATA_O) : $(APPDATA_C) $(MASTERDEP) $(APPDATA_H)
+	$(CC) $(ANSI) $(MAKEOUTPUT) $(APPDATA_O) $(APPDATA_C)
+
+
+clean:
+	-rm -f $(OBJECTS)
+	-rm -f $(BACKUPS)
+
+clobber: clean
+	-rm -f $(EXEC)
+December 2000
+-------------
+The secure delete program has exisited for a long time before the Colelus
+Project.  It started in 1998 and was written by David Duncan Ross Palmer.
+Originally it was written in C++ with very poor regard for portabilly.
+
+In 2000 it was rewritten and not tested, it's now ANSI C
+
+Status: Won't compile
+For more info email: Overlord@DayboLogic.co.uk
+make -f Makefile.gnu
+make -f Makefile.bor

dlutils/Makefile.bor

+# Makefile for the Daybo Logic utilities library
+# This Makefile was written by and is maintained by Overlord David Duncan
+# Ross Palmer.  Authors of individual modules may differ as stated.
+# This Makefile is for Borland C, type make -f Makefile.bor
+
+
+# The path and filenames we use
+DIRSEP=/
+PARENT=..
+LIBTITLE=dlutils
+OBJ=obj
+CSOURCE=c
+SEP=.
+LIBNAME=$(LIBTITLE)$(SEP)lib
+LIBHEAD=$(LIBTITLE)$(SEP)h
+OBJECTS=byteswap$(SEP)$(OBJ) \
+	checksum$(SEP)$(OBJ) \
+	stricmp$(SEP)$(OBJ) \
+	strlwr$(SEP)$(OBJ) \
+	strupr$(SEP)$(OBJ) \
+	blocking$(SEP)$(OBJ) \
+	chkfile32$(SEP)$(OBJ) \
+	filelen$(SEP)$(OBJ)
+
+# The tools we use and command line parameters
+# -O1 = Smallest possible code
+COMPILE=bcc32 $(IPATH) -c -A -O1
+MAKELIB=tlib
+ERASE=erase
+FILEEXISTS=if exist
+
+# Borland only runs on x86, which is little endian
+ENDIAN=__L_ENDIAN__
+
+# Global definitions used to make all modules
+# HDRSTOP = Precompiled header stop points
+GDEFS=-DHDRSTOP
+
+# Because DOS was an annoying command line limit we have to build in small stages
+$(LIBNAME) : $(OBJECTS)
+	$(MAKELIB) $(LIBNAME) -+byteswap$(SEP)$(OBJ)
+	$(MAKELIB) $(LIBNAME) -+checksum$(SEP)$(OBJ)
+	$(MAKELIB) $(LIBNAME) -+stricmp$(SEP)$(OBJ)
+	$(MAKELIB) $(LIBNAME) -+strlwr$(SEP)$(OBJ)
+	$(MAKELIB) $(LIBNAME) -+strupr$(SEP)$(OBJ)
+	$(MAKELIB) $(LIBNAME) -+blocking$(SEP)$(OBJ)
+	$(MAKELIB) $(LIBNAME) -+chkfile32$(SEP)$(OBJ)
+	$(MAKELIB) $(LIBNAME) -+filelen$(SEP)$(OBJ)
+
+byteswap$(SEP)$(OBJ) : byteswap$(SEP)$(CSOURCE) $(LIBHEAD)
+	$(COMPILE) $(GDEFS) -D$(ENDIAN) byteswap$(SEP)$(CSOURCE)
+
+checksum$(SEP)$(OBJ) : checksum$(SEP)$(CSOURCE) $(LIBHEAD)
+	$(COMPILE) $(GDEFS) checksum$(SEP)$(CSOURCE)
+
+stricmp$(SEP)$(OBJ) : stricmp$(SEP)$(CSOURCE) $(LIBHEAD)
+	$(COMPILE) $(GDEFS) stricmp$(SEP)$(CSOURCE)
+
+strlwr$(SEP)$(OBJ) : strlwr$(SEP)$(CSOURCE) $(LIBHEAD)
+	$(COMPILE) $(GDEFS) strlwr$(SEP)$(CSOURCE)
+
+strupr$(SEP)$(OBJ) : strupr$(SEP)$(CSOURCE) $(LIBHEAD)
+	$(COMPILE) $(GDEFS) strupr$(SEP)$(CSOURCE)
+
+blocking$(SEP)$(OBJ) : blocking$(SEP)$(CSOURCE) $(LIBHEAD)
+	$(COMPILE) $(GDEFS) blocking$(SEP)$(CSOURCE)
+
+chkfile32$(SEP)$(OBJ) : chkfile32$(SEP)$(CSOURCE) $(LIBHEAD)
+	$(COMPILE) $(GDEFS) chkfile32$(SEP)$(CSOURCE)
+
+filelen$(SEP)$(OBJ) : filelen$(SEP)$(CSOURCE) $(LIBHEAD)
+	$(COMPILE) $(GDEFS) filelen$(SEP)$(CSOURCE)
+
+all : $(LIBNAME)
+
+clean:
+	#Must delete all objects seperately thanks to DOS
+	-$(FILEEXISTS) byteswap$(SEP)$(OBJ) $(ERASE) byteswap$(SEP)$(OBJ)
+	-$(FILEEXISTS) checksum$(SEP)$(OBJ) $(ERASE) checksum$(SEP)$(OBJ)
+	-$(FILEEXISTS) stricmp$(SEP)$(OBJ) $(ERASE) stricmp$(SEP)$(OBJ)
+	-$(FILEEXISTS) strlwr$(SEP)$(OBJ) $(ERASE) strlwr$(SEP)$(OBJ)
+	-$(FILEEXISTS) strupr$(SEP)$(OBJ) $(ERASE) strupr$(SEP)$(OBJ)
+	-$(FILEEXISTS) blocking$(SEP)$(OBJ) $(ERASE) blocking$(SEP)$(OBJ)
+	-$(FILEEXISTS) chkfile32$(SEP)$(OBJ) $(ERASE) chkfile32$(SEP)$(OBJ)
+	-$(FILEEXISTS) filelen$(SEP)$(OBJ) $(ERASE) filelen$(SEP)$(OBJ)
+	-$(FILEEXISTS) $(LIBTITLE)$(SEP)bak $(ERASE) $(LIBTITLE)$(SEP)bak
+	-$(FILEEXISTS) $(LIBNAME) $(ERASE) $(LIBNAME)

dlutils/Makefile.gnu

+# Makefile for the Colelus utilities library
+# This Makefile was written by and is maintained by Overlord David Duncan
+# Ross Palmer.  Authors of individual modules may differ as stated.
+
+
+# The path and filenames we use
+ROOT=/colelus
+THISFILE=Makefile.gnu
+NULLDEV=/dev/null
+LIBTITLE=utils
+LIBNAME=lib$(LIBTITLE).a
+PUBLIC=$(ROOT)/public
+IPATH=-I$(PUBLIC) -I$(PUBLIC)/sdk/inc
+COLELUSH=$(PUBLIC)/sdk/inc/colelus.h
+LIBHEAD=$(LIBTITLE).h
+BEGINCH=$(PUBLIC)/sdk/inc/beginch.h
+ENDCH=$(PUBLIC)/sdk/inc/endch.h
+OBJECTS=byteswap.o checksum.o stricmp.o strlwr.o strupr.o blocking.o chkfile32.o filelen.o
+BACKUPS=*~
+MASTERDEP=$(LIBTITLE).h $(THISFILE)
+
+# The tools we use and command line parameters
+COMPILE=gcc $(IPATH) -c -ansi -pedantic -Wall
+MAKELIB1=ar cru
+MAKELIB2=ranlib $(LIBNAME)
+ERASE=rm -f
+
+all : $(LIBNAME)
+
+$(LIBNAME) : $(OBJECTS) $(MASTERDEP)
+	$(MAKELIB1) $(LIBNAME) $(OBJECTS)
+	$(MAKELIB2)
+
+byteswap.o : byteswap.c $(COLELUSH) $(LIBHEAD) $(MASTERDEP)
+	$(COMPILE) byteswap.c
+
+checksum.o : checksum.c $(COLELUSH) $(LIBHEAD) $(MASTERDEP)
+	$(COMPILE) checksum.c
+
+stricmp.o : stricmp.c $(COLELUSH) $(LIBHEAD) $(MASTERDEP)
+	$(COMPILE) stricmp.c
+
+strlwr.o : strlwr.c $(COLELUSH) $(LIBHEAD) $(MASTERDEP)
+	$(COMPILE) strlwr.c
+
+strupr.o : strupr.c $(COLELUSH) $(LIBHEAD) $(MASTERDEP)
+	$(COMPILE) strupr.c
+
+blocking.o : blocking.c $(COLELUSH) $(LIBHEAD) $(MASTERDEP)
+	$(COMPILE) blocking.c
+
+chkfile32.o : chkfile32.c $(COLELUSH) $(LIBHEAD) $(MASTERDEP)
+	$(COMPILE) chkfile32.c
+
+filelen.o : filelen.c $(COLELUSH) $(LIBHEAD) $(MASTERDEP)
+	$(COMPILE) filelen.c
+
+# Header configuration (not sure if this works)
+$(LIBHEAD) : $(BEGINCH) $(ENDCH)
+
+clean:
+	@-$(ERASE) $(OBJECTS) $(BACKUPS) > $(NULLDEV)
+
+clobber: clean
+	@-$(ERASE) $(LIBNAME) > $(NULLDEV)

dlutils/blocking.c

+/* Nigel Crouch (NigelCrouch@Hotmail.com) and David Duncan Ross Palmer (Overlord@DayboLogic.co.uk)
+   File blocking calculator.  Returns information needed to read a file in blocks.
+
+   (C) Copyright 1998-2000 Daybo Logic, all rights reserved.
+*/
+
+#include <stddef.h>
+#include <stdio.h>
+#ifdef HDRSTOP
+# pragma hdrstop
+#endif /*HDRSTOP*/
+
+#include "dlutils.h"
+
+int dlutils_CalcFileBlockSize(unsigned long FileLength, DLUTILS_FILE_BLOCK_SIZE* CallerFileBlockSizePtr, const size_t BufferSize)
+{
+  /* Mathematics by Nigel Crouch, written in C by D. D. R. Palmer. */
+  /* initialize structure */
+  CallerFileBlockSizePtr->BufferSize = 0UL;
+  CallerFileBlockSizePtr->Loops = 0UL;
+  CallerFileBlockSizePtr->Remainder = 0UL;
+
+  if (FileLength == 0)
+  {
+    /* zero file length, handle this error */
+    return 0; /*FALSE*/
+  }
+
+  if (FileLength <= BufferSize)
+    CallerFileBlockSizePtr->BufferSize = FileLength;
+  else
+    CallerFileBlockSizePtr->BufferSize = BufferSize;
+
+  CallerFileBlockSizePtr->Loops = FileLength / (CallerFileBlockSizePtr->BufferSize);
+  CallerFileBlockSizePtr->Remainder = (FileLength - (CallerFileBlockSizePtr->BufferSize) * CallerFileBlockSizePtr->Loops);
+  return 1; /*TRUE*/
+}
+/*-------------------------------------------------------------------------*/

dlutils/byteswap.c

+/* Byte swapper (processor portability aid)
+
+Author: Overlord David Duncan Ross Palmer
+Company: Daybo Logic
+Library: Colelus Utilities
+Language compliance: ANSI C (1990)
+
+Last modified - 27th December 2000: Overlord
+*/
+
+#include <stddef.h>
+#include <stdio.h>
+#ifdef HDRSTOP
+# pragma hdrstop
+#endif /*HDRSTOP*/
+
+#include "dlutils.h"
+
+typedef unsigned char BYTE;
+#define BYTE_T
+
+#ifdef __B_ENDIAN__ /* Big endian CPU (such as Mac) - MOTOROLA */
+
+ #define MAKEWORD(a, b)     (((WORD)((BYTE)(b))) << 8))) | ((WORD)(((BYTE)(a))
+ #define MAKEDW(a, b)       (((DWORD)((WORD)(b))) << 16))) | ((DWORD)(((WORD)(a))
+ #define LOWORD(l)          ((WORD)(((DWORD)(l) >> 16) & 0xFFFF))
+ #define HIWORD(l)          ((WORD)(l))
+ #define LOBYTE(w)          ((BYTE)(((WORD)(w) >> 8) & 0xFF))
+ #define HIBYTE(w)          ((BYTE)(w))
+
+#elif defined(__L_ENDIAN__) /* Little endian CPU (such as I.B.M. P.C.) - INTEL */
+
+ #define MAKEWORD(a, b)     ((WORD)(((BYTE)(a)) | (((WORD)((BYTE)(b))) << 8)))
+ #define MAKEDW(a, b)       ((DWORD)(((WORD)(a)) | (((DWORD)((WORD)(b))) << 16)))
+ #define LOWORD(l)          ((WORD)(l))
+ #define HIWORD(l)          ((WORD)(((DWORD)(l) >> 16) & 0xFFFF))
+ #define LOBYTE(w)          ((BYTE)(w))
+ #define HIBYTE(w)          ((BYTE)(((WORD)(w) >> 8) & 0xFF))
+
+#else
+
+ #error ("Machine byte order MUST be specified")
+
+#endif
+/*-------------------------------------------------------------------------*/
+WORD utils_RevWORD(const WORD W)
+{
+  return MAKEWORD(HIBYTE(W), LOWORD(W)); /* Reverse word and return */
+}
+/*-------------------------------------------------------------------------*/
+DWORD utils_RevDWORD(const DWORD DW)
+{
+  WORD DWH = HIWORD(DW);
+  WORD DWL = LOWORD(DW);
+
+  DWH = utils_RevWORD(DWH); /* Reverse BYTEs in high WORD */
+  DWL = utils_RevWORD(DWL); /* Reverse BYTEs in low WORD */
+
+  return MAKEDW(DWH, DWL); /* Make DWORD from WORDs backtofront */
+}
+/*-------------------------------------------------------------------------*/

dlutils/checksum.c

+/*
+  File: Utils\Checksum.C
+  Author: OverlordDDRP (Overlord@DayboLogic.co.uk)
+  Title: Very simple checksum routines for Colelus developers
+  Version: 1.00
+*/
+#include <stddef.h>
+#include <stdio.h>
+#ifdef HDRSTOP
+#  pragma hdrstop
+#endif /*HDRSTOP*/
+
+#include "dlutils.h"
+
+typedef unsigned char BYTE;
+#define BYTE_T
+/*-------------------------------------------------------------------------*/
+WORD utils_CalcChk16(const void* RawData, const size_t SizeOfData)
+{
+  WORD genChk16 = 0; /* Generated 16-bit checksum */
+  size_t offset;
+  BYTE* castedPtr = (BYTE*)RawData; /* Cast to BYTEs from raw pointer */
+
+  if (!castedPtr || !SizeOfData) return genChk16; /* Safety */
+
+  for ( offset = 0U; offset < SizeOfData; offset++ )
+	 genChk16 += *((BYTE*)(castedPtr + offset)); /* Add value of byte to total */
+
+  return genChk16; /* Give 16-bit checksum to caller */
+}
+/*-------------------------------------------------------------------------*/
+DWORD utils_CalcChk32(const void* RawData, const size_t SizeOfData)
+{
+  DWORD genChk32 = 0; /* Generated 32-bit checksum */
+  size_t offset;
+  BYTE* castedPtr = (BYTE*)RawData; /* Cast to BYTEs from raw pointer */
+
+  if (!castedPtr || !SizeOfData) return genChk32; /* Safety */
+
+  for ( offset = 0U; offset < SizeOfData; offset++ )
+	 genChk32 += *((BYTE*)(castedPtr + offset)); /* Add value of byte to total */
+
+  return genChk32; /* Give 32-bit checksum to caller */
+}
+/*-------------------------------------------------------------------------*/

dlutils/chkfile32.c

+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#ifdef HDRSTOP
+# pragma hdrstop
+#endif /*HDRSTOP*/
+
+#include "dlutils.h"
+
+/* Local types */
+typedef unsigned long ULONG;
+typedef unsigned char BYTE;
+/*-------------------------------------------------------------------------*/
+DWORD utils_CalcFileChecksum32(FILE* HFile)
+{
+  /* Var declarations */
+  ULONG lenChkFile, iLoops;
+  DWORD chk32 = (DWORD)0UL;
+  DLUTILS_FILE_BLOCK_SIZE fileBlockSize;
+  BYTE *currentData, *remainingData;
+  unsigned dataIndex;
+  long int stackedFilePos;
+
+  if (!HFile) return chk32;
+  stackedFilePos = ftell(HFile);
+  if (stackedFilePos == -1L)
+    return chk32; /*0UL*/
+  if ( !dlutils_GetFileLength(HFile, &lenChkFile) ) /* Save the length of this file */
+    return chk32;
+
+  if (!lenChkFile)
+  {
+    fclose(HFile);
+    return chk32; /* Don't waste time, a zero length file's checksum is always 0 */
+  }
+
+  dlutils_CalcFileBlockSize(lenChkFile, &fileBlockSize, (size_t)4096U); /* Call Nigel's well-magic wonderful fast function!, buffer 4K for read loops */
+  currentData = (BYTE*)malloc(fileBlockSize.BufferSize); /* Create a buffer for file I/O */
+
+  fseek(HFile, 0, SEEK_SET); /* Reset to file begining */
+  for (iLoops=0;iLoops<fileBlockSize.Loops;iLoops++)
+  {
+    if (fread(currentData, fileBlockSize.BufferSize, 1, HFile) < 1) /* Read data into buffer */
+    {
+      /* EOF should never occur - AND HAS! */
+      fprintf(stderr, "Unexpected EOF during file checksummer\n");
+      abort();
+    }
+    for ( dataIndex = 0U; dataIndex < fileBlockSize.BufferSize; dataIndex++ ) /* Go through all of the CurrentData read from the file*/
+      chk32 += currentData[dataIndex]; /* Add the current byte to the total 32-bit CRC checksum */
+  }
+  /* Now add the remainder */
+  if (fileBlockSize.Remainder)
+  {
+    remainingData = (BYTE*)malloc(fileBlockSize.Remainder); /* Create buffer for remainder */
+    fread(remainingData, fileBlockSize.Remainder, 1, HFile); /* Put remaining data in this buffer */
+  for ( dataIndex = 0U; dataIndex < fileBlockSize.Remainder; dataIndex++ ) /* go through all of the remaining data byte by byte */
+    chk32 += remainingData[dataIndex]; /* Add the remainder to the total */
+
+    free(remainingData); /* Deallocate buffer */
+  }
+
+  /* Cleanup */
+  if (currentData) free(currentData);
+
+  rewind(HFile);
+  fseek(HFile, stackedFilePos, SEEK_SET); /* Restore file pos */
+  return chk32; /* Give the 32-bit CRC value to the caller */
+}
+/*----------------------------------------------------------------------------*/

dlutils/dlutils.h

+/*
+  Header for general internal Daybo Logic utilities.
+  What are the utilities?
+  The utilities may look very simple coding which could be done my anybody
+  on the team in their own modules, however that would be such a waste of
+  space, it is much better if we all collect portable C routines for simple
+  operations into the utilities library.  The person who started this
+  library is called David Duncan Ross Palmer (OverlordDDRP) and you can
+  contact him about this library at Overlord@DayboLogic.co.uk or on
+  Check his personal web site http://daybologic.com/overlord
+  for contact details or if he's moved you can probally access the same
+  info from the company site http://www.daybologic.com
+
+  NOTE: The simple thing, the one you don't have to email me and ask is
+  that all exported symbols must start with 'dlutils_'
+*/
+
+#ifndef __INC_DLUTILS_UTILS_H
+#define __INC_DLUTILS_UTILS_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*-------------------------------------------------------------------------*/
+/* These types are needed for the library to function correctly, they're
+pretty standard types but you might not want them to interfear with your
+own types so define DLUTILS_NOTYPES before including this to disable them.
+If you disable them you must provide all the required types yourself,
+the required types are: WORD = 16-bit and DWORD = 32-bit */
+
+#ifndef DLUTILS_NOTYPES
+
+# ifndef WORD_T
+   typedef unsigned short WORD;
+#  define WORD_T
+# endif
+
+# ifndef DWORD_T
+#  if ( MAX_ULONG > 0xFFFFFFFFUL ) /* 64-bit machine (or more) */
+    typedef unsigned int DWORD;
+#  else /* 32-bit machine (or less) */
+    typedef unsigned long DWORD;
+#  endif
+#  define DWORD_T
+# endif
+
+#endif /*!DLUTILS_NOTYPES*/
+/*-------------------------------------------------------------------------*/
+/* Calculate a block's 16-bit checksum */
+WORD dlutils_CalcChk16(const void* RawData, const size_t SizeOfData);
+/* Calculate a block's 32-bit checksum */
+DWORD dlutils_CalcChk32(const void* RawData, const size_t SizeOfData);
+/* Sorry there is no 64-bit function supported yet, if you need it I'll add it */
+/*DWORD dlutils_CalcChk64(const void* RawData, const size_t SizeOfData, DWORD* PHiDW);*/
+/*-------------------------------------------------------------------------*/
+WORD dlutils_RevWORD(const WORD W); /* Reverses BYTEs in a WORD */
+DWORD dlutils_RevDWORD(const DWORD DW); /* Reverses WORDs in a DWORD and BYTEs in those WORDs */
+/*-------------------------------------------------------------------------*/
+int dlutils_stricmp(const char* s1, const char* s2); /* Case insensitive compare, use this not stricmp()! */
+/*-------------------------------------------------------------------------*/
+char* dlutils_strupr(char* s); /* Converts a string to uppercase just like non-ANSI strupr() */
+char* dlutils_strlwr(char* s); /* Converts a string to lowercase just like ANSI 1995 strlwr() */
+/*-------------------------------------------------------------------------*/
+typedef struct _DLUTILS_FILE_BLOCK_SIZE
+{
+  unsigned long BufferSize;
+  unsigned long Loops;
+  unsigned long Remainder;
+} DLUTILS_FILE_BLOCK_SIZE;
+int dlutils_CalcFileBlockSize(unsigned long FileLength, DLUTILS_FILE_BLOCK_SIZE* CallerFileBlockSizePtr, const size_t BufferSize);
+/*-------------------------------------------------------------------------*/
+DWORD dlutils_CalcFileChecksum32(FILE* HFile);
+/*-------------------------------------------------------------------------*/
+int dlutils_GetFileLength(FILE* HFile, unsigned long* PLength);
+/*-------------------------------------------------------------------------*/
+#ifdef __cplusplus
+}
+#endif
+#endif /*!__INC_DLUTILS_UTILS_H*/

dlutils/filelen.c

+/* DDRP's simple file length (overlord@daybologic.co.uk) */
+
+#include <stdio.h>
+#ifdef HDRSTOP
+# pragma hdrstop
+#endif /*HDRSTOP*/
+
+#include "dlutils.h"
+
+int utils_GetFileLength(FILE* HFile, unsigned long* PLength)
+{
+  long int length;
+  long int oldFilePos;
+
+  if ( !HFile ) return 0; /*FALSE*/
+  oldFilePos = ftell(HFile); /* Save current file offset */
+  rewind(HFile); /* Reset any EOF conditions and the like */
+  fseek(HFile, 0, SEEK_END); /* Seek to end */
+  length = ftell(HFile);
+  /* Restore pos */
+  if (length == -1L) rewind(HFile);
+  fseek(HFile, oldFilePos, SEEK_SET);
+
+  if ( PLength )
+    *PLength = (long int)length;
+
+  if ( length == -1L )
+    return 0; /*FALSE*/
+
+  return 1; /* TRUE (Success) */
+}

dlutils/revision.txt

+29th May 2000
+-------------
+I first created this library, I copied as much as I could from other
+Daybo Logic libraries which I had created in the past to save time.
+I intended this library for Colelus developers.  The idea being, why
+the hell would one want everybody else having their own checksum
+routines, their own methods for swapping bytes and the like.  It may not
+seem like much space would be wasted and indeed it is true that these
+little routines don't take up a lot of space.  It is just the complete
+waste of time it is to program these things.  So now common routines
+will go in \Colelus\Private\Lib\Utils.  Today I first created the header
+file too.
+
+26th June 2000
+--------------
+First built the files as a library, certain things needed cleaning up,
+they still belonged to namespaces of previous libraries and the like.
+Found that the checksum rotuines I had mashed together were far from
+compilable.
+
+28th June 2000
+--------------
+Found that the names for the byte swap routines were bad which would
+have caused linker problems, the name of the functions were ok in the
+headers called 'utils_'.. but then in the actual C files and
+consequently the public sybols they were called 'dlutils_'..
+
+27th August 2000
+----------------
+Converted all filesname to lowercase and created the makefile
+
+2rd October 2000
+----------------
+Created blocking.c, filelen.c & chkfile32.c.  That's file blocking (Nigel
+Crouch and I), simple file length calculator and a utility to get the
+checksum (32-bit) of a file.
+
+5th October 2000
+----------------
+Corrected an error with Borland's compiler.  Well, I won't put it like that
+it's my fault not Borland's.  On GNU, string.h must have been included by
+one of the other headers for some reason.  In Borland's compiler, I needed
+to include string.h in makerttb.c
+
+29th November 2000
+------------------
+Added another parameter to utils_CalcFileBlockSize(), it now wants the caller
+to specify the duffer rather than guess it'self depensing on flag or segmented
+memory model, this seem better to be but will cause some code problems if
+people have started using this function, easy to fix however.  Minor header
+inclusion changes to get rid of a pragma warning.
+
+28th December 2000
+------------------
+Rewrote stricmp(), changed all utils_ stuff to dlutils_ and renamed the
+library.

dlutils/stricmp.c

+/*
+Replacement for stricmp() because that is non-ANSI
+
+Author: Overlord David Duncan Ross Palmer
+Company: Daybo Logic
+Library: Colelus Utilities
+Language compliance: ANSI C (1990)
+
+Last modified 27th December 2000: Overlord (overlord@daybologic.co.uk)
+27th Dec 2000: Rewrote, it used to copy, make lowercase then compare,
+now I do the loop myself with tolower(), this involves no malloc()s so
+is safer incase of lack of memory.  It's probally a lot faster too.
+*/
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+#ifdef HDRSTOP
+# pragma hdrstop
+#endif /*HDRSTOP*/
+
+#include "dlutils.h"
+/*---------------------------------------------------------------*/
+int dlutils_stricmp(const char* s1, const char* s2)
+{
+  size_t i = (size_t)0U;
+  int ret = 0;
+
+  if ( !s1 || !s2 ) return -1; /* Safety */
+
+  while ( s1[i] != '\0' && s2[i] != '\0' )
+  {
+    /* Make lowercase */
+    char c1 = isalpha(s1[i]) ? (tolower(s1[i])) : (s1[i]);
+    char c2 = isalpha(s2[i]) ? (tolower(s2[i])) : (s2[i]);
+
+    ret += ( c1 - c2 ); /* Change mismatch (0 effect if no difference) */
+    i++; /* For next loop */
+  }
+  return ret;
+}
+/*
+
+Replacement for strlwr()
+While strupr() is still not ANSI, strlwr() appears to have been
+added in the 1995 revision to the standard, pretty strange they
+did not add both!  One could use strlwr() from the 1995 ANSI but
+seeing as there is no atrupr() still it makes sense to write both,
+after all, it's difficult to remembr which is there and which isn't
+
+Author: Overlord David Duncan Ross Palmer
+Company: Daybo Logic
+Library: Colelus Utilities
+Language compliance: ANSI C (1990)
+
+Created: 2nd October 2000
+Last modified: 27th December 2000
+*/
+
+#include <string.h>
+#include <ctype.h>
+#include <stddef.h>
+#include <stdio.h>
+#ifdef HDRSTOP
+# pragma hdrstop
+#endif /*HDRSTOP*/
+
+#include "dlutils.h"
+/*---------------------------------------------------------------*/
+char* dlutils_strlwr(char* s)
+{
+  unsigned int index = 0U;
+
+  if (!s) return s; /* Get out before damage is done */
+  while ( s[index] != '\0' )
+  {
+    s[index] = (char)tolower( (int)(s[index]) );
+    index++;
+  };
+  return s;
+}
+/*
+
+Replacement for strupr() because that is non-ANSI
+
+Author: Overlord David Duncan Ross Palmer
+Company: Daybo Logic
+Library: Colelus Utilities
+Language compliance: ANSI C (1990)
+
+Created : 26th June 2000
+Last modified: 27th December 2000
+
+24th July 2000: Optimized out a loop, instead of strlen() and then a loop
+only one loop is used looping for NULL.
+*/
+
+#include <string.h>
+#include <ctype.h>
+#include <stddef.h>
+#include <stdio.h>
+#ifdef HDRSTOP
+# pragma hdrstop
+#endif /*HDRSTOP*/
+
+#include "dlutils.h"
+/*---------------------------------------------------------------*/
+char* utils_strupr(char* s)
+{
+  unsigned int index = 0U;
+
+  if (!s) return s; /* Get out before damage is done */
+  while ( s[index] != '\0' )
+  {
+    s[index] = (char)toupper( (int)(s[index]) );
+    index++;
+  };
+  return s;
+}
+		    GNU GENERAL PUBLIC LICENSE
+		       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+                       59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+			    Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+		    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+			    NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+		     END OF TERMS AND CONDITIONS
+
+	    How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) 19yy  <name of author>
+
+    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, or
+    (at your option) any later version.
+
+    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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) 19yy name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Library General
+Public License instead of this License.

dpcrtlmm/Makefile.bor

+# Make file for DPCRTLMM
+# Written by Overlord David Duncan Ross Palmer
+# Overlord@DayboLogic.co.uk
+# 24th August 2000
+# Last modified 12th December 2000
+
+# This Makefile designed for Borland C++, you'll have to change the tools
+# at the top of the file in the variables section to use Micro$oft or Colelus
+# linker.  I have made everything easy to modify by putting it at the top
+# of the file but if you have problems, email me.
+
+# Paths & filenames - If this file is not called Makefile remember to
+# change the variable 'THISFILE'
+THISFILE=Makefile.bor
+LIBTITLE=dpcrtlmm
+LIBNAME=$(LIBTITLE).lib
+# Master dependancies ALWAYS cause a rebuild
+MASTERDEP=build.h dpcrtlmm.h $(THISFILE)
+
+# Tools
+LIBRARY=tlib
+# -A : ANSI C only
+# -c : Compile with no link
+COMPILE=bcc32
+ANSI=-A -c
+CFLGS=-O   # Mad optimization, no debugging please :)
+
+# File control commands
+FILEEXISTS=if exist
+ERASE=erase
+PRINT=@echo
+BLANKLINE=.
+
+all : $(LIBNAME) example
+
+example : example1.exe example2.exe example3.exe
+
+example1.exe : $(MASTERDEP) example1.obj $(LIBNAME)
+	$(PRINT)$(BLANKLINE)
+	$(PRINT) Building example1 program
+	$(COMPILE) -eexample1.exe example1.obj $(LIBNAME)
+
+example2.exe : $(MASTERDEP) example2.obj dpccap.obj $(LIBNAME)
+	$(PRINT)$(BLANKLINE)
+	$(PRINT) Building example2 program
+	$(COMPILE) -eexample2.exe example2.obj dpccap.obj $(LIBNAME)
+
+example3.exe : $(MASTERDEP) example3.obj $(LIBNAME)
+	$(PRINT)$(BLANKLINE)
+	$(PRINT) Building example3 program
+	$(COMPILE) -eexample3.exe example3.obj $(LIBNAME)
+
+example1.obj : $(MASTERDEP) example1.c
+	$(COMPILE) $(ANSI) $(CFLGS) example1.c
+
+example2.obj : $(MASTERDEP) example2.cpp
+	$(COMPILE) $(ANSI) $(CFLGS) example2.cpp
+
+example3.obj : $(MASTERDEP) example3.c
+	$(COMPILE) $(ANSI) $(CFLGS) example3.c
+
+dpccap.obj : $(MASTERDEP) dpccap.cpp
+	$(COMPILE) $(ANSI) $(CFLGS) dpccap.cpp
+
+$(LIBNAME) : alloc.obj blkarray.obj calloc.obj free.obj isbad.obj stats.obj dbghooks.obj locktrap.obj safelist.obj dpcrtlmm.obj log.obj vptrap.obj trap.obj realloc.obj intdata.obj iblkptr.obj getblksz.obj bloclock.obj bdflags.obj
+	-$(LIBRARY) $(LIBNAME) -+alloc.obj
+	-$(LIBRARY) $(LIBNAME) -+blkarray.obj
+	-$(LIBRARY) $(LIBNAME) -+calloc.obj
+	-$(LIBRARY) $(LIBNAME) -+free.obj
+	-$(LIBRARY) $(LIBNAME) -+isbad.obj
+	-$(LIBRARY) $(LIBNAME) -+stats.obj
+	-$(LIBRARY) $(LIBNAME) -+dbghooks.obj
+	-$(LIBRARY) $(LIBNAME) -+locktrap.obj
+	-$(LIBRARY) $(LIBNAME) -+safelist.obj
+	-$(LIBRARY) $(LIBNAME) -+dpcrtlmm.obj
+	-$(LIBRARY) $(LIBNAME) -+log.obj
+	-$(LIBRARY) $(LIBNAME) -+vptrap.obj
+	-$(LIBRARY) $(LIBNAME) -+trap.obj
+	-$(LIBRARY) $(LIBNAME) -+realloc.obj
+	-$(LIBRARY) $(LIBNAME) -+intdata.obj
+	-$(LIBRARY) $(LIBNAME) -+iblkptr.obj
+	-$(LIBRARY) $(LIBNAME) -+getblksz.obj
+	-$(LIBRARY) $(LIBNAME) -+bloclock.obj
+	-$(LIBRARY) $(LIBNAME) -+bdflags.obj
+	$(PRINT)$(BLANKLINE)
+	$(PRINT) (C)2000, Overlord DDRP, Daybo Logic.
+	$(PRINT) Please read the license agreement before proceeding
+	$(PRINT) http://daybologic.com/Dev/dpcrtlmm
+
+alloc.obj : $(MASTERDEP) intdata.h log.h vptrap.h dbghooks.h
+	$(COMPILE) $(ANSI) $(CFLGS) alloc.c
+
+blkarray.obj : $(MASTERDEP) intdata.h log.h trap.h safelist.h dbghooks.h
+	$(COMPILE) $(ANSI) $(CFLGS) blkarray.c
+
+calloc.obj : $(MASTERDEP) intdata.h log.h iblkptr.h dbghooks.h
+	$(COMPILE) $(ANSI) $(CFLGS) calloc.c
+
+free.obj : $(MASTERDEP) intdata.h vptrap.h locktrap.h log.h trap.h dbghooks.h
+	$(COMPILE) $(ANSI) $(CFLGS) free.c
+
+isbad.obj : $(MASTERDEP) intdata.h trap.h safelist.h
+	$(COMPILE) $(ANSI) $(CFLGS) isbad.c
+
+stats.obj : $(MASTERDEP) intdata.h
+	$(COMPILE) $(ANSI) $(CFLGS) stats.c
+
+dbghooks.obj : $(MASTERDEP) intdata.h log.h dbghooks.h
+	$(COMPILE) $(ANSI) $(CFLGS) dbghooks.c
+
+locktrap.obj : $(MASTERDEP) intdata.h trap.h locktrap.h
+	$(COMPILE) $(ANSI) $(CFLGS) locktrap.c
+
+safelist.obj : $(MASTERDEP) intdata.h safelist.h
+	$(COMPILE) $(ANSI) $(CFLGS) safelist.c
+
+dpcrtlmm.obj : $(MASTERDEP)
+	$(COMPILE) $(ANSI) $(CFLGS) dpcrtlmm.c
+
+log.obj : $(MASTERDEP) intdata.h log.h
+	$(COMPILE) $(ANSI) $(CFLGS) log.c
+
+vptrap.obj : $(MASTERDEP) intdata.h trap.h log.h safelist.h vptrap.h
+	$(COMPILE) $(ANSI) $(CFLGS) vptrap.c
+
+trap.obj : $(MASTERDEP) intdata.h log.h trap.h dbghooks.h
+	$(COMPILE) $(ANSI) $(CFLGS) trap.c
+
+realloc.obj : $(MASTERDEP) intdata.h vptrap.h locktrap.h iblkptr.h dbghooks.h
+	$(COMPILE) $(ANSI) $(CFLGS) realloc.c
+
+intdata.obj : $(MASTERDEP) intdata.h
+	$(COMPILE) $(ANSI) $(CFLGS) intdata.c
+
+iblkptr.obj : $(MASTERDEP) intdata.h trap.h vptrap.h iblkptr.h
+	$(COMPILE) $(ANSI) $(CFLGS) iblkptr.c
+
+getblksz.obj : $(MASTERDEP) intdata.h trap.h vptrap.h iblkptr.h
+	$(COMPILE) $(ANSI) $(CFLGS) getblksz.c
+
+bloclock.obj : $(MASTERDEP)
+	$(COMPILE) $(ANSI) $(CFLGS) bloclock.c
+
+bdflags.obj : $(MASTERDEP) intdata.h vptrap.h iblkptr.h dbghooks.h
+	$(COMPILE) $(ANSI) $(CFLGS) bdflags.c
+
+clean:
+	$(FILEEXISTS) alloc.obj $(ERASE) alloc.obj
+	$(FILEEXISTS) blkarray.obj $(ERASE) blkarray.obj
+	$(FILEEXISTS) calloc.obj $(ERASE) calloc.obj
+	$(FILEEXISTS) free.obj $(ERASE) free.obj
+	$(FILEEXISTS) isbad.obj $(ERASE) isbad.obj
+	$(FILEEXISTS) stats.obj $(ERASE) stats.obj
+	$(FILEEXISTS) dbghooks.obj $(ERASE) dbghooks.obj
+	$(FILEEXISTS) locktrap.obj $(ERASE) locktrap.obj
+	$(FILEEXISTS) safelist.obj $(ERASE) safelist.obj
+	$(FILEEXISTS) dpcrtlmm.obj $(ERASE) dpcrtlmm.obj
+	$(FILEEXISTS) log.obj $(ERASE) log.obj
+	$(FILEEXISTS) vptrap.obj $(ERASE) vptrap.obj
+	$(FILEEXISTS) trap.obj $(ERASE) trap.obj
+	$(FILEEXISTS) realloc.obj $(ERASE) realloc.obj
+	$(FILEEXISTS) intdata.obj $(ERASE) intdata.obj
+	$(FILEEXISTS) iblkptr.obj $(ERASE) iblkptr.obj
+	$(FILEEXISTS) getblksz.obj $(ERASE) getblksz.obj
+	$(FILEEXISTS) bloclock.obj $(ERASE) bloclock.obj
+	$(FILEEXISTS) bdflags.obj $(ERASE) bdflags.obj
+	$(FILEEXISTS) $(LIBTITLE).bak $(ERASE) $(LIBTITLE).bak
+	$(FILEEXISTS) dpccap.obj $(ERASE) dpccap.obj
+	$(FILEEXISTS) example1.obj $(ERASE) example1.obj
+	$(FILEEXISTS) example2.obj $(ERASE) example2.obj
+	$(FILEEXISTS) example3.obj $(ERASE) example3.obj
+	$(FILEEXISTS) example1.tds $(ERASE) example1.tds
+	$(FILEEXISTS) example2.tds $(ERASE) example2.tds
+	$(FILEEXISTS) example3.tds $(ERASE) example3.tds
+	$(FILEEXISTS) DPCRTLMM.LOG $(ERASE) DPCRTLMM.LOG
+	#Don't forget Borland's annoying tds file, probally only made
+	#When not in optimization mode (not sure though), better
+	#get rid of it
+	$(FILEEXISTS) example.tds $(ERASE) example.tds
+
+# Clobber only used by maintainer generally (me), so that I may delete
+# ALL binaries which users of the lib wouldn't generally need to do.
+clobber: clean
+	$(FILEEXISTS) example1.exe $(ERASE) example1.exe
+	$(FILEEXISTS) example2.exe $(ERASE) example2.exe
+	$(FILEEXISTS) example3.exe $(ERASE) example3.exe
+	$(FILEEXISTS) $(LIBNAME) $(ERASE) $(LIBNAME)

dpcrtlmm/Makefile.gnu

+# Make file for DPCRTLMM
+# Written by Overlord David Duncan Ross Palmer
+# Overlord@DayboLogic.co.uk
+# 15th September 2000
+
+# This Makefile designed for GNU tools, gcc GNU C compiler, GNU's make
+# not neccersarily on UNIX but that's what I'm building on.  If you have
+# Borland C++ please use Makefile.bor instead.
+
+# Paths & filenames - Name of the makefile can be overridden on the command line in the form
+# make THISFILE=newmakefilename
+#
+# Normal make creates the library but not the examples
+# make example creates all example programs
+# make example1 builds the C example program only
+# make example2 builds the C++ example program only 
+# make example3 builds the C-stress test program only
+# make clean deletes all temporary binaries used to create the library
+# make clobber deletes target binaries (example programs and library).
+# make test builds all and then clobbers, it's for me to test the build before
+#      distribution only.
+# make all creates library and example programs
+
+# Tools
+LIBRARY=ar
+LIBOPTS=cru
+# -ansi : Only accept ANSI C code
+# -pedantic : Be very fussy about ANSI related problems
+# -c : Compile with no link
+# -g : Debug info
+# -Wall : Every possible warning please
+ANSI=-ansi -pedantic -Wall
+COMPILE=gcc -g -c $(ANSI)
+CPP_COMPILE=g++ -g -c $(ANSI)
+LINK=gcc -g $(ANSI)
+RANLIB=ranlib $(LIBNAME)
+
+# File control commands
+ERASE=rm -f
+
+# File names and extensions
+OBJ=.o
+C=.c
+H=.h
+CPP=.cpp
+
+# Main data for make rules
+THISFILE=Makefile.gnu
+LIBTITLE=dpcrtlmm
+LIBNAME=lib$(LIBTITLE).a
+# Master dependancies ALWAYS cause a rebuild
+MASTERDEP=build$(H) dpcrtlmm$(H) $(THISFILE)
+OBJECTS=alloc$(OBJ) blkarray$(OBJ) calloc$(OBJ) free$(OBJ) isbad$(OBJ) stats$(OBJ) dbghooks$(OBJ) locktrap$(OBJ) safelist$(OBJ) dpcrtlmm$(OBJ) log$(OBJ) vptrap$(OBJ) trap$(OBJ) realloc$(OBJ) intdata$(OBJ) iblkptr$(OBJ) getblksz$(OBJ) bloclock$(OBJ) bdflags$(OBJ)
+LOGFILE=DPCRTLMM.LOG
+COREDUMPS=example1.core example2.core example3.core
+BACKUPS=*~
+LIBADD=$(LIBRARY) $(LIBOPTS) $(LIBNAME)
+
+# Build rules
+
+$(LIBNAME) : $(MASTERDEP) $(OBJECTS)
+	$(LIBADD) alloc$(OBJ)
+	$(LIBADD) blkarray$(OBJ)
+	$(LIBADD) calloc$(OBJ)
+	$(LIBADD) free$(OBJ)
+	$(LIBADD) isbad$(OBJ)
+	$(LIBADD) stats$(OBJ)
+	$(LIBADD) dbghooks$(OBJ)
+	$(LIBADD) locktrap$(OBJ)
+	$(LIBADD) safelist$(OBJ)
+	$(LIBADD) dpcrtlmm$(OBJ)
+	$(LIBADD) log$(OBJ)
+	$(LIBADD) vptrap$(OBJ)
+	$(LIBADD) trap$(OBJ)
+	$(LIBADD) realloc$(OBJ)
+	$(LIBADD) intdata$(OBJ)
+	$(LIBADD) iblkptr$(OBJ)
+	$(LIBADD) getblksz$(OBJ)
+	$(LIBADD) bloclock$(OBJ)
+	$(LIBADD) bdflags$(OBJ)
+	$(RANLIB)
+
+alloc$(OBJ) : alloc$(C) $(MASTERDEP) intdata$(H) log$(H) vptrap$(H) dbghooks$(H)
+	$(COMPILE) alloc$(C)
+
+blkarray$(OBJ) : blkarray$(C) $(MASTERDEP) intdata$(H) log$(H) trap$(H) safelist$(H) dbghooks$(H)
+	$(COMPILE) blkarray$(C)
+
+calloc$(OBJ) : calloc$(C) $(MASTERDEP) intdata$(H) log$(H) iblkptr$(H) dbghooks$(H)
+	$(COMPILE) calloc$(C)
+
+free$(OBJ) : free$(C) $(MASTERDEP) intdata$(H) vptrap$(H) locktrap$(H) log$(H) trap$(H) dbghooks$(H)
+	$(COMPILE) free$(C)
+
+isbad$(OBJ) : isbad$(C) $(MASTERDEP) intdata$(H) trap$(H) safelist$(H)
+	$(COMPILE) isbad$(C)
+
+stats$(OBJ) : stats$(C) $(MASTERDEP) intdata$(H)
+	$(COMPILE) stats$(C)
+
+dbghooks$(OBJ) : dbghooks$(C) $(MASTERDEP) intdata$(H) log$(H) dbghooks$(H)
+	$(COMPILE) dbghooks$(C)
+
+locktrap$(OBJ) : locktrap$(C) $(MASTERDEP) intdata$(H) trap$(H) locktrap$(H)
+	$(COMPILE) locktrap$(C)
+
+safelist$(OBJ) : safelist$(C) $(MASTERDEP) intdata$(H) safelist$(H)
+	$(COMPILE) safelist$(C)
+
+dpcrtlmm$(OBJ) : dpcrtlmm$(C) $(MASTERDEP) intdata$(H) trap$(H) log$(H) safelist$(H) dbghooks$(H)
+	$(COMPILE) dpcrtlmm$(C)
+
+log$(OBJ) : log$(C) $(MASTERDEP) intdata$(H) log$(H)
+	$(COMPILE) log$(C)
+
+vptrap$(OBJ) : vptrap$(C) $(MASTERDEP) intdata$(H) trap$(H) log$(H) safelist$(H) vptrap$(H)
+	$(COMPILE) vptrap$(C)
+
+trap$(OBJ) : trap$(C) $(MASTERDEP) intdata$(H) log$(H) trap$(H) dbghooks$(H)
+	$(COMPILE) trap$(C)
+
+realloc$(OBJ) : realloc$(C) $(MASTERDEP) intdata$(H) vptrap$(H) locktrap$(H) iblkptr$(H) dbghooks$(H) log$(H)
+	$(COMPILE) realloc$(C)
+
+intdata$(OBJ) : intdata$(C) $(MASTERDEP) intdata$(H)
+	$(COMPILE) intdata$(C)
+
+iblkptr$(OBJ) : iblkptr$(C) $(MASTERDEP) intdata$(H) trap$(H) vptrap$(H) iblkptr$(H)
+	$(COMPILE) iblkptr$(C)
+
+getblksz$(OBJ) : getblksz$(C) $(MASTERDEP) intdata$(H) trap$(H) vptrap$(H) iblkptr$(H)
+	$(COMPILE) getblksz$(C)
+
+bloclock$(OBJ) : bloclock$(C) $(MASTERDEP)
+	$(COMPILE) bloclock$(C)
+
+bdflags$(OBJ) : bdflags$(C) $(MASTERDEP) intdata$(H) vptrap$(H) iblkptr$(H) dbghooks$(H)
+	$(COMPILE) bdflags$(C)
+
+critical$(OBJ) : critical$(C) $(MASTERDEP) critical$(H)
+	$(COMPILE) critical$(C)
+
+clean:
+	@-$(ERASE) $(OBJECTS)
+	@-$(ERASE) $(LOGFILE) $(COREDUMPS) $(BACKUPS)
+	@-$(ERASE) example1$(OBJ) example2$(OBJ) example3$(OBJ)
+	@-$(ERASE) dpccap$(OBJ)
+
+# Destroy everything including final executables and library
+clobber: clean
+	@-$(ERASE) $(LIBNAME)
+	@-$(ERASE) example1 example2 example3
+
+
+example : example1 example2 example3  #Type make -f Makefile.gnu example to make all examples
+
+# example1 program (C)
+
+example1 : $(MASTERDEP) example1$(OBJ) $(LIBNAME)
+	$(LINK) -o example1 example1$(OBJ) $(LIBNAME)
+
+example1$(OBJ) : $(MASTERDEP) example1$(C)
+	$(COMPILE) example1$(C)
+
+# example2 program (C++)
+
+example2 : $(MASTERDEP) example2$(OBJ) dpccap$(OBJ) $(LIBNAME)
+	$(LINK) -o example2 example2$(OBJ) dpccap$(OBJ) $(LIBNAME)
+
+example2$(OBJ) : $(MASTERDEP) example2$(CPP) dpccap$(CPP)
+	$(CPP_COMPILE) example2$(CPP)
+
+dpccap$(OBJ) : $(MASTERDEP) dpccap$(CPP) dpccap$(H)
+	$(CPP_COMPILE) dpccap$(CPP)
+
+# Stress test (example3)
+
+example3 : $(MASTERDEP) example3$(OBJ) $(LIBNAME)
+	$(LINK) -o example3 example3$(OBJ) $(LIBNAME)
+
+example3$(OBJ) : $(MASTERDEP) example3$(C) intdata$(H) safelist$(H)
+	$(COMPILE) example3$(C)
+
+
+all : $(LIBNAME) example
+
+test : # Maintainer thing only
+	make -f $(THISFILE) clobber
+	make -f $(THISFILE) all
+	make -f $(THISFILE) clobber
+/*
+    DPCRTLMM Memory management library : Primary allocator
+    Copyright (C) 2000 David Duncan Ross Palmer, Daybo Logic.
+
+    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, or
+    (at your option) any later version.
+
+    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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+Contact me: Overlord@DayboLogic.co.uk
+Get updates: http://daybologic.com/Dev/dpcrtlmm
+My official site: http://daybologic.com/overlord
+*/
+#define DPCRTLMM_SOURCE
+/* Main allocation function and block array grower
+ - Overlord David Duncan Ross Palmer
+ Copyright (C)2000 OverlordDDRP, Daybo Logic, all rights reserved.
+ Overlord@DayboLogic.co.uk
+*/
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#ifdef DPCRTLMM_HDRSTOP
+#  pragma hdrstop
+#endif /*DPCRTLMM_HDRSTOP*/
+
+#include "build.h" /* General build parameters */
+#ifdef DPCRTLMM_WANTFARDATA
+#  include <alloc.h>
+#endif /*DPCRTLMM_WANTFARDATA*/
+#include "dpcrtlmm.h" /* Main library header */
+#include "intdata.h" /* Internal library data */
+#include "log.h" /* Main logging support */
+#include "vptrap.h" /* _VerifyPtrs() */
+#include "dbghooks.h" /* Debug hook executive and support functions */
+
+
+/*-------------------------------------------------------------------------*/
+/* Internal functions (local) */
+
+static void OurLog(const unsigned short Severity, const char* Message);
+
+/* Grow the array by 'GrowByElems' elements, returns FALSE if
+it fails but then the original array is still valid and no
+bigger.  Always make sure the array pointer is resolved, NULL
+pointers are not acceptable and will be caught with assert() */
+
+static unsigned int GrowBlockArray(PS_DPCRTLMM_BLOCKDESCARRAY PCurrentBlockArray, const unsigned int GrowByElems);
+
+
+#ifdef OURLOG /* Somebody else using OURLOG? */
+#  undef OURLOG /* Don't want their version */
+#endif /*OURLOG*/
+
+/* Shortcut for typecast */
+#define OURLOG(sev, msg) OurLog(((const unsigned short)(sev)), (msg))
+/*-------------------------------------------------------------------------*/
+void DPCRTLMM_FARDATA* dpcrtlmm_Alloc(PS_DPCRTLMM_BLOCKDESCARRAY PBlockArray, const size_t NewBlockSize)
+{
+  /* locals */
+  void DPCRTLMM_FARDATA* genBlockPtr; /* Generated block pointer */
+  char logMsg[MAX_TRAP_STRING_LENGTH + 1];
+  #ifdef DPCRTLMM_DEBUGHOOKS
+  S_DPCRTLMM_DEBUGHOOKINFO debugHookInfo;
+  #endif /*DPCRTLMM_DEBUGHOOKS*/
+  PS_DPCRTLMM_BLOCKDESCARRAY PRArr = _ResolveArrayPtr(PBlockArray); /* Resolving is done because of a possible NULL */
+
+  _VerifyPtrs("Alloc()", PBlockArray, NULL); /* Haults program if array not valid, third arg is not applicable here */
+
+  sprintf(logMsg, "Program Requested to allocate %u byte block for array 0x%p",
+	  NewBlockSize,
+	  PBlockArray
+	  );
+  OURLOG(DPCRTLMM_LOG_MESSAGE, logMsg);
+
+  genBlockPtr = DPCRTLMM_MALLOC(NewBlockSize); /* Allocate block */
+  if (!genBlockPtr) /* Out of memory? */
+  {
+    /* Use buffer for log messages, it's the same size as for traps */
+    sprintf(logMsg, "Attempt to allocate block of %u bytes for array at base 0x%p has failed",
+	    NewBlockSize,
+	    PBlockArray
+    );
+    OURLOG(DPCRTLMM_LOG_MESSAGE, logMsg); /* I haven't made this a warning because it can happen in a very legitimate situation where the caller may be prepared for a large allocation to handle */
+    return NULL; /* No pointer generated */
+  }
+
+  /* Now add the block to the array, first grow array */
+  if (!GrowBlockArray(PRArr, 1))
+  {
+    /* Attempt to enlarge the array failed? */
+    DPCRTLMM_FREE(genBlockPtr); /* Release the new block of memory */
+
+    sprintf(logMsg, "Attempt to enlarge array at base 0x%p by one element failed",
+	    PBlockArray
+    );
+    /* This could be quite critical, if the memory manager is running our of space */
+    OURLOG(DPCRTLMM_LOG_WARNING, logMsg);
+    return NULL; /* Give up */
+  }
+
+  /* Now the block's address can be added to the array */
+  PRArr->Descriptors[PRArr->Count-1].PBase = genBlockPtr; /* Put pointer to base of block in block descriptor in the array */
+  PRArr->Descriptors[PRArr->Count-1].Size = NewBlockSize; /* Save size so caller can find it out leter */
+
+  /* Update library statistics */
+  dpcrtlmm_int__blockCount++;
+  dpcrtlmm_int__allocCharge += NewBlockSize;
+  /* Update peaks */
+  if ( dpcrtlmm_int__blockCount > dpcrtlmm_int__blockCountPeak )
+    dpcrtlmm_int__blockCountPeak = dpcrtlmm_int__blockCount;
+  if ( dpcrtlmm_int__allocCharge > dpcrtlmm_int__allocPeak )
+    dpcrtlmm_int__allocPeak = dpcrtlmm_int__allocCharge;
+
+  sprintf(logMsg, "New block of %u bytes is at 0x%p, descarray (0x%p) was extended to hold a new descriptor\nAlloc() returns 0x%p\nLeaving...",
+	  NewBlockSize,
+	  genBlockPtr,
+	  PBlockArray,
+	  genBlockPtr
+  );
+  OURLOG(DPCRTLMM_LOG_MESSAGE, logMsg); /* Actually this is a bit of a library debugging commend, perhaps verbose, I could remove it */
+
+  /* Call the debug hook executive */
+  #ifdef DPCRTLMM_DEBUGHOOKS
+  memset(&debugHookInfo, 0, sizeof(S_DPCRTLMM_DEBUGHOOKINFO)); /* Init structure */
+  debugHookInfo.PRelArr = PRArr; /* Use resolved value, NULL means N/A, this is the only point at which the array pointer address is exposed to the caller directly (expect other debug hook calls of course) */
+  debugHookInfo.PRelDesc = genBlockPtr;
+  debugHookInfo.HookType = DPCRTLMM_HOOK_ALLOC;
+  debugHookInfo.AllocReq = (unsigned int)NewBlockSize;
+  debugHookInfo.Success = 1U; /* TRUE */
+  dpcrtlmm_int_CallDebugHook(DPCRTLMM_HOOK_ALLOC, &debugHookInfo);
+  #endif /*DPCRTLMM_DEBUGHOOKS*/
+
+  return genBlockPtr; /* Give pointer to the caller */
+}
+/*-------------------------------------------------------------------------*/
+static unsigned int GrowBlockArray(PS_DPCRTLMM_BLOCKDESCARRAY PCurrentBlockArray, const unsigned int GrowByElems)
+{
+  PS_DPCRTLMM_BLOCKDESCRIPTOR ptr; /* Pointer to block descriptors during enlargement */
+  unsigned int oldCount; /* Count before enlargement */
+  unsigned int initi; /* Initialization interator */
+
+  #ifdef NDEBUG /* Not in debug mode? */
+    if (!PCurrentBlockArray) return 0U; /* Just get out indicating error before disaster */
+  #else /* Debug mode */
+    assert(PCurrentBlockArray);
+  #endif /*NDEBUG*/
+
+  if (!GrowByElems) /* Want to grow by nothing? */
+  {
+    OURLOG(DPCRTLMM_LOG_WARNING, "Attempt to GrowBlockArray() by no items, ignored");
+    return 1U; /* Success, already this size, it's great when there's nothing to do isn't it, programmer's are lazy */
+  }
+
+  oldCount = PCurrentBlockArray->Count; /* Take count before we grow array */
+  ptr = DPCRTLMM_REALLOC( PCurrentBlockArray->Descriptors, (oldCount + GrowByElems) * sizeof(S_DPCRTLMM_BLOCKDESCRIPTOR) ); /* Grow array */
+  if (!ptr) /* Couldn't grow? */
+    return 0U; /* Fail */
+
+  /* Update array information */
+  PCurrentBlockArray->Count += GrowByElems;
+  PCurrentBlockArray->Descriptors = ptr; /* Possible relocation might mean the pointer to the descriptors may need updating, make it so */
+
+  for ( initi = oldCount; initi < PCurrentBlockArray->Count; initi++ ) /* All new descriptors in the array that we just created */
+  {
+    PCurrentBlockArray->Descriptors[initi].PBase = NULL; /* No block assigned to this new descriptor yet */
+    PCurrentBlockArray->Descriptors[initi].Size = (size_t)0U; /* Therefore no size either */
+    PCurrentBlockArray->Descriptors[initi].Flags = 0U; /* No flags set */
+  }
+  return 1U; /* Success */
+}
+/*-------------------------------------------------------------------------*/
+static void OurLog(const unsigned short Severity, const char* Str)
+{
+   /* Our job is to add "Alloc() to the start of the string, saves data space
+  if everybody in this module calls this instead of _Log() directly.
+  We can't use LOG() twice because the information will be put on different
+  lines so a copy is needed. */
+
+  if (Str && Str[0]) /* Valid string of at least on character sent to us? */
+  {
+    char* PcopyStr;
+    const char FuncName[] = "Alloc(): "; /* Prefix */
+
+    PcopyStr = (char*)malloc( sizeof(FuncName) + strlen(Str) ); /* Allocate space for copy, note that NULL termination is automatic because using sizeof() */
+    if (PcopyStr)
+    {
+      strcpy(PcopyStr, FuncName); /* Prepend prefix */
+      strcat(PcopyStr, Str); /* Add log string after the prefix */
+
+      dpcrtlmm_int_Log(Severity, PcopyStr); /* Pass on to the normal logger */
+
+      free(PcopyStr); /* Copy can now be released */
+    }
+  }
+  return;
+}
+/*-------------------------------------------------------------------------*/

dpcrtlmm/bdflags.c

+/*
+    DPCRTLMM Memory management library : Descriptor flags modifiers
+    Copyright (C) 2000 David Duncan Ross Palmer, Daybo Logic.
+
+    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, or
+    (at your option) any later version.
+
+    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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+Contact me: Overlord@DayboLogic.co.uk
+Get updates: http://daybologic.com/Dev/dpcrtlmm
+My official site: http://daybologic.com/overlord
+*/
+#define DPCRTLMM_SOURCE
+/* Raw block descriptor flag modifiers : Overlord David Duncan Ross Palmer
+Copyright Y2K Daybo Logic, all rights reserved.
+Now supports NULL arrays
+*/
+#include <stddef.h>
+#include <string.h> /* memset() */
+#ifdef DPCRTLMM_HDRSTOP
+#  pragma hdrstop
+#endif /*DPCRTLMM_HDRSTOP*/
+
+#include "build.h" /* General build parameters */
+#include "dpcrtlmm.h" /* Main library header */
+#include "intdata.h" /* Internal library data */
+#include "vptrap.h" /* _VerifyPtrs() (replaces BBA/BBP traps) */
+#include "iblkptr.h" /* For getting array descriptor index for a particular block */
+#include "dbghooks.h" /* The debug hook executive */
+/*-------------------------------------------------------------------------*/
+/* NOTE: Adding of the hook caller in here has caused two variables
+both holding the index of the block, this should be optimized away when
+I can be bothered */
+unsigned char dpcrtlmm_ModifyDescriptorFlags(const PS_DPCRTLMM_BLOCKDESCARRAY PBlockArray, const void DPCRTLMM_FARDATA* Ptr, const unsigned char* PNewFlags)
+{
+  /* locals */
+  const char funcName[] = "ModifyDescriptorFlags()"; /* Name of this function */
+  unsigned int blockIndex; /* Index of block descriptor into the array */
+  unsigned char oldFlags; /* Old flags, returned to caller */
+  #ifdef DPCRTLMM_DEBUGHOOKS
+  S_DPCRTLMM_DEBUGHOOKINFO debugHookInfo;
+  unsigned int indexOfBlock;
+  #endif /*DPCRTLMM_DEBUGHOOKS*/
+  PS_DPCRTLMM_BLOCKDESCARRAY PRArr; /* Holds resolved pointer array */
+
+  /* Bah, this is a pain supporting this particular hook */
+  #ifdef DPCRTLMM_DEBUGHOOKS
+  memset(&debugHookInfo, 0, sizeof(S_DPCRTLMM_DEBUGHOOKINFO));
+
+  debugHookInfo.PRelArr = _ResolveArrayPtr(PBlockArray);
+  indexOfBlock = dpcrtlmm_int_IndexFromBlockPtr(PBlockArray, Ptr);
+  debugHookInfo.PRelDesc = &_ResolveArrayPtr(PBlockArray)->Descriptors[indexOfBlock]; /* Looked up the right descriptor to suit hook requirements */
+  debugHookInfo.HookType = DPCRTLMM_HOOK_MODIFYDESCFLAGS;
+  #endif /*DPCRTLMM_DEBUGHOOKS*/
+
+  _VerifyPtrs(funcName, PBlockArray, Ptr); /* Make sure invalid pointers don't get past here */
+
+  PRArr = _ResolveArrayPtr(PBlockArray); /* Makes NULL goto &_defaultArray */
+  blockIndex = _IndexFromBlockPtr(PRArr, Ptr); /* Get the index */
+  oldFlags = PRArr->Descriptors[blockIndex].Flags; /* Save current flags */
+  if (PNewFlags) /* Caller passed new flags */
+    PRArr->Descriptors[blockIndex].Flags = *PNewFlags; /* Modify the flags */
+
+  #ifdef DPCRTLMM_DEBUGHOOKS
+  debugHookInfo.Success = 1U;
+  debugHookInfo.Misc0 = (unsigned long)oldFlags;
+  debugHookInfo.Misc1 = (unsigned long)( (PNewFlags) ? (*PNewFlags) : (oldFlags) );
+  dpcrtlmm_int_CallDebugHook(DPCRTLMM_HOOK_MODIFYDESCFLAGS, &debugHookInfo);
+  #endif /*DPCRTLMM_DEBUGHOOKS*/
+
+  return oldFlags; /* Give the old flags back to the caller */
+}
+/*-------------------------------------------------------------------------*/

dpcrtlmm/blkarray.c

+/*
+    DPCRTLMM Memory management library : Block array controls
+    Copyright (C) 2000 David Duncan Ross Palmer, Daybo Logic.
+
+    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, or
+    (at your option) any later version.
+
+    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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+Contact me: Overlord@DayboLogic.co.uk
+Get updates: http://daybologic.com/Dev/dpcrtlmm
+My official site: http://daybologic.com/overlord
+*/
+#define DPCRTLMM_SOURCE
+/*
+#############################################################################
+# Block array creation and destruction functions                            #
+# Normally each module or section of a program will make it's own array     #
+# using the functions herin, if it is too much hastle (because of cleaning  #
+# up each module) or the program wants to hide behind a normal allocation   #
+# function re-routed to us via a hack then only one block array exists per  #
+# per program.                                                              #
+#############################################################################
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h> /* memset() */
+#ifdef DPCRTLMM_HDRSTOP
+#  pragma hdrstop
+#endif /*DPCRTLMM_HDRSTOP*/
+
+#include "build.h" /* General build parameters */
+#ifdef DPCRTLMM_WANTFARDATA
+#  include <alloc.h>
+#endif /*DPCRTLMM_WANTFARDATA*/
+#include "dpcrtlmm.h" /* Main library header */
+#include "intdata.h" /* Access to internal data */
+#include "log.h" /* LOG macro */
+#include "trap.h" /* _Trap() */
+#include "safelist.h" /* Safety list support functions */
+#include "dbghooks.h" /* For the debug hook executive */
+/*-------------------------------------------------------------------------*/
+PS_DPCRTLMM_BLOCKDESCARRAY dpcrtlmm_CreateBlockArray()
+{
+  PS_DPCRTLMM_BLOCKDESCARRAY Parray; /* Pointer for caller */
+  #ifdef DPCRTLMM_LOG
+  char logMsg[MAX_TRAP_STRING_LENGTH+1];
+  #endif /*DPCRTLMM_LOG*/
+  #ifdef DPCRTLMM_DEBUGHOOKS
+  S_DPCRTLMM_DEBUGHOOKINFO debugHookInfo;
+  #endif /*DPCRTLMM_DEBUGHOOKS*/
+
+  #ifdef DPCRTLMM_DEBUGHOOKS
+  memset(&debugHookInfo, 0, sizeof(S_DPCRTLMM_DEBUGHOOKINFO)); /* Init debug hook info */
+  debugHookInfo.HookType = DPCRTLMM_HOOK_CREATEBLOCKARRAY;
+  debugHookInfo.AllocReq = (unsigned int)sizeof(S_DPCRTLMM_BLOCKDESCARRAY); /* Ha, this is only vaugly relavant, this will do */
+  #endif /*DPCRTLMM_DEBUGHOOKS*/
+
+  Parray = (S_DPCRTLMM_BLOCKDESCARRAY*)malloc( sizeof(S_DPCRTLMM_BLOCKDESCARRAY) ); /* Alloc the array for the caller */
+  if (!Parray) /* Failed to alloc */
+  {
+    /* Memory outages while in memory manager mode must be warned about! */
+    WARNING("CreateBlockArray(): Couldn\'t allocate the new block array!");
+    #ifdef DPCRTLMM_DEBUGHOOKS
+    /* PRelArr is nothing, we couldn't allocate one :( */
+    /* PRelDesc is nothing, there is no related descriptor */
+    debugHookInfo.Success = 0U; /* Ahh, no failure! */
+    /* The rest are reserved or not used */
+    dpcrtlmm_int_CallDebugHook(DPCRTLMM_HOOK_CREATEBLOCKARRAY, &debugHookInfo);   /* Call the debug hook executive */
+    #endif /*DPCRTLMM_DEBUGHOOKS*/
+    return Parray; /* Give the NULL pointer back to the caller */
+  }
+  Parray->Count = 0U; /* No descriptors in list */
+  Parray->Descriptors = NULL; /* Nothing in block list */
+
+  /* The array base must be added to the list of acceptable arrays,
+     (the so called safety list)
+  */
+  if ( !SafetyList_AddBase(Parray) ) /* Add to safety list */
+  {
+    /* Failed to add to the list?!  Memory outages while in memory manager must be warned about */
+    WARNING("CreateBlockArray(): The array base address could not be added to the safety list");
+    DPCRTLMM_FREE(Parray); /* Free the array again */
+    Parray = NULL; /* So caller sees there's nothing allocated */
+  }
+
+  #ifdef DPCRTLMM_LOG
+  /* Safe, log progress */
+  sprintf(logMsg, "CreateBlockArray() returns base 0x%p", Parray);
+  MESSAGE(logMsg);
+  #endif /*DPCRTLMM_LOG*/
+
+  #ifdef DPCRTLMM_DEBUGHOOKS
+  /* Set up more hook information to indicate success */
+  debugHookInfo.PRelArr = Parray; /* The relavant array in this case is the one allocated */
+  debugHookInfo.Success = 1U; /* Yay, success! */
+  dpcrtlmm_int_CallDebugHook(DPCRTLMM_HOOK_CREATEBLOCKARRAY, &debugHookInfo);   /* Call the debug hook executive */
+  #endif /*DPCRTLMM_DEBUGHOOKS*/
+  return Parray; /* Give new pointer to the caller */
+}
+/*-------------------------------------------------------------------------*/
+void dpcrtlmm_DestroyBlockArray( PS_DPCRTLMM_BLOCKDESCARRAY PBlockArray )
+{
+  /* locals */
+  unsigned int sli; /* Safety list loop processing */
+  char trapStr[MAX_TRAP_STRING_LENGTH+1]; /* Sometimes used for creating trap strings */
+  #ifdef DPCRTLMM_DEBUGHOOKS
+  S_DPCRTLMM_DEBUGHOOKINFO debugHookInfo; /* Used for calling the debug hook executive */
+  #endif /*DPCRTLMM_DEBUGHOOKS*/
+
+  #ifdef DPCRTLMM_DEBUGHOOKS
+  /* Set up common stuff for the debug hook info */
+  debugHookInfo.PRelArr = _ResolveArrayPtr(PBlockArray);
+  /* There is no relavent descriptor */
+  debugHookInfo.HookType = DPCRTLMM_HOOK_DESTROYBLOCKARRAY;
+  /* There is no allocation request */
+  #endif /*DPCRTLMM_DEBUGHOOKS*/
+
+  for ( sli = 0U; sli < DPCRTLMM_SAFETYLIST_MAXSIZE; sli++ ) /* For all the possible items in the safety list */
+  {
+    if (_safetyList[sli]) /* Is this entry used? */
+    {
+      if (_safetyList[sli] == PBlockArray) /* Pointer match! */
+      {
+        if (_safetyList[sli]->Count) /* Any descriptors remaining? */
+        {
+          unsigned long totBytes = 0UL;
+          unsigned int li;
+
+          for ( li = 0; li < _safetyList[sli]->Count; li++ ) /* All blocks */
+          {
+            totBytes += _safetyList[sli]->Descriptors[li].Size; /* Add size of block to total */
+          }
+
+          sprintf(trapStr, "DestroyBlockArray(): %u blocks of memory not freed from array based at 0x%p\n                      Total bytes leakage for this array: %lu",
+                  _safetyList[sli]->Count,
+                  _safetyList[sli],
+                  totBytes
+          );
+          _Trap(DPCRTLMM_TRAP_UNFREED_BLOCKS, trapStr);
+        }
+        if (_safetyList[sli]->Descriptors) /* Descriptors not zero? */
+        {
+          sprintf(trapStr, "DestroyBlockArray(): Base of raw descriptor array not freed!\n0x%p->0x%p (PBlockArray->Descriptors must be NULL)",
+                  _safetyList[sli],
+                  _safetyList[sli]->Descriptors
+          );
+          _Trap(DPCRTLMM_TRAP_BASENONZERO, trapStr);
+        }
+        DPCRTLMM_FREE(_safetyList[sli]); /* BUG FIX: Forgot to release the memory for the array block pointer */
+        _safetyList[sli] = NULL; /* Remove this array from the safety list */
+        #ifdef DPCRTLMM_LOG