Boost logo

Boost-Build :

From: Michael van der Westhuizen (r1mikey_at_[hidden])
Date: 2005-10-29 19:29:51


Hi Reece,

On 10/29/05, Reece Dunn <msclrhd_at_[hidden]> wrote:
[snip]
> I have attached the patch for an initial port of native bjam response
> file support based on Matt's code. This allows for:
[snip]
> The patch currently only supports NT (because of getTempPath()), so I
> would like help porting to other OSes. Linux would probably be:
>
> const char * getTempPath( void )
> {
> return "/tmp/";
> }

It's normally accepted (in POSIX systems) to allow a user to override
the temporary directory using the TMPDIR environment variable. The
following code will provide that behaviour, and, from your example
above, should just plug in where you need the system specific code.

Hope this helps,
Michael

#include <string.h>
#include <stdlib.h>
#include <stdio.h>

const char * getTempDir()
{
static char tempPath[_MAX_PATH];
static char * pTempPath = NULL;

if( NULL == pTempPath )
{
char * temp_env;
char * temp_dir;

temp_dir = temp_env = 0;

memset( tempPath, 0, sizeof( tempPath ) );

if( 0 == ( temp_env = getenv( "TMPDIR" ) ) )
{
strncpy( tempPath, "/tmp", sizeof( tempPath ) - 1 );
}
else
{
if( strlen( temp_env ) >= _MAX_PATH )
{
fprintf( stderr, "%s\n", "potential overflow "
"caused by TMPDIR environment variable" );
fflush( stderr );
exit( 1 );
}

strncpy( tempPath, temp_env, sizeof( tempPath ) - 1 );
}

pTempPath = tempPath;
}

return pTempPath;
}

 


Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk