From 8273af2a31ce2985ebd7d9f4bccf8bc1960e28ba Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Mon, 31 Oct 2005 06:36:54 +0000 Subject: [PATCH] Add common path_tmpdir function to get system dependent path to temporary a directory. [SVN r31509] --- src/engine/execnt.c | 37 +++---------------------------------- src/engine/pathsys.h | 7 +++++++ src/engine/pathunix.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/engine/execnt.c b/src/engine/execnt.c index 3d929bbd8..9b62c169b 100644 --- a/src/engine/execnt.c +++ b/src/engine/execnt.c @@ -13,6 +13,7 @@ # include "jam.h" # include "lists.h" # include "execcmd.h" +# include "pathsys.h" # include "debug.h" # include # include @@ -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 ); } diff --git a/src/engine/pathsys.h b/src/engine/pathsys.h index cf0afd66d..0dbfda791 100644 --- a/src/engine/pathsys.h +++ b/src/engine/pathsys.h @@ -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 diff --git a/src/engine/pathunix.c b/src/engine/pathunix.c index 5ed5190c3..0e6ee9e71 100644 --- a/src/engine/pathunix.c +++ b/src/engine/pathunix.c @@ -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 */