blob: 30cd7a44792865ee701b143c62e95ea68209b520 [file] [log] [blame]
Elliott Hughes38104452015-04-17 13:57:15 -07001/*
2 * Copyright (C) 2015 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#ifndef _ADB_UTILS_H_
18#define _ADB_UTILS_H_
19
20#include <string>
21
Elliott Hughes7cf35752015-04-17 17:03:59 -070022bool getcwd(std::string* cwd);
Elliott Hughes38104452015-04-17 13:57:15 -070023bool directory_exists(const std::string& path);
Elliott Hughesd189cfb2015-07-30 17:42:01 -070024std::string adb_basename(const std::string& path);
Elliott Hughes38104452015-04-17 13:57:15 -070025
Alex Vallée28d1f8d2015-05-06 16:26:00 -040026bool mkdirs(const std::string& path);
Alex Valléee9163152015-05-06 17:22:25 -040027
Elliott Hughes38104452015-04-17 13:57:15 -070028std::string escape_arg(const std::string& s);
29
Elliott Hughes88b4c852015-04-30 17:32:03 -070030void dump_hex(const void* ptr, size_t byte_count);
31
Elliott Hughes09ccf1f2015-07-18 12:21:30 -070032// Parses 'address' into 'host' and 'port'.
33// If no port is given, takes the default from *port.
34// 'canonical_address' then becomes "host:port" or "[host]:port" as appropriate.
35// Note that no real checking is done that 'host' or 'port' is valid; that's
36// left to getaddrinfo(3).
37// Returns false on failure and sets *error to an appropriate message.
38bool parse_host_and_port(const std::string& address,
39 std::string* canonical_address,
40 std::string* host, int* port,
41 std::string* error);
42
Elliott Hughes43df1092015-07-23 17:12:58 -070043int network_connect(const std::string& host, int port, int type, int timeout, std::string* error);
44
Elliott Hughes38104452015-04-17 13:57:15 -070045#endif