From 58553216380b1c343e501be5dd2f707b45b3aff5 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 24 May 2019 15:24:18 +0100 Subject: [PATCH] improve realpath() compat on older libc older libc didn't allow a NULL for the second param --- ChangeLog | 3 +++ configure.ac | 6 +++--- libvips/iofuncs/init.c | 13 +++++-------- libvips/iofuncs/util.c | 11 ++++++----- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 52e1e299..b0fce75e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +24/5/19 started 8.8.1 +- improve realpath() use on older libc + 21/9/18 started 8.8.0 - much faster smartcrop [lovell] - add low/high to smartcrop [jcupitt] diff --git a/configure.ac b/configure.ac index 6844c671..826b3b34 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # also update the version number in the m4 macros below -AC_INIT([vips], [8.8.0], [vipsip@jiscmail.ac.uk]) +AC_INIT([vips], [8.8.1], [vipsip@jiscmail.ac.uk]) # required for gobject-introspection AC_PREREQ(2.62) @@ -18,7 +18,7 @@ AC_CONFIG_MACRO_DIR([m4]) # user-visible library versioning m4_define([vips_major_version], [8]) m4_define([vips_minor_version], [8]) -m4_define([vips_micro_version], [0]) +m4_define([vips_micro_version], [1]) m4_define([vips_version], [vips_major_version.vips_minor_version.vips_micro_version]) @@ -38,7 +38,7 @@ VIPS_VERSION_STRING=$VIPS_VERSION-`date -u -r ChangeLog` # binary interface changes not backwards compatible?: reset age to 0 LIBRARY_CURRENT=52 -LIBRARY_REVISION=0 +LIBRARY_REVISION=1 LIBRARY_AGE=10 # patched into include/vips/version.h diff --git a/libvips/iofuncs/init.c b/libvips/iofuncs/init.c index eb8bbda9..87008822 100644 --- a/libvips/iofuncs/init.c +++ b/libvips/iofuncs/init.c @@ -979,24 +979,22 @@ guess_prefix( const char *argv0, const char *name ) } } -#ifdef HAVE_REALPATH - /* Try to guess from cwd. Only if this is a relative path, though. No - * realpath on winders, but fortunately it seems to always generate - * a full path in argv[0]. + /* Try to guess from cwd. Only if this is a relative path, though. */ if( !g_path_is_absolute( argv0 ) ) { + char *dir; char full_path[VIPS_PATH_MAX]; char *resolved; - char *dir; dir = g_get_current_dir(); vips_snprintf( full_path, VIPS_PATH_MAX, "%s" G_DIR_SEPARATOR_S "%s", dir, argv0 ); g_free( dir ); - if( (resolved = realpath( full_path, NULL )) ) { + if( (resolved = vips_realpath( full_path )) ) { prefix = extract_prefix( resolved, name ); - free( resolved ); + g_free( resolved ); + if( prefix ) { #ifdef DEBUG printf( "vips_guess_prefix: found \"%s\" " @@ -1006,7 +1004,6 @@ guess_prefix( const char *argv0, const char *name ) } } } -#endif /*HAVE_REALPATH*/ /* Fall back to the configure-time prefix. */ diff --git a/libvips/iofuncs/util.c b/libvips/iofuncs/util.c index e0eeb734..efb4643e 100644 --- a/libvips/iofuncs/util.c +++ b/libvips/iofuncs/util.c @@ -1875,9 +1875,12 @@ vips_realpath( const char *path ) #ifdef HAVE_REALPATH { - char *real2; + char buf[PATH_MAX]; - if( !(real = realpath( path, NULL )) ) { + /* More modern realpath() allow NULL for the second param, but we want + * to work with older libc as well. + */ + if( !(real = realpath( path, buf )) ) { vips_error_system( errno, "vips_realpath", "%s", _( "unable to form filename" ) ); return( NULL ); @@ -1885,9 +1888,7 @@ vips_realpath( const char *path ) /* We must return a path that can be freed with g_free(). */ - real2 = g_strdup( real ); - free( real ); - real = real2; + real = g_strdup( real ); } #else /*!HAVE_REALPATH*/ {