Elliott Hughes | 3810445 | 2015-04-17 13:57:15 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
Josh Gao | 1eef478 | 2015-11-20 15:37:31 -0800 | [diff] [blame^] | 22 | void close_stdin(); |
| 23 | |
Elliott Hughes | 7cf3575 | 2015-04-17 17:03:59 -0700 | [diff] [blame] | 24 | bool getcwd(std::string* cwd); |
Elliott Hughes | 3810445 | 2015-04-17 13:57:15 -0700 | [diff] [blame] | 25 | bool directory_exists(const std::string& path); |
Spencer Low | 939d000 | 2015-08-01 17:29:23 -0700 | [diff] [blame] | 26 | |
| 27 | // Like the regular basename and dirname, but thread-safe on all |
| 28 | // platforms and capable of correctly handling exotic Windows paths. |
Elliott Hughes | d189cfb | 2015-07-30 17:42:01 -0700 | [diff] [blame] | 29 | std::string adb_basename(const std::string& path); |
Spencer Low | 939d000 | 2015-08-01 17:29:23 -0700 | [diff] [blame] | 30 | std::string adb_dirname(const std::string& path); |
Elliott Hughes | 3810445 | 2015-04-17 13:57:15 -0700 | [diff] [blame] | 31 | |
Alex Vallée | 28d1f8d | 2015-05-06 16:26:00 -0400 | [diff] [blame] | 32 | bool mkdirs(const std::string& path); |
Alex Vallée | e916315 | 2015-05-06 17:22:25 -0400 | [diff] [blame] | 33 | |
Elliott Hughes | 3810445 | 2015-04-17 13:57:15 -0700 | [diff] [blame] | 34 | std::string escape_arg(const std::string& s); |
| 35 | |
Yabin Cui | 19bec5b | 2015-09-22 15:52:57 -0700 | [diff] [blame] | 36 | std::string dump_hex(const void* ptr, size_t byte_count); |
Elliott Hughes | 88b4c85 | 2015-04-30 17:32:03 -0700 | [diff] [blame] | 37 | |
Elliott Hughes | 09ccf1f | 2015-07-18 12:21:30 -0700 | [diff] [blame] | 38 | // Parses 'address' into 'host' and 'port'. |
| 39 | // If no port is given, takes the default from *port. |
| 40 | // 'canonical_address' then becomes "host:port" or "[host]:port" as appropriate. |
| 41 | // Note that no real checking is done that 'host' or 'port' is valid; that's |
| 42 | // left to getaddrinfo(3). |
| 43 | // Returns false on failure and sets *error to an appropriate message. |
| 44 | bool parse_host_and_port(const std::string& address, |
| 45 | std::string* canonical_address, |
| 46 | std::string* host, int* port, |
| 47 | std::string* error); |
| 48 | |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 49 | std::string perror_str(const char* msg); |
| 50 | |
Yabin Cui | 5fc2231 | 2015-10-06 15:10:05 -0700 | [diff] [blame] | 51 | bool set_file_block_mode(int fd, bool block); |
| 52 | |
Elliott Hughes | 3810445 | 2015-04-17 13:57:15 -0700 | [diff] [blame] | 53 | #endif |