Android-cuttlefish cvd tool
util.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <inttypes.h>
20#include <stdlib.h>
21
22#include <string>
23#include <vector>
24
26#include <bootimg.h>
27#include <liblp/liblp.h>
28#include <sparse/sparse.h>
29
30using SparsePtr = std::unique_ptr<sparse_file, decltype(&sparse_file_destroy)>;
31
32/* util stuff */
33double now();
34void set_verbose();
35
36// These printf-like functions are implemented in terms of vsnprintf, so they
37// use the same attribute for compile-time format string checking.
38void die(const char* fmt, ...) __attribute__((__noreturn__))
39__attribute__((__format__(__printf__, 1, 2)));
40
41void verbose(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)));
42
43void die(const std::string& str) __attribute__((__noreturn__));
44
45bool should_flash_in_userspace(const android::fs_mgr::LpMetadata& metadata,
46 const std::string& partition_name);
47bool is_sparse_file(android::base::borrowed_fd fd);
48int64_t get_file_size(android::base::borrowed_fd fd);
49std::string fb_fix_numeric_var(std::string var);
50
52 public:
53 virtual ~ImageSource(){};
54 virtual bool ReadFile(const std::string& name, std::vector<char>* out) const = 0;
55 virtual android::base::unique_fd OpenFile(const std::string& name) const = 0;
56};
Definition: util.h:51
virtual bool ReadFile(const std::string &name, std::vector< char > *out) const =0
virtual ~ImageSource()
Definition: util.h:53
virtual android::base::unique_fd OpenFile(const std::string &name) const =0
Definition: unique_fd.h:61
int64_t get_file_size(android::base::borrowed_fd fd)
Definition: util.cpp:105
double now()
Definition: util.cpp:45
std::unique_ptr< sparse_file, decltype(&sparse_file_destroy)> SparsePtr
Definition: util.h:30
std::string fb_fix_numeric_var(std::string var)
Definition: util.cpp:113
void void verbose(const char *fmt,...) __attribute__((__format__(__printf__
void die(const char *fmt,...) __attribute__((__noreturn__)) __attribute__((__format__(__printf__
void set_verbose()
Definition: util.cpp:65
bool is_sparse_file(android::base::borrowed_fd fd)
Definition: util.cpp:100
bool should_flash_in_userspace(const android::fs_mgr::LpMetadata &metadata, const std::string &partition_name)
Definition: util.cpp:82
Definition: map_ptr.h:34
Definition: result.h:31
class incremental::File __attribute__
Definition: logging.h:464
constexpr const char * str
Definition: utils.h:180