diff options
author | Elliott Hughes <enh@google.com> | 2015-06-23 20:27:58 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2015-06-23 20:56:01 -0700 |
commit | b3748de33f651597259f52e4645571a1da2e32dd (patch) | |
tree | 96ecf31d36bf62db8062b16fbf7b8e3bfced7e6d | |
parent | 21ba889aded6167859c88f51dec54838b8e407a1 (diff) | |
download | system_core-b3748de33f651597259f52e4645571a1da2e32dd.tar.gz system_core-b3748de33f651597259f52e4645571a1da2e32dd.tar.bz2 system_core-b3748de33f651597259f52e4645571a1da2e32dd.zip |
Move fastboot to C++.
Minimal conversion.
Change-Id: I32cbf125be481a8757720d10fa303c38a7fd5e38
-rw-r--r-- | fastboot/Android.mk | 7 | ||||
-rw-r--r-- | fastboot/engine.cpp (renamed from fastboot/engine.c) | 48 | ||||
-rw-r--r-- | fastboot/fs.cpp (renamed from fastboot/fs.c) | 2 | ||||
-rw-r--r-- | fastboot/protocol.cpp (renamed from fastboot/protocol.c) | 4 | ||||
-rw-r--r-- | fastboot/usb_linux.cpp (renamed from fastboot/usb_linux.c) | 2 | ||||
-rw-r--r-- | fastboot/usbtest.cpp (renamed from fastboot/usbtest.c) | 0 | ||||
-rw-r--r-- | fastboot/util.cpp (renamed from fastboot/util.c) | 0 | ||||
-rw-r--r-- | fastboot/util_linux.cpp (renamed from fastboot/util_linux.c) | 2 |
8 files changed, 27 insertions, 38 deletions
diff --git a/fastboot/Android.mk b/fastboot/Android.mk index 66a470a64..6443a1fc5 100644 --- a/fastboot/Android.mk +++ b/fastboot/Android.mk @@ -21,7 +21,7 @@ include $(CLEAR_VARS) LOCAL_C_INCLUDES := $(LOCAL_PATH)/../mkbootimg \ $(LOCAL_PATH)/../../extras/ext4_utils \ $(LOCAL_PATH)/../../extras/f2fs_utils -LOCAL_SRC_FILES := protocol.c engine.c bootimg_utils.cpp fastboot.cpp util.c fs.c +LOCAL_SRC_FILES := protocol.cpp engine.cpp bootimg_utils.cpp fastboot.cpp util.cpp fs.cpp LOCAL_MODULE := fastboot LOCAL_MODULE_TAGS := debug LOCAL_CONLYFLAGS += -std=gnu99 @@ -30,7 +30,7 @@ LOCAL_CFLAGS += -Wall -Wextra -Werror -Wunreachable-code LOCAL_CFLAGS += -DFASTBOOT_REVISION='"$(fastboot_version)"' ifeq ($(HOST_OS),linux) - LOCAL_SRC_FILES += usb_linux.c util_linux.c + LOCAL_SRC_FILES += usb_linux.cpp util_linux.cpp endif ifeq ($(HOST_OS),darwin) @@ -97,10 +97,9 @@ endif $(call dist-for-goals,dist_files sdk,$(my_dist_files)) my_dist_files := - ifeq ($(HOST_OS),linux) include $(CLEAR_VARS) -LOCAL_SRC_FILES := usbtest.c usb_linux.c util.c +LOCAL_SRC_FILES := usbtest.cpp usb_linux.cpp util.cpp LOCAL_MODULE := usbtest LOCAL_CFLAGS := -Werror include $(BUILD_HOST_EXECUTABLE) diff --git a/fastboot/engine.c b/fastboot/engine.cpp index 2f90e419a..66b8140f3 100644 --- a/fastboot/engine.c +++ b/fastboot/engine.cpp @@ -45,10 +45,6 @@ #include <sys/mman.h> #endif -#ifndef __unused -#define __unused __attribute__((__unused__)) -#endif - #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) #define OP_DOWNLOAD 1 @@ -73,7 +69,7 @@ struct Action unsigned size; const char *msg; - int (*func)(Action *a, int status, char *resp); + int (*func)(Action* a, int status, const char* resp); double start; }; @@ -121,8 +117,7 @@ int fb_format_supported(usb_handle *usb, const char *partition, const char *type return !!fs_get_generator(fs_type); } -static int cb_default(Action *a, int status, char *resp) -{ +static int cb_default(Action* a, int status, const char* resp) { if (status) { fprintf(stderr,"FAILED (%s)\n", resp); } else { @@ -135,12 +130,11 @@ static int cb_default(Action *a, int status, char *resp) static Action *queue_action(unsigned op, const char *fmt, ...) { - Action *a; va_list ap; size_t cmdsize; - a = calloc(1, sizeof(Action)); - if (a == 0) die("out of memory"); + Action* a = reinterpret_cast<Action*>(calloc(1, sizeof(Action))); + if (a == nullptr) die("out of memory"); va_start(ap, fmt); cmdsize = vsnprintf(a->cmd, sizeof(a->cmd), fmt, ap); @@ -198,8 +192,7 @@ void fb_queue_flash_sparse(const char *ptn, struct sparse_file *s, unsigned sz) a->msg = mkmsg("writing '%s'", ptn); } -static int match(char *str, const char **value, unsigned count) -{ +static int match(const char* str, const char** value, unsigned count) { unsigned n; for (n = 0; n < count; n++) { @@ -222,9 +215,9 @@ static int match(char *str, const char **value, unsigned count) -static int cb_check(Action *a, int status, char *resp, int invert) +static int cb_check(Action* a, int status, const char* resp, int invert) { - const char **value = a->data; + const char** value = reinterpret_cast<const char**>(a->data); unsigned count = a->size; unsigned n; int yes; @@ -265,18 +258,16 @@ static int cb_check(Action *a, int status, char *resp, int invert) return -1; } -static int cb_require(Action *a, int status, char *resp) -{ +static int cb_require(Action*a, int status, const char* resp) { return cb_check(a, status, resp, 0); } -static int cb_reject(Action *a, int status, char *resp) -{ +static int cb_reject(Action* a, int status, const char* resp) { return cb_check(a, status, resp, 1); } void fb_queue_require(const char *prod, const char *var, - int invert, unsigned nvalues, const char **value) + int invert, unsigned nvalues, const char **value) { Action *a; a = queue_action(OP_QUERY, "getvar:%s", var); @@ -285,11 +276,10 @@ void fb_queue_require(const char *prod, const char *var, a->size = nvalues; a->msg = mkmsg("checking %s", var); a->func = invert ? cb_reject : cb_require; - if (a->data == 0) die("out of memory"); + if (a->data == nullptr) die("out of memory"); } -static int cb_display(Action *a, int status, char *resp) -{ +static int cb_display(Action* a, int status, const char* resp) { if (status) { fprintf(stderr, "%s FAILED (%s)\n", a->cmd, resp); return status; @@ -303,17 +293,16 @@ void fb_queue_display(const char *var, const char *prettyname) Action *a; a = queue_action(OP_QUERY, "getvar:%s", var); a->data = strdup(prettyname); - if (a->data == 0) die("out of memory"); + if (a->data == nullptr) die("out of memory"); a->func = cb_display; } -static int cb_save(Action *a, int status, char *resp) -{ +static int cb_save(Action* a, int status, const char* resp) { if (status) { fprintf(stderr, "%s FAILED (%s)\n", a->cmd, resp); return status; } - strncpy(a->data, resp, a->size); + strncpy(reinterpret_cast<char*>(a->data), resp, a->size); return 0; } @@ -326,8 +315,7 @@ void fb_queue_query_save(const char *var, char *dest, unsigned dest_size) a->func = cb_save; } -static int cb_do_nothing(Action *a __unused, int status __unused, char *resp __unused) -{ +static int cb_do_nothing(Action*, int , const char*) { fprintf(stderr,"\n"); return 0; } @@ -398,7 +386,7 @@ int fb_execute_queue(usb_handle *usb) } else if (a->op == OP_NOTICE) { fprintf(stderr,"%s\n",(char*)a->data); } else if (a->op == OP_DOWNLOAD_SPARSE) { - status = fb_download_data_sparse(usb, a->data); + status = fb_download_data_sparse(usb, reinterpret_cast<sparse_file*>(a->data)); status = a->func(a, status, status ? fb_get_error() : ""); if (status) break; } else if (a->op == OP_WAIT_FOR_DISCONNECT) { @@ -414,5 +402,5 @@ int fb_execute_queue(usb_handle *usb) int fb_queue_is_empty(void) { - return (action_list == NULL); + return (action_list == nullptr); } diff --git a/fastboot/fs.c b/fastboot/fs.cpp index 8a15e6fab..d8f9e165d 100644 --- a/fastboot/fs.c +++ b/fastboot/fs.cpp @@ -38,7 +38,7 @@ static int generate_f2fs_image(int fd, long long partSize) static const struct fs_generator { - char *fs_type; //must match what fastboot reports for partition type + const char* fs_type; //must match what fastboot reports for partition type int (*generate)(int fd, long long partSize); //returns 0 or error value } generators[] = { diff --git a/fastboot/protocol.c b/fastboot/protocol.cpp index 5b9760081..00c8a034d 100644 --- a/fastboot/protocol.c +++ b/fastboot/protocol.cpp @@ -223,9 +223,9 @@ static int usb_buf_len; static int fb_download_data_sparse_write(void *priv, const void *data, int len) { int r; - usb_handle *usb = priv; + usb_handle* usb = reinterpret_cast<usb_handle*>(priv); int to_write; - const char *ptr = data; + const char* ptr = reinterpret_cast<const char*>(data); if (usb_buf_len) { to_write = min(USB_BUF_SIZE - usb_buf_len, len); diff --git a/fastboot/usb_linux.c b/fastboot/usb_linux.cpp index 022f3643d..9078c8f2d 100644 --- a/fastboot/usb_linux.c +++ b/fastboot/usb_linux.cpp @@ -340,7 +340,7 @@ static usb_handle *find_usb_device(const char *base, ifc_match_func callback) if(filter_usb_device(de->d_name, desc, n, writable, callback, &in, &out, &ifc) == 0) { - usb = calloc(1, sizeof(usb_handle)); + usb = reinterpret_cast<usb_handle*>(calloc(1, sizeof(usb_handle))); strcpy(usb->fname, devname); usb->ep_in = in; usb->ep_out = out; diff --git a/fastboot/usbtest.c b/fastboot/usbtest.cpp index e6e2b37e0..e6e2b37e0 100644 --- a/fastboot/usbtest.c +++ b/fastboot/usbtest.cpp diff --git a/fastboot/util.c b/fastboot/util.cpp index f2bbd3472..f2bbd3472 100644 --- a/fastboot/util.c +++ b/fastboot/util.cpp diff --git a/fastboot/util_linux.c b/fastboot/util_linux.cpp index 91c37764e..b78819952 100644 --- a/fastboot/util_linux.c +++ b/fastboot/util_linux.cpp @@ -26,6 +26,8 @@ * SUCH DAMAGE. */ +#include "fastboot.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> |