| 1586 | } |
| 1587 | |
| 1588 | Status SystemTools::FileTimeCompare(std::string const& f1, |
| 1589 | std::string const& f2, int* result) |
| 1590 | { |
| 1591 | // Default to same time. |
| 1592 | *result = 0; |
| 1593 | #if !defined(_WIN32) || defined(__CYGWIN__) |
| 1594 | // POSIX version. Use stat function to get file modification time. |
| 1595 | struct stat s1; |
| 1596 | if (stat(f1.c_str(), &s1) != 0) { |
| 1597 | return Status::POSIX_errno(); |
| 1598 | } |
| 1599 | struct stat s2; |
| 1600 | if (stat(f2.c_str(), &s2) != 0) { |
| 1601 | return Status::POSIX_errno(); |
| 1602 | } |
| 1603 | # if KWSYS_CXX_STAT_HAS_ST_MTIM |
| 1604 | // Compare using nanosecond resolution. |
| 1605 | if (s1.st_mtim.tv_sec < s2.st_mtim.tv_sec) { |
| 1606 | *result = -1; |
| 1607 | } else if (s1.st_mtim.tv_sec > s2.st_mtim.tv_sec) { |
| 1608 | *result = 1; |
| 1609 | } else if (s1.st_mtim.tv_nsec < s2.st_mtim.tv_nsec) { |
| 1610 | *result = -1; |
| 1611 | } else if (s1.st_mtim.tv_nsec > s2.st_mtim.tv_nsec) { |
| 1612 | *result = 1; |
| 1613 | } |
| 1614 | # elif KWSYS_CXX_STAT_HAS_ST_MTIMESPEC |
| 1615 | // Compare using nanosecond resolution. |
| 1616 | if (s1.st_mtimespec.tv_sec < s2.st_mtimespec.tv_sec) { |
| 1617 | *result = -1; |
| 1618 | } else if (s1.st_mtimespec.tv_sec > s2.st_mtimespec.tv_sec) { |
| 1619 | *result = 1; |
| 1620 | } else if (s1.st_mtimespec.tv_nsec < s2.st_mtimespec.tv_nsec) { |
| 1621 | *result = -1; |
| 1622 | } else if (s1.st_mtimespec.tv_nsec > s2.st_mtimespec.tv_nsec) { |
| 1623 | *result = 1; |
| 1624 | } |
| 1625 | # else |
| 1626 | // Compare using 1 second resolution. |
| 1627 | if (s1.st_mtime < s2.st_mtime) { |
| 1628 | *result = -1; |
| 1629 | } else if (s1.st_mtime > s2.st_mtime) { |
| 1630 | *result = 1; |
| 1631 | } |
| 1632 | # endif |
| 1633 | #else |
| 1634 | // Windows version. Get the modification time from extended file attributes. |
| 1635 | WIN32_FILE_ATTRIBUTE_DATA f1d; |
| 1636 | WIN32_FILE_ATTRIBUTE_DATA f2d; |
| 1637 | if (!GetFileAttributesExW(Encoding::ToWindowsExtendedPath(f1).c_str(), |
| 1638 | GetFileExInfoStandard, &f1d)) { |
| 1639 | return Status::Windows_GetLastError(); |
| 1640 | } |
| 1641 | if (!GetFileAttributesExW(Encoding::ToWindowsExtendedPath(f2).c_str(), |
| 1642 | GetFileExInfoStandard, &f2d)) { |
| 1643 | return Status::Windows_GetLastError(); |
| 1644 | } |
| 1645 | |