From 5cdc5736f3b088890e4553e1443bffd18343f4f2 Mon Sep 17 00:00:00 2001 From: yangfl Date: Wed, 26 Jan 2022 02:54:06 +0800 Subject: [PATCH] Replace mknod() with creat() For mknod(), mode must be S_IFIFO otherwise the behaviour is unspecified according to SUS, and apparently Debian/kFreeBSD is in the hater list. --- src/lite.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lite.h b/src/lite.h index 944135b..4ce3c62 100644 --- a/src/lite.h +++ b/src/lite.h @@ -139,10 +139,15 @@ int whichp (const char *cmd); */ static inline int touch(const char *path) { + int fd; + if (utimensat(AT_FDCWD, path, NULL, 0)) { - if (errno == ENOENT) - return mknod((path), S_IFREG|0644, 0); - return -1; + if (errno != ENOENT) + return -1; + fd = creat(path, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); + if (fd < 0) + return -1; + close(fd); } return 0; }