From 628c5597b9c5ca73173b90f9b32915a630ad888c Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Fri, 19 May 2017 17:50:44 +0200 Subject: [PATCH] Fix issue #6: touch does not update mtime if file exists Signed-off-by: Joachim Nilsson --- lite.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lite.h b/lite.h index da6eb63..5fdc429 100644 --- a/lite.h +++ b/lite.h @@ -86,10 +86,15 @@ void progress (int percent, int max_width); void progress_simple(int percent); #ifndef touch +#include /* utimensat() */ +#include /* utimensat() on *BSD */ static inline int touch(const char *path) { - if (mknod((path), S_IFREG|0644, 0) && errno != EEXIST) + if (mknod((path), S_IFREG|0644, 0)) { + if (errno == EEXIST) + return utimensat(0, path, NULL, 0); return -1; + } return 0; } #endif