| 146 | } |
| 147 | |
| 148 | FileInfo StatToFileInfo(const struct stat& s) { |
| 149 | FileInfo info; |
| 150 | if (S_ISREG(s.st_mode)) { |
| 151 | info.set_type(FileType::File); |
| 152 | info.set_size(static_cast<int64_t>(s.st_size)); |
| 153 | } else if (S_ISDIR(s.st_mode)) { |
| 154 | info.set_type(FileType::Directory); |
| 155 | info.set_size(kNoSize); |
| 156 | } else { |
| 157 | info.set_type(FileType::Unknown); |
| 158 | info.set_size(kNoSize); |
| 159 | } |
| 160 | # ifdef __APPLE__ |
| 161 | // macOS doesn't use the POSIX-compliant spelling |
| 162 | info.set_mtime(ToTimePoint(s.st_mtimespec)); |
| 163 | # elif defined(_AIX) && defined(_ALL_SOURCE) |
| 164 | // In AIX with _ALL_SOURCE, stat struct member st_mtim is of type st_timespec_t. |
| 165 | struct timespec times; |
| 166 | times.tv_sec = s.st_mtim.tv_sec; |
| 167 | times.tv_nsec = static_cast<int64_t>(s.st_mtim.tv_nsec); |
| 168 | info.set_mtime(ToTimePoint(times)); |
| 169 | # else |
| 170 | info.set_mtime(ToTimePoint(s.st_mtim)); |
| 171 | # endif |
| 172 | return info; |
| 173 | } |
| 174 | |
| 175 | Result<FileInfo> StatFile(const std::string& path) { |
| 176 | FileInfo info; |
no test coverage detected