+ /*
+ * Did the user specify a directory? If not, path = NULL.
+ */
+ path = utf8_opendir ( (const char *)val.psz_string );
+ if( path != NULL )
+ {
+ char *psz_prefix = var_GetNonEmptyString( p_vout, "snapshot-prefix" );
+ if( psz_prefix == NULL )
+ psz_prefix = strdup( "vlcsnap-" );
+ else
+ {
+ char *psz_tmp = str_format( p_vout, psz_prefix );
+ filename_sanitize( psz_tmp );
+ free( psz_prefix );
+ psz_prefix = psz_tmp;
+ }
+
+ closedir( path );
+ if( var_GetBool( p_vout, "snapshot-sequential" ) == true )
+ {
+ int i_num = var_GetInteger( p_vout, "snapshot-num" );
+ FILE *p_file;
+ do
+ {
+ if( asprintf( &psz_filename, "%s" DIR_SEP "%s%05d.%s",
+ val.psz_string, psz_prefix, i_num++,
+ format.psz_string ) == -1 )
+ {
+ msg_Err( p_vout, "could not create snapshot" );
+ image_HandlerDelete( p_image );
+ return VLC_EGENERIC;
+ }
+ }
+ while( ( p_file = utf8_fopen( psz_filename, "r" ) ) && !fclose( p_file ) );
+ var_SetInteger( p_vout, "snapshot-num", i_num );
+ }
+ else
+ {
+ if( asprintf( &psz_filename, "%s" DIR_SEP "%s%u.%s",
+ val.psz_string, psz_prefix,
+ (unsigned int)(p_pic->date / 100000) & 0xFFFFFF,
+ format.psz_string ) == -1 )
+ {
+ msg_Err( p_vout, "could not create snapshot" );
+ image_HandlerDelete( p_image );
+ return VLC_EGENERIC;
+ }
+ }
+
+ free( psz_prefix );
+ }
+ else // The user specified a full path name (including file name)
+ {
+ psz_filename = str_format( p_vout, val.psz_string );
+ path_sanitize( psz_filename );
+ }
+