diff options
-rw-r--r-- | src/libutil/util.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/libutil/util.c b/src/libutil/util.c index bc62bb919..915d77222 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -1872,21 +1872,23 @@ rspamd_file_xopen (const char *fname, int oflags, guint mode, struct stat sb; int fd, flags = oflags; - if (lstat (fname, &sb) == -1) { + if (!(oflags & O_CREAT)) { + if (lstat(fname, &sb) == -1) { - if (errno != ENOENT) { - return (-1); + if (errno != ENOENT) { + return (-1); + } } - } - else if (!S_ISREG (sb.st_mode)) { - if (S_ISLNK (sb.st_mode)) { - if (!allow_symlink) { + else if (!S_ISREG (sb.st_mode)) { + if (S_ISLNK (sb.st_mode)) { + if (!allow_symlink) { + return -1; + } + } + else { return -1; } } - else { - return -1; - } } #ifdef HAVE_OCLOEXEC |