aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-07-05 23:18:43 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-07-05 23:18:43 +0200
commitb0b7d209fa978ff4a6b9c8cc5a8e4a3207cdd63f (patch)
treec1cc7a030287b847da03b0bcc5687a7ac3553242
parent5fe14d15635d62becb90a7c4277b89e8981b983c (diff)
Fix race-condition things
-rw-r--r--cbs.h16
1 files changed, 6 insertions, 10 deletions
diff --git a/cbs.h b/cbs.h
index 6618636..941fb35 100644
--- a/cbs.h
+++ b/cbs.h
@@ -222,21 +222,17 @@ fexists(const char *f)
int
fmdcmp(const char *lhs, const char *rhs)
{
- int errnol, errnor;
+ int retl, retr;
struct stat sbl, sbr;
- stat(lhs, &sbl); errnol = errno;
- errno = 0;
- stat(rhs, &sbr); errnor = errno;
-
- assert(errnol == 0 || errnol == ENOENT);
- assert(errnor == 0 || errnor == ENOENT);
+ retl = stat(lhs, &sbl);
+ retr = stat(rhs, &sbr);
- if (errnol == ENOENT && errnor == ENOENT)
+ if (retl == -1 && retr == -1)
return 0;
- if (errnol == ENOENT)
+ if (retl == -1)
return -1;
- if (errnor == ENOENT)
+ if (retr == -1)
return +1;
return sbl.st_mtim.tv_sec == sbr.st_mtim.tv_sec