use GetTempPath() on WIndows

This commit is contained in:
John Cupitt 2010-07-29 10:18:44 +00:00
parent 030a567f79
commit f822234c4e
7 changed files with 38 additions and 18 deletions

View File

@ -2,6 +2,7 @@
- im_vips2bufjpeg() writes to a linked list, so it will work for any size
image and header
- added im_vips2bufpng()
- use GetTempPath() to pick a temp dir on Windows
12/5/10 started 7.22.2
- the conditional image of ifthenelse can be any format, a (!=0) is added if

5
TODO
View File

@ -1,8 +1,3 @@
- use GetTempPath
http://msdn.microsoft.com/en-us/library/aa364992%28VS.85%29.aspx
instead of $TMPDIR on win
- lcms2 needs testing

View File

@ -59,10 +59,8 @@
* Copy an image to a disc file, then copy again to output. If the image is
* already a disc file, just copy straight through.
*
* The disc file is allocated in the same way as im_system_image(). A disc
* file is created in /tmp (change this with the TMPDIR environment
* variable) named something like "vips-12-34985.v" and the image is written
* to that file. The file is automatically deleted when @out is closed.
* The disc file is allocated in the same way as im_system_image().
* The file is automatically deleted when @out is closed.
*
* See also: im_copy(), im_system_image().
*

View File

@ -81,8 +81,8 @@
* "vips_XXXXXX.v", and that filename given to the command. The file is
* deleted when the command finishes.
*
* The environment variable TMPDIR can be used to set the temporary
* directory. If it is not set, it defaults to "/tmp".
* See im_system_image() for details on how VIPS selects a temporary
* directory.
*
* In all cases, @log must be freed with im_free().
*

View File

@ -100,6 +100,10 @@ system_image( IMAGE *im,
* can be used to set a different temporary directory. If @in_format is
* something like "%%s.png", the file will be written in PNG format.
*
* On Windows, if the environment variable TMPDIR is not defined, VIPS calls
* GetTempPath() to get the user's preferred temporary area. If that fails, it
* defaults to C:\temp.
*
* Next an output filename is created in the same way using @out_format. The
* command string to run is made by substituting the first %%s in @cmd_format
* for the name of the input file and the second %%s for the output filename.

View File

@ -1528,6 +1528,32 @@ im_amiMSBfirst( void )
return( 1 );
}
/* Return the tmp dir. On Windows, GetTempPath() will also check the values of
* TMP, TEMP and USERPROFILE.
*/
static const char *
im__temp_dir( void )
{
const char *tmpd;
if( !(tmpd = g_getenv( "TMPDIR" )) ) {
#ifdef OS_WIN32
static gboolean done = FALSE;
static char buf[256];
if( !done ) {
if( !GetTempPath( 256, buf ) )
strcpy( buf, "C:\\temp" );
}
tmpd = buf;
#else /*!OS_WIN32*/
tmpd = "/tmp";
#endif /*!OS_WIN32*/
}
return( tmpd );
}
/* Make a temporary file name. The format parameter is something like "%s.jpg"
* and will be expanded to something like "/tmp/vips-12-34587.jpg".
*
@ -1539,19 +1565,15 @@ im__temp_name( const char *format )
{
static int serial = 1;
const char *tmpd;
char file[FILENAME_MAX];
char file2[FILENAME_MAX];
char *name;
int fd;
if( !(tmpd = g_getenv( "TMPDIR" )) )
tmpd = "/tmp";
im_snprintf( file, FILENAME_MAX, "vips-%d-XXXXXX", serial++ );
im_snprintf( file2, FILENAME_MAX, format, file );
name = g_build_filename( tmpd, file2, NULL );
name = g_build_filename( im__temp_dir(), file2, NULL );
if( (fd = g_mkstemp( name )) == -1 ) {
im_error( "tempfile",

View File

@ -288,13 +288,13 @@ im_rank_image( IMAGE **in, IMAGE *out, int n, int index )
}
if( im_poutcheck( out ) )
return( -1 );
for( i = 0; i < n; i++ ) {
for( i = 0; i < n; i++ )
if( im_pincheck( in[i] ) ||
im_check_uncoded( "im_rank_image", in[i] ) ||
im_check_noncomplex( "im_rank_image", in[i] ) ||
im_check_size_same( "im_rank_image", in[i], in[0] ) ||
im_check_format_same( "im_rank_image", in[i], in[0] ) ||
im_check_bands( "im_rank_image", in[i], 3 ) )
im_check_bands_same( "im_rank_image", in[i], in[0] ) )
return( -1 );
if( !(rank = rank_new( in, out, n, index )) ||