• 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,
40                const string& shellflag,
41                const string& cmd,
42                RedirectStderr redirect_stderr,
43                string* out);
44 
45 void GetExecutablePath(string* path);
46 
47 void Glob(const char* pat, vector<string>** files);
48 
49 const unordered_map<string, vector<string>*>& GetAllGlobCache();
50 
51 void ClearGlobCache();
52 
53 #define HANDLE_EINTR(x)                  \
54   ({                                     \
55     int r;                               \
56     do {                                 \
57       r = (x);                           \
58     } while (r == -1 && errno == EINTR); \
59     r;                                   \
60   })
61 
62 #endif  // FILEUTIL_H_
63