update_engine: Run clang-format on common/
BUG=none
TEST=unittest
Change-Id: Icdaf5017e03a197bc576f08f4b8dcdd00cff217c
Reviewed-on: https://chromium-review.googlesource.com/1407541
Commit-Ready: Amin Hassani <ahassani@chromium.org>
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Sen Jiang <senj@chromium.org>
diff --git a/common/utils.h b/common/utils.h
index 4b83cc4..9160d9f 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -46,7 +46,7 @@
// Formats |vec_str| as a string of the form ["<elem1>", "<elem2>"].
// Does no escaping, only use this for presentation in error messages.
-std::string StringVectorToString(const std::vector<std::string> &vec_str);
+std::string StringVectorToString(const std::vector<std::string>& vec_str);
// Calculates the p2p file id from payload hash and size
std::string CalculateP2PFileId(const brillo::Blob& payload_hash,
@@ -81,11 +81,14 @@
// Calls pread() repeatedly until count bytes are read, or EOF is reached.
// Returns number of bytes read in *bytes_read. Returns true on success.
-bool PReadAll(int fd, void* buf, size_t count, off_t offset,
- ssize_t* out_bytes_read);
+bool PReadAll(
+ int fd, void* buf, size_t count, off_t offset, ssize_t* out_bytes_read);
-bool PReadAll(const FileDescriptorPtr& fd, void* buf, size_t count,
- off_t offset, ssize_t* out_bytes_read);
+bool PReadAll(const FileDescriptorPtr& fd,
+ void* buf,
+ size_t count,
+ off_t offset,
+ ssize_t* out_bytes_read);
// Opens |path| for reading and appends its entire content to the container
// pointed to by |out_p|. Returns true upon successfully reading all of the
@@ -94,7 +97,9 @@
// |size| is not -1, only up to |size| bytes are read in.
bool ReadFile(const std::string& path, brillo::Blob* out_p);
bool ReadFile(const std::string& path, std::string* out_p);
-bool ReadFileChunk(const std::string& path, off_t offset, off_t size,
+bool ReadFileChunk(const std::string& path,
+ off_t offset,
+ off_t size,
brillo::Blob* out_p);
// Invokes |cmd| in a pipe and appends its stdout to the container pointed to by
@@ -155,8 +160,7 @@
// {"/dev/sda", 1} => "/dev/sda1"
// {"/dev/mmcblk2", 12} => "/dev/mmcblk2p12"
// Returns empty string when invalid parameters are passed in
-std::string MakePartitionName(const std::string& disk_name,
- int partition_num);
+std::string MakePartitionName(const std::string& disk_name, int partition_num);
// Similar to "MakePartitionName" but returns a name that is suitable for
// mounting. On NAND system we can write to "/dev/ubiX_0", which is what
@@ -217,12 +221,12 @@
HexDumpArray(vect.data(), vect.size());
}
-template<typename T>
-bool VectorIndexOf(const std::vector<T>& vect, const T& value,
+template <typename T>
+bool VectorIndexOf(const std::vector<T>& vect,
+ const T& value,
typename std::vector<T>::size_type* out_index) {
- typename std::vector<T>::const_iterator it = std::find(vect.begin(),
- vect.end(),
- value);
+ typename std::vector<T>::const_iterator it =
+ std::find(vect.begin(), vect.end(), value);
if (it == vect.end()) {
return false;
} else {
@@ -278,7 +282,7 @@
// into account so the result may up to one hour off. This is because
// the glibc date and timezone routines depend on the TZ environment
// variable and changing environment variables is not thread-safe.
-bool ConvertToOmahaInstallDate(base::Time time, int *out_num_days);
+bool ConvertToOmahaInstallDate(base::Time time, int* out_num_days);
// Look for the minor version value in the passed |store| and set
// |minor_version| to that value. Return whether the value was found and valid.
@@ -289,8 +293,10 @@
// extents are read from the file at |path|. |out_data_size| is the size of
// |out_data|. Returns false if the number of bytes to read given in
// |extents| does not equal |out_data_size|.
-bool ReadExtents(const std::string& path, const std::vector<Extent>& extents,
- brillo::Blob* out_data, ssize_t out_data_size,
+bool ReadExtents(const std::string& path,
+ const std::vector<Extent>& extents,
+ brillo::Blob* out_data,
+ ssize_t out_data_size,
size_t block_size);
// Read the current boot identifier and store it in |boot_id|. This identifier
@@ -322,7 +328,6 @@
} // namespace utils
-
// Utility class to close a file descriptor
class ScopedFdCloser {
public:
@@ -332,6 +337,7 @@
*fd_ = -1;
}
void set_should_close(bool should_close) { should_close_ = should_close; }
+
private:
int* fd_;
bool should_close_ = true;
@@ -342,8 +348,7 @@
class ScopedPathUnlinker {
public:
explicit ScopedPathUnlinker(const std::string& path)
- : path_(path),
- should_remove_(true) {}
+ : path_(path), should_remove_(true) {}
~ScopedPathUnlinker() {
if (should_remove_ && unlink(path_.c_str()) < 0) {
PLOG(ERROR) << "Unable to unlink path " << path_;
@@ -389,54 +394,54 @@
} // namespace chromeos_update_engine
-#define TEST_AND_RETURN_FALSE_ERRNO(_x) \
- do { \
- bool _success = static_cast<bool>(_x); \
- if (!_success) { \
- std::string _msg = \
- chromeos_update_engine::utils::ErrnoNumberAsString(errno); \
- LOG(ERROR) << #_x " failed: " << _msg; \
- return false; \
- } \
+#define TEST_AND_RETURN_FALSE_ERRNO(_x) \
+ do { \
+ bool _success = static_cast<bool>(_x); \
+ if (!_success) { \
+ std::string _msg = \
+ chromeos_update_engine::utils::ErrnoNumberAsString(errno); \
+ LOG(ERROR) << #_x " failed: " << _msg; \
+ return false; \
+ } \
} while (0)
-#define TEST_AND_RETURN_FALSE(_x) \
- do { \
- bool _success = static_cast<bool>(_x); \
- if (!_success) { \
- LOG(ERROR) << #_x " failed."; \
- return false; \
- } \
+#define TEST_AND_RETURN_FALSE(_x) \
+ do { \
+ bool _success = static_cast<bool>(_x); \
+ if (!_success) { \
+ LOG(ERROR) << #_x " failed."; \
+ return false; \
+ } \
} while (0)
-#define TEST_AND_RETURN_ERRNO(_x) \
- do { \
- bool _success = static_cast<bool>(_x); \
- if (!_success) { \
- std::string _msg = \
- chromeos_update_engine::utils::ErrnoNumberAsString(errno); \
- LOG(ERROR) << #_x " failed: " << _msg; \
- return; \
- } \
+#define TEST_AND_RETURN_ERRNO(_x) \
+ do { \
+ bool _success = static_cast<bool>(_x); \
+ if (!_success) { \
+ std::string _msg = \
+ chromeos_update_engine::utils::ErrnoNumberAsString(errno); \
+ LOG(ERROR) << #_x " failed: " << _msg; \
+ return; \
+ } \
} while (0)
-#define TEST_AND_RETURN(_x) \
- do { \
- bool _success = static_cast<bool>(_x); \
- if (!_success) { \
- LOG(ERROR) << #_x " failed."; \
- return; \
- } \
+#define TEST_AND_RETURN(_x) \
+ do { \
+ bool _success = static_cast<bool>(_x); \
+ if (!_success) { \
+ LOG(ERROR) << #_x " failed."; \
+ return; \
+ } \
} while (0)
-#define TEST_AND_RETURN_FALSE_ERRCODE(_x) \
- do { \
- errcode_t _error = (_x); \
- if (_error) { \
- errno = _error; \
- LOG(ERROR) << #_x " failed: " << _error; \
- return false; \
- } \
+#define TEST_AND_RETURN_FALSE_ERRCODE(_x) \
+ do { \
+ errcode_t _error = (_x); \
+ if (_error) { \
+ errno = _error; \
+ LOG(ERROR) << #_x " failed: " << _error; \
+ return false; \
+ } \
} while (0)
#endif // UPDATE_ENGINE_COMMON_UTILS_H_