mirror of
https://github.com/boostorg/build.git
synced 2026-02-13 12:22:17 +00:00
Add common path_tmpdir function to get system dependent path to temporary a directory.
[SVN r31509]
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
# include "jam.h"
|
||||
# include "lists.h"
|
||||
# include "execcmd.h"
|
||||
# include "pathsys.h"
|
||||
# include "debug.h"
|
||||
# include <errno.h>
|
||||
# include <assert.h>
|
||||
@@ -440,34 +441,6 @@ void execnt_unit_test()
|
||||
#endif
|
||||
}
|
||||
|
||||
/* SVA - handle temp dirs with spaces in the path */
|
||||
static const char *getTempDir(void)
|
||||
{
|
||||
static char tempPath[_MAX_PATH];
|
||||
static char *pTempPath=NULL;
|
||||
|
||||
if(pTempPath == NULL)
|
||||
{
|
||||
char *p;
|
||||
|
||||
p = getenv("TEMP");
|
||||
if(p == NULL)
|
||||
{
|
||||
p = getenv("TMP");
|
||||
}
|
||||
if(p == NULL)
|
||||
{
|
||||
pTempPath = "\\temp";
|
||||
}
|
||||
else
|
||||
{
|
||||
GetShortPathName(p, tempPath, _MAX_PATH);
|
||||
pTempPath = tempPath;
|
||||
}
|
||||
}
|
||||
return pTempPath;
|
||||
}
|
||||
|
||||
/* 64-bit arithmetic helpers */
|
||||
|
||||
/* Compute the carry bit from the addition of two 32-bit unsigned numbers */
|
||||
@@ -577,18 +550,14 @@ execcmd(
|
||||
|
||||
if( !cmdtab[ slot ].tempfile )
|
||||
{
|
||||
const char *tempdir;
|
||||
DWORD procID;
|
||||
|
||||
tempdir = getTempDir();
|
||||
const char *tempdir = path_tmpdir();
|
||||
DWORD procID = GetCurrentProcessId();
|
||||
|
||||
/* SVA - allocate 64 other just to be safe */
|
||||
cmdtab[ slot ].tempfile = malloc( strlen( tempdir ) + 64 );
|
||||
if ( DEBUG_PROFILE )
|
||||
profile_memory( strlen( tempdir ) + 64 );
|
||||
|
||||
procID = GetCurrentProcessId();
|
||||
|
||||
sprintf( cmdtab[ slot ].tempfile, "%s\\jam%d-%02d.bat",
|
||||
tempdir, procID, slot );
|
||||
}
|
||||
|
||||
@@ -63,4 +63,11 @@ char* short_path_to_long_path(char* short_path);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef USE_PATHUNIX
|
||||
/** Returns a static pointer to the system dependent path to the temporary
|
||||
directory. NOTE: *without* a trailing path separator.
|
||||
*/
|
||||
const char * path_tmpdir(void);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
/* This file is ALSO:
|
||||
* Copyright 2001-2004 David Abrahams.
|
||||
* Copyright 2005 Rene Rivera.
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
@@ -393,5 +394,34 @@ char* short_path_to_long_path(char* short_path)
|
||||
|
||||
#endif
|
||||
|
||||
static string path_tmpdir_buffer[1];
|
||||
static const char * path_tmpdir_result = 0;
|
||||
|
||||
const char * path_tmpdir()
|
||||
{
|
||||
if (!path_tmpdir_result)
|
||||
{
|
||||
# ifdef OS_NT
|
||||
DWORD pathLength = 0;
|
||||
pathLength = GetTempPath(pathLength,NULL);
|
||||
string_new(path_tmpdir_buffer);
|
||||
string_reserve(path_tmpdir_buffer,pathLength);
|
||||
pathLength = GetTempPathA(pathLength,path_tmpdir_buffer[0].value);
|
||||
path_tmpdir_buffer[0].value[pathLength] = '\0';
|
||||
path_tmpdir_buffer[0].size = pathLength-1;
|
||||
# else
|
||||
const char * t = getenv("TMPDIR");
|
||||
if (!t)
|
||||
{
|
||||
t = "/tmp";
|
||||
}
|
||||
string_new(path_tmpdir_buffer);
|
||||
string_append(path_tmpdir_buffer,t);
|
||||
# endif
|
||||
path_tmpdir_result = path_tmpdir_buffer[0].value;
|
||||
}
|
||||
return path_tmpdir_result;
|
||||
}
|
||||
|
||||
|
||||
# endif /* unix, NT, OS/2, AmigaOS */
|
||||
|
||||
Reference in New Issue
Block a user