diff options
author | crupest <crupest@outlook.com> | 2023-10-15 23:45:46 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2023-10-15 23:45:46 +0800 |
commit | 9b818f45345b41854bca1022daddcf19304030fc (patch) | |
tree | 9c20e48b2e11214d4861aa56e96c647c032b4163 /src | |
parent | 5d077a761fdb0873d593f7d3b03922bef2efe79a (diff) | |
download | cru-9b818f45345b41854bca1022daddcf19304030fc.tar.gz cru-9b818f45345b41854bca1022daddcf19304030fc.tar.bz2 cru-9b818f45345b41854bca1022daddcf19304030fc.zip |
Fix unix file stream creation mode and readable check bug.
Diffstat (limited to 'src')
-rw-r--r-- | src/common/platform/unix/UnixFileStream.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/common/platform/unix/UnixFileStream.cpp b/src/common/platform/unix/UnixFileStream.cpp index a952a7f2..37f5110c 100644 --- a/src/common/platform/unix/UnixFileStream.cpp +++ b/src/common/platform/unix/UnixFileStream.cpp @@ -18,7 +18,11 @@ bool OflagCanSeek([[maybe_unused]] int oflag) { return true; } -bool OflagCanRead(int oflag) { return oflag & O_RDONLY || oflag & O_RDWR; } +bool OflagCanRead(int oflag) { + // There is a problem: O_RDONLY is 0. So we must test it specially. + // If it is not write-only. Then it can read. + return !(oflag & O_WRONLY); +} bool OflagCanWrite(int oflag) { return oflag & O_WRONLY || oflag & O_RDWR; } @@ -36,11 +40,12 @@ int MapSeekOrigin(Stream::SeekOrigin origin) { } } // namespace -UnixFileStream::UnixFileStream(const char *path, int oflag) { - file_descriptor_ = ::open(path, oflag); +UnixFileStream::UnixFileStream(const char *path, int oflag, mode_t mode) { + file_descriptor_ = ::open(path, oflag, mode); if (file_descriptor_ == -1) { - throw ErrnoException(Format(u"Failed to open file {} with oflag {}.", - String::FromUtf8(path), oflag)); + throw ErrnoException( + Format(u"Failed to open file {} with oflag {}, mode {}.", + String::FromUtf8(path), oflag, mode)); } can_seek_ = OflagCanSeek(oflag); |