summaryrefslogtreecommitdiffstats
path: root/otautil
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2018-07-17 23:57:38 +0200
committerandroid-build-merger <android-build-merger@google.com>2018-07-17 23:57:38 +0200
commit2f9d61ad25b6c219eb273db2dddbe38378902dbd (patch)
tree5bf35c6deefe6bcaeca33b371719f570a0b1147d /otautil
parentMerge "applypatch: Consolidate CacheSizeCheck() and MakeFreeSpaceOnCache()." (diff)
parentMerge "Fix the arguments passed to getopt_long(3)." (diff)
downloadandroid_bootable_recovery-2f9d61ad25b6c219eb273db2dddbe38378902dbd.tar
android_bootable_recovery-2f9d61ad25b6c219eb273db2dddbe38378902dbd.tar.gz
android_bootable_recovery-2f9d61ad25b6c219eb273db2dddbe38378902dbd.tar.bz2
android_bootable_recovery-2f9d61ad25b6c219eb273db2dddbe38378902dbd.tar.lz
android_bootable_recovery-2f9d61ad25b6c219eb273db2dddbe38378902dbd.tar.xz
android_bootable_recovery-2f9d61ad25b6c219eb273db2dddbe38378902dbd.tar.zst
android_bootable_recovery-2f9d61ad25b6c219eb273db2dddbe38378902dbd.zip
Diffstat (limited to 'otautil')
-rw-r--r--otautil/include/otautil/sysutil.h5
-rw-r--r--otautil/sysutil.cpp9
2 files changed, 14 insertions, 0 deletions
diff --git a/otautil/include/otautil/sysutil.h b/otautil/include/otautil/sysutil.h
index 649f8ffae..2eeb7c302 100644
--- a/otautil/include/otautil/sysutil.h
+++ b/otautil/include/otautil/sysutil.h
@@ -54,4 +54,9 @@ class MemMapping {
// command should start with "reboot," (e.g. "reboot,bootloader" or "reboot,").
bool reboot(const std::string& command);
+// Returns a null-terminated char* array, where the elements point to the C-strings in the given
+// vector, plus an additional nullptr at the end. This is a helper function that facilitates
+// calling C functions (such as getopt(3)) that expect an array of C-strings.
+std::vector<char*> StringVectorToNullTerminatedArray(const std::vector<std::string>& args);
+
#endif // _OTAUTIL_SYSUTIL
diff --git a/otautil/sysutil.cpp b/otautil/sysutil.cpp
index ab1513088..d8969a0bb 100644
--- a/otautil/sysutil.cpp
+++ b/otautil/sysutil.cpp
@@ -23,6 +23,7 @@
#include <sys/stat.h>
#include <sys/types.h>
+#include <algorithm>
#include <string>
#include <vector>
@@ -211,3 +212,11 @@ bool reboot(const std::string& command) {
}
return android::base::SetProperty(ANDROID_RB_PROPERTY, cmd);
}
+
+std::vector<char*> StringVectorToNullTerminatedArray(const std::vector<std::string>& args) {
+ std::vector<char*> result(args.size());
+ std::transform(args.cbegin(), args.cend(), result.begin(),
+ [](const std::string& arg) { return const_cast<char*>(arg.c_str()); });
+ result.push_back(nullptr);
+ return result;
+}