try to handle mmap failing in source

Some filesystems have mmap disabled. Make vips_source_map() fall back to
read if mmap fails.

See https://github.com/libvips/libvips/discussions/2415
This commit is contained in:
John Cupitt 2021-09-08 09:24:36 +01:00
parent f2dd4471eb
commit cfd9dc3f01
1 changed files with 20 additions and 17 deletions

View File

@ -1002,23 +1002,26 @@ vips_source_map( VipsSource *source, size_t *length_out )
vips_source_test_features( source ) )
return( NULL );
if( !source->data ) {
/* Seekable descriptors can simply be mapped. Seekable sources
* can be read. All other sources must be streamed into memory.
*/
if( vips_source_is_mappable( source ) ) {
if( vips_source_descriptor_to_memory( source ) )
return( NULL );
}
else if( !source->is_pipe ) {
if( vips_source_read_to_memory( source ) )
return( NULL );
}
else {
if( vips_source_pipe_read_to_position( source, -1 ) )
return( NULL );
}
}
/* Try to map the file into memory, if possible. Some filesystems have
* mmap disabled, so we don't give up if this fails.
*/
if( !source->data &&
vips_source_is_mappable( source ) )
(void) vips_source_descriptor_to_memory( source );
/* If it's not a pipe, we can rewind, get the length, and read the
* whole thing.
*/
if( !source->data &&
!source->is_pipe &&
vips_source_read_to_memory( source ) )
return( NULL );
/* We don't know the length and must read and assemble in chunks.
*/
if( !source->data &&
vips_source_pipe_read_to_position( source, -1 ) )
return( NULL );
if( length_out )
*length_out = source->length;