futility/updater_archive.c
/* Callback for archive_zip_read_file on a ZIP file. */
Callback for archive_zip_read_file on a ZIP file.
Callback for archive_zip_read_file on a ZIP file .
static int archive_zip_read_file(void *handle, const char *fname,
			     uint8_t **data, uint32_t *size, int64_t *mtime)
{
	struct zip *zip = (struct zip *)handle;
	struct zip_file *fp;
	struct zip_stat stat;
	assert(zip);
	*data = NULL;
	*size = 0;
	zip_stat_init(&stat);
	if (zip_stat(zip, fname, 0, &stat)) {
		ERROR("Fail to stat entry in ZIP: %s\n", fname);
		return 1;
	}
	fp = zip_fopen(zip, fname, 0);
	if (!fp) {
		ERROR("Failed to open entry in ZIP: %s\n", fname);
		return 1;
	}
	*data = (uint8_t *)malloc(stat.size);
	if (*data) {
		if (zip_fread(fp, *data, stat.size) == stat.size) {
			if (mtime)
				*mtime = stat.mtime;
			*size = stat.size;
		} else {
			ERROR("Failed to read entry in zip: %s\n", fname);
			free(*data);
			*data = NULL;
		}
	}
	zip_fclose(fp);
	return *data == NULL;
}
static int archive_zip_read_file ( void * handle , const char * fname , uint8_t * * data , uint32_t * size , int64_t * mtime ) { struct zip * zip = ( struct zip * ) handle ; struct zip_file * fp ; struct zip_stat stat ; assert ( zip ) ; * data = NULL ; * size = 0 ; zip_stat_init ( & stat ) ; if ( zip_stat ( zip , fname , 0 , & stat ) ) { ERROR ( " \n " , fname ) ; return 1 ; } fp = zip_fopen ( zip , fname , 0 ) ; if ( ! fp ) { ERROR ( " \n " , fname ) ; return 1 ; } * data = ( uint8_t * ) malloc ( stat . size ) ; if ( * data ) { if ( zip_fread ( fp , * data , stat . size ) == stat . size ) { if ( mtime ) * mtime = stat . mtime ; * size = stat . size ; } else { ERROR ( " \n " , fname ) ; free ( * data ) ; * data = NULL ; } } zip_fclose ( fp ) ; return * data == NULL ; }
Callback for archive_zip_read_file on a ZIP file.
Callback for archive_zip_read_file on a ZIP file .