• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2020 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #include <grpc/support/port_platform.h>
18 
19 #ifdef GPR_WINDOWS_STAT
20 
21 #include <errno.h>
22 #include <sys/stat.h>
23 #include <sys/types.h>
24 
25 #include "absl/log/check.h"
26 #include "absl/log/log.h"
27 #include "src/core/util/crash.h"
28 #include "src/core/util/stat.h"
29 #include "src/core/util/strerror.h"
30 
31 namespace grpc_core {
32 
GetFileModificationTime(const char * filename,time_t * timestamp)33 absl::Status GetFileModificationTime(const char* filename, time_t* timestamp) {
34   CHECK_NE(filename, nullptr);
35   CHECK_NE(timestamp, nullptr);
36   struct _stat buf;
37   if (_stat(filename, &buf) != 0) {
38     std::string error_msg = StrError(errno);
39     LOG(ERROR) << "_stat failed for filename " << filename << " with error "
40                << error_msg;
41     return absl::Status(absl::StatusCode::kInternal, error_msg);
42   }
43   // Last file/directory modification time.
44   *timestamp = buf.st_mtime;
45   return absl::OkStatus();
46 }
47 
48 }  // namespace grpc_core
49 
50 #endif  // GPR_WINDOWS_STAT
51