aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/deprecated/fgood/fgood.cpp
diff options
context:
space:
mode:
authorvitalyisaev <vitalyisaev@ydb.tech>2023-11-30 13:26:22 +0300
committervitalyisaev <vitalyisaev@ydb.tech>2023-11-30 15:44:45 +0300
commit0a98fece5a9b54f16afeb3a94b3eb3105e9c3962 (patch)
tree291d72dbd7e9865399f668c84d11ed86fb190bbf /library/cpp/deprecated/fgood/fgood.cpp
parentcb2c8d75065e5b3c47094067cb4aa407d4813298 (diff)
downloadydb-0a98fece5a9b54f16afeb3a94b3eb3105e9c3962.tar.gz
YQ Connector:Use docker-compose in integrational tests
Diffstat (limited to 'library/cpp/deprecated/fgood/fgood.cpp')
-rw-r--r--library/cpp/deprecated/fgood/fgood.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/library/cpp/deprecated/fgood/fgood.cpp b/library/cpp/deprecated/fgood/fgood.cpp
new file mode 100644
index 0000000000..5d4725bfae
--- /dev/null
+++ b/library/cpp/deprecated/fgood/fgood.cpp
@@ -0,0 +1,70 @@
+#include "fgood.h"
+
+#include <util/generic/cast.h>
+#include <util/string/cast.h>
+#include <util/system/fstat.h>
+
+#ifdef _win32_
+#include <io.h>
+#endif
+
+i64 TFILEPtr::length() const {
+#ifdef _win32_
+ FHANDLE fd = (FHANDLE)_get_osfhandle(fileno(m_file));
+#else
+ FHANDLE fd = fileno(m_file);
+#endif
+ i64 rv = GetFileLength(fd);
+ if (rv < 0)
+ ythrow yexception() << "TFILEPtr::length() " << Name.data() << ": " << LastSystemErrorText();
+ return rv;
+}
+
+FILE* OpenFILEOrFail(const TString& name, const char* mode) {
+ FILE* res = ::fopen(name.data(), mode);
+ if (!res) {
+ ythrow yexception() << "can't open \'" << name << "\' with mode \'" << mode << "\': " << LastSystemErrorText();
+ }
+ return res;
+}
+
+void TFILECloser::Destroy(FILE* file) {
+ ::fclose(file);
+}
+
+#ifdef _freebsd_ // fgetln
+#define getline getline_alt_4test
+#endif // _freebsd_
+
+bool getline(TFILEPtr& f, TString& s) {
+ char buf[4096];
+ char* buf_ptr;
+ if (s.capacity() > sizeof(buf)) {
+ s.resize(s.capacity());
+ if ((buf_ptr = fgets(s.begin(), IntegerCast<int>(s.capacity()), f)) == nullptr)
+ return false;
+ } else {
+ if ((buf_ptr = fgets(buf, sizeof(buf), f)) == nullptr)
+ return false;
+ }
+ size_t buf_len = strlen(buf_ptr);
+ bool line_complete = buf_len && buf_ptr[buf_len - 1] == '\n';
+ if (line_complete)
+ buf_len--;
+ if (buf_ptr == s.begin())
+ s.resize(buf_len);
+ else
+ s.AssignNoAlias(buf, buf_len);
+ if (line_complete)
+ return true;
+ while (fgets(buf, sizeof(buf), f)) {
+ size_t buf_len2 = strlen(buf);
+ if (buf_len2 && buf[buf_len2 - 1] == '\n') {
+ buf[buf_len2 - 1] = 0;
+ s.append(buf, buf_len2 - 1);
+ return true;
+ }
+ s.append(buf, buf_len2);
+ }
+ return true;
+}