• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
15 #ifndef FILEUTIL_H_
16 #define FILEUTIL_H_
17 
18 #include <errno.h>
19 
20 #include <memory>
21 #include <string>
22 #include <unordered_map>
23 #include <vector>
24 
25 #include "string_piece.h"
26 
27 using namespace std;
28 
29 bool Exists(StringPiece f);
30 double GetTimestampFromStat(const struct stat& st);
31 double GetTimestamp(StringPiece f);
32 
33 enum struct RedirectStderr {
34   NONE,
35   STDOUT,
36   DEV_NULL,
37 };
38 
39 int RunCommand(const string& shell, const string& shellflag,
40                const string& cmd, RedirectStderr redirect_stderr,
41                string* out);
42 
43 void GetExecutablePath(string* path);
44 
45 void Glob(const char* pat, vector<string>** files);
46 
47 const unordered_map<string, vector<string>*>& GetAllGlobCache();
48 
49 void ClearGlobCache();
50 
51 #define HANDLE_EINTR(x) ({                                \
52       int r;                                              \
53       do {                                                \
54         r = (x);                                          \
55       } while (r == -1 && errno == EINTR);                \
56       r;                                                  \
57     })
58 
59 #endif  // FILEUTIL_H_
60