mirror of
https://github.com/troglobit/libite.git
synced 2026-10-02 13:52:51 +07:00
touch(): behavioral change, call utimensat() first, then mknod()
Optimize for the case the file exists already. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
+3
-3
@@ -117,9 +117,9 @@ int whichp (const char *cmd);
|
||||
#include <sys/time.h> /* utimensat() on *BSD */
|
||||
static inline int touch(const char *path)
|
||||
{
|
||||
if (mknod((path), S_IFREG|0644, 0)) {
|
||||
if (errno == EEXIST)
|
||||
return utimensat(AT_FDCWD, path, NULL, 0);
|
||||
if (utimensat(AT_FDCWD, path, NULL, 0)) {
|
||||
if (errno == ENOENT)
|
||||
return mknod((path), S_IFREG|0644, 0);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user