Switch mkbootfs to C++.
Minimum changes just to get it to compile as C++, no real cleanup.
Change-Id: I8ff3fa35a07cdc9a6a246e79e33581e5d6598833
diff --git a/mkbootfs/Android.bp b/mkbootfs/Android.bp
index cd2a624..e0191f0 100644
--- a/mkbootfs/Android.bp
+++ b/mkbootfs/Android.bp
@@ -6,7 +6,7 @@
cc_binary_host {
name: "mkbootfs",
- srcs: ["mkbootfs.c"],
+ srcs: ["mkbootfs.cpp"],
cflags: ["-Werror"],
static_libs: [
"libbase",
diff --git a/mkbootfs/mkbootfs.c b/mkbootfs/mkbootfs.cpp
similarity index 96%
rename from mkbootfs/mkbootfs.c
rename to mkbootfs/mkbootfs.cpp
index 84a0a4e..65cf497 100644
--- a/mkbootfs/mkbootfs.c
+++ b/mkbootfs/mkbootfs.cpp
@@ -75,7 +75,7 @@
}
}
-static void _eject(struct stat *s, char *out, int olen, char *data, unsigned datasize)
+static void _eject(struct stat *s, const char *out, int olen, char *data, unsigned datasize)
{
// Nothing is special about this value, just picked something in the
// approximate range that was being used already, and avoiding small
@@ -151,9 +151,10 @@
DIR* d = opendir(in);
if (d == NULL) err(1, "cannot open directory '%s'", in);
+ // TODO: switch to std::vector
int size = 32;
int entries = 0;
- char** names = malloc(size * sizeof(char*));
+ char** names = (char**) malloc(size * sizeof(char*));
if (names == NULL) {
errx(1, "failed to allocate dir names array (size %d)", size);
}
@@ -167,7 +168,7 @@
if (entries >= size) {
size *= 2;
- names = realloc(names, size * sizeof(char*));
+ names = (char**) realloc(names, size * sizeof(char*));
if (names == NULL) {
errx(1, "failed to reallocate dir names array (size %d)", size);
}
@@ -445,15 +446,12 @@
int num_dirs = argc - optind;
argv += optind;
- while(num_dirs-- > 0){
+ while (num_dirs-- > 0){
char *x = strchr(*argv, '=');
- if(x != 0) {
- *x++ = 0;
- } else {
- x = "";
+ if (x != nullptr) {
+ *x++ = '\0';
}
-
- archive(*argv, x);
+ archive(*argv, x ?: "");
argv++;
}