diff options
author | Tianjie Xu <xunchang@google.com> | 2017-11-06 19:56:27 +0100 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-11-06 19:56:27 +0100 |
commit | bf41f2aa238a9d928473c69c93308eb0b4f9719d (patch) | |
tree | e5b3cb24be5eff1e6796814b3a023160a42acd97 /bootloader_message/bootloader_message.cpp | |
parent | Merge "Clean up fuse_sideload and add a testcase." (diff) | |
parent | Switch to bionic gtest in bootable/recovery (diff) | |
download | android_bootable_recovery-bf41f2aa238a9d928473c69c93308eb0b4f9719d.tar android_bootable_recovery-bf41f2aa238a9d928473c69c93308eb0b4f9719d.tar.gz android_bootable_recovery-bf41f2aa238a9d928473c69c93308eb0b4f9719d.tar.bz2 android_bootable_recovery-bf41f2aa238a9d928473c69c93308eb0b4f9719d.tar.lz android_bootable_recovery-bf41f2aa238a9d928473c69c93308eb0b4f9719d.tar.xz android_bootable_recovery-bf41f2aa238a9d928473c69c93308eb0b4f9719d.tar.zst android_bootable_recovery-bf41f2aa238a9d928473c69c93308eb0b4f9719d.zip |
Diffstat (limited to '')
-rw-r--r-- | bootloader_message/bootloader_message.cpp | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/bootloader_message/bootloader_message.cpp b/bootloader_message/bootloader_message.cpp index f91446b43..aaeffdc5c 100644 --- a/bootloader_message/bootloader_message.cpp +++ b/bootloader_message/bootloader_message.cpp @@ -159,14 +159,8 @@ bool clear_bootloader_message(std::string* err) { bool write_bootloader_message(const std::vector<std::string>& options, std::string* err) { bootloader_message boot = {}; - strlcpy(boot.command, "boot-recovery", sizeof(boot.command)); - strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery)); - for (const auto& s : options) { - strlcat(boot.recovery, s.c_str(), sizeof(boot.recovery)); - if (s.back() != '\n') { - strlcat(boot.recovery, "\n", sizeof(boot.recovery)); - } - } + update_bootloader_message_in_struct(&boot, options); + return write_bootloader_message(boot, err); } @@ -175,20 +169,27 @@ bool update_bootloader_message(const std::vector<std::string>& options, std::str if (!read_bootloader_message(&boot, err)) { return false; } + update_bootloader_message_in_struct(&boot, options); - // Zero out the entire fields. - memset(boot.command, 0, sizeof(boot.command)); - memset(boot.recovery, 0, sizeof(boot.recovery)); + return write_bootloader_message(boot, err); +} + +bool update_bootloader_message_in_struct(bootloader_message* boot, + const std::vector<std::string>& options) { + if (!boot) return false; + // Replace the command & recovery fields. + memset(boot->command, 0, sizeof(boot->command)); + memset(boot->recovery, 0, sizeof(boot->recovery)); - strlcpy(boot.command, "boot-recovery", sizeof(boot.command)); - strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery)); + strlcpy(boot->command, "boot-recovery", sizeof(boot->command)); + strlcpy(boot->recovery, "recovery\n", sizeof(boot->recovery)); for (const auto& s : options) { - strlcat(boot.recovery, s.c_str(), sizeof(boot.recovery)); + strlcat(boot->recovery, s.c_str(), sizeof(boot->recovery)); if (s.back() != '\n') { - strlcat(boot.recovery, "\n", sizeof(boot.recovery)); + strlcat(boot->recovery, "\n", sizeof(boot->recovery)); } } - return write_bootloader_message(boot, err); + return true; } bool write_reboot_bootloader(std::string* err) { |