aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-06-21 02:03:02 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-06-21 02:03:48 +0200
commit3aa4521484ce60af0ea81107e5d3234ac2c79f50 (patch)
tree1872016599ac0333d39557fb30701bb6cf5c3469
parentb18ea0266394aab045ddd6c56fb556d525ad30ee (diff)
Let fmdcmp() work even when the arguments don’t exist
-rw-r--r--cbs.h21
1 files changed, 15 insertions, 6 deletions
diff --git a/cbs.h b/cbs.h
index a94d3d9..e08034f 100644
--- a/cbs.h
+++ b/cbs.h
@@ -230,14 +230,25 @@ fexists(const char *f)
int
fmdcmp(const char *lhs, const char *rhs)
{
+ int errnol, errnor;
struct stat sbl, sbr;
- assert(stat(lhs, &sbl) != -1);
- assert(stat(rhs, &sbr) != -1);
+ stat(lhs, &sbl); errnol = errno;
+ stat(rhs, &sbr); errnor = errno;
+
+ assert(errnol == 0 || errnol == ENOENT);
+ assert(errnor == 0 || errnor == ENOENT);
+
+ if (errnol == ENOENT && errnor == ENOENT)
+ return 0;
+ if (errnol == ENOENT)
+ return -1;
+ if (errnor == ENOENT)
+ return +1;
return sbl.st_mtim.tv_sec == sbr.st_mtim.tv_sec
- ? sbl.st_mtim.tv_nsec - sbr.st_mtim.tv_nsec
- : sbl.st_mtim.tv_sec - sbr.st_mtim.tv_sec;
+ ? sbl.st_mtim.tv_nsec - sbr.st_mtim.tv_nsec
+ : sbl.st_mtim.tv_sec - sbr.st_mtim.tv_sec;
}
bool
@@ -255,8 +266,6 @@ fmdolder(const char *lhs, const char *rhs)
bool
foutdated(const char *src, char **deps, size_t n)
{
- if (!fexists(src))
- return true;
for (size_t i = 0; i < n; i++) {
if (fmdolder(src, deps[i]))
return true;