more cleaning up
This commit is contained in:
parent
ca5816a62c
commit
c383614c28
@ -276,6 +276,7 @@ GSList *vips__gslist_gvalue_copy( const GSList *list );
|
||||
GSList *vips__gslist_gvalue_merge( GSList *a, const GSList *b );
|
||||
char *vips__gslist_gvalue_get( const GSList *list );
|
||||
|
||||
gint64 vips__seek_no_error( int fd, gint64 pos, int whence );
|
||||
gint64 vips__seek( int fd, gint64 pos, int whence );
|
||||
int vips__ftruncate( int fd, gint64 pos );
|
||||
int vips_existsf( const char *name, ... )
|
||||
|
@ -33,7 +33,6 @@
|
||||
|
||||
/* TODO
|
||||
*
|
||||
* - make something to parse input and implement rad load
|
||||
* - gaussblur is missing the vector path again argh
|
||||
* - can we map and then close the fd? how about on Windows?
|
||||
* - make a subclass that lets you set vfuncs as params, inc. close(),
|
||||
@ -294,9 +293,7 @@ vips_streami_seek_real( VipsStreami *streami, gint64 offset, int whence )
|
||||
/* Like _read_real(), we must not set a vips_error. We need to use the
|
||||
* vips__seek() wrapper so we can seek long files on Windows.
|
||||
*/
|
||||
vips_error_freeze();
|
||||
new_pos = vips__seek( stream->descriptor, offset, whence );
|
||||
vips_error_thaw();
|
||||
new_pos = vips__seek_no_error( stream->descriptor, offset, whence );
|
||||
|
||||
return( new_pos );
|
||||
}
|
||||
@ -774,8 +771,7 @@ vips_streami_pipe_to_memory( VipsStreami *streami )
|
||||
if( vips_streami_pipe_read_to_position( streami, -1 ) )
|
||||
return( -1 );
|
||||
|
||||
/* Move header_bytes into the memory blob and set up as a memory
|
||||
* source.
|
||||
/* Steal the header_bytes pointer and turn into a memory source.
|
||||
*/
|
||||
streami->length = streami->header_bytes->len;
|
||||
streami->data = streami->header_bytes->data;
|
||||
@ -801,6 +797,9 @@ vips_streami_descriptor_to_memory( VipsStreami *streami )
|
||||
if( !(streami->mmap_baseaddr = vips__mmap( stream->descriptor,
|
||||
FALSE, streami->length, 0 )) )
|
||||
return( -1 );
|
||||
|
||||
/* And it's now a memory source.
|
||||
*/
|
||||
streami->data = streami->mmap_baseaddr;
|
||||
streami->mmap_length = streami->length;
|
||||
|
||||
@ -831,13 +830,13 @@ vips_streami_map( VipsStreami *streami, size_t *length_out )
|
||||
if( vips_streami_unminimise( streami ) )
|
||||
return( NULL );
|
||||
|
||||
/* Pipes need to be converted to memory streams.
|
||||
/* Pipes need to be read into memory.
|
||||
*/
|
||||
if( streami->is_pipe &&
|
||||
vips_streami_pipe_to_memory( streami ) )
|
||||
return( NULL );
|
||||
|
||||
/* Seekable descriptor sources can be mmaped and become memory
|
||||
/* Seekable descriptors can be mmaped and become memory
|
||||
* sources.
|
||||
*/
|
||||
if( !streami->data &&
|
||||
@ -929,9 +928,6 @@ vips_streami_seek( VipsStreami *streami, gint64 offset, int whence )
|
||||
return( -1 );
|
||||
break;
|
||||
}
|
||||
|
||||
if( vips_streami_pipe_read_to_position( streami, new_pos ) )
|
||||
return( -1 );
|
||||
}
|
||||
else {
|
||||
if( (new_pos = class->seek( streami, offset, whence )) == -1 )
|
||||
@ -948,6 +944,12 @@ vips_streami_seek( VipsStreami *streami, gint64 offset, int whence )
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
/* For pipes, we have to fake seek by reading to that point.
|
||||
*/
|
||||
if( streami->is_pipe &&
|
||||
vips_streami_pipe_read_to_position( streami, new_pos ) )
|
||||
return( -1 );
|
||||
|
||||
streami->read_position = new_pos;
|
||||
|
||||
SANITY( streami );
|
||||
|
@ -1031,7 +1031,7 @@ vips__gslist_gvalue_get( const GSList *list )
|
||||
/* Need our own seek(), since lseek() on win32 can't do long files.
|
||||
*/
|
||||
gint64
|
||||
vips__seek( int fd, gint64 pos, int whence )
|
||||
vips__seek_no_error( int fd, gint64 pos, int whence )
|
||||
{
|
||||
gint64 new_pos;
|
||||
|
||||
@ -1043,22 +1043,35 @@ vips__seek( int fd, gint64 pos, int whence )
|
||||
|
||||
/* Whence uses the same numbering on win32 and posix.
|
||||
*/
|
||||
|
||||
p.QuadPart = pos;
|
||||
if( !SetFilePointerEx( hFile, p, &q, whence ) ) {
|
||||
vips_error_system( GetLastError(), "vips__seek",
|
||||
"%s", _( "unable to seek" ) );
|
||||
if( !SetFilePointerEx( hFile, p, &q, whence ) )
|
||||
return( -1 );
|
||||
}
|
||||
new_pos = q.QuadPart;
|
||||
}
|
||||
#else /*!OS_WIN32*/
|
||||
if( (new_pos = lseek( fd, pos, whence )) == (off_t) -1 ) {
|
||||
new_pos = lseek( fd, pos, whence );
|
||||
#endif /*OS_WIN32*/
|
||||
|
||||
return( new_pos );
|
||||
}
|
||||
|
||||
/* Need our own seek(), since lseek() on win32 can't do long files.
|
||||
*/
|
||||
gint64
|
||||
vips__seek( int fd, gint64 pos, int whence )
|
||||
{
|
||||
gint64 new_pos;
|
||||
|
||||
if( (new_pos = vips__seek_no_error( fd, pos, whence )) == -1 ) {
|
||||
#ifdef OS_WIN32
|
||||
vips_error_system( GetLastError(), "vips__seek",
|
||||
"%s", _( "unable to seek" ) );
|
||||
#else /*!OS_WIN32*/
|
||||
vips_error_system( errno, "vips__seek",
|
||||
"%s", _( "unable to seek" ) );
|
||||
#endif /*OS_WIN32*/
|
||||
return( -1 );
|
||||
}
|
||||
#endif /*OS_WIN32*/
|
||||
|
||||
return( new_pos );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user