Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5a755077 authored by Jerry Zhang's avatar Jerry Zhang
Browse files

libsparse: Change source files to cpp

Bug: 78793464
Test: compiles
Change-Id: Ib8b933fe3ccb8dfa49a77f7955891678bf0df086
parent 50e6029a
Loading
Loading
Loading
Loading
+9 −9
Original line number Original line Diff line number Diff line
@@ -6,11 +6,11 @@ cc_library {
    recovery_available: true,
    recovery_available: true,
    unique_host_soname: true,
    unique_host_soname: true,
    srcs: [
    srcs: [
        "backed_block.c",
        "backed_block.cpp",
        "output_file.c",
        "output_file.cpp",
        "sparse.c",
        "sparse.cpp",
        "sparse_crc32.c",
        "sparse_crc32.cpp",
        "sparse_err.c",
        "sparse_err.cpp",
        "sparse_read.cpp",
        "sparse_read.cpp",
    ],
    ],
    cflags: ["-Werror"],
    cflags: ["-Werror"],
@@ -31,8 +31,8 @@ cc_binary {
    name: "simg2img",
    name: "simg2img",
    host_supported: true,
    host_supported: true,
    srcs: [
    srcs: [
        "simg2img.c",
        "simg2img.cpp",
        "sparse_crc32.c",
        "sparse_crc32.cpp",
    ],
    ],
    static_libs: [
    static_libs: [
        "libsparse",
        "libsparse",
@@ -46,7 +46,7 @@ cc_binary {
cc_binary {
cc_binary {
    name: "img2simg",
    name: "img2simg",
    host_supported: true,
    host_supported: true,
    srcs: ["img2simg.c"],
    srcs: ["img2simg.cpp"],
    static_libs: [
    static_libs: [
        "libsparse",
        "libsparse",
        "libz",
        "libz",
@@ -58,7 +58,7 @@ cc_binary {


cc_binary_host {
cc_binary_host {
    name: "append2simg",
    name: "append2simg",
    srcs: ["append2simg.c"],
    srcs: ["append2simg.cpp"],
    static_libs: [
    static_libs: [
        "libsparse",
        "libsparse",
        "libz",
        "libz",
+0 −1
Original line number Original line Diff line number Diff line
@@ -16,7 +16,6 @@


#define _FILE_OFFSET_BITS 64
#define _FILE_OFFSET_BITS 64
#define _LARGEFILE64_SOURCE 1
#define _LARGEFILE64_SOURCE 1
#define _GNU_SOURCE


#include <errno.h>
#include <errno.h>
#include <fcntl.h>
#include <fcntl.h>
+7 −6
Original line number Original line Diff line number Diff line
@@ -122,7 +122,8 @@ void backed_block_destroy(struct backed_block *bb)


struct backed_block_list *backed_block_list_new(unsigned int block_size)
struct backed_block_list *backed_block_list_new(unsigned int block_size)
{
{
	struct backed_block_list *b = calloc(sizeof(struct backed_block_list), 1);
	struct backed_block_list *b = reinterpret_cast<backed_block_list*>(
            calloc(sizeof(struct backed_block_list), 1));
	b->block_size = block_size;
	b->block_size = block_size;
	return b;
	return b;
}
}
@@ -292,7 +293,7 @@ static int queue_bb(struct backed_block_list *bbl, struct backed_block *new_bb)
int backed_block_add_fill(struct backed_block_list *bbl, unsigned int fill_val,
int backed_block_add_fill(struct backed_block_list *bbl, unsigned int fill_val,
		unsigned int len, unsigned int block)
		unsigned int len, unsigned int block)
{
{
	struct backed_block *bb = calloc(1, sizeof(struct backed_block));
	struct backed_block *bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
	if (bb == NULL) {
	if (bb == NULL) {
		return -ENOMEM;
		return -ENOMEM;
	}
	}
@@ -310,7 +311,7 @@ int backed_block_add_fill(struct backed_block_list *bbl, unsigned int fill_val,
int backed_block_add_data(struct backed_block_list *bbl, void *data,
int backed_block_add_data(struct backed_block_list *bbl, void *data,
		unsigned int len, unsigned int block)
		unsigned int len, unsigned int block)
{
{
	struct backed_block *bb = calloc(1, sizeof(struct backed_block));
	struct backed_block *bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
	if (bb == NULL) {
	if (bb == NULL) {
		return -ENOMEM;
		return -ENOMEM;
	}
	}
@@ -328,7 +329,7 @@ int backed_block_add_data(struct backed_block_list *bbl, void *data,
int backed_block_add_file(struct backed_block_list *bbl, const char *filename,
int backed_block_add_file(struct backed_block_list *bbl, const char *filename,
		int64_t offset, unsigned int len, unsigned int block)
		int64_t offset, unsigned int len, unsigned int block)
{
{
	struct backed_block *bb = calloc(1, sizeof(struct backed_block));
	struct backed_block *bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
	if (bb == NULL) {
	if (bb == NULL) {
		return -ENOMEM;
		return -ENOMEM;
	}
	}
@@ -347,7 +348,7 @@ int backed_block_add_file(struct backed_block_list *bbl, const char *filename,
int backed_block_add_fd(struct backed_block_list *bbl, int fd, int64_t offset,
int backed_block_add_fd(struct backed_block_list *bbl, int fd, int64_t offset,
		unsigned int len, unsigned int block)
		unsigned int len, unsigned int block)
{
{
	struct backed_block *bb = calloc(1, sizeof(struct backed_block));
	struct backed_block *bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
	if (bb == NULL) {
	if (bb == NULL) {
		return -ENOMEM;
		return -ENOMEM;
	}
	}
@@ -373,7 +374,7 @@ int backed_block_split(struct backed_block_list *bbl, struct backed_block *bb,
		return 0;
		return 0;
	}
	}


	new_bb = malloc(sizeof(struct backed_block));
	new_bb = reinterpret_cast<backed_block*>(malloc(sizeof(struct backed_block)));
	if (new_bb == NULL) {
	if (new_bb == NULL) {
		return -ENOMEM;
		return -ENOMEM;
	}
	}
+0 −0

File moved.

+15 −12
Original line number Original line Diff line number Diff line
@@ -326,7 +326,7 @@ int read_all(int fd, void *buf, size_t len)
{
{
	size_t total = 0;
	size_t total = 0;
	int ret;
	int ret;
	char *ptr = buf;
	char *ptr = reinterpret_cast<char*>(buf);


	while (total < len) {
	while (total < len) {
		ret = read(fd, ptr, len - total);
		ret = read(fd, ptr, len - total);
@@ -557,13 +557,13 @@ static int output_file_init(struct output_file *out, int block_size,
	out->crc32 = 0;
	out->crc32 = 0;
	out->use_crc = crc;
	out->use_crc = crc;


	out->zero_buf = calloc(block_size, 1);
	out->zero_buf = reinterpret_cast<char*>(calloc(block_size, 1));
	if (!out->zero_buf) {
	if (!out->zero_buf) {
		error_errno("malloc zero_buf");
		error_errno("malloc zero_buf");
		return -ENOMEM;
		return -ENOMEM;
	}
	}


	out->fill_buf = calloc(block_size, 1);
	out->fill_buf = reinterpret_cast<uint32_t*>(calloc(block_size, 1));
	if (!out->fill_buf) {
	if (!out->fill_buf) {
		error_errno("malloc fill_buf");
		error_errno("malloc fill_buf");
		ret = -ENOMEM;
		ret = -ENOMEM;
@@ -584,8 +584,8 @@ static int output_file_init(struct output_file *out, int block_size,
				.file_hdr_sz = SPARSE_HEADER_LEN,
				.file_hdr_sz = SPARSE_HEADER_LEN,
				.chunk_hdr_sz = CHUNK_HEADER_LEN,
				.chunk_hdr_sz = CHUNK_HEADER_LEN,
				.blk_sz = out->block_size,
				.blk_sz = out->block_size,
				.total_blks = DIV_ROUND_UP(out->len, out->block_size),
				.total_blks = static_cast<unsigned>(DIV_ROUND_UP(out->len, out->block_size)),
				.total_chunks = chunks,
				.total_chunks = static_cast<unsigned>(chunks),
				.image_checksum = 0
				.image_checksum = 0
		};
		};


@@ -610,7 +610,8 @@ err_fill_buf:


static struct output_file *output_file_new_gz(void)
static struct output_file *output_file_new_gz(void)
{
{
	struct output_file_gz *outgz = calloc(1, sizeof(struct output_file_gz));
	struct output_file_gz *outgz = reinterpret_cast<struct output_file_gz*>(
            calloc(1, sizeof(struct output_file_gz)));
	if (!outgz) {
	if (!outgz) {
		error_errno("malloc struct outgz");
		error_errno("malloc struct outgz");
		return NULL;
		return NULL;
@@ -623,7 +624,8 @@ static struct output_file *output_file_new_gz(void)


static struct output_file *output_file_new_normal(void)
static struct output_file *output_file_new_normal(void)
{
{
	struct output_file_normal *outn = calloc(1, sizeof(struct output_file_normal));
	struct output_file_normal *outn = reinterpret_cast<struct output_file_normal*>(
            calloc(1, sizeof(struct output_file_normal)));
	if (!outn) {
	if (!outn) {
		error_errno("malloc struct outn");
		error_errno("malloc struct outn");
		return NULL;
		return NULL;
@@ -642,7 +644,8 @@ struct output_file *output_file_open_callback(
	int ret;
	int ret;
	struct output_file_callback *outc;
	struct output_file_callback *outc;


	outc = calloc(1, sizeof(struct output_file_callback));
	outc = reinterpret_cast<struct output_file_callback*>(
            calloc(1, sizeof(struct output_file_callback)));
	if (!outc) {
	if (!outc) {
		error_errno("malloc struct outc");
		error_errno("malloc struct outc");
		return NULL;
		return NULL;
@@ -716,15 +719,15 @@ int write_fd_chunk(struct output_file *out, unsigned int len,
#ifndef _WIN32
#ifndef _WIN32
	if (buffer_size > SIZE_MAX)
	if (buffer_size > SIZE_MAX)
		return -E2BIG;
		return -E2BIG;
	char *data = mmap64(NULL, buffer_size, PROT_READ, MAP_SHARED, fd,
	char *data = reinterpret_cast<char*>(mmap64(NULL, buffer_size, PROT_READ, MAP_SHARED, fd,
			aligned_offset);
			aligned_offset));
	if (data == MAP_FAILED) {
	if (data == MAP_FAILED) {
		return -errno;
		return -errno;
	}
	}
	ptr = data + aligned_diff;
	ptr = data + aligned_diff;
#else
#else
	off64_t pos;
	off64_t pos;
	char *data = malloc(len);
	char *data = reinterpret_cast<char*>(malloc(len));
	if (!data) {
	if (!data) {
		return -errno;
		return -errno;
	}
	}
Loading