Implement TMPNAME and TMPFILE auto variables for Windows and Unix platforms.

[SVN r31561]
This commit is contained in:
Rene Rivera 2005-11-05 07:05:28 +00:00
parent 6ff174db28
commit f43778a768
6 changed files with 90 additions and 2 deletions

View File

@ -68,6 +68,14 @@ char* short_path_to_long_path(char* short_path);
directory. NOTE: *without* a trailing path separator.
*/
const char * path_tmpdir(void);
/** Returns a new temporary name.
*/
const char * path_tmpnam(void);
/** Returns a new temporary path.
*/
const char * path_tmpfile(void);
#endif
#endif

View File

@ -16,6 +16,11 @@
# include "strings.h"
# include "newstr.h"
# include "filesys.h"
# include <time.h>
# include <stdlib.h>
# ifndef OS_NT
# include <unistd.h>
# endif
# ifdef USE_PATHUNIX
@ -407,7 +412,7 @@ const char * path_tmpdir()
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].value[pathLength-1] = '\0';
path_tmpdir_buffer[0].size = pathLength-1;
# else
const char * t = getenv("TMPDIR");
@ -423,5 +428,34 @@ const char * path_tmpdir()
return path_tmpdir_result;
}
const char * path_tmpnam(void)
{
char name_buffer[64];
# ifdef OS_NT
unsigned long c0 = GetCurrentProcessId();
# else
unsigned long c0 = getpid();
# endif
static unsigned long c1 = 0;
if (0 == c1) c1 = time(0)&0xffff;
c1 += 1;
sprintf(name_buffer,"jam%lx%lx.000",c0,c1);
return newstr(name_buffer);
}
const char * path_tmpfile(void)
{
const char * result = 0;
string file_path;
string_copy(&file_path,path_tmpdir());
string_push_back(&file_path,PATH_DELIM);
string_append(&file_path,path_tmpnam());
result = newstr(file_path.value);
string_free(&file_path);
return result;
}
# endif /* unix, NT, OS/2, AmigaOS */

View File

@ -439,9 +439,11 @@ var_get( char *symbol )
}
else if ( strcmp( "TMPNAME", symbol ) == 0 )
{
result = list_new( L0, newstr( (char*)path_tmpnam() ) );
}
else if ( strcmp( "TMPFILE", symbol ) == 0 )
{
result = list_new( L0, newstr( (char*)path_tmpfile() ) );
}
#if 0
/* Not really usefull at the moment. */

View File

@ -68,6 +68,14 @@ char* short_path_to_long_path(char* short_path);
directory. NOTE: *without* a trailing path separator.
*/
const char * path_tmpdir(void);
/** Returns a new temporary name.
*/
const char * path_tmpnam(void);
/** Returns a new temporary path.
*/
const char * path_tmpfile(void);
#endif
#endif

View File

@ -16,6 +16,11 @@
# include "strings.h"
# include "newstr.h"
# include "filesys.h"
# include <time.h>
# include <stdlib.h>
# ifndef OS_NT
# include <unistd.h>
# endif
# ifdef USE_PATHUNIX
@ -407,7 +412,7 @@ const char * path_tmpdir()
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].value[pathLength-1] = '\0';
path_tmpdir_buffer[0].size = pathLength-1;
# else
const char * t = getenv("TMPDIR");
@ -423,5 +428,34 @@ const char * path_tmpdir()
return path_tmpdir_result;
}
const char * path_tmpnam(void)
{
char name_buffer[64];
# ifdef OS_NT
unsigned long c0 = GetCurrentProcessId();
# else
unsigned long c0 = getpid();
# endif
static unsigned long c1 = 0;
if (0 == c1) c1 = time(0)&0xffff;
c1 += 1;
sprintf(name_buffer,"jam%lx%lx.000",c0,c1);
return newstr(name_buffer);
}
const char * path_tmpfile(void)
{
const char * result = 0;
string file_path;
string_copy(&file_path,path_tmpdir());
string_push_back(&file_path,PATH_DELIM);
string_append(&file_path,path_tmpnam());
result = newstr(file_path.value);
string_free(&file_path);
return result;
}
# endif /* unix, NT, OS/2, AmigaOS */

View File

@ -439,9 +439,11 @@ var_get( char *symbol )
}
else if ( strcmp( "TMPNAME", symbol ) == 0 )
{
result = list_new( L0, newstr( (char*)path_tmpnam() ) );
}
else if ( strcmp( "TMPFILE", symbol ) == 0 )
{
result = list_new( L0, newstr( (char*)path_tmpfile() ) );
}
#if 0
/* Not really usefull at the moment. */