#include <exec/types.h>
#include <exec/memory.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <st/textmessage.h>
#include <st/st_proto.h>


/**********************************************************/
         void SafeFreeString0(register struct String0 *string)
/**********************************************************
    Free (safe) whatever the string "string0" points at
 **********************************************************/
{	if(string->String && (string->FreeLen > 0)) {
			FreeMem(string->String, string->FreeLen);
			string->String = NULL;
			string->StrLen = string->FreeLen = 0;
	}
}

/**********************************************************/
char *AllocString0(register struct String0 *string, register long length)
/**********************************************************
       Get some memory for the string0 buffer type
     If length<1 then initialize the string0 struct
 **********************************************************/
{
	if(length < 1) {
		string->String = NULL;
		string->StrLen = string->FreeLen = 0;
		return(0);
	}
	/* Memory for the reply string */
	if(! (string->String =
				AllocMem(length, MEMF_PUBLIC | MEMF_CLEAR) )) {
		fpf(Output(),"*** Couldn't allocate %ld bytes\n", length);
		return(NULL);
	}
	string->StrLen = -1; string->FreeLen = length;
	return(string->String);
}
