X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=src%2Ftype3_AndroidCloud%2Fanbox-master%2Fsrc%2Fanbox%2Futils.h;fp=src%2Ftype3_AndroidCloud%2Fanbox-master%2Fsrc%2Fanbox%2Futils.h;h=4b45a088e66c7024c5779cd937b4b0e0f12671f9;hb=e26c1ec581be598521517829adba8c8dd23a768f;hp=0000000000000000000000000000000000000000;hpb=6699c1aea74eeb0eb400e6299079f0c7576f716f;p=iec.git diff --git a/src/type3_AndroidCloud/anbox-master/src/anbox/utils.h b/src/type3_AndroidCloud/anbox-master/src/anbox/utils.h new file mode 100644 index 0000000..4b45a08 --- /dev/null +++ b/src/type3_AndroidCloud/anbox-master/src/anbox/utils.h @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2016 Simon Fels + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + */ + +#ifndef ANBOX_UTILS_H_ +#define ANBOX_UTILS_H_ + +#include + +#include +#include + +namespace anbox { +namespace utils { + +std::vector collect_arguments(int argc, char **argv); + +std::string read_file_if_exists_or_throw(const std::string &file_path); + +bool write_to_file(const std::string &file_path, + const std::string &content = ""); +int write_to_fd(int fd, const char *content, ssize_t len); +int write_file_at(int dirfd, const char *path, const char *content); + +bool string_starts_with(const std::string &text, const std::string &prefix); + +std::vector string_split(const std::string &text, char sep); + +std::string strip_surrounding_quotes(const std::string &text); + +std::string hex_dump(const uint8_t *data, uint32_t size); + +std::string get_env_value(const std::string &name, + const std::string &default_value = ""); +bool is_env_set(const std::string &name); + +void ensure_paths(const std::vector &paths); + +std::string prefix_dir_from_env(const std::string &path, + const std::string &env_var); + +std::string process_get_exe_path(const pid_t &pid); + +bool is_mounted(const std::string &path); + +std::string find_program_on_path(const std::string &name); + +template +static std::string string_format(const std::string &fmt_str, Types &&... args); +} // namespace utils +} // namespace anbox + +namespace impl { +// Base case, just return the passed in boost::format instance. +inline boost::format &string_format(boost::format &f) { return f; } +// Sprintf recursively walks the parameter pack at compile time. +template +inline boost::format &string_format(boost::format &f, Head const &head, + Tail &&... tail) { + return string_format(f % head, std::forward(tail)...); +} +} // namespace impl + +template +inline std::string anbox::utils::string_format(const std::string &format, + Types &&... args) { + boost::format f(format); + return impl::string_format(f, std::forward(args)...).str(); +} + +#endif