aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-06-21 23:36:17 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-06-21 23:36:17 +0200
commit1db63fcedab0b288820d66e100b1877b1a5a8851 (patch)
tree5b299c261259759c057a7297da14d781b5a9759d
parentc976a61f60e32be3391c759ef86a41db4bbd62b0 (diff)
Fix fmdcmp()
-rw-r--r--cbs.h15
1 files changed, 13 insertions, 2 deletions
diff --git a/cbs.h b/cbs.h
index 266b949..9220ed1 100644
--- a/cbs.h
+++ b/cbs.h
@@ -210,10 +210,21 @@ 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