int vips_snprintf( char *str, size_t size, const char *format, ... ) { va_list ap; int n; va_start( ap, format ); n = vips_vsnprintf( str, size, format, ap ); va_end( ap ); return( n ); }
/* Load all plugins in a directory ... look for '.plg' suffix. Error if we had * any probs. */ static int vips_load_plugins( const char *fmt, ... ) { va_list ap; char dir_name[VIPS_PATH_MAX]; GDir *dir; const char *name; int result; /* Silently succeed if we can't do modules. */ if( !g_module_supported() ) return( 0 ); va_start( ap, fmt ); (void) vips_vsnprintf( dir_name, VIPS_PATH_MAX - 1, fmt, ap ); va_end( ap ); #ifdef DEBUG printf( "vips_load_plugins: searching \"%s\"\n", dir_name ); #endif /*DEBUG*/ if( !(dir = g_dir_open( dir_name, 0, NULL )) ) /* Silent success for dir not there. */ return( 0 ); result = 0; while( (name = g_dir_read_name( dir )) ) if( vips_ispostfix( name, ".plg" ) ) { char path[VIPS_PATH_MAX]; GModule *module; vips_snprintf( path, VIPS_PATH_MAX - 1, "%s" G_DIR_SEPARATOR_S "%s", dir_name, name ); #ifdef DEBUG printf( "vips_load_plugins: loading \"%s\"\n", path ); #endif /*DEBUG*/ module = g_module_open( path, G_MODULE_BIND_LAZY ); if( !module ) { vips_warn( "vips_init", _( "unable to load \"%s\" -- %s" ), path, g_module_error() ); result = -1; } } g_dir_close( dir ); return( result ); }
/* Test for file exists. */ int vips_existsf( const char *name, ... ) { va_list ap; char buf1[PATH_MAX]; va_start( ap, name ); (void) vips_vsnprintf( buf1, PATH_MAX - 1, name, ap ); va_end( ap ); /* Try that. */ if( !access( buf1, R_OK ) ) return( 1 ); return( 0 ); }
/* Make a directory. */ int vips_mkdirf( const char *name, ... ) { va_list ap; char buf1[PATH_MAX]; va_start( ap, name ); (void) vips_vsnprintf( buf1, PATH_MAX - 1, name, ap ); va_end( ap ); /* Try that. */ if( mkdir( buf1, 0755 ) ) { vips_error( "mkdirf", _( "unable to create directory \"%s\", %s" ), buf1, strerror( errno ) ); return( -1 ); } return( 0 ); }
/* Do popen(), with printf-style args. */ FILE * vips_popenf( const char *fmt, const char *mode, ... ) { va_list args; char buf[4096]; FILE *fp; va_start( args, mode ); (void) vips_vsnprintf( buf, 4096, fmt, args ); va_end( args ); #ifdef DEBUG printf( "vips_popenf: running: %s\n", buf ); #endif /*DEBUG*/ if( !(fp = popen( buf, mode )) ) { vips_error( "popenf", "%s", strerror( errno ) ); return( NULL ); } return( fp ); }