Shinichiro Hamaji | 1d545aa | 2015-06-23 15:29:13 +0900 | [diff] [blame] | 1 | // Copyright 2015 Google Inc. All rights reserved |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 15 | #ifndef FILEUTIL_H_ |
| 16 | #define FILEUTIL_H_ |
| 17 | |
Shinichiro Hamaji | 706c27f | 2016-04-11 18:35:06 +0900 | [diff] [blame] | 18 | #include <errno.h> |
| 19 | |
Shinichiro Hamaji | 0e3873a | 2015-07-05 15:48:28 +0900 | [diff] [blame] | 20 | #include <memory> |
Shinichiro Hamaji | 94d6f2a | 2015-07-05 05:32:25 +0900 | [diff] [blame] | 21 | #include <string> |
Shinichiro Hamaji | a09ed28 | 2015-07-31 12:21:54 +0900 | [diff] [blame] | 22 | #include <unordered_map> |
Shinichiro Hamaji | 0e3873a | 2015-07-05 15:48:28 +0900 | [diff] [blame] | 23 | #include <vector> |
Shinichiro Hamaji | 94d6f2a | 2015-07-05 05:32:25 +0900 | [diff] [blame] | 24 | |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 25 | #include "string_piece.h" |
| 26 | |
Shinichiro Hamaji | 94d6f2a | 2015-07-05 05:32:25 +0900 | [diff] [blame] | 27 | using namespace std; |
| 28 | |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 29 | bool Exists(StringPiece f); |
Shinichiro Hamaji | 6ce977d | 2015-10-15 16:01:16 +0900 | [diff] [blame] | 30 | double GetTimestampFromStat(const struct stat& st); |
Shinichiro Hamaji | fda7943 | 2015-07-05 03:17:34 +0900 | [diff] [blame] | 31 | double GetTimestamp(StringPiece f); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 32 | |
Shinichiro Hamaji | c9b0aca | 2015-07-31 16:47:56 +0900 | [diff] [blame] | 33 | enum struct RedirectStderr { |
| 34 | NONE, |
| 35 | STDOUT, |
| 36 | DEV_NULL, |
| 37 | }; |
| 38 | |
Dan Willemsen | 064be22 | 2016-09-30 20:17:14 -0700 | [diff] [blame] | 39 | int RunCommand(const string& shell, const string& shellflag, |
| 40 | const string& cmd, RedirectStderr redirect_stderr, |
Shinichiro Hamaji | 94d6f2a | 2015-07-05 05:32:25 +0900 | [diff] [blame] | 41 | string* out); |
| 42 | |
Shinichiro Hamaji | b58bb4b | 2015-07-30 18:02:51 +0900 | [diff] [blame] | 43 | void GetExecutablePath(string* path); |
| 44 | |
Shinichiro Hamaji | 0e3873a | 2015-07-05 15:48:28 +0900 | [diff] [blame] | 45 | void Glob(const char* pat, vector<string>** files); |
| 46 | |
Shinichiro Hamaji | a09ed28 | 2015-07-31 12:21:54 +0900 | [diff] [blame] | 47 | const unordered_map<string, vector<string>*>& GetAllGlobCache(); |
| 48 | |
| 49 | void ClearGlobCache(); |
| 50 | |
Shinichiro Hamaji | 706c27f | 2016-04-11 18:35:06 +0900 | [diff] [blame] | 51 | #define HANDLE_EINTR(x) ({ \ |
| 52 | int r; \ |
| 53 | do { \ |
| 54 | r = (x); \ |
| 55 | } while (r == -1 && errno == EINTR); \ |
| 56 | r; \ |
| 57 | }) |
| 58 | |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 59 | #endif // FILEUTIL_H_ |