/* Read a few bytes from the start of a file. For sniffing file types. * Filename may contain a mode. */ int vips__get_bytes( const char *filename, unsigned char buf[], int len ) { char name[FILENAME_MAX]; char mode[FILENAME_MAX]; int fd; /* Split off the mode part. */ im_filename_split( filename, name, mode ); /* File may not even exist (for tmp images for example!) * so no hasty messages. And the file might be truncated, so no error * on read either. */ if( (fd = vips__open_read( name )) == -1 ) return( 0 ); if( read( fd, buf, len ) != len ) { close( fd ); return( 0 ); } close( fd ); return( 1 ); }
/* Read a few bytes from the start of a file. This is used for sniffing file * types, so we must read binary. * * Return the number of bytes actually read (the file might be shorter than * len), or 0 for error. */ guint64 vips__get_bytes( const char *filename, unsigned char buf[], guint64 len ) { int fd; guint64 bytes_read; /* File may not even exist (for tmp images for example!) * so no hasty messages. And the file might be truncated, so no error * on read either. */ if( (fd = vips__open_read( filename )) == -1 ) return( 0 ); bytes_read = read( fd, buf, len ); close( fd ); return( bytes_read ); }