extractor_datasource.c (libextractor-1.10) | : | extractor_datasource.c (libextractor-1.11) | ||
---|---|---|---|---|
skipping to change at line 228 | skipping to change at line 228 | |||
if (pos > bfds->fsize) | if (pos > bfds->fsize) | |||
{ | { | |||
LOG ("Invalid seek operation\n"); | LOG ("Invalid seek operation\n"); | |||
return -1; /* invalid */ | return -1; /* invalid */ | |||
} | } | |||
if (NULL == bfds->buffer) | if (NULL == bfds->buffer) | |||
{ | { | |||
bfds->buffer_pos = pos; | bfds->buffer_pos = pos; | |||
return 0; | return 0; | |||
} | } | |||
position = (int64_t) LSEEK (bfds->fd, pos, SEEK_SET); | position = (int64_t) lseek (bfds->fd, pos, SEEK_SET); | |||
if (position < 0) | if (position < 0) | |||
{ | { | |||
LOG_STRERROR ("lseek"); | LOG_STRERROR ("lseek"); | |||
return -1; | return -1; | |||
} | } | |||
bfds->fpos = position; | bfds->fpos = position; | |||
bfds->buffer_pos = 0; | bfds->buffer_pos = 0; | |||
rd = read (bfds->fd, bfds->buffer, bfds->buffer_size); | rd = read (bfds->fd, bfds->buffer, bfds->buffer_size); | |||
if (rd < 0) | if (rd < 0) | |||
{ | { | |||
skipping to change at line 1187 | skipping to change at line 1187 | |||
struct EXTRACTOR_Datasource *ds; | struct EXTRACTOR_Datasource *ds; | |||
enum ExtractorCompressionType ct; | enum ExtractorCompressionType ct; | |||
int fd; | int fd; | |||
struct stat sb; | struct stat sb; | |||
int64_t fsize; | int64_t fsize; | |||
int winmode = 0; | int winmode = 0; | |||
#if WINDOWS | #if WINDOWS | |||
winmode = O_BINARY; | winmode = O_BINARY; | |||
#endif | #endif | |||
if (-1 == (fd = OPEN (filename, O_RDONLY | O_LARGEFILE | winmode))) | if (-1 == (fd = open (filename, O_RDONLY | O_LARGEFILE | winmode))) | |||
{ | { | |||
LOG_STRERROR_FILE ("open", filename); | LOG_STRERROR_FILE ("open", filename); | |||
return NULL; | return NULL; | |||
} | } | |||
if ( (0 != FSTAT (fd, &sb)) || | if ( (0 != fstat (fd, &sb)) || | |||
(S_ISDIR (sb.st_mode)) ) | (S_ISDIR (sb.st_mode)) ) | |||
{ | { | |||
if (! S_ISDIR (sb.st_mode)) | if (! S_ISDIR (sb.st_mode)) | |||
LOG_STRERROR_FILE ("fstat", filename); | LOG_STRERROR_FILE ("fstat", filename); | |||
else | else | |||
LOG ("Skipping directory `%s'\n", filename); | LOG ("Skipping directory `%s'\n", filename); | |||
(void) CLOSE (fd); | (void) close (fd); | |||
return NULL; | return NULL; | |||
} | } | |||
fsize = (int64_t) sb.st_size; | fsize = (int64_t) sb.st_size; | |||
if (0 == fsize) | if (0 == fsize) | |||
{ | { | |||
(void) CLOSE (fd); | (void) close (fd); | |||
return NULL; | return NULL; | |||
} | } | |||
bfds = bfds_new (NULL, fd, fsize); | bfds = bfds_new (NULL, fd, fsize); | |||
if (NULL == bfds) | if (NULL == bfds) | |||
{ | { | |||
(void) CLOSE (fd); | (void) close (fd); | |||
return NULL; | return NULL; | |||
} | } | |||
if (NULL == (ds = malloc (sizeof (struct EXTRACTOR_Datasource)))) | if (NULL == (ds = malloc (sizeof (struct EXTRACTOR_Datasource)))) | |||
{ | { | |||
LOG_STRERROR ("malloc"); | LOG_STRERROR ("malloc"); | |||
bfds_delete (bfds); | bfds_delete (bfds); | |||
(void) CLOSE (fd); | (void) close (fd); | |||
return NULL; | return NULL; | |||
} | } | |||
ds->bfds = bfds; | ds->bfds = bfds; | |||
ds->fd = fd; | ds->fd = fd; | |||
ds->cfs = NULL; | ds->cfs = NULL; | |||
ct = get_compression_type (bfds); | ct = get_compression_type (bfds); | |||
if ( (COMP_TYPE_ZLIB == ct) || | if ( (COMP_TYPE_ZLIB == ct) || | |||
(COMP_TYPE_BZ2 == ct) ) | (COMP_TYPE_BZ2 == ct) ) | |||
{ | { | |||
ds->cfs = cfs_new (bfds, fsize, ct, proc, proc_cls); | ds->cfs = cfs_new (bfds, fsize, ct, proc, proc_cls); | |||
if (NULL == ds->cfs) | if (NULL == ds->cfs) | |||
{ | { | |||
LOG ("Failed to initialize decompressor\n"); | LOG ("Failed to initialize decompressor\n"); | |||
bfds_delete (bfds); | bfds_delete (bfds); | |||
free (ds); | free (ds); | |||
(void) CLOSE (fd); | (void) close (fd); | |||
return NULL; | return NULL; | |||
} | } | |||
} | } | |||
return ds; | return ds; | |||
} | } | |||
/** | /** | |||
* Create a datasource from a buffer in memory. | * Create a datasource from a buffer in memory. | |||
* | * | |||
* @param buf data in memory | * @param buf data in memory | |||
skipping to change at line 1304 | skipping to change at line 1304 | |||
* | * | |||
* @param ds source to destroy | * @param ds source to destroy | |||
*/ | */ | |||
void | void | |||
EXTRACTOR_datasource_destroy_ (struct EXTRACTOR_Datasource *ds) | EXTRACTOR_datasource_destroy_ (struct EXTRACTOR_Datasource *ds) | |||
{ | { | |||
if (NULL != ds->cfs) | if (NULL != ds->cfs) | |||
cfs_destroy (ds->cfs); | cfs_destroy (ds->cfs); | |||
bfds_delete (ds->bfds); | bfds_delete (ds->bfds); | |||
if (-1 != ds->fd) | if (-1 != ds->fd) | |||
(void) CLOSE (ds->fd); | (void) close (ds->fd); | |||
free (ds); | free (ds); | |||
} | } | |||
/** | /** | |||
* Make 'size' bytes of data from the data source available at 'data'. | * Make 'size' bytes of data from the data source available at 'data'. | |||
* | * | |||
* @param cls must be a 'struct EXTRACTOR_Datasource' | * @param cls must be a 'struct EXTRACTOR_Datasource' | |||
* @param data where the data should be copied to | * @param data where the data should be copied to | |||
* @param size maximum number of bytes requested | * @param size maximum number of bytes requested | |||
* @return number of bytes now available in data (can be smaller than 'size'), | * @return number of bytes now available in data (can be smaller than 'size'), | |||
End of changes. 9 change blocks. | ||||
9 lines changed or deleted | 9 lines changed or added |