From feca00958c83967bae5033599127bd3b92da400d Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 16 Aug 2016 18:33:48 +0100 Subject: [PATCH] seems to be sort-of working! --- configure.ac | 4 +- libvips/include/vips/util.h | 3 + libvips/iofuncs/memory.c | 2 +- libvips/iofuncs/util.c | 107 +++++++++++++++++++++++------------- tools/vipsthumbnail.c | 1 - 5 files changed, 77 insertions(+), 40 deletions(-) diff --git a/configure.ac b/configure.ac index e2df036f..2d5f4238 100644 --- a/configure.ac +++ b/configure.ac @@ -236,7 +236,9 @@ fi if test x"$vips_os_darwin" = x"yes"; then profile_dir="/Library/ColorSync/Profiles" elif test x"$vips_os_win32" = x"yes"; then - profile_dir="C:\\Windows\\System32\\spool\\drivers\\color" + # need double escapes since this will get pasted into a #define in a C + # header + profile_dir="C:\\\\Windows\\\\System32\\\\spool\\\\drivers\\\\color" else profile_dir="/usr/share/color/icc" fi diff --git a/libvips/include/vips/util.h b/libvips/include/vips/util.h index 01cd8091..6dc9870c 100644 --- a/libvips/include/vips/util.h +++ b/libvips/include/vips/util.h @@ -222,6 +222,9 @@ int vips_filename_suffix_match( const char *path, const char *suffixes[] ); gint64 vips_file_length( int fd ); int vips__write( int fd, const void *buf, size_t count ); +int vips__open( const char *filename, int flags, ... ); +FILE *vips__fopen( const char *filename, const char *mode ); + FILE *vips__file_open_read( const char *filename, const char *fallback_dir, gboolean text_mode ); FILE *vips__file_open_write( const char *filename, diff --git a/libvips/iofuncs/memory.c b/libvips/iofuncs/memory.c index ca5e2cca..d6c00173 100644 --- a/libvips/iofuncs/memory.c +++ b/libvips/iofuncs/memory.c @@ -365,7 +365,7 @@ vips_tracked_open( const char *pathname, int flags, ... ) mode = va_arg( ap, int ); va_end( ap ); - if( (fd = open( pathname, flags, mode )) == -1 ) + if( (fd = vips__open( pathname, flags, mode )) == -1 ) return( -1 ); vips_tracked_init(); diff --git a/libvips/iofuncs/util.c b/libvips/iofuncs/util.c index 823b08bf..8af09230 100644 --- a/libvips/iofuncs/util.c +++ b/libvips/iofuncs/util.c @@ -543,6 +543,74 @@ vips__write( int fd, const void *buf, size_t count ) return( 0 ); } +/* open() with a utf8 filename. + */ +int +vips__open( const char *filename, int flags, ... ) +{ + int fd; + mode_t mode; + va_list ap; + + va_start( ap, flags ); + mode = va_arg( ap, int ); + va_end( ap ); + +#ifdef OS_WIN32 + GError *error = NULL; + wchar_t *path16; + + if( !(path16 = (wchar_t *) + g_utf8_to_utf16( filename, -1, NULL, NULL, &error )) ) { + vips_g_error( &error ); + return( -1 ); + } + + fd = _wopen( path16, flags, mode ); + + g_free( path16 ); +#else /*!OS_WIN32*/ + fd = open( filename, flags, mode ); +#endif + + return( fd ); +} + +/* fopen() with utf8 filename and mode. + */ +FILE * +vips__fopen( const char *filename, const char *mode ) +{ + FILE *fp; + +#ifdef OS_WIN32 + GError *error = NULL; + wchar_t *path16, *mode16; + + if( !(path16 = (wchar_t *) + g_utf8_to_utf16( filename, -1, NULL, NULL, &error )) ) { + vips_g_error( &error ); + return( NULL ); + } + + if( !(mode16 = (wchar_t *) + g_utf8_to_utf16( mode, -1, NULL, NULL, &error )) ) { + g_free( path16 ); + vips_g_error( &error ); + return( NULL ); + } + + fp = _wfopen( path16, mode16 ); + + g_free( path16 ); + g_free( mode16 ); +#else /*!OS_WIN32*/ + fp = fopen( filename, mode ); +#endif + + return( fp ); +} + /* Does a filename contain a directory separator? */ static gboolean @@ -558,41 +626,6 @@ filename_hasdir( const char *filename ) return( hasdir ); } -/* fopen() with utf8 filename and mode. - */ -static FILE * -vips__fopen( const char *filename, const char *mode ) -{ - FILE *fp; - -#ifdef OS_WIN32 - GError *error = NULL; - wchar_t *path16, *mode16; - - if( !(path16 = (wchar_t *) - g_utf8_to_utf16( filename, -1, NULL, NULL, &error )) ) { - vips_g_error( error ); - return( NULL ); - } - - if( !(mode16 = (wchar_t *) - g_utf8_to_utf16( mode, -1, NULL, NULL, &error )) ) { - g_free( path16 ); - vips_g_error( error ); - return( NULL ); - } - - fp = _wfopen( path16, mode16 ); - - g_free( path16 ); - g_free( mode16 ); -#else /*!OS_WIN32*/ - fp = fopen( filename, mode ); -#endif - - return( fp ); -} - /* Open a file. We take an optional fallback dir as well and will try opening * there if opening directly fails. * @@ -796,7 +829,7 @@ vips__get_bytes( const char *filename, unsigned char buf[], int len ) * so no hasty messages. And the file might be truncated, so no error * on read either. */ - if( (fd = open( name, MODE_READONLY )) == -1 ) + if( (fd = vips__open( name, MODE_READONLY )) == -1 ) return( 0 ); if( read( fd, buf, len ) != len ) { close( fd ); @@ -1070,7 +1103,7 @@ vips_existsf( const char *name, ... ) path = g_strdup_vprintf( name, ap ); va_end( ap ); - result = access( path, R_OK ); + result = g_access( path, R_OK ); g_free( path ); diff --git a/tools/vipsthumbnail.c b/tools/vipsthumbnail.c index 17dd8235..8439cd69 100644 --- a/tools/vipsthumbnail.c +++ b/tools/vipsthumbnail.c @@ -684,7 +684,6 @@ main( int argc, char **argv ) * the args. */ #ifdef HAVE_G_WIN32_GET_COMMAND_LINE - printf( "using g_win32_get_command_line()\n" ); argv = g_win32_get_command_line(); #endif /*HAVE_G_WIN32_GET_COMMAND_LINE*/