"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "libvips/iofuncs/util.c" between
vips-8.10.6.tar.gz and vips-8.11.0.tar.gz

About: VIPS is a free image processing system (see also the GUI nip2).

util.c  (vips-8.10.6):util.c  (vips-8.11.0)
skipping to change at line 56 skipping to change at line 56
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif /*HAVE_UNISTD_H*/ #endif /*HAVE_UNISTD_H*/
#ifdef HAVE_IO_H #ifdef HAVE_IO_H
#include <io.h> #include <io.h>
#endif /*HAVE_IO_H*/ #endif /*HAVE_IO_H*/
#include <fcntl.h> #include <fcntl.h>
#ifdef OS_WIN32
#include <windows.h>
#endif /*OS_WIN32*/
#include <vips/vips.h> #include <vips/vips.h>
#include <vips/debug.h> #include <vips/debug.h>
#include <vips/internal.h> #include <vips/internal.h>
#ifdef G_OS_WIN32
#include <windows.h>
#endif /*G_OS_WIN32*/
/* Temp buffer for snprintf() layer on old systems. /* Temp buffer for snprintf() layer on old systems.
*/ */
#define MAX_BUF (100000) #define MAX_BUF (100000)
/* Try to make an O_BINARY ... sometimes need the leading '_'. /* Try to make an O_BINARY ... sometimes need the leading '_'.
*/ */
#ifdef BINARY_OPEN #if defined(G_PLATFORM_WIN32) || defined(G_WITH_CYGWIN)
#ifndef O_BINARY #ifndef O_BINARY
#ifdef _O_BINARY #ifdef _O_BINARY
#define O_BINARY _O_BINARY #define O_BINARY _O_BINARY
#endif /*_O_BINARY*/ #endif /*_O_BINARY*/
#endif /*!O_BINARY*/ #endif /*!O_BINARY*/
#endif /*BINARY_OPEN*/ #endif /*defined(G_PLATFORM_WIN32) || defined(G_WITH_CYGWIN)*/
/* If we have O_BINARY, add it to a mode flags set. /* If we have O_BINARY, add it to a mode flags set.
*/ */
#ifdef O_BINARY #ifdef O_BINARY
#define BINARYIZE(M) ((M) | O_BINARY) #define BINARYIZE(M) ((M) | O_BINARY)
#else /*!O_BINARY*/ #else /*!O_BINARY*/
#define BINARYIZE(M) (M) #define BINARYIZE(M) (M)
#endif /*O_BINARY*/ #endif /*O_BINARY*/
/* Open mode for image write ... on some systems, have to set BINARY too. /* Open mode for image write ... on some systems, have to set BINARY too.
skipping to change at line 565 skipping to change at line 565
g_free( basename ); g_free( basename );
return( result ); return( result );
} }
/* Get file length ... 64-bitally. -1 for error. /* Get file length ... 64-bitally. -1 for error.
*/ */
gint64 gint64
vips_file_length( int fd ) vips_file_length( int fd )
{ {
#ifdef OS_WIN32 #ifdef G_OS_WIN32
struct _stati64 st; struct _stati64 st;
if( _fstati64( fd, &st ) == -1 ) { if( _fstati64( fd, &st ) == -1 ) {
#else /*!OS_WIN32*/ #else /*!G_OS_WIN32*/
struct stat st; struct stat st;
if( fstat( fd, &st ) == -1 ) { if( fstat( fd, &st ) == -1 ) {
#endif /*OS_WIN32*/ #endif /*G_OS_WIN32*/
vips_error_system( errno, "vips_file_length", vips_error_system( errno, "vips_file_length",
"%s", _( "unable to get file stats" ) ); "%s", _( "unable to get file stats" ) );
return( -1 ); return( -1 );
} }
return( st.st_size ); return( st.st_size );
} }
/* Wrap write() up /* Wrap write() up
*/ */
skipping to change at line 603 skipping to change at line 603
return( -1 ); return( -1 );
} }
buf = (void *) ((char *) buf + nwritten); buf = (void *) ((char *) buf + nwritten);
count -= nwritten; count -= nwritten;
} while( count > 0 ); } while( count > 0 );
return( 0 ); return( 0 );
} }
#ifdef OS_WIN32 #ifdef G_OS_WIN32
/* Set the create date on a file. On Windows, the create date may be copied /* Set the create date on a file. On Windows, the create date may be copied
* over from an existing file of the same name, unless you reset it. * over from an existing file of the same name, unless you reset it.
* *
* See https://blogs.msdn.microsoft.com/oldnewthing/20050715-14/?p=34923 * See https://blogs.msdn.microsoft.com/oldnewthing/20050715-14/?p=34923
*/ */
void void
vips__set_create_time( int fd ) vips__set_create_time( int fd )
{ {
HANDLE handle; HANDLE handle;
SYSTEMTIME st; SYSTEMTIME st;
FILETIME ft; FILETIME ft;
if( (handle = _get_osfhandle( fd )) == INVALID_HANDLE_VALUE ) if( (handle = (HANDLE) _get_osfhandle( fd )) == INVALID_HANDLE_VALUE )
return; return;
GetSystemTime( &st ); GetSystemTime( &st );
SystemTimeToFileTime( &st, &ft ); SystemTimeToFileTime( &st, &ft );
SetFileTime( handle, &ft, &ft, &ft ); SetFileTime( handle, &ft, &ft, &ft );
} }
#endif /*OS_WIN32*/ #endif /*G_OS_WIN32*/
/* open() with a utf8 filename, setting errno. /* open() with a utf8 filename, setting errno.
*/ */
int int
vips__open( const char *filename, int flags, int mode ) vips__open( const char *filename, int flags, int mode )
{ {
int fd; int fd;
/* Various bad things happen if you accidentally open a directory as a /* Various bad things happen if you accidentally open a directory as a
* file. * file.
*/ */
if( g_file_test( filename, G_FILE_TEST_IS_DIR ) ) { if( g_file_test( filename, G_FILE_TEST_IS_DIR ) ) {
errno = EISDIR; errno = EISDIR;
return( -1 ); return( -1 );
} }
fd = g_open( filename, flags, mode ); fd = g_open( filename, flags, mode );
#ifdef OS_WIN32 #ifdef G_OS_WIN32
if( mode & O_CREAT ) if( mode & O_CREAT )
vips__set_create_time( fd ); vips__set_create_time( fd );
#endif #endif /*G_OS_WIN32*/
return( fd ); return( fd );
} }
int int
vips__open_read( const char *filename ) vips__open_read( const char *filename )
{ {
return( vips__open( filename, MODE_READONLY, 0 ) ); return( vips__open( filename, MODE_READONLY, 0 ) );
} }
/* fopen() with utf8 filename and mode, setting errno. /* fopen() with utf8 filename and mode, setting errno.
*/ */
FILE * FILE *
vips__fopen( const char *filename, const char *mode ) vips__fopen( const char *filename, const char *mode )
{ {
FILE *fp; FILE *fp;
fp = g_fopen( filename, mode ); fp = g_fopen( filename, mode );
#ifdef OS_WIN32 #ifdef G_OS_WIN32
if( mode[0] == 'w' ) if( mode[0] == 'w' )
vips__set_create_time( _fileno( fp ) ); vips__set_create_time( _fileno( fp ) );
#endif #endif /*G_OS_WIN32*/
return( fp ); return( fp );
} }
/* Does a filename contain a directory separator? /* Does a filename contain a directory separator?
*/ */
static gboolean static gboolean
filename_hasdir( const char *filename ) filename_hasdir( const char *filename )
{ {
char *dirname; char *dirname;
skipping to change at line 701 skipping to change at line 701
* directly first, and if that fails and the filename does not contain a * directly first, and if that fails and the filename does not contain a
* directory separator, we try looking in the fallback dir. * directory separator, we try looking in the fallback dir.
*/ */
FILE * FILE *
vips__file_open_read( const char *filename, const char *fallback_dir, vips__file_open_read( const char *filename, const char *fallback_dir,
gboolean text_mode ) gboolean text_mode )
{ {
char *mode; char *mode;
FILE *fp; FILE *fp;
#ifdef BINARY_OPEN #if defined(G_PLATFORM_WIN32) || defined(G_WITH_CYGWIN)
if( text_mode ) if( text_mode )
mode = "r"; mode = "r";
else else
mode = "rb"; mode = "rb";
#else /*BINARY_OPEN*/ #else /*!defined(G_PLATFORM_WIN32) && !defined(G_WITH_CYGWIN)*/
mode = "r"; mode = "r";
#endif /*BINARY_OPEN*/ #endif /*defined(G_PLATFORM_WIN32) || defined(G_WITH_CYGWIN)*/
if( (fp = vips__fopen( filename, mode )) ) if( (fp = vips__fopen( filename, mode )) )
return( fp ); return( fp );
if( fallback_dir && if( fallback_dir &&
!filename_hasdir( filename ) ) { !filename_hasdir( filename ) ) {
char *path; char *path;
path = g_build_filename( fallback_dir, filename, NULL ); path = g_build_filename( fallback_dir, filename, NULL );
fp = vips__fopen( path, mode ); fp = vips__fopen( path, mode );
skipping to change at line 737 skipping to change at line 737
return( NULL ); return( NULL );
} }
FILE * FILE *
vips__file_open_write( const char *filename, gboolean text_mode ) vips__file_open_write( const char *filename, gboolean text_mode )
{ {
char *mode; char *mode;
FILE *fp; FILE *fp;
#ifdef BINARY_OPEN #if defined(G_PLATFORM_WIN32) || defined(G_WITH_CYGWIN)
if( text_mode ) if( text_mode )
mode = "w"; mode = "w";
else else
mode = "wb"; mode = "wb";
#else /*BINARY_OPEN*/ #else /*!defined(G_PLATFORM_WIN32) && !defined(G_WITH_CYGWIN)*/
mode = "w"; mode = "w";
#endif /*BINARY_OPEN*/ #endif /*defined(G_PLATFORM_WIN32) || defined(G_WITH_CYGWIN)*/
if( !(fp = vips__fopen( filename, mode )) ) { if( !(fp = vips__fopen( filename, mode )) ) {
vips_error_system( errno, "vips__file_open_write", vips_error_system( errno, "vips__file_open_write",
_( "unable to open file \"%s\" for writing" ), _( "unable to open file \"%s\" for writing" ),
filename ); filename );
return( NULL ); return( NULL );
} }
return( fp ); return( fp );
} }
skipping to change at line 1092 skipping to change at line 1092
g_assert( (size_t) (q - all) == length ); g_assert( (size_t) (q - all) == length );
return( all ); return( all );
} }
gint64 gint64
vips__seek_no_error( int fd, gint64 pos, int whence ) vips__seek_no_error( int fd, gint64 pos, int whence )
{ {
gint64 new_pos; gint64 new_pos;
#ifdef OS_WIN32 #ifdef G_OS_WIN32
new_pos = _lseeki64( fd, pos, whence ); new_pos = _lseeki64( fd, pos, whence );
#else /*!OS_WIN32*/ #else /*!G_OS_WIN32*/
/* On error, eg. opening a directory and seeking to the end, lseek() /* On error, eg. opening a directory and seeking to the end, lseek()
* on linux seems to return 9223372036854775807 ((1 << 63) - 1) * on linux seems to return 9223372036854775807 ((1 << 63) - 1)
* rather than (off_t) -1 for reasons I don't understand. * rather than (off_t) -1 for reasons I don't understand.
*/ */
new_pos = lseek( fd, pos, whence ); new_pos = lseek( fd, pos, whence );
#endif /*OS_WIN32*/ #endif /*G_OS_WIN32*/
return( new_pos ); return( new_pos );
} }
/* Need our own seek(), since lseek() on win32 can't do long files. /* Need our own seek(), since lseek() on win32 can't do long files.
*/ */
gint64 gint64
vips__seek( int fd, gint64 pos, int whence ) vips__seek( int fd, gint64 pos, int whence )
{ {
gint64 new_pos; gint64 new_pos;
skipping to change at line 1131 skipping to change at line 1131
/* Need our own ftruncate(), since ftruncate() on win32 can't do long files. /* Need our own ftruncate(), since ftruncate() on win32 can't do long files.
DANGER ... this moves the file pointer to the end of file on win32, DANGER ... this moves the file pointer to the end of file on win32,
but not on *nix; don't make any assumptions about the file pointer but not on *nix; don't make any assumptions about the file pointer
position after calling this position after calling this
*/ */
int int
vips__ftruncate( int fd, gint64 pos ) vips__ftruncate( int fd, gint64 pos )
{ {
#ifdef OS_WIN32 #ifdef G_OS_WIN32
{ {
HANDLE hFile = (HANDLE) _get_osfhandle( fd ); HANDLE hFile = (HANDLE) _get_osfhandle( fd );
if( vips__seek( fd, pos, SEEK_SET ) == -1 ) if( vips__seek( fd, pos, SEEK_SET ) == -1 )
return( -1 ); return( -1 );
if( !SetEndOfFile( hFile ) ) { if( !SetEndOfFile( hFile ) ) {
vips_error_system( GetLastError(), "vips__ftruncate", vips_error_system( GetLastError(), "vips__ftruncate",
"%s", _( "unable to truncate" ) ); "%s", _( "unable to truncate" ) );
return( -1 ); return( -1 );
} }
} }
#else /*!OS_WIN32*/ #else /*!G_OS_WIN32*/
if( ftruncate( fd, pos ) ) { if( ftruncate( fd, pos ) ) {
vips_error_system( errno, "vips__ftruncate", vips_error_system( errno, "vips__ftruncate",
"%s", _( "unable to truncate" ) ); "%s", _( "unable to truncate" ) );
return( -1 ); return( -1 );
} }
#endif /*OS_WIN32*/ #endif /*G_OS_WIN32*/
return( 0 ); return( 0 );
} }
/* TRUE if file exists. True for directories as well. /* TRUE if file exists. True for directories as well.
*/ */
gboolean gboolean
vips_existsf( const char *name, ... ) vips_existsf( const char *name, ... )
{ {
va_list ap; va_list ap;
skipping to change at line 1525 skipping to change at line 1525
start[0] = p; start[0] = p;
for( n = 0; for( n = 0;
n < MAX_TOKENS && n < MAX_TOKENS &&
(p = vips__token_get( start[n], &tokens[n], (p = vips__token_get( start[n], &tokens[n],
str, VIPS_PATH_MAX )); str, VIPS_PATH_MAX ));
n++, start[n] = p ) n++, start[n] = p )
; ;
/* Too many tokens? /* Too many tokens?
*/ */
if( n == MAX_TOKENS ) if( n >= MAX_TOKENS )
return( NULL ); return( NULL );
/* No rightmost close bracket? /* No rightmost close bracket?
*/ */
if( n == 0 || if( n == 0 ||
tokens[n - 1] != VIPS_TOKEN_RIGHT ) tokens[n - 1] != VIPS_TOKEN_RIGHT )
return( NULL ); return( NULL );
nest = 0; nest = 0;
for( i = n - 1; i >= 0; i-- ) { for( i = n - 1; i >= 0; i-- ) {
skipping to change at line 1623 skipping to change at line 1623
/* Return the tmp dir. On Windows, GetTempPath() will also check the values of /* Return the tmp dir. On Windows, GetTempPath() will also check the values of
* TMP, TEMP and USERPROFILE. * TMP, TEMP and USERPROFILE.
*/ */
static const char * static const char *
vips__temp_dir( void ) vips__temp_dir( void )
{ {
const char *tmpd; const char *tmpd;
if( !(tmpd = g_getenv( "TMPDIR" )) ) { if( !(tmpd = g_getenv( "TMPDIR" )) ) {
#ifdef OS_WIN32 #ifdef G_OS_WIN32
static gboolean done = FALSE; static gboolean done = FALSE;
static char buf[256]; static char buf[256];
if( !done ) { if( !done ) {
if( !GetTempPath( 256, buf ) ) if( !GetTempPath( 256, buf ) )
strcpy( buf, "C:\\temp" ); strcpy( buf, "C:\\temp" );
} }
tmpd = buf; tmpd = buf;
#else /*!OS_WIN32*/ #else /*!G_OS_WIN32*/
tmpd = "/tmp"; tmpd = "/tmp";
#endif /*!OS_WIN32*/ #endif /*!G_OS_WIN32*/
} }
return( tmpd ); return( tmpd );
} }
/* Make a temporary file name. The format parameter is something like "%s.jpg" /* 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". * and will be expanded to something like "/tmp/vips-12-34587.jpg".
* *
* You need to free the result. * You need to free the result.
*/ */
char * char *
vips__temp_name( const char *format ) vips__temp_name( const char *format )
{ {
static int global_serial = 0; static int global_serial = 0;
char file[FILENAME_MAX]; char file[FILENAME_MAX];
char file2[FILENAME_MAX]; char file2[FILENAME_MAX];
char *name; char *name;
/* Old glibs named this differently. int serial = g_atomic_int_add( &global_serial, 1 );
*/
int serial =
#if GLIB_CHECK_VERSION( 2, 30, 0 )
g_atomic_int_add( &global_serial, 1 );
#else
g_atomic_int_exchange_and_add( &global_serial, 1 );
#endif
vips_snprintf( file, FILENAME_MAX, "vips-%d-%u", vips_snprintf( file, FILENAME_MAX, "vips-%d-%u",
serial, g_random_int() ); serial, g_random_int() );
vips_snprintf( file2, FILENAME_MAX, format, file ); vips_snprintf( file2, FILENAME_MAX, format, file );
name = g_build_filename( vips__temp_dir(), file2, NULL ); name = g_build_filename( vips__temp_dir(), file2, NULL );
/* We could use something like g_mkstemp() to guarantee uniqueness /* We could use something like g_mkstemp() to guarantee uniqueness
* across processes, but the extra FS calls can be difficult for * across processes, but the extra FS calls can be difficult for
* selinux. * selinux.
* *
skipping to change at line 1964 skipping to change at line 1957
vips__random_add( guint32 seed, int value ) vips__random_add( guint32 seed, int value )
{ {
seed = ((2166136261u ^ seed) * 16777619u) ^ value; seed = ((2166136261u ^ seed) * 16777619u) ^ value;
return( vips__random( seed ) ); return( vips__random( seed ) );
} }
static void * static void *
vips_icc_dir_once( void *null ) vips_icc_dir_once( void *null )
{ {
#ifdef OS_WIN32 #ifdef G_OS_WIN32
/* From glib get_windows_directory_root() /* From glib get_windows_directory_root()
*/ */
wchar_t wwindowsdir[MAX_PATH]; wchar_t wwindowsdir[MAX_PATH];
if( GetWindowsDirectoryW( wwindowsdir, G_N_ELEMENTS( wwindowsdir ) ) ) { if( GetWindowsDirectoryW( wwindowsdir, G_N_ELEMENTS( wwindowsdir ) ) ) {
/* Usually X:\Windows, but in terminal server environments /* Usually X:\Windows, but in terminal server environments
* might be an UNC path, AFAIK. * might be an UNC path, AFAIK.
*/ */
char *windowsdir; char *windowsdir;
skipping to change at line 1986 skipping to change at line 1979
-1, NULL, NULL, NULL)) ) { -1, NULL, NULL, NULL)) ) {
gchar *full_path; gchar *full_path;
full_path = g_build_filename( windowsdir, full_path = g_build_filename( windowsdir,
"system32", "spool", "drivers", "color", NULL ); "system32", "spool", "drivers", "color", NULL );
g_free( windowsdir ); g_free( windowsdir );
return( (void *) full_path ); return( (void *) full_path );
} }
} }
#endif #endif /*G_OS_WIN32*/
return( (void *) VIPS_ICC_DIR ); return( (void *) VIPS_ICC_DIR );
} }
const char * const char *
vips__icc_dir( void ) vips__icc_dir( void )
{ {
static GOnce once = G_ONCE_INIT; static GOnce once = G_ONCE_INIT;
return( (const char *) g_once( &once, return( (const char *) g_once( &once,
vips_icc_dir_once, NULL ) ); vips_icc_dir_once, NULL ) );
} }
#ifdef OS_WIN32 #ifdef G_OS_WIN32
static HMODULE vips__dll = NULL; static HMODULE vips__dll = NULL;
#ifdef DLL_EXPORT #ifdef DLL_EXPORT
BOOL WINAPI BOOL WINAPI
DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
{ {
if( fdwReason == DLL_PROCESS_ATTACH ) if( fdwReason == DLL_PROCESS_ATTACH )
vips__dll = hinstDLL; vips__dll = hinstDLL;
return( TRUE ); return( TRUE );
} }
#endif #endif
#endif #endif /*G_OS_WIN32*/
static void * static void *
vips__windows_prefix_once( void *null ) vips__windows_prefix_once( void *null )
{ {
char *prefix; char *prefix;
#ifdef OS_WIN32 #ifdef G_OS_WIN32
prefix = g_win32_get_package_installation_directory_of_module( prefix = g_win32_get_package_installation_directory_of_module(
vips__dll ); vips__dll );
#else #else /*!G_OS_WIN32*/
prefix = (char *) g_getenv( "VIPSHOME" ); prefix = (char *) g_getenv( "VIPSHOME" );
#endif #endif /*G_OS_WIN32*/
return( (void *) prefix ); return( (void *) prefix );
} }
const char * const char *
vips__windows_prefix( void ) vips__windows_prefix( void )
{ {
static GOnce once = G_ONCE_INIT; static GOnce once = G_ONCE_INIT;
return( (const char *) g_once( &once, return( (const char *) g_once( &once,
 End of changes. 38 change blocks. 
47 lines changed or deleted 40 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)