diff options
author | myltsev <myltsev@yandex-team.ru> | 2022-02-10 16:46:03 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:03 +0300 |
commit | 9166d66c30c23c9e85a7c88185a068987148d23f (patch) | |
tree | 421bdcec5755d9e441c485560aab5ab8d74c7475 /util | |
parent | 8d3a5ed3a188a34167eaee54f1691ce5c9edf2f3 (diff) | |
download | ydb-9166d66c30c23c9e85a7c88185a068987148d23f.tar.gz |
Restoring authorship annotation for <myltsev@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util')
-rw-r--r-- | util/charset/wide_ut.cpp | 18 | ||||
-rw-r--r-- | util/draft/datetime.h | 2 | ||||
-rw-r--r-- | util/generic/mapfindptr.h | 8 | ||||
-rw-r--r-- | util/generic/mapfindptr_ut.cpp | 10 | ||||
-rw-r--r-- | util/generic/strbuf.h | 10 | ||||
-rw-r--r-- | util/generic/strbuf_ut.cpp | 20 | ||||
-rw-r--r-- | util/generic/string_ut.cpp | 2 | ||||
-rw-r--r-- | util/stream/file.cpp | 2 | ||||
-rw-r--r-- | util/stream/file_ut.cpp | 30 | ||||
-rw-r--r-- | util/stream/mem.cpp | 4 | ||||
-rw-r--r-- | util/stream/str.h | 22 | ||||
-rw-r--r-- | util/stream/zlib.cpp | 48 | ||||
-rw-r--r-- | util/stream/zlib.h | 6 | ||||
-rw-r--r-- | util/stream/zlib_ut.cpp | 26 | ||||
-rw-r--r-- | util/system/file.cpp | 66 | ||||
-rw-r--r-- | util/system/file.h | 28 | ||||
-rw-r--r-- | util/system/filemap.cpp | 12 | ||||
-rw-r--r-- | util/system/fstat.cpp | 22 | ||||
-rw-r--r-- | util/system/tempfile.cpp | 20 | ||||
-rw-r--r-- | util/system/tempfile.h | 8 | ||||
-rw-r--r-- | util/system/tempfile_ut.cpp | 28 |
21 files changed, 196 insertions, 196 deletions
diff --git a/util/charset/wide_ut.cpp b/util/charset/wide_ut.cpp index d8f3233e73..d24d8ceb87 100644 --- a/util/charset/wide_ut.cpp +++ b/util/charset/wide_ut.cpp @@ -193,7 +193,7 @@ public: void TestUTF8ToWide(); void TestWideToUTF8(); void TestGetNumOfUTF8Chars(); - void TestSubstrUTF8(); + void TestSubstrUTF8(); void TestUnicodeCase(); void TestUnicodeDetails(); void TestHexConversion(); @@ -549,14 +549,14 @@ void TConversionTest::TestGetNumOfUTF8Chars() { UNIT_ASSERT_EQUAL(GetNumberOfUTF8Chars("привет!"), 7); } -void TConversionTest::TestSubstrUTF8() { - TStringBuf utextBuf(utext, sizeof(utext)); - UNIT_ASSERT(SubstrUTF8(utextBuf, 0, 2) == utextBuf.substr(0, 4)); - UNIT_ASSERT(SubstrUTF8(utextBuf, 1, 1) == utextBuf.substr(2, 2)); - UNIT_ASSERT(SubstrUTF8(utextBuf, 1, 2) == utextBuf.substr(2, 4)); - UNIT_ASSERT(SubstrUTF8(utextBuf, 1, 3) == utextBuf.substr(2, 6)); -} - +void TConversionTest::TestSubstrUTF8() { + TStringBuf utextBuf(utext, sizeof(utext)); + UNIT_ASSERT(SubstrUTF8(utextBuf, 0, 2) == utextBuf.substr(0, 4)); + UNIT_ASSERT(SubstrUTF8(utextBuf, 1, 1) == utextBuf.substr(2, 2)); + UNIT_ASSERT(SubstrUTF8(utextBuf, 1, 2) == utextBuf.substr(2, 4)); + UNIT_ASSERT(SubstrUTF8(utextBuf, 1, 3) == utextBuf.substr(2, 6)); +} + inline bool MustBeSurrogate(wchar32 ch) { return ch > 0xFFFF; } diff --git a/util/draft/datetime.h b/util/draft/datetime.h index 8a387ea6f1..df814d26da 100644 --- a/util/draft/datetime.h +++ b/util/draft/datetime.h @@ -138,7 +138,7 @@ inline TString date2str(const time_t date) { memset(&dateTm, 0, sizeof(dateTm)); localtime_r(&date, &dateTm); char buf[9]; - strftime(buf, sizeof(buf), "%Y%m%d", &dateTm); + strftime(buf, sizeof(buf), "%Y%m%d", &dateTm); return TString(buf); } diff --git a/util/generic/mapfindptr.h b/util/generic/mapfindptr.h index bc10cac60f..98aad17984 100644 --- a/util/generic/mapfindptr.h +++ b/util/generic/mapfindptr.h @@ -36,14 +36,14 @@ struct TMapOps { inline auto FindPtr(const K& key) const { return MapFindPtr(static_cast<const Derived&>(*this), key); } - + template <class K, class DefaultValue> inline auto Value(const K& key, const DefaultValue& defaultValue) const -> std::remove_reference_t<decltype(*this->FindPtr(key))> { if (auto found = FindPtr(key)) { - return *found; - } + return *found; + } return defaultValue; - } + } template <class K, class V> inline const V& ValueRef(const K& key, V& defaultValue) const { diff --git a/util/generic/mapfindptr_ut.cpp b/util/generic/mapfindptr_ut.cpp index 613da7a96b..52a7c23794 100644 --- a/util/generic/mapfindptr_ut.cpp +++ b/util/generic/mapfindptr_ut.cpp @@ -29,9 +29,9 @@ Y_UNIT_TEST_SUITE(TMapFindPtrTest) { const TTestMap& b = a; UNIT_ASSERT(b.FindPtr(42) && *b.FindPtr(42) == "dog"); UNIT_ASSERT_EQUAL(b.FindPtr(0), nullptr); - - UNIT_ASSERT_STRINGS_EQUAL(b.Value(42, "cat"), "dog"); - UNIT_ASSERT_STRINGS_EQUAL(b.Value(0, "alien"), "alien"); + + UNIT_ASSERT_STRINGS_EQUAL(b.Value(42, "cat"), "dog"); + UNIT_ASSERT_STRINGS_EQUAL(b.Value(0, "alien"), "alien"); } Y_UNIT_TEST(TestTemplateFind) { @@ -39,8 +39,8 @@ Y_UNIT_TEST_SUITE(TMapFindPtrTest) { m[TString("x")] = 2; - UNIT_ASSERT(m.FindPtr(TStringBuf("x"))); - UNIT_ASSERT_EQUAL(*m.FindPtr(TStringBuf("x")), 2); + UNIT_ASSERT(m.FindPtr(TStringBuf("x"))); + UNIT_ASSERT_EQUAL(*m.FindPtr(TStringBuf("x")), 2); } Y_UNIT_TEST(TestValue) { diff --git a/util/generic/strbuf.h b/util/generic/strbuf.h index 70b9360d58..f1b4e654c5 100644 --- a/util/generic/strbuf.h +++ b/util/generic/strbuf.h @@ -303,20 +303,20 @@ public: } Y_PURE_FUNCTION inline TdSelf Before(TCharType c) const noexcept { - TdSelf l, r; + TdSelf l, r; return TrySplit(c, l, r) ? l : *this; } - + Y_PURE_FUNCTION inline TdSelf RAfter(TCharType c) const noexcept { TdSelf l, r; return TryRSplit(c, l, r) ? r : *this; } Y_PURE_FUNCTION inline TdSelf RBefore(TCharType c) const noexcept { - TdSelf l, r; + TdSelf l, r; return TryRSplit(c, l, r) ? l : *this; - } - + } + public: inline bool AfterPrefix(const TdSelf& prefix, TdSelf& result) const noexcept { if (this->StartsWith(prefix)) { diff --git a/util/generic/strbuf_ut.cpp b/util/generic/strbuf_ut.cpp index 69cde785af..695ca33b06 100644 --- a/util/generic/strbuf_ut.cpp +++ b/util/generic/strbuf_ut.cpp @@ -55,7 +55,7 @@ Y_UNIT_TEST_SUITE(TStrBufTest) { UNIT_ASSERT_VALUES_EQUAL(str.After('w'), TStringBuf("erty")); UNIT_ASSERT_VALUES_EQUAL(str.After('x'), TStringBuf("qwerty")); UNIT_ASSERT_VALUES_EQUAL(str.After('y'), TStringBuf()); - UNIT_ASSERT_STRINGS_EQUAL(str.After('='), str); + UNIT_ASSERT_STRINGS_EQUAL(str.After('='), str); // Also works properly on empty strings TStringBuf empty; @@ -72,15 +72,15 @@ Y_UNIT_TEST_SUITE(TStrBufTest) { } Y_UNIT_TEST(TestRAfterBefore) { - TStringBuf str("a/b/c"); - UNIT_ASSERT_STRINGS_EQUAL(str.RAfter('/'), "c"); - UNIT_ASSERT_STRINGS_EQUAL(str.RAfter('_'), str); - UNIT_ASSERT_STRINGS_EQUAL(str.RAfter('a'), "/b/c"); - UNIT_ASSERT_STRINGS_EQUAL(str.RBefore('/'), "a/b"); - UNIT_ASSERT_STRINGS_EQUAL(str.RBefore('_'), str); - UNIT_ASSERT_STRINGS_EQUAL(str.RBefore('a'), ""); - } - + TStringBuf str("a/b/c"); + UNIT_ASSERT_STRINGS_EQUAL(str.RAfter('/'), "c"); + UNIT_ASSERT_STRINGS_EQUAL(str.RAfter('_'), str); + UNIT_ASSERT_STRINGS_EQUAL(str.RAfter('a'), "/b/c"); + UNIT_ASSERT_STRINGS_EQUAL(str.RBefore('/'), "a/b"); + UNIT_ASSERT_STRINGS_EQUAL(str.RBefore('_'), str); + UNIT_ASSERT_STRINGS_EQUAL(str.RBefore('a'), ""); + } + Y_UNIT_TEST(TestAfterPrefix) { TStringBuf str("cat_dog"); diff --git a/util/generic/string_ut.cpp b/util/generic/string_ut.cpp index ac82e9091d..775e571b42 100644 --- a/util/generic/string_ut.cpp +++ b/util/generic/string_ut.cpp @@ -32,7 +32,7 @@ public: UNIT_ASSERT(s.size() == sizeof(data)); UNIT_ASSERT(s.StartsWith(s)); UNIT_ASSERT(s.EndsWith(s)); - UNIT_ASSERT(s.Contains('\0')); + UNIT_ASSERT(s.Contains('\0')); const char raw_def[] = "def"; const char raw_zero[] = "\0"; diff --git a/util/stream/file.cpp b/util/stream/file.cpp index dc5d2f6311..895e627966 100644 --- a/util/stream/file.cpp +++ b/util/stream/file.cpp @@ -20,7 +20,7 @@ TUnbufferedFileInput::TUnbufferedFileInput(const TFile& file) } size_t TUnbufferedFileInput::DoRead(void* buf, size_t len) { - return File_.ReadOrFail(buf, len); + return File_.ReadOrFail(buf, len); } size_t TUnbufferedFileInput::DoSkip(size_t len) { diff --git a/util/stream/file_ut.cpp b/util/stream/file_ut.cpp index ac0f09796e..7780a72e04 100644 --- a/util/stream/file_ut.cpp +++ b/util/stream/file_ut.cpp @@ -56,19 +56,19 @@ Y_UNIT_TEST_SUITE(TFileTest) { UNIT_ASSERT(s.empty()); } } - -#ifdef _unix_ - Y_UNIT_TEST(PipeReadLineTest) { - int fds[2]; - UNIT_ASSERT(pipe(fds) == 0); - TFile readEnd(fds[0]); - TFileInput fileInput(readEnd); - UNIT_ASSERT_VALUES_EQUAL(write(fds[1], "hello\n", 6), 6); - - TString line; - UNIT_ASSERT(fileInput.ReadLine(line)); - UNIT_ASSERT_STRINGS_EQUAL(line, "hello"); - close(fds[1]); - } -#endif + +#ifdef _unix_ + Y_UNIT_TEST(PipeReadLineTest) { + int fds[2]; + UNIT_ASSERT(pipe(fds) == 0); + TFile readEnd(fds[0]); + TFileInput fileInput(readEnd); + UNIT_ASSERT_VALUES_EQUAL(write(fds[1], "hello\n", 6), 6); + + TString line; + UNIT_ASSERT(fileInput.ReadLine(line)); + UNIT_ASSERT_STRINGS_EQUAL(line, "hello"); + close(fds[1]); + } +#endif } diff --git a/util/stream/mem.cpp b/util/stream/mem.cpp index 22a3339e27..31b46e907f 100644 --- a/util/stream/mem.cpp +++ b/util/stream/mem.cpp @@ -18,8 +18,8 @@ TMemoryInput::TMemoryInput(const TStringBuf buf) noexcept : Buf_(buf.data()) , Len_(buf.size()) { -} - +} + TMemoryInput::~TMemoryInput() = default; size_t TMemoryInput::DoNext(const void** ptr, size_t len) { diff --git a/util/stream/str.h b/util/stream/str.h index 028bd572c0..adac7ec4bc 100644 --- a/util/stream/str.h +++ b/util/stream/str.h @@ -26,7 +26,7 @@ public: * this stream is in use. * * For reading data from `TStringBuf`s, see `TMemoryInput` (`util/stream/mem.h`). - * + * * @param s String to read from. */ inline TStringInput(const TString& s) noexcept @@ -108,27 +108,27 @@ private: * String input/output stream, similar to `std::stringstream`. */ class TStringStream: private TEmbedPolicy<TString>, public TStringInput, public TStringOutput { - using TEmbeddedString = TEmbedPolicy<TString>; + using TEmbeddedString = TEmbedPolicy<TString>; public: inline TStringStream() - : TEmbeddedString() - , TStringInput(*TEmbeddedString::Ptr()) - , TStringOutput(*TEmbeddedString::Ptr()) + : TEmbeddedString() + , TStringInput(*TEmbeddedString::Ptr()) + , TStringOutput(*TEmbeddedString::Ptr()) { } inline TStringStream(const TString& string) - : TEmbeddedString(string) - , TStringInput(*TEmbeddedString::Ptr()) - , TStringOutput(*TEmbeddedString::Ptr()) + : TEmbeddedString(string) + , TStringInput(*TEmbeddedString::Ptr()) + , TStringOutput(*TEmbeddedString::Ptr()) { } inline TStringStream(const TStringStream& other) - : TEmbeddedString(other.Str()) - , TStringInput(*TEmbeddedString::Ptr()) - , TStringOutput(*TEmbeddedString::Ptr()) + : TEmbeddedString(other.Str()) + , TStringInput(*TEmbeddedString::Ptr()) + , TStringOutput(*TEmbeddedString::Ptr()) { } diff --git a/util/stream/zlib.cpp b/util/stream/zlib.cpp index 60f4e9439f..a9fe352239 100644 --- a/util/stream/zlib.cpp +++ b/util/stream/zlib.cpp @@ -80,17 +80,17 @@ namespace { class TZLibDecompress::TImpl: private TZLibCommon, public TChunkedZeroCopyInput { public: - inline TImpl(IZeroCopyInput* in, ZLib::StreamType type, TStringBuf dict) + inline TImpl(IZeroCopyInput* in, ZLib::StreamType type, TStringBuf dict) : TChunkedZeroCopyInput(in) - , Dict(dict) + , Dict(dict) { if (inflateInit2(Z(), opts[type]) != Z_OK) { ythrow TZLibDecompressorError() << "can not init inflate engine"; } - - if (dict.size() && type == ZLib::Raw) { - SetDict(); - } + + if (dict.size() && type == ZLib::Raw) { + SetDict(); + } } virtual ~TImpl() { @@ -113,11 +113,11 @@ public: } switch (inflate(Z(), Z_SYNC_FLUSH)) { - case Z_NEED_DICT: { - SetDict(); - continue; - } - + case Z_NEED_DICT: { + SetDict(); + continue; + } + case Z_STREAM_END: { if (AllowMultipleStreams_) { if (inflateReset(Z()) != Z_OK) { @@ -151,21 +151,21 @@ private: return Next(&Z()->next_in, &Z()->avail_in); } - void SetDict() { - if (inflateSetDictionary(Z(), (const Bytef*)Dict.data(), Dict.size()) != Z_OK) { - ythrow TZLibCompressorError() << "can not set inflate dictionary"; - } - } - + void SetDict() { + if (inflateSetDictionary(Z(), (const Bytef*)Dict.data(), Dict.size()) != Z_OK) { + ythrow TZLibCompressorError() << "can not set inflate dictionary"; + } + } + bool AllowMultipleStreams_ = true; - TStringBuf Dict; + TStringBuf Dict; }; namespace { class TDecompressStream: public IZeroCopyInput, public TZLibDecompress::TImpl, public TAdditionalStorage<TDecompressStream> { public: - inline TDecompressStream(IInputStream* input, ZLib::StreamType type, TStringBuf dict) - : TZLibDecompress::TImpl(this, type, dict) + inline TDecompressStream(IInputStream* input, ZLib::StreamType type, TStringBuf dict) + : TZLibDecompress::TImpl(this, type, dict) , Stream_(input) { } @@ -318,13 +318,13 @@ private: THolder<gz_header> GZHeader_; }; -TZLibDecompress::TZLibDecompress(IZeroCopyInput* input, ZLib::StreamType type, TStringBuf dict) - : Impl_(new TZeroCopyDecompress(input, type, dict)) +TZLibDecompress::TZLibDecompress(IZeroCopyInput* input, ZLib::StreamType type, TStringBuf dict) + : Impl_(new TZeroCopyDecompress(input, type, dict)) { } -TZLibDecompress::TZLibDecompress(IInputStream* input, ZLib::StreamType type, size_t buflen, TStringBuf dict) - : Impl_(new (buflen) TDecompressStream(input, type, dict)) +TZLibDecompress::TZLibDecompress(IInputStream* input, ZLib::StreamType type, size_t buflen, TStringBuf dict) + : Impl_(new (buflen) TDecompressStream(input, type, dict)) { } diff --git a/util/stream/zlib.h b/util/stream/zlib.h index e7de7c81b7..ead8c1e013 100644 --- a/util/stream/zlib.h +++ b/util/stream/zlib.h @@ -47,9 +47,9 @@ namespace ZLib { */ class TZLibDecompress: public IInputStream { public: - TZLibDecompress(IZeroCopyInput* input, ZLib::StreamType type = ZLib::Auto, TStringBuf dict = {}); - TZLibDecompress(IInputStream* input, ZLib::StreamType type = ZLib::Auto, size_t buflen = ZLib::ZLIB_BUF_LEN, - TStringBuf dict = {}); + TZLibDecompress(IZeroCopyInput* input, ZLib::StreamType type = ZLib::Auto, TStringBuf dict = {}); + TZLibDecompress(IInputStream* input, ZLib::StreamType type = ZLib::Auto, size_t buflen = ZLib::ZLIB_BUF_LEN, + TStringBuf dict = {}); /** * Allows/disallows multiple sequential compressed streams. Allowed by default. diff --git a/util/stream/zlib_ut.cpp b/util/stream/zlib_ut.cpp index 2290b4a9de..15f77f3ce4 100644 --- a/util/stream/zlib_ut.cpp +++ b/util/stream/zlib_ut.cpp @@ -75,21 +75,21 @@ Y_UNIT_TEST_SUITE(TZLibTest) { } } - Y_UNIT_TEST(Dictionary) { + Y_UNIT_TEST(Dictionary) { static constexpr TStringBuf data = "<html><body></body></html>"; static constexpr TStringBuf dict = "</<html><body>"; - for (auto type : {ZLib::Raw, ZLib::ZLib}) { - TStringStream compressed; - { - TZLibCompress compressor(TZLibCompress::TParams(&compressed).SetDict(dict).SetType(type)); - compressor.Write(data); - } - - TZLibDecompress decompressor(&compressed, type, ZLib::ZLIB_BUF_LEN, dict); - UNIT_ASSERT_STRINGS_EQUAL(decompressor.ReadAll(), data); - } - } - + for (auto type : {ZLib::Raw, ZLib::ZLib}) { + TStringStream compressed; + { + TZLibCompress compressor(TZLibCompress::TParams(&compressed).SetDict(dict).SetType(type)); + compressor.Write(data); + } + + TZLibDecompress decompressor(&compressed, type, ZLib::ZLIB_BUF_LEN, dict); + UNIT_ASSERT_STRINGS_EQUAL(decompressor.ReadAll(), data); + } + } + Y_UNIT_TEST(DecompressTwoStreams) { // Check that Decompress(Compress(X) + Compress(Y)) == X + Y TTempFile tmpFile(ZDATA); diff --git a/util/system/file.cpp b/util/system/file.cpp index 4a261d020c..b468d2cfb4 100644 --- a/util/system/file.cpp +++ b/util/system/file.cpp @@ -16,7 +16,7 @@ #include <util/random/random.h> -#include <util/generic/size_literals.h> +#include <util/generic/size_literals.h> #include <util/generic/string.h> #include <util/generic/ylimits.h> #include <util/generic/yexception.h> @@ -932,31 +932,31 @@ public: return res; } - // Maximum amount of bytes to be read via single system call. - // Some libraries fail when it is greater than max int. - // Syscalls can cause contention if they operate on very large data blocks. - static constexpr size_t MaxReadPortion = 1_GB; - + // Maximum amount of bytes to be read via single system call. + // Some libraries fail when it is greater than max int. + // Syscalls can cause contention if they operate on very large data blocks. + static constexpr size_t MaxReadPortion = 1_GB; + i32 RawRead(void* bufferIn, size_t numBytes) { - const size_t toRead = Min(MaxReadPortion, numBytes); - return Handle_.Read(bufferIn, toRead); - } - - size_t ReadOrFail(void* buf, size_t numBytes) { - const i32 reallyRead = RawRead(buf, numBytes); - - if (reallyRead < 0) { - ythrow TFileError() << "can not read data from " << FileName_.Quote(); - } - - return reallyRead; - } - + const size_t toRead = Min(MaxReadPortion, numBytes); + return Handle_.Read(bufferIn, toRead); + } + + size_t ReadOrFail(void* buf, size_t numBytes) { + const i32 reallyRead = RawRead(buf, numBytes); + + if (reallyRead < 0) { + ythrow TFileError() << "can not read data from " << FileName_.Quote(); + } + + return reallyRead; + } + size_t Read(void* bufferIn, size_t numBytes) { ui8* buf = (ui8*)bufferIn; while (numBytes) { - const size_t reallyRead = ReadOrFail(buf, numBytes); + const size_t reallyRead = ReadOrFail(buf, numBytes); if (reallyRead == 0) { // file exhausted @@ -976,16 +976,16 @@ public: } } - // Maximum amount of bytes to be written via single system call. - // Some libraries fail when it is greater than max int. - // Syscalls can cause contention if they operate on very large data blocks. - static constexpr size_t MaxWritePortion = 1_GB; - + // Maximum amount of bytes to be written via single system call. + // Some libraries fail when it is greater than max int. + // Syscalls can cause contention if they operate on very large data blocks. + static constexpr size_t MaxWritePortion = 1_GB; + void Write(const void* buffer, size_t numBytes) { const ui8* buf = (const ui8*)buffer; while (numBytes) { - const i32 toWrite = (i32)Min(MaxWritePortion, numBytes); + const i32 toWrite = (i32)Min(MaxWritePortion, numBytes); const i32 reallyWritten = Handle_.Write(buf, toWrite); if (reallyWritten < 0) { @@ -1001,7 +1001,7 @@ public: ui8* buf = (ui8*)bufferIn; while (numBytes) { - const i32 toRead = (i32)Min(MaxReadPortion, numBytes); + const i32 toRead = (i32)Min(MaxReadPortion, numBytes); const i32 reallyRead = RawPread(buf, toRead, offset); if (reallyRead < 0) { @@ -1035,7 +1035,7 @@ public: const ui8* buf = (const ui8*)buffer; while (numBytes) { - const i32 toWrite = (i32)Min(MaxWritePortion, numBytes); + const i32 toWrite = (i32)Min(MaxWritePortion, numBytes); const i32 reallyWritten = Handle_.Pwrite(buf, toWrite, offset); if (reallyWritten < 0) { @@ -1175,10 +1175,10 @@ i32 TFile::RawRead(void* buf, size_t len) { return Impl_->RawRead(buf, len); } -size_t TFile::ReadOrFail(void* buf, size_t len) { - return Impl_->ReadOrFail(buf, len); -} - +size_t TFile::ReadOrFail(void* buf, size_t len) { + return Impl_->ReadOrFail(buf, len); +} + void TFile::Load(void* buf, size_t len) { Impl_->Load(buf, len); } diff --git a/util/system/file.h b/util/system/file.h index 9502e159b6..62622501c9 100644 --- a/util/system/file.h +++ b/util/system/file.h @@ -172,28 +172,28 @@ public: void LinkTo(const TFile& f) const; TFile Duplicate() const; - // Reads up to 1 GB without retrying, returns -1 on error - i32 RawRead(void* buf, size_t len); - // Reads up to 1 GB without retrying, throws on error - size_t ReadOrFail(void* buf, size_t len); - // Retries incomplete reads until EOF, throws on error + // Reads up to 1 GB without retrying, returns -1 on error + i32 RawRead(void* buf, size_t len); + // Reads up to 1 GB without retrying, throws on error + size_t ReadOrFail(void* buf, size_t len); + // Retries incomplete reads until EOF, throws on error size_t Read(void* buf, size_t len); - // Reads exactly len bytes, throws on premature EOF or error + // Reads exactly len bytes, throws on premature EOF or error void Load(void* buf, size_t len); - - // Retries incomplete writes, will either write len bytes or throw + + // Retries incomplete writes, will either write len bytes or throw void Write(const void* buf, size_t len); - - // Retries incomplete reads until EOF, throws on error + + // Retries incomplete reads until EOF, throws on error size_t Pread(void* buf, size_t len, i64 offset) const; // Single pread call i32 RawPread(void* buf, ui32 len, i64 offset) const; - // Reads exactly len bytes, throws on premature EOF or error + // Reads exactly len bytes, throws on premature EOF or error void Pload(void* buf, size_t len, i64 offset) const; - - // Retries incomplete writes, will either write len bytes or throw + + // Retries incomplete writes, will either write len bytes or throw void Pwrite(const void* buf, size_t len, i64 offset) const; - + void Flock(int op); //do not use, their meaning very platform-dependant diff --git a/util/system/filemap.cpp b/util/system/filemap.cpp index 7454a4cb94..7cd3a9b42f 100644 --- a/util/system/filemap.cpp +++ b/util/system/filemap.cpp @@ -153,14 +153,14 @@ public: } void CheckFile() const { - if (!File_.IsOpen()) { + if (!File_.IsOpen()) { ythrow yexception() << "TMemoryMap: FILE '" << DbgName_ << "' is not open, " << LastSystemErrorText(); - } - if (Length_ < 0) { + } + if (Length_ < 0) { ythrow yexception() << "'" << DbgName_ << "' is not a regular file"; - } - } - + } + } + inline TImpl(FILE* f, EOpenMode om, TString dbgName) : File_(Duplicate(f)) , DbgName_(std::move(dbgName)) diff --git a/util/system/fstat.cpp b/util/system/fstat.cpp index 81e98cbc6b..cadd0f4540 100644 --- a/util/system/fstat.cpp +++ b/util/system/fstat.cpp @@ -6,7 +6,7 @@ #include <util/folder/path.h> #include <cerrno> - + #if defined(_win_) #include "fs_win.h" @@ -174,11 +174,11 @@ i64 GetFileLength(FHANDLE fd) { if (::fstat(fd, &statbuf) != 0) { return -1L; } - if (!(statbuf.st_mode & (S_IFREG | S_IFBLK | S_IFCHR))) { - // st_size only makes sense for regular files or devices - errno = EINVAL; - return -1L; - } + if (!(statbuf.st_mode & (S_IFREG | S_IFBLK | S_IFCHR))) { + // st_size only makes sense for regular files or devices + errno = EINVAL; + return -1L; + } return statbuf.st_size; #else #error unsupported platform @@ -199,11 +199,11 @@ i64 GetFileLength(const char* name) { if (r == -1) { return -1; } - if (!(buf.st_mode & (S_IFREG | S_IFBLK | S_IFCHR))) { - // st_size only makes sense for regular files or devices - errno = EINVAL; - return -1; - } + if (!(buf.st_mode & (S_IFREG | S_IFBLK | S_IFCHR))) { + // st_size only makes sense for regular files or devices + errno = EINVAL; + return -1; + } return (i64)buf.st_size; #else #error unsupported platform diff --git a/util/system/tempfile.cpp b/util/system/tempfile.cpp index a2e9f49eb1..74a64f854d 100644 --- a/util/system/tempfile.cpp +++ b/util/system/tempfile.cpp @@ -1,20 +1,20 @@ -#include "tempfile.h" - +#include "tempfile.h" + TTempFileHandle::TTempFileHandle() : TTempFile(MakeTempName()) , TFile(CreateFile()) { -} - +} + TTempFileHandle::TTempFileHandle(const TString& fname) - : TTempFile(fname) - , TFile(CreateFile()) -{ -} - + : TTempFile(fname) + , TFile(CreateFile()) +{ +} + TTempFileHandle TTempFileHandle::InCurrentDir(const TString& filePrefix, const TString& extension) { return TTempFileHandle(MakeTempName(".", filePrefix.c_str(), extension.c_str())); -} +} TTempFileHandle TTempFileHandle::InDir(const TFsPath& dirPath, const TString& filePrefix, const TString& extension) { return TTempFileHandle(MakeTempName(dirPath.c_str(), filePrefix.c_str(), extension.c_str())); diff --git a/util/system/tempfile.h b/util/system/tempfile.h index de249c129d..9bde1c669f 100644 --- a/util/system/tempfile.h +++ b/util/system/tempfile.h @@ -27,14 +27,14 @@ private: class TTempFileHandle: public TTempFile, public TFile { public: - TTempFileHandle(); + TTempFileHandle(); TTempFileHandle(const TString& fname); - + static TTempFileHandle InCurrentDir(const TString& filePrefix = "yandex", const TString& extension = "tmp"); static TTempFileHandle InDir(const TFsPath& dirPath, const TString& filePrefix = "yandex", const TString& extension = "tmp"); -private: - TFile CreateFile() const; +private: + TFile CreateFile() const; }; /* diff --git a/util/system/tempfile_ut.cpp b/util/system/tempfile_ut.cpp index e4a0923d0b..6f749d4e0e 100644 --- a/util/system/tempfile_ut.cpp +++ b/util/system/tempfile_ut.cpp @@ -1,25 +1,25 @@ -#include "tempfile.h" - +#include "tempfile.h" + #include <library/cpp/testing/unittest/registar.h> - -#include <util/folder/dirut.h> + +#include <util/folder/dirut.h> #include <util/generic/yexception.h> -#include <util/stream/file.h> - +#include <util/stream/file.h> + #include <algorithm> Y_UNIT_TEST_SUITE(TTempFileHandle) { Y_UNIT_TEST(Create) { TString path; - { - TTempFileHandle tmp; - path = tmp.Name(); - tmp.Write("hello world\n", 12); - tmp.FlushData(); + { + TTempFileHandle tmp; + path = tmp.Name(); + tmp.Write("hello world\n", 12); + tmp.FlushData(); UNIT_ASSERT_STRINGS_EQUAL(TUnbufferedFileInput(tmp.Name()).ReadAll(), "hello world\n"); - } + } UNIT_ASSERT(!NFs::Exists(path)); - } + } Y_UNIT_TEST(InCurrentDir) { #ifndef _win32_ @@ -115,7 +115,7 @@ Y_UNIT_TEST_SUITE(TTempFileHandle) { Y_UNIT_TEST(NonExistingDirectory) { UNIT_ASSERT_EXCEPTION(TTempFileHandle::InDir("nonexsistingdirname"), TSystemError); } -} +} Y_UNIT_TEST_SUITE(MakeTempName) { Y_UNIT_TEST(Default) { |