mirror of
https://github.com/troglobit/libite.git
synced 2026-10-19 10:59:32 +00: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:
1 parent
8ce46eb439
commit
7ad11a31df
1 file changed
+3
-3
+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