summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJerry Zhang2018-06-12 18:18:53 -0500
committerJerry Zhang2018-06-13 13:17:22 -0500
commit5a755077958dd4f7fb668a125b57dea8d85cd9a8 (patch)
treecb399ec8b78c7ee4fff1f472908dd207dd26fd75 /libsparse
parent50e6029a4e4b9c9bd6065548ced523ec5b01e705 (diff)
downloadplatform-system-core-5a755077958dd4f7fb668a125b57dea8d85cd9a8.tar.gz
platform-system-core-5a755077958dd4f7fb668a125b57dea8d85cd9a8.tar.xz
platform-system-core-5a755077958dd4f7fb668a125b57dea8d85cd9a8.zip
libsparse: Change source files to cpp
Bug: 78793464 Test: compiles Change-Id: Ib8b933fe3ccb8dfa49a77f7955891678bf0df086
Diffstat (limited to 'libsparse')
-rw-r--r--libsparse/Android.bp18
-rw-r--r--libsparse/append2simg.cpp (renamed from libsparse/append2simg.c)1
-rw-r--r--libsparse/backed_block.cpp (renamed from libsparse/backed_block.c)13
-rw-r--r--libsparse/img2simg.cpp (renamed from libsparse/img2simg.c)0
-rw-r--r--libsparse/output_file.cpp (renamed from libsparse/output_file.c)27
-rw-r--r--libsparse/simg2img.cpp (renamed from libsparse/simg2img.c)0
-rw-r--r--libsparse/simg2simg.cpp (renamed from libsparse/simg2simg.c)1
-rw-r--r--libsparse/sparse.cpp (renamed from libsparse/sparse.c)6
-rw-r--r--libsparse/sparse_crc32.cpp (renamed from libsparse/sparse_crc32.c)5
-rw-r--r--libsparse/sparse_crc32.h8
-rw-r--r--libsparse/sparse_err.cpp (renamed from libsparse/sparse_err.c)0
11 files changed, 37 insertions, 42 deletions
diff --git a/libsparse/Android.bp b/libsparse/Android.bp
index c7c089f49..8ad339f5f 100644
--- a/libsparse/Android.bp
+++ b/libsparse/Android.bp
@@ -6,11 +6,11 @@ cc_library {
6 recovery_available: true, 6 recovery_available: true,
7 unique_host_soname: true, 7 unique_host_soname: true,
8 srcs: [ 8 srcs: [
9 "backed_block.c", 9 "backed_block.cpp",
10 "output_file.c", 10 "output_file.cpp",
11 "sparse.c", 11 "sparse.cpp",
12 "sparse_crc32.c", 12 "sparse_crc32.cpp",
13 "sparse_err.c", 13 "sparse_err.cpp",
14 "sparse_read.cpp", 14 "sparse_read.cpp",
15 ], 15 ],
16 cflags: ["-Werror"], 16 cflags: ["-Werror"],
@@ -31,8 +31,8 @@ cc_binary {
31 name: "simg2img", 31 name: "simg2img",
32 host_supported: true, 32 host_supported: true,
33 srcs: [ 33 srcs: [
34 "simg2img.c", 34 "simg2img.cpp",
35 "sparse_crc32.c", 35 "sparse_crc32.cpp",
36 ], 36 ],
37 static_libs: [ 37 static_libs: [
38 "libsparse", 38 "libsparse",
@@ -46,7 +46,7 @@ cc_binary {
46cc_binary { 46cc_binary {
47 name: "img2simg", 47 name: "img2simg",
48 host_supported: true, 48 host_supported: true,
49 srcs: ["img2simg.c"], 49 srcs: ["img2simg.cpp"],
50 static_libs: [ 50 static_libs: [
51 "libsparse", 51 "libsparse",
52 "libz", 52 "libz",
@@ -58,7 +58,7 @@ cc_binary {
58 58
59cc_binary_host { 59cc_binary_host {
60 name: "append2simg", 60 name: "append2simg",
61 srcs: ["append2simg.c"], 61 srcs: ["append2simg.cpp"],
62 static_libs: [ 62 static_libs: [
63 "libsparse", 63 "libsparse",
64 "libz", 64 "libz",
diff --git a/libsparse/append2simg.c b/libsparse/append2simg.cpp
index eef876400..83450a0d9 100644
--- a/libsparse/append2simg.c
+++ b/libsparse/append2simg.cpp
@@ -16,7 +16,6 @@
16 16
17#define _FILE_OFFSET_BITS 64 17#define _FILE_OFFSET_BITS 64
18#define _LARGEFILE64_SOURCE 1 18#define _LARGEFILE64_SOURCE 1
19#define _GNU_SOURCE
20 19
21#include <errno.h> 20#include <errno.h>
22#include <fcntl.h> 21#include <fcntl.h>
diff --git a/libsparse/backed_block.c b/libsparse/backed_block.cpp
index 794cd6b17..fb26d1a6e 100644
--- a/libsparse/backed_block.c
+++ b/libsparse/backed_block.cpp
@@ -122,7 +122,8 @@ void backed_block_destroy(struct backed_block *bb)
122 122
123struct backed_block_list *backed_block_list_new(unsigned int block_size) 123struct backed_block_list *backed_block_list_new(unsigned int block_size)
124{ 124{
125 struct backed_block_list *b = calloc(sizeof(struct backed_block_list), 1); 125 struct backed_block_list *b = reinterpret_cast<backed_block_list*>(
126 calloc(sizeof(struct backed_block_list), 1));
126 b->block_size = block_size; 127 b->block_size = block_size;
127 return b; 128 return b;
128} 129}
@@ -292,7 +293,7 @@ static int queue_bb(struct backed_block_list *bbl, struct backed_block *new_bb)
292int backed_block_add_fill(struct backed_block_list *bbl, unsigned int fill_val, 293int backed_block_add_fill(struct backed_block_list *bbl, unsigned int fill_val,
293 unsigned int len, unsigned int block) 294 unsigned int len, unsigned int block)
294{ 295{
295 struct backed_block *bb = calloc(1, sizeof(struct backed_block)); 296 struct backed_block *bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
296 if (bb == NULL) { 297 if (bb == NULL) {
297 return -ENOMEM; 298 return -ENOMEM;
298 } 299 }
@@ -310,7 +311,7 @@ int backed_block_add_fill(struct backed_block_list *bbl, unsigned int fill_val,
310int backed_block_add_data(struct backed_block_list *bbl, void *data, 311int backed_block_add_data(struct backed_block_list *bbl, void *data,
311 unsigned int len, unsigned int block) 312 unsigned int len, unsigned int block)
312{ 313{
313 struct backed_block *bb = calloc(1, sizeof(struct backed_block)); 314 struct backed_block *bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
314 if (bb == NULL) { 315 if (bb == NULL) {
315 return -ENOMEM; 316 return -ENOMEM;
316 } 317 }
@@ -328,7 +329,7 @@ int backed_block_add_data(struct backed_block_list *bbl, void *data,
328int backed_block_add_file(struct backed_block_list *bbl, const char *filename, 329int backed_block_add_file(struct backed_block_list *bbl, const char *filename,
329 int64_t offset, unsigned int len, unsigned int block) 330 int64_t offset, unsigned int len, unsigned int block)
330{ 331{
331 struct backed_block *bb = calloc(1, sizeof(struct backed_block)); 332 struct backed_block *bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
332 if (bb == NULL) { 333 if (bb == NULL) {
333 return -ENOMEM; 334 return -ENOMEM;
334 } 335 }
@@ -347,7 +348,7 @@ int backed_block_add_file(struct backed_block_list *bbl, const char *filename,
347int backed_block_add_fd(struct backed_block_list *bbl, int fd, int64_t offset, 348int backed_block_add_fd(struct backed_block_list *bbl, int fd, int64_t offset,
348 unsigned int len, unsigned int block) 349 unsigned int len, unsigned int block)
349{ 350{
350 struct backed_block *bb = calloc(1, sizeof(struct backed_block)); 351 struct backed_block *bb = reinterpret_cast<backed_block*>(calloc(1, sizeof(struct backed_block)));
351 if (bb == NULL) { 352 if (bb == NULL) {
352 return -ENOMEM; 353 return -ENOMEM;
353 } 354 }
@@ -373,7 +374,7 @@ int backed_block_split(struct backed_block_list *bbl, struct backed_block *bb,
373 return 0; 374 return 0;
374 } 375 }
375 376
376 new_bb = malloc(sizeof(struct backed_block)); 377 new_bb = reinterpret_cast<backed_block*>(malloc(sizeof(struct backed_block)));
377 if (new_bb == NULL) { 378 if (new_bb == NULL) {
378 return -ENOMEM; 379 return -ENOMEM;
379 } 380 }
diff --git a/libsparse/img2simg.c b/libsparse/img2simg.cpp
index a0db36f45..a0db36f45 100644
--- a/libsparse/img2simg.c
+++ b/libsparse/img2simg.cpp
diff --git a/libsparse/output_file.c b/libsparse/output_file.cpp
index 002ad2746..8d915508c 100644
--- a/libsparse/output_file.c
+++ b/libsparse/output_file.cpp
@@ -326,7 +326,7 @@ int read_all(int fd, void *buf, size_t len)
326{ 326{
327 size_t total = 0; 327 size_t total = 0;
328 int ret; 328 int ret;
329 char *ptr = buf; 329 char *ptr = reinterpret_cast<char*>(buf);
330 330
331 while (total < len) { 331 while (total < len) {
332 ret = read(fd, ptr, len - total); 332 ret = read(fd, ptr, len - total);
@@ -350,7 +350,7 @@ static int write_sparse_skip_chunk(struct output_file *out, int64_t skip_len)
350 int ret; 350 int ret;
351 351
352 if (skip_len % out->block_size) { 352 if (skip_len % out->block_size) {
353 error("don't care size %"PRIi64" is not a multiple of the block size %u", 353 error("don't care size %" PRIi64 " is not a multiple of the block size %u",
354 skip_len, out->block_size); 354 skip_len, out->block_size);
355 return -1; 355 return -1;
356 } 356 }
@@ -557,13 +557,13 @@ static int output_file_init(struct output_file *out, int block_size,
557 out->crc32 = 0; 557 out->crc32 = 0;
558 out->use_crc = crc; 558 out->use_crc = crc;
559 559
560 out->zero_buf = calloc(block_size, 1); 560 out->zero_buf = reinterpret_cast<char*>(calloc(block_size, 1));
561 if (!out->zero_buf) { 561 if (!out->zero_buf) {
562 error_errno("malloc zero_buf"); 562 error_errno("malloc zero_buf");
563 return -ENOMEM; 563 return -ENOMEM;
564 } 564 }
565 565
566 out->fill_buf = calloc(block_size, 1); 566 out->fill_buf = reinterpret_cast<uint32_t*>(calloc(block_size, 1));
567 if (!out->fill_buf) { 567 if (!out->fill_buf) {
568 error_errno("malloc fill_buf"); 568 error_errno("malloc fill_buf");
569 ret = -ENOMEM; 569 ret = -ENOMEM;
@@ -584,8 +584,8 @@ static int output_file_init(struct output_file *out, int block_size,
584 .file_hdr_sz = SPARSE_HEADER_LEN, 584 .file_hdr_sz = SPARSE_HEADER_LEN,
585 .chunk_hdr_sz = CHUNK_HEADER_LEN, 585 .chunk_hdr_sz = CHUNK_HEADER_LEN,
586 .blk_sz = out->block_size, 586 .blk_sz = out->block_size,
587 .total_blks = DIV_ROUND_UP(out->len, out->block_size), 587 .total_blks = static_cast<unsigned>(DIV_ROUND_UP(out->len, out->block_size)),
588 .total_chunks = chunks, 588 .total_chunks = static_cast<unsigned>(chunks),
589 .image_checksum = 0 589 .image_checksum = 0
590 }; 590 };
591 591
@@ -610,7 +610,8 @@ err_fill_buf:
610 610
611static struct output_file *output_file_new_gz(void) 611static struct output_file *output_file_new_gz(void)
612{ 612{
613 struct output_file_gz *outgz = calloc(1, sizeof(struct output_file_gz)); 613 struct output_file_gz *outgz = reinterpret_cast<struct output_file_gz*>(
614 calloc(1, sizeof(struct output_file_gz)));
614 if (!outgz) { 615 if (!outgz) {
615 error_errno("malloc struct outgz"); 616 error_errno("malloc struct outgz");
616 return NULL; 617 return NULL;
@@ -623,7 +624,8 @@ static struct output_file *output_file_new_gz(void)
623 624
624static struct output_file *output_file_new_normal(void) 625static struct output_file *output_file_new_normal(void)
625{ 626{
626 struct output_file_normal *outn = calloc(1, sizeof(struct output_file_normal)); 627 struct output_file_normal *outn = reinterpret_cast<struct output_file_normal*>(
628 calloc(1, sizeof(struct output_file_normal)));
627 if (!outn) { 629 if (!outn) {
628 error_errno("malloc struct outn"); 630 error_errno("malloc struct outn");
629 return NULL; 631 return NULL;
@@ -642,7 +644,8 @@ struct output_file *output_file_open_callback(
642 int ret; 644 int ret;
643 struct output_file_callback *outc; 645 struct output_file_callback *outc;
644 646
645 outc = calloc(1, sizeof(struct output_file_callback)); 647 outc = reinterpret_cast<struct output_file_callback*>(
648 calloc(1, sizeof(struct output_file_callback)));
646 if (!outc) { 649 if (!outc) {
647 error_errno("malloc struct outc"); 650 error_errno("malloc struct outc");
648 return NULL; 651 return NULL;
@@ -716,15 +719,15 @@ int write_fd_chunk(struct output_file *out, unsigned int len,
716#ifndef _WIN32 719#ifndef _WIN32
717 if (buffer_size > SIZE_MAX) 720 if (buffer_size > SIZE_MAX)
718 return -E2BIG; 721 return -E2BIG;
719 char *data = mmap64(NULL, buffer_size, PROT_READ, MAP_SHARED, fd, 722 char *data = reinterpret_cast<char*>(mmap64(NULL, buffer_size, PROT_READ, MAP_SHARED, fd,
720 aligned_offset); 723 aligned_offset));
721 if (data == MAP_FAILED) { 724 if (data == MAP_FAILED) {
722 return -errno; 725 return -errno;
723 } 726 }
724 ptr = data + aligned_diff; 727 ptr = data + aligned_diff;
725#else 728#else
726 off64_t pos; 729 off64_t pos;
727 char *data = malloc(len); 730 char *data = reinterpret_cast<char*>(malloc(len));
728 if (!data) { 731 if (!data) {
729 return -errno; 732 return -errno;
730 } 733 }
diff --git a/libsparse/simg2img.c b/libsparse/simg2img.cpp
index b9b438e63..b9b438e63 100644
--- a/libsparse/simg2img.c
+++ b/libsparse/simg2img.cpp
diff --git a/libsparse/simg2simg.c b/libsparse/simg2simg.cpp
index 5f9ccf678..6f02f4fcc 100644
--- a/libsparse/simg2simg.c
+++ b/libsparse/simg2simg.cpp
@@ -16,7 +16,6 @@
16 16
17#define _FILE_OFFSET_BITS 64 17#define _FILE_OFFSET_BITS 64
18#define _LARGEFILE64_SOURCE 1 18#define _LARGEFILE64_SOURCE 1
19#define _GNU_SOURCE
20 19
21#include <fcntl.h> 20#include <fcntl.h>
22#include <stdbool.h> 21#include <stdbool.h>
diff --git a/libsparse/sparse.c b/libsparse/sparse.cpp
index 466435f7b..992945f44 100644
--- a/libsparse/sparse.c
+++ b/libsparse/sparse.cpp
@@ -29,7 +29,7 @@
29 29
30struct sparse_file *sparse_file_new(unsigned int block_size, int64_t len) 30struct sparse_file *sparse_file_new(unsigned int block_size, int64_t len)
31{ 31{
32 struct sparse_file *s = calloc(sizeof(struct sparse_file), 1); 32 struct sparse_file *s = reinterpret_cast<sparse_file*>(calloc(sizeof(struct sparse_file), 1));
33 if (!s) { 33 if (!s) {
34 return NULL; 34 return NULL;
35 } 35 }
@@ -209,7 +209,7 @@ struct chunk_data {
209 209
210static int foreach_chunk_write(void *priv, const void *data, size_t len) 210static int foreach_chunk_write(void *priv, const void *data, size_t len)
211{ 211{
212 struct chunk_data *chk = priv; 212 struct chunk_data *chk = reinterpret_cast<chunk_data*>(priv);
213 213
214 return chk->write(chk->priv, data, len, chk->block, chk->nr_blocks); 214 return chk->write(chk->priv, data, len, chk->block, chk->nr_blocks);
215} 215}
@@ -252,7 +252,7 @@ int sparse_file_foreach_chunk(struct sparse_file *s, bool sparse, bool crc,
252 252
253static int out_counter_write(void *priv, const void *data __unused, size_t len) 253static int out_counter_write(void *priv, const void *data __unused, size_t len)
254{ 254{
255 int64_t *count = priv; 255 int64_t *count = reinterpret_cast<int64_t*>(priv);
256 *count += len; 256 *count += len;
257 return 0; 257 return 0;
258} 258}
diff --git a/libsparse/sparse_crc32.c b/libsparse/sparse_crc32.cpp
index 38bfe4aa0..97c5a1001 100644
--- a/libsparse/sparse_crc32.c
+++ b/libsparse/sparse_crc32.cpp
@@ -44,6 +44,7 @@
44 44
45/* Code taken from FreeBSD 8 */ 45/* Code taken from FreeBSD 8 */
46#include <stdint.h> 46#include <stdint.h>
47#include <stdio.h>
47 48
48static uint32_t crc32_tab[] = { 49static uint32_t crc32_tab[] = {
49 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 50 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
@@ -98,9 +99,9 @@ static uint32_t crc32_tab[] = {
98 * in sys/libkern.h, where it can be inlined. 99 * in sys/libkern.h, where it can be inlined.
99 */ 100 */
100 101
101uint32_t sparse_crc32(uint32_t crc_in, const void *buf, int size) 102uint32_t sparse_crc32(uint32_t crc_in, const void *buf, size_t size)
102{ 103{
103 const uint8_t *p = buf; 104 const uint8_t *p = reinterpret_cast<const uint8_t*>(buf);
104 uint32_t crc; 105 uint32_t crc;
105 106
106 crc = crc_in ^ ~0U; 107 crc = crc_in ^ ~0U;
diff --git a/libsparse/sparse_crc32.h b/libsparse/sparse_crc32.h
index 50cd9e989..e42c1eb98 100644
--- a/libsparse/sparse_crc32.h
+++ b/libsparse/sparse_crc32.h
@@ -19,14 +19,6 @@
19 19
20#include <stdint.h> 20#include <stdint.h>
21 21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26uint32_t sparse_crc32(uint32_t crc, const void *buf, size_t size); 22uint32_t sparse_crc32(uint32_t crc, const void *buf, size_t size);
27 23
28#ifdef __cplusplus
29}
30#endif
31
32#endif 24#endif
diff --git a/libsparse/sparse_err.c b/libsparse/sparse_err.cpp
index 0f392ad60..0f392ad60 100644
--- a/libsparse/sparse_err.c
+++ b/libsparse/sparse_err.cpp