Beispiel #1
0
int decompress_file_to_buffer(char * path, void * dst, uint32_t dstlen) {

	int ret = -1;
	uint32_t header_len, comp_len, decomp_len;

	void * dst_temp;

	dst_temp = calloc(dstlen, 1);

	/* Validate buffer */
	if (dst_temp == NULL || dst == NULL || dstlen < 1) {
		printf("Buffer error");
		goto err_open;
	}

	/* Read decompressed size */
	if (lzo_header(path, &header_len, &decomp_len, &comp_len) != 0) {
		log_error("Failed to read header");
		goto err_open;
	}

	/* Open file */
	FILE * fp = fopen(path, "r");
	if (!fp) {
		log_error("Cannot open %s", path);
		goto err_open;
	}

	struct stat statbuf;
	stat(path, &statbuf);

	/* Read file into buffer */
	if (fread(dst_temp, 1, statbuf.st_size, fp) != (size_t) statbuf.st_size) {
		log_error("Failed to read complete file");
		goto err_read;
	}

	/* Decompress */
	if (lzo_decompress_buffer(dst_temp, statbuf.st_size, dst, dstlen, NULL) != 0) {
		log_error("Failed to decompress buffer");
		goto err_read;
	}

	ret = decomp_len;

err_read:
	fclose(fp);
err_open:
	free(dst_temp);
	return ret;

}
Beispiel #2
0
ftp_return_t ftp_ram_done(void * state) {

#ifdef __arm__
	if (lzo_match_magic((void *)file_mem_addr)) {
		if (lzo_decompress_buffer((void *)file_mem_addr, UPLOAD_SIZE, (void *)(UPLOAD_ADDR), UPLOAD_SIZE, NULL) != 0) {
			printf("Unpacking LZO compressed RAM image failed\r\n");
			ftp_ram_abort(NULL);
			return FTP_RET_IO;
		}
	}
#endif

	return ftp_ram_abort(NULL);

}