blob: 264d9e1749d8aa201e506a02ea457d62b45fc04d [file] [log] [blame]
Shinichiro Hamaji1d545aa2015-06-23 15:29:13 +09001// 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 Hamaji776ca302015-06-06 03:52:48 +090015#ifndef FILEUTIL_H_
16#define FILEUTIL_H_
17
Shinichiro Hamaji706c27f2016-04-11 18:35:06 +090018#include <errno.h>
19
Shinichiro Hamaji0e3873a2015-07-05 15:48:28 +090020#include <memory>
Shinichiro Hamaji94d6f2a2015-07-05 05:32:25 +090021#include <string>
Shinichiro Hamajia09ed282015-07-31 12:21:54 +090022#include <unordered_map>
Shinichiro Hamaji0e3873a2015-07-05 15:48:28 +090023#include <vector>
Shinichiro Hamaji94d6f2a2015-07-05 05:32:25 +090024
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090025#include "string_piece.h"
26
Shinichiro Hamaji94d6f2a2015-07-05 05:32:25 +090027using namespace std;
28
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090029bool Exists(StringPiece f);
Shinichiro Hamaji6ce977d2015-10-15 16:01:16 +090030double GetTimestampFromStat(const struct stat& st);
Shinichiro Hamajifda79432015-07-05 03:17:34 +090031double GetTimestamp(StringPiece f);
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090032
Shinichiro Hamajic9b0aca2015-07-31 16:47:56 +090033enum struct RedirectStderr {
34 NONE,
35 STDOUT,
36 DEV_NULL,
37};
38
Dan Willemsen064be222016-09-30 20:17:14 -070039int RunCommand(const string& shell, const string& shellflag,
40 const string& cmd, RedirectStderr redirect_stderr,
Shinichiro Hamaji94d6f2a2015-07-05 05:32:25 +090041 string* out);
42
Shinichiro Hamajib58bb4b2015-07-30 18:02:51 +090043void GetExecutablePath(string* path);
44
Shinichiro Hamaji0e3873a2015-07-05 15:48:28 +090045void Glob(const char* pat, vector<string>** files);
46
Shinichiro Hamajia09ed282015-07-31 12:21:54 +090047const unordered_map<string, vector<string>*>& GetAllGlobCache();
48
49void ClearGlobCache();
50
Shinichiro Hamaji706c27f2016-04-11 18:35:06 +090051#define HANDLE_EINTR(x) ({ \
52 int r; \
53 do { \
54 r = (x); \
55 } while (r == -1 && errno == EINTR); \
56 r; \
57 })
58
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090059#endif // FILEUTIL_H_