libsparse: Change source files to cpp

Bug: 78793464
Test: compiles
Change-Id: Ib8b933fe3ccb8dfa49a77f7955891678bf0df086
This commit is contained in:
Jerry Zhang 2018-06-12 16:18:53 -07:00
parent 50e6029a4e
commit 5a75507795
11 changed files with 37 additions and 42 deletions

View File

@ -6,11 +6,11 @@ cc_library {
recovery_available: true,
unique_host_soname: true,
srcs: [
"backed_block.c",
"output_file.c",
"sparse.c",
"sparse_crc32.c",
"sparse_err.c",
"backed_block.cpp",
"output_file.cpp",
"sparse.cpp",
"sparse_crc32.cpp",
"sparse_err.cpp",
"sparse_read.cpp",
],
cflags: ["-Werror"],
@ -31,8 +31,8 @@ cc_binary {
name: "simg2img",
host_supported: true,
srcs: [
"simg2img.c",
"sparse_crc32.c",
"simg2img.cpp",
"sparse_crc32.cpp",
],
static_libs: [
"libsparse",
@ -46,7 +46,7 @@ cc_binary {
cc_binary {
name: "img2simg",
host_supported: true,
srcs: ["img2simg.c"],
srcs: ["img2simg.cpp"],
static_libs: [
"libsparse",
"libz",
@ -58,7 +58,7 @@ cc_binary {
cc_binary_host {
name: "append2simg",
srcs: ["append2simg.c"],
srcs: ["append2simg.cpp"],
static_libs: [
"libsparse",
"libz",

View File

@ -16,7 +16,6 @@
#define _FILE_OFFSET_BITS 64
#define _LARGEFILE64_SOURCE 1
#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>

View File

@ -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 *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;
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,
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) {
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,
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) {
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,
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) {
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,
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) {
return -ENOMEM;
}
@ -373,7 +374,7 @@ int backed_block_split(struct backed_block_list *bbl, struct backed_block *bb,
return 0;
}
new_bb = malloc(sizeof(struct backed_block));
new_bb = reinterpret_cast<backed_block*>(malloc(sizeof(struct backed_block)));
if (new_bb == NULL) {
return -ENOMEM;
}

View File

@ -326,7 +326,7 @@ int read_all(int fd, void *buf, size_t len)
{
size_t total = 0;
int ret;
char *ptr = buf;
char *ptr = reinterpret_cast<char*>(buf);
while (total < len) {
ret = read(fd, ptr, len - total);
@ -350,7 +350,7 @@ static int write_sparse_skip_chunk(struct output_file *out, int64_t skip_len)
int ret;
if (skip_len % out->block_size) {
error("don't care size %"PRIi64" is not a multiple of the block size %u",
error("don't care size %" PRIi64 " is not a multiple of the block size %u",
skip_len, out->block_size);
return -1;
}
@ -557,13 +557,13 @@ static int output_file_init(struct output_file *out, int block_size,
out->crc32 = 0;
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) {
error_errno("malloc zero_buf");
return -ENOMEM;
}
out->fill_buf = calloc(block_size, 1);
out->fill_buf = reinterpret_cast<uint32_t*>(calloc(block_size, 1));
if (!out->fill_buf) {
error_errno("malloc fill_buf");
ret = -ENOMEM;
@ -584,8 +584,8 @@ static int output_file_init(struct output_file *out, int block_size,
.file_hdr_sz = SPARSE_HEADER_LEN,
.chunk_hdr_sz = CHUNK_HEADER_LEN,
.blk_sz = out->block_size,
.total_blks = DIV_ROUND_UP(out->len, out->block_size),
.total_chunks = chunks,
.total_blks = static_cast<unsigned>(DIV_ROUND_UP(out->len, out->block_size)),
.total_chunks = static_cast<unsigned>(chunks),
.image_checksum = 0
};
@ -610,7 +610,8 @@ err_fill_buf:
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) {
error_errno("malloc struct outgz");
return NULL;
@ -623,7 +624,8 @@ static struct output_file *output_file_new_gz(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) {
error_errno("malloc struct outn");
return NULL;
@ -642,7 +644,8 @@ struct output_file *output_file_open_callback(
int ret;
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) {
error_errno("malloc struct outc");
return NULL;
@ -716,15 +719,15 @@ int write_fd_chunk(struct output_file *out, unsigned int len,
#ifndef _WIN32
if (buffer_size > SIZE_MAX)
return -E2BIG;
char *data = mmap64(NULL, buffer_size, PROT_READ, MAP_SHARED, fd,
aligned_offset);
char *data = reinterpret_cast<char*>(mmap64(NULL, buffer_size, PROT_READ, MAP_SHARED, fd,
aligned_offset));
if (data == MAP_FAILED) {
return -errno;
}
ptr = data + aligned_diff;
#else
off64_t pos;
char *data = malloc(len);
char *data = reinterpret_cast<char*>(malloc(len));
if (!data) {
return -errno;
}

View File

@ -16,7 +16,6 @@
#define _FILE_OFFSET_BITS 64
#define _LARGEFILE64_SOURCE 1
#define _GNU_SOURCE
#include <fcntl.h>
#include <stdbool.h>

View File

@ -29,7 +29,7 @@
struct sparse_file *sparse_file_new(unsigned int block_size, int64_t len)
{
struct sparse_file *s = calloc(sizeof(struct sparse_file), 1);
struct sparse_file *s = reinterpret_cast<sparse_file*>(calloc(sizeof(struct sparse_file), 1));
if (!s) {
return NULL;
}
@ -209,7 +209,7 @@ struct chunk_data {
static int foreach_chunk_write(void *priv, const void *data, size_t len)
{
struct chunk_data *chk = priv;
struct chunk_data *chk = reinterpret_cast<chunk_data*>(priv);
return chk->write(chk->priv, data, len, chk->block, chk->nr_blocks);
}
@ -252,7 +252,7 @@ int sparse_file_foreach_chunk(struct sparse_file *s, bool sparse, bool crc,
static int out_counter_write(void *priv, const void *data __unused, size_t len)
{
int64_t *count = priv;
int64_t *count = reinterpret_cast<int64_t*>(priv);
*count += len;
return 0;
}

View File

@ -44,6 +44,7 @@
/* Code taken from FreeBSD 8 */
#include <stdint.h>
#include <stdio.h>
static uint32_t crc32_tab[] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
@ -98,9 +99,9 @@ static uint32_t crc32_tab[] = {
* in sys/libkern.h, where it can be inlined.
*/
uint32_t sparse_crc32(uint32_t crc_in, const void *buf, int size)
uint32_t sparse_crc32(uint32_t crc_in, const void *buf, size_t size)
{
const uint8_t *p = buf;
const uint8_t *p = reinterpret_cast<const uint8_t*>(buf);
uint32_t crc;
crc = crc_in ^ ~0U;

View File

@ -19,14 +19,6 @@
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
uint32_t sparse_crc32(uint32_t crc, const void *buf, size_t size);
#ifdef __cplusplus
}
#endif
#endif