Source

replaceables / DOS / _TMPPATH.C

/* Platform specific - DOS
version of 'replacables_GetTempPath()'/ */

#include <StdLib.H>
#include <String.H>
#include "Stds\DLStdInc.H" /* Daybo Logic standard inclusions */
#pragma hdrstop

#include "Replace\DOS\_TmpPath.H"
/*-------------------------------------------------------------------------*/
DWORD replaceables_GetTempPath(
	DWORD nBufferLength, /* # chars buffer can take */
	char* lpBuffer /* Address of buffer to take string */
)
{
	/* vars */
	char* envstrptr; /* pointer to an environment string */

	envstrptr = getenv("TMP"); /* get TMP environment */
	if (envstrptr) /* Environment pointer OK */
	{
		if (strlen(envstrptr) <= nBufferLength) /* user buffer large enough? */
		{
			strcpy(lpBuffer, envstrptr); /* copy environment string */
			return 0; /* no further processing required */
		}
		else
		{
			/* buffer was not enough */
			return strlen(envstrptr)+1; /* give buffer size required */
		}
	}
	envstrptr = getenv("TEMP"); /* use other environment (TEMP) as replacemanet, incase no TMP (which takes priority) */
	if (envstrptr) /* Environment pointer OK */
	{
		if (strlen(envstrptr) <= nBufferLength) /* user buffer large enough? */
		{
			strcpy(lpBuffer, envstrptr); /* copy environment string */
			return 0; /* success */
		}
		else /* buffer was not large enough */
		{
			return strlen(envstrptr)+1; /* give buffer size required */
		}
	}

	/* no appropriate temporary paths */
	if (nBufferLength <= 2) /* not even enough for two characters? */
	{
		return 3; /* please alloc array of three bytes */
	}
	strcpy(lpBuffer, ".\\"); /* say current directory */
	return 0; /* OK */
}
/*-------------------------------------------------------------------------*/