diff options
Diffstat (limited to 'fastboot/engine.cpp')
-rw-r--r-- | fastboot/engine.cpp | 57 |
1 files changed, 23 insertions, 34 deletions
diff --git a/fastboot/engine.cpp b/fastboot/engine.cpp index a0e990a85..63e89714a 100644 --- a/fastboot/engine.cpp +++ b/fastboot/engine.cpp @@ -75,41 +75,35 @@ static Action *action_last = 0; -int fb_getvar(struct usb_handle *usb, char *response, const char *fmt, ...) -{ - char cmd[CMD_SIZE] = "getvar:"; - int getvar_len = strlen(cmd); - va_list args; - - response[FB_RESPONSE_SZ] = '\0'; - va_start(args, fmt); - vsnprintf(cmd + getvar_len, sizeof(cmd) - getvar_len, fmt, args); - va_end(args); - cmd[CMD_SIZE - 1] = '\0'; - return fb_command_response(usb, cmd, response); +bool fb_getvar(usb_handle* usb, const std::string& key, std::string* value) { + std::string cmd = "getvar:"; + cmd += key; + + char buf[FB_RESPONSE_SZ + 1]; + memset(buf, 0, sizeof(buf)); + if (fb_command_response(usb, cmd.c_str(), buf)) { + return false; + } + *value = buf; + return true; } -/* Return true if this partition is supported by the fastboot format command. - * It is also used to determine if we should first erase a partition before - * flashing it with an ext4 filesystem. See needs_erase() - * - * Not all devices report the filesystem type, so don't report any errors, - * just return false. - */ -int fb_format_supported(usb_handle *usb, const char *partition, const char *type_override) -{ - char fs_type[FB_RESPONSE_SZ + 1] = {0,}; - int status; - +// Return true if this partition is supported by the fastboot format command. +// It is also used to determine if we should first erase a partition before +// flashing it with an ext4 filesystem. See needs_erase() +// +// Not all devices report the filesystem type, so don't report any errors, +// just return false. +bool fb_format_supported(usb_handle *usb, const char *partition, const char *type_override) { if (type_override) { - return !!fs_get_generator(type_override); + return fs_get_generator(type_override) != nullptr; } - status = fb_getvar(usb, fs_type, "partition-type:%s", partition); - if (status) { - return 0; + std::string partition_type; + if (!fb_getvar(usb, std::string("partition-type:") + partition, &partition_type)) { + return false; } - return !!fs_get_generator(fs_type); + return fs_get_generator(partition_type.c_str()) != nullptr; } static int cb_default(Action* a, int status, const char* resp) { @@ -394,8 +388,3 @@ int fb_execute_queue(usb_handle *usb) fprintf(stderr,"finished. total time: %.3fs\n", (now() - start)); return status; } - -int fb_queue_is_empty(void) -{ - return (action_list == nullptr); -} |