From dd35d6ffc7cb3bb558cde3b53d485e790781139d Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 11 Apr 2014 22:51:39 +0100 Subject: [PATCH] add "%%" escape --- TODO | 2 -- libvips/iofuncs/system.c | 10 ++++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index f2257760..b3a4177b 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,3 @@ -- vips_system needs to use "%%" for a % character, for compatibility with - vips 7.38 - can we use postbuild elsewhere? look at use of "preclose" / "written", etc. diff --git a/libvips/iofuncs/system.c b/libvips/iofuncs/system.c index 1f5cc241..1082ec1c 100644 --- a/libvips/iofuncs/system.c +++ b/libvips/iofuncs/system.c @@ -119,6 +119,7 @@ vips_system_build( VipsObject *object ) char line[VIPS_PATH_MAX]; char txt[VIPS_PATH_MAX]; VipsBuf buf = VIPS_BUF_STATIC( txt ); + char *p; int result; if( VIPS_OBJECT_CLASS( vips_system_parent_class )->build( object ) ) @@ -164,6 +165,15 @@ vips_system_build( VipsObject *object ) cmd, VIPS_PATH_MAX, system->out_name ) ) return( -1 ); + /* Swap all "%%" in the string for a single "%". We need this for + * compatibility with older printf-based vips_system()s which + * needed a double %%. + */ + for( p = cmd; *p; p++ ) + if( p[0] == '%' && + p[1] == '%' ) + memmove( p, p + 1, strlen( p ) ); + if( !(fp = vips_popenf( "%s", "r", cmd )) ) return( -1 );