blob: ba5b9b65b80deb63e763943a055b8755fdca93de [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 Willemsen3ce083f2017-10-11 22:17:48 -070039int RunCommand(const string& shell,
40 const string& shellflag,
41 const string& cmd,
42 RedirectStderr redirect_stderr,
Shinichiro Hamaji94d6f2a2015-07-05 05:32:25 +090043 string* out);
44
Shinichiro Hamajib58bb4b2015-07-30 18:02:51 +090045void GetExecutablePath(string* path);
46
Shinichiro Hamaji0e3873a2015-07-05 15:48:28 +090047void Glob(const char* pat, vector<string>** files);
48
Shinichiro Hamajia09ed282015-07-31 12:21:54 +090049const unordered_map<string, vector<string>*>& GetAllGlobCache();
50
51void ClearGlobCache();
52
Dan Willemsen3ce083f2017-10-11 22:17:48 -070053#define HANDLE_EINTR(x) \
54 ({ \
55 int r; \
56 do { \
57 r = (x); \
58 } while (r == -1 && errno == EINTR); \
59 r; \
60 })
Shinichiro Hamaji706c27f2016-04-11 18:35:06 +090061
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090062#endif // FILEUTIL_H_