diff options
Diffstat (limited to 'src/libutil/cxx/locked_file.cxx')
-rw-r--r-- | src/libutil/cxx/locked_file.cxx | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libutil/cxx/locked_file.cxx b/src/libutil/cxx/locked_file.cxx index f392d9b4a..13406c6cf 100644 --- a/src/libutil/cxx/locked_file.cxx +++ b/src/libutil/cxx/locked_file.cxx @@ -30,6 +30,11 @@ auto raii_locked_file::open(const char *fname, int flags) -> tl::expected<raii_l #ifdef O_CLOEXEC oflags |= O_CLOEXEC; #endif + + if (fname == nullptr) { + return tl::make_unexpected("cannot open file; filename is nullptr"); + } + auto fd = ::open(fname, oflags); if (fd == -1) { @@ -67,6 +72,11 @@ auto raii_locked_file::create(const char *fname, int flags, int perms) -> tl::ex #ifdef O_CLOEXEC oflags |= O_CLOEXEC | O_CREAT | O_EXCL; #endif + + if (fname == nullptr) { + return tl::make_unexpected("cannot open file; filename is nullptr"); + } + auto fd = ::open(fname, oflags, perms); if (fd == -1) { @@ -93,6 +103,10 @@ auto raii_locked_file::create_temp(const char *fname, int flags, int perms) -> t #ifdef O_CLOEXEC oflags |= O_CLOEXEC | O_CREAT | O_EXCL; #endif + if (fname == nullptr) { + return tl::make_unexpected("cannot open file; filename is nullptr"); + } + auto fd = ::open(fname, oflags, perms); if (fd == -1) { |