aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorleo <leo@yandex-team.ru>2022-02-10 16:46:40 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:40 +0300
commit980edcd3304699edf9d4e4d6a656e585028e2a72 (patch)
tree139f47f3911484ae9af0eb347b1a88bd6c4bb35f
parentb036a557f285146e5e35d4213e29a094ab907bcf (diff)
downloadydb-980edcd3304699edf9d4e4d6a656e585028e2a72.tar.gz
Restoring authorship annotation for <leo@yandex-team.ru>. Commit 1 of 2.
-rw-r--r--contrib/libs/jemalloc/spinlock.h4
-rw-r--r--contrib/libs/libidn/nfkc.c12
-rw-r--r--contrib/libs/pcre/pcre_internal.h6
-rw-r--r--contrib/libs/pcre/ya.make6
-rw-r--r--contrib/libs/pire/pire/fsm.h2
-rw-r--r--contrib/libs/pire/pire/glue.h2
-rw-r--r--contrib/libs/pire/pire/scanners/common.h2
-rw-r--r--contrib/libs/pire/pire/scanners/loaded.h2
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/config.h2
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/math.h12
-rw-r--r--contrib/tools/bison/gnulib/platform/win64/stdint.h.disabled18
-rw-r--r--contrib/tools/bison/gnulib/src/bison-system.h6
-rw-r--r--contrib/tools/bison/gnulib/src/c-stack.c6
-rw-r--r--contrib/tools/bison/gnulib/src/perror.c2
-rw-r--r--contrib/tools/bison/gnulib/src/snprintf.c6
-rw-r--r--contrib/tools/bison/gnulib/src/vasnprintf.c6
-rw-r--r--contrib/tools/bison/gnulib/src/vasprintf.c6
-rw-r--r--contrib/tools/bison/gnulib/src/xvasprintf.c6
-rw-r--r--contrib/tools/bison/gnulib/ya.make12
-rw-r--r--contrib/tools/ragel6/main.cpp10
-rw-r--r--contrib/tools/ragel6/rlscan.cpp10
-rw-r--r--contrib/tools/ragel6/rlscan.rl10
-rw-r--r--library/cpp/actors/dnscachelib/dnscache.cpp2
-rw-r--r--library/cpp/archive/yarchive_ut.cpp4
-rw-r--r--library/cpp/blockcodecs/core/stream.h2
-rw-r--r--library/cpp/charset/codepage.cpp4
-rw-r--r--library/cpp/charset/codepage.h10
-rw-r--r--library/cpp/charset/codepage_ut.cpp4
-rw-r--r--library/cpp/charset/doccodes.h4
-rw-r--r--library/cpp/charset/recyr.hh10
-rw-r--r--library/cpp/charset/ya.make4
-rw-r--r--library/cpp/codecs/greedy_dict/ut/greedy_dict_ut.cpp2
-rw-r--r--library/cpp/containers/2d_array/2d_array.h150
-rw-r--r--library/cpp/containers/atomizer/atomizer.h154
-rw-r--r--library/cpp/containers/comptrie/comptrie_builder.inl2
-rw-r--r--library/cpp/containers/str_map/str_map.h202
-rw-r--r--library/cpp/coroutine/engine/coroutine_ut.cpp4
-rw-r--r--library/cpp/coroutine/engine/poller.h2
-rw-r--r--library/cpp/coroutine/listener/listen.h4
-rw-r--r--library/cpp/deprecated/mapped_file/mapped_file.cpp6
-rw-r--r--library/cpp/deprecated/mapped_file/mapped_file.h20
-rw-r--r--library/cpp/digest/md5/md5.cpp84
-rw-r--r--library/cpp/digest/md5/md5.h6
-rw-r--r--library/cpp/digest/old_crc/crc.h4
-rw-r--r--library/cpp/digest/old_crc/gencrc/main.cpp2
-rw-r--r--library/cpp/digest/sfh/sfh.h4
-rw-r--r--library/cpp/getopt/small/opt.cpp6
-rw-r--r--library/cpp/getopt/small/opt2.cpp2
-rw-r--r--library/cpp/getopt/small/posix_getopt.cpp2
-rw-r--r--library/cpp/getopt/ut/opt2_ut.cpp4
-rw-r--r--library/cpp/http/fetch/exthttpcodes.cpp44
-rw-r--r--library/cpp/http/fetch/exthttpcodes.h42
-rw-r--r--library/cpp/http/fetch/http_digest.cpp238
-rw-r--r--library/cpp/http/fetch/http_digest.h32
-rw-r--r--library/cpp/http/fetch/http_socket.cpp242
-rw-r--r--library/cpp/http/fetch/httpfetcher.h212
-rw-r--r--library/cpp/http/fetch/httpfsm.h74
-rw-r--r--library/cpp/http/fetch/httpfsm.rl6434
-rw-r--r--library/cpp/http/fetch/httpheader.h84
-rw-r--r--library/cpp/http/fetch/httpload.cpp376
-rw-r--r--library/cpp/http/fetch/httpload.h316
-rw-r--r--library/cpp/http/fetch/httpparser.h606
-rw-r--r--library/cpp/http/fetch/httpzreader.h440
-rw-r--r--library/cpp/http/fetch/ya.make28
-rw-r--r--library/cpp/http/io/chunk_ut.cpp2
-rw-r--r--library/cpp/http/io/compression_ut.cpp2
-rw-r--r--library/cpp/http/io/headers.cpp2
-rw-r--r--library/cpp/http/io/headers.h2
-rw-r--r--library/cpp/http/io/stream.cpp22
-rw-r--r--library/cpp/http/io/stream.h2
-rw-r--r--library/cpp/http/io/stream_ut.cpp12
-rw-r--r--library/cpp/http/misc/httpdate.cpp12
-rw-r--r--library/cpp/http/misc/httpdate.h2
-rw-r--r--library/cpp/http/misc/httpreqdata.h36
-rw-r--r--library/cpp/http/server/http.cpp28
-rw-r--r--library/cpp/http/server/http.h6
-rw-r--r--library/cpp/ipv6_address/ipv6_address.h4
-rw-r--r--library/cpp/lfalloc/ya.make2
-rw-r--r--library/cpp/lfalloc/yt/ya.make2
-rw-r--r--library/cpp/logger/backend.h4
-rw-r--r--library/cpp/logger/file.h4
-rw-r--r--library/cpp/logger/log.h2
-rw-r--r--library/cpp/logger/log_ut.cpp4
-rw-r--r--library/cpp/logger/null.h2
-rw-r--r--library/cpp/logger/priority.h2
-rw-r--r--library/cpp/logger/record.h4
-rw-r--r--library/cpp/logger/stream.h2
-rw-r--r--library/cpp/logger/system.h2
-rw-r--r--library/cpp/logger/thread.h2
-rw-r--r--library/cpp/messagebus/coreconn.cpp2
-rw-r--r--library/cpp/messagebus/coreconn.h8
-rw-r--r--library/cpp/messagebus/handler.cpp2
-rw-r--r--library/cpp/messagebus/locator.cpp6
-rw-r--r--library/cpp/messagebus/message.cpp4
-rw-r--r--library/cpp/messagebus/messqueue.cpp24
-rw-r--r--library/cpp/messagebus/network.cpp8
-rw-r--r--library/cpp/messagebus/oldmodule/module.cpp46
-rw-r--r--library/cpp/messagebus/oldmodule/module.h10
-rw-r--r--library/cpp/messagebus/oldmodule/startsession.cpp6
-rw-r--r--library/cpp/messagebus/protobuf/ybusbuf.h4
-rw-r--r--library/cpp/messagebus/scheduler/scheduler.cpp2
-rw-r--r--library/cpp/messagebus/session.cpp2
-rw-r--r--library/cpp/messagebus/synchandler.cpp2
-rw-r--r--library/cpp/messagebus/test/perftest/perftest.cpp8
-rw-r--r--library/cpp/messagebus/test/ut/one_way_ut.cpp4
-rw-r--r--library/cpp/messagebus/ya.make2
-rw-r--r--library/cpp/messagebus/ybus.h6
-rw-r--r--library/cpp/mime/types/mime.cpp4
-rw-r--r--library/cpp/mime/types/mime.h10
-rw-r--r--library/cpp/monlib/service/service.h2
-rw-r--r--library/cpp/on_disk/chunks/chunked_helpers.h6
-rw-r--r--library/cpp/on_disk/chunks/chunks_ut.cpp26
-rw-r--r--library/cpp/packers/packers.h76
-rw-r--r--library/cpp/regex/pcre/regexp.cpp8
-rw-r--r--library/cpp/regex/pire/regexp.h2
-rw-r--r--library/cpp/streams/bzip2/bzip2_ut.cpp2
-rw-r--r--library/cpp/streams/lz/lz_ut.cpp2
-rw-r--r--library/cpp/string_utils/base64/base64.cpp10
-rw-r--r--library/cpp/string_utils/quote/quote.cpp34
-rw-r--r--library/cpp/string_utils/url/url.cpp90
-rw-r--r--library/cpp/string_utils/url/url.h10
-rw-r--r--library/cpp/uri/common.cpp4
-rw-r--r--library/cpp/uri/uri-ru_ut.cpp12
-rw-r--r--library/cpp/uri/uri.cpp4
-rw-r--r--library/cpp/uri/uri.h6
-rw-r--r--library/cpp/uri/uri_ut.cpp18
-rw-r--r--tools/archiver/ya.make2
-rw-r--r--util/datetime/cputimer.cpp24
-rw-r--r--util/datetime/cputimer.h14
-rw-r--r--util/datetime/parser.rl626
-rw-r--r--util/datetime/strptime.cpp132
-rw-r--r--util/datetime/systime.cpp50
-rw-r--r--util/datetime/systime.h16
-rw-r--r--util/draft/ya.make12
-rw-r--r--util/folder/dirut.cpp390
-rw-r--r--util/folder/dirut.h12
-rw-r--r--util/folder/dirut_ut.cpp8
-rw-r--r--util/folder/filelist.cpp2
-rw-r--r--util/folder/filelist.h10
-rw-r--r--util/folder/fts.cpp1284
-rw-r--r--util/generic/buffer.cpp2
-rw-r--r--util/generic/buffer.h2
-rw-r--r--util/generic/hash.h8
-rw-r--r--util/generic/intrlist_ut.cpp10
-rw-r--r--util/generic/ptr.h14
-rw-r--r--util/generic/ptr_ut.cpp106
-rw-r--r--util/generic/refcount.h2
-rw-r--r--util/generic/strbase.h2
-rw-r--r--util/generic/string.cpp10
-rw-r--r--util/generic/string.h6
-rw-r--r--util/generic/string_ut.h24
-rw-r--r--util/generic/vector.h4
-rw-r--r--util/generic/yexception_ut.cpp4
-rw-r--r--util/generic/ymath.cpp2
-rw-r--r--util/generic/ymath.h6
-rw-r--r--util/memory/blob.cpp54
-rw-r--r--util/memory/blob.h8
-rw-r--r--util/memory/blob_ut.cpp8
-rw-r--r--util/memory/segmented_string_pool.h154
-rw-r--r--util/memory/segpool_alloc.h2
-rw-r--r--util/network/address.h2
-rw-r--r--util/network/init.h6
-rw-r--r--util/network/ip.h2
-rw-r--r--util/network/pollerimpl.h10
-rw-r--r--util/network/sock.h12
-rw-r--r--util/network/socket.cpp56
-rw-r--r--util/network/socket.h16
-rw-r--r--util/network/socket_ut.cpp20
-rw-r--r--util/str_stl.h10
-rw-r--r--util/stream/file.cpp16
-rw-r--r--util/stream/file.h2
-rw-r--r--util/stream/pipe.cpp4
-rw-r--r--util/stream/zlib_ut.cpp2
-rw-r--r--util/string/cstriter.h2
-rw-r--r--util/string/strip_ut.cpp2
-rw-r--r--util/string/util.cpp6
-rw-r--r--util/string/util.h16
-rw-r--r--util/string/vector.h2
-rw-r--r--util/system/atomic_gcc.h12
-rw-r--r--util/system/atomic_ut.cpp10
-rw-r--r--util/system/atomic_win.h18
-rw-r--r--util/system/backtrace_ut.cpp4
-rw-r--r--util/system/byteorder.h2
-rw-r--r--util/system/compat.cpp22
-rw-r--r--util/system/compat.h20
-rw-r--r--util/system/condvar.cpp2
-rw-r--r--util/system/context.h2
-rw-r--r--util/system/datetime.h2
-rw-r--r--util/system/defaults.h6
-rw-r--r--util/system/dynlib.h108
-rw-r--r--util/system/err.cpp4
-rw-r--r--util/system/error.h4
-rw-r--r--util/system/error_ut.cpp12
-rw-r--r--util/system/event.cpp20
-rw-r--r--util/system/event.h8
-rw-r--r--util/system/execpath.cpp2
-rw-r--r--util/system/execpath_ut.cpp2
-rw-r--r--util/system/fhandle.h16
-rw-r--r--util/system/file.cpp540
-rw-r--r--util/system/file.h154
-rw-r--r--util/system/file_ut.cpp170
-rw-r--r--util/system/filemap.cpp48
-rw-r--r--util/system/filemap.h78
-rw-r--r--util/system/filemap_ut.cpp12
-rw-r--r--util/system/flock.cpp38
-rw-r--r--util/system/flock.h24
-rw-r--r--util/system/fs.cpp42
-rw-r--r--util/system/fs.h2
-rw-r--r--util/system/fs_ut.cpp88
-rw-r--r--util/system/fs_win.cpp90
-rw-r--r--util/system/fs_win.h12
-rw-r--r--util/system/fstat.cpp58
-rw-r--r--util/system/fstat.h4
-rw-r--r--util/system/fstat_ut.cpp22
-rw-r--r--util/system/hostname.cpp4
-rw-r--r--util/system/info.cpp6
-rw-r--r--util/system/info.h2
-rw-r--r--util/system/maxlen.h4
-rw-r--r--util/system/mktemp.cpp4
-rw-r--r--util/system/mktemp_system.cpp6
-rw-r--r--util/system/mutex.h2
-rw-r--r--util/system/sem.cpp38
-rw-r--r--util/system/sem.h16
-rw-r--r--util/system/sigset.h20
-rw-r--r--util/system/sys_alloc.h6
-rw-r--r--util/system/sysstat.cpp86
-rw-r--r--util/system/sysstat.h74
-rw-r--r--util/system/thread.cpp12
-rw-r--r--util/system/thread.h2
-rw-r--r--util/system/tls.h12
-rw-r--r--util/system/user.cpp2
-rw-r--r--util/system/utime.h8
-rw-r--r--util/system/winint.h18
-rw-r--r--util/system/yassert.h2
-rw-r--r--util/thread/pool.cpp10
-rw-r--r--util/thread/pool.h6
-rw-r--r--util/ya.make4
237 files changed, 4627 insertions, 4627 deletions
diff --git a/contrib/libs/jemalloc/spinlock.h b/contrib/libs/jemalloc/spinlock.h
index 93fcf10e12..3e355a9324 100644
--- a/contrib/libs/jemalloc/spinlock.h
+++ b/contrib/libs/jemalloc/spinlock.h
@@ -7,9 +7,9 @@ typedef volatile intptr_t spinlock_t;
#define SPIN_L AllocAcquireAdaptiveLock
#define SPIN_U AllocReleaseAdaptiveLock
-#define _SPINLOCK_INITIALIZER 0
+#define _SPINLOCK_INITIALIZER 0
#define _SPINUNLOCK(_lck) SPIN_U(_lck)
-#define _SPINLOCK(_lck) SPIN_L(_lck)
+#define _SPINLOCK(_lck) SPIN_L(_lck)
#if defined(__cplusplus)
extern "C" {
diff --git a/contrib/libs/libidn/nfkc.c b/contrib/libs/libidn/nfkc.c
index 2bb2e62fbc..16fc7c7ece 100644
--- a/contrib/libs/libidn/nfkc.c
+++ b/contrib/libs/libidn/nfkc.c
@@ -329,12 +329,12 @@ g_unichar_to_utf8 (gunichar c, gchar * outbuf)
* This value must be freed with g_free().
**/
static gunichar *
-g_utf8_to_ucs4_fast (const gchar * str, glong len, size_t * items_written)
+g_utf8_to_ucs4_fast (const gchar * str, glong len, size_t * items_written)
{
gint j, charlen;
gunichar *result;
- gint n_chars, i;
- const gchar *p = str;
+ gint n_chars, i;
+ const gchar *p = str;
g_return_val_if_fail (str != NULL, NULL);
@@ -440,7 +440,7 @@ g_utf8_to_ucs4_fast (const gchar * str, glong len, size_t * items_written)
static gchar *
g_ucs4_to_utf8 (const gunichar * str,
glong len,
- size_t * items_read, size_t * items_written, GError ** error)
+ size_t * items_read, size_t * items_written, GError ** error)
{
gint result_length;
gchar *result = NULL;
@@ -975,7 +975,7 @@ stringprep_unichar_to_utf8 (uint32_t c, char *outbuf)
uint32_t *
stringprep_utf8_to_ucs4 (const char *str, ssize_t len, size_t * items_written)
{
- return g_utf8_to_ucs4_fast (str, (glong) len, items_written);
+ return g_utf8_to_ucs4_fast (str, (glong) len, items_written);
}
/**
@@ -1000,7 +1000,7 @@ char *
stringprep_ucs4_to_utf8 (const uint32_t * str, ssize_t len,
size_t * items_read, size_t * items_written)
{
- return g_ucs4_to_utf8 (str, len, items_read, items_written, NULL);
+ return g_ucs4_to_utf8 (str, len, items_read, items_written, NULL);
}
/**
diff --git a/contrib/libs/pcre/pcre_internal.h b/contrib/libs/pcre/pcre_internal.h
index 97ff55d03b..011a05e75a 100644
--- a/contrib/libs/pcre/pcre_internal.h
+++ b/contrib/libs/pcre/pcre_internal.h
@@ -174,7 +174,7 @@ PCRE_EXP_DATA_DEFN only if they are not already set. */
/* When compiling with the MSVC compiler, it is sometimes necessary to include
a "calling convention" before exported function names. (This is secondhand
information; I know nothing about MSVC myself). For example, something like
-
+
void __cdecl function(....)
might be needed. In order so make this easy, all the exported functions have
@@ -183,8 +183,8 @@ set, we ensure here that it has no effect. */
#ifndef PCRE_CALL_CONVENTION
#define PCRE_CALL_CONVENTION
-#endif
-
+#endif
+
/* We need to have types that specify unsigned 8, 16 and 32-bit integers. We
cannot determine these outside the compilation (e.g. by running a program as
part of "configure") because PCRE is often cross-compiled for use on other
diff --git a/contrib/libs/pcre/ya.make b/contrib/libs/pcre/ya.make
index 85ae150697..085d3c28d2 100644
--- a/contrib/libs/pcre/ya.make
+++ b/contrib/libs/pcre/ya.make
@@ -29,10 +29,10 @@ NO_COMPILER_WARNINGS()
NO_RUNTIME()
-CFLAGS(
+CFLAGS(
GLOBAL -DPCRE_STATIC
- -DHAVE_CONFIG_H
-)
+ -DHAVE_CONFIG_H
+)
# JIT adds ≈108KB to binary size which may be critical for mobile and embedded devices binary distributions
DEFAULT(ARCADIA_PCRE_ENABLE_JIT yes)
diff --git a/contrib/libs/pire/pire/fsm.h b/contrib/libs/pire/pire/fsm.h
index 4dad06ca06..2d7858f9e0 100644
--- a/contrib/libs/pire/pire/fsm.h
+++ b/contrib/libs/pire/pire/fsm.h
@@ -250,7 +250,7 @@ namespace Pire {
};
template<class Scanner>
- void BuildScanner(const Fsm& fsm, Scanner& r)
+ void BuildScanner(const Fsm& fsm, Scanner& r)
{
TSet<size_t> dead;
if (Scanner::DeadFlag)
diff --git a/contrib/libs/pire/pire/glue.h b/contrib/libs/pire/pire/glue.h
index bac086f2f0..1df1423e71 100644
--- a/contrib/libs/pire/pire/glue.h
+++ b/contrib/libs/pire/pire/glue.h
@@ -97,7 +97,7 @@ private:
return ind;
}
}
- return (size_t)-1;
+ return (size_t)-1;
}
static size_t Hash(const key_type& st) {
diff --git a/contrib/libs/pire/pire/scanners/common.h b/contrib/libs/pire/pire/scanners/common.h
index de5ea0af7b..e2970c881b 100644
--- a/contrib/libs/pire/pire/scanners/common.h
+++ b/contrib/libs/pire/pire/scanners/common.h
@@ -59,7 +59,7 @@ namespace Pire {
, PtrSize(sizeof(void*))
, MaxWordSize(sizeof(Impl::MaxSizeWord))
, Type(type)
- , HdrSize((ui32)hdrsize)
+ , HdrSize((ui32)hdrsize)
{}
void Validate(ui32 type, size_t hdrsize) const
diff --git a/contrib/libs/pire/pire/scanners/loaded.h b/contrib/libs/pire/pire/scanners/loaded.h
index 120dc403b7..81ac456741 100644
--- a/contrib/libs/pire/pire/scanners/loaded.h
+++ b/contrib/libs/pire/pire/scanners/loaded.h
@@ -194,7 +194,7 @@ public:
size_t shift = (newState - oldState) * StateSize();
Transition tr;
- tr.shift = (ui32)shift;
+ tr.shift = (ui32)shift;
tr.action = action;
m_jumps[TransitionIndex(oldState, c)] = tr;
}
diff --git a/contrib/tools/bison/gnulib/platform/win64/config.h b/contrib/tools/bison/gnulib/platform/win64/config.h
index cf3d366e18..51e6b982a2 100644
--- a/contrib/tools/bison/gnulib/platform/win64/config.h
+++ b/contrib/tools/bison/gnulib/platform/win64/config.h
@@ -911,7 +911,7 @@
/* #undef HAVE_SLEEP */
/* Define to 1 if you have the `snprintf' function. */
-#define HAVE_SNPRINTF 1
+#define HAVE_SNPRINTF 1
/* Define if the return value of the snprintf function is the number of of
bytes (excluding the terminating NUL) that would have been produced if the
diff --git a/contrib/tools/bison/gnulib/platform/win64/math.h b/contrib/tools/bison/gnulib/platform/win64/math.h
index b2a0023d11..04629dc036 100644
--- a/contrib/tools/bison/gnulib/platform/win64/math.h
+++ b/contrib/tools/bison/gnulib/platform/win64/math.h
@@ -34,8 +34,8 @@
#define _GL_M4_MATH_H
#if _MSC_VER >= 1800 // [
-#else // ] _MSC_VER >= 1600 [
-
+#else // ] _MSC_VER >= 1600 [
+
#ifndef _GL_INLINE_HEADER_BEGIN
#error "Please include config.h first."
#endif
@@ -1289,7 +1289,7 @@ _GL_WARN_ON_USE (frexpf, "frexpf is unportable - "
If x is zero: mantissa = x, exp = 0.
If x is infinite or NaN: mantissa = x, exp unspecified.
Store exp in *EXPPTR and return mantissa. */
-#if 0
+#if 0
# if 1
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# define frexp rpl_frexp
@@ -1314,7 +1314,7 @@ _GL_WARN_ON_USE (frexp, "frexp is unportable - "
If x is zero: mantissa = x, exp = 0.
If x is infinite or NaN: mantissa = x, exp unspecified.
Store exp in *EXPPTR and return mantissa. */
-#if 0
+#if 0
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# undef frexpl
# define frexpl rpl_frexpl
@@ -2593,7 +2593,7 @@ _GL_WARN_REAL_FLOATING_DECL (signbit);
_GL_INLINE_HEADER_END
-#endif
-
+#endif
+
#endif /* _GL_M4_MATH_H */
#endif /* _GL_M4_MATH_H */
diff --git a/contrib/tools/bison/gnulib/platform/win64/stdint.h.disabled b/contrib/tools/bison/gnulib/platform/win64/stdint.h.disabled
index 35ff0479f4..4ca637e223 100644
--- a/contrib/tools/bison/gnulib/platform/win64/stdint.h.disabled
+++ b/contrib/tools/bison/gnulib/platform/win64/stdint.h.disabled
@@ -35,9 +35,9 @@
#endif // _MSC_VER ]
-#ifndef _MSC_STDINT_H_
-
-#if _MSC_VER >= 1600
+#ifndef _MSC_STDINT_H_
+
+#if _MSC_VER >= 1600
# ifndef __clang__
# include <../include/stdint.h>
# else
@@ -45,11 +45,11 @@
# endif
#endif
-#ifndef _MSC_STDINT_H_
-#define _MSC_STDINT_H_
-
-#if _MSC_VER < 1600
+#ifndef _MSC_STDINT_H_
+#define _MSC_STDINT_H_
+#if _MSC_VER < 1600
+
#include <limits.h>
// For Visual Studio 6 in C++ mode and for many Visual Studio versions when
@@ -259,7 +259,7 @@ typedef uint64_t uintmax_t;
#endif // __STDC_CONSTANT_MACROS ]
-#endif // _MSC_VER < 1600 ]
+#endif // _MSC_VER < 1600 ]
#endif // _MSC_STDINT_H_ ]
-#endif // _MSC_STDINT_H_ ]
+#endif // _MSC_STDINT_H_ ]
diff --git a/contrib/tools/bison/gnulib/src/bison-system.h b/contrib/tools/bison/gnulib/src/bison-system.h
index 472a1921a7..c5efc92458 100644
--- a/contrib/tools/bison/gnulib/src/bison-system.h
+++ b/contrib/tools/bison/gnulib/src/bison-system.h
@@ -53,10 +53,10 @@
(STRNCMP_LIT (S, Literal) == 0)
# include <unistd.h>
-#if (defined _MSC_VER) && (_MSC_VER < 1800)
-#else
+#if (defined _MSC_VER) && (_MSC_VER < 1800)
+#else
# include <inttypes.h>
-#endif
+#endif
# ifndef UINTPTR_MAX
/* This isn't perfect, but it's good enough for Bison, which needs
diff --git a/contrib/tools/bison/gnulib/src/c-stack.c b/contrib/tools/bison/gnulib/src/c-stack.c
index b146cf254e..ac9076388a 100644
--- a/contrib/tools/bison/gnulib/src/c-stack.c
+++ b/contrib/tools/bison/gnulib/src/c-stack.c
@@ -323,10 +323,10 @@ c_stack_action (void (*action) (int))
int
c_stack_action (void (*action) (int) __attribute__ ((unused)))
{
-#if (defined _MSC_VER) && (_MSC_VER < 1800)
-#else
+#if (defined _MSC_VER) && (_MSC_VER < 1800)
+#else
errno = ENOTSUP;
-#endif
+#endif
return -1;
}
diff --git a/contrib/tools/bison/gnulib/src/perror.c b/contrib/tools/bison/gnulib/src/perror.c
index 74e088cc73..3010a22287 100644
--- a/contrib/tools/bison/gnulib/src/perror.c
+++ b/contrib/tools/bison/gnulib/src/perror.c
@@ -28,5 +28,5 @@ void
perror (const char *string)
{
if (string != NULL && *string != '\0')
- fprintf (stderr, "%s\n", string);
+ fprintf (stderr, "%s\n", string);
}
diff --git a/contrib/tools/bison/gnulib/src/snprintf.c b/contrib/tools/bison/gnulib/src/snprintf.c
index 9c34de3bb2..d9b8d7ad20 100644
--- a/contrib/tools/bison/gnulib/src/snprintf.c
+++ b/contrib/tools/bison/gnulib/src/snprintf.c
@@ -64,10 +64,10 @@ snprintf (char *str, size_t size, const char *format, ...)
if (INT_MAX < len)
{
-#if (defined _MSC_VER) && (MSC_VER < 1800)
-#else
+#if (defined _MSC_VER) && (MSC_VER < 1800)
+#else
errno = EOVERFLOW;
-#endif
+#endif
return -1;
}
diff --git a/contrib/tools/bison/gnulib/src/vasnprintf.c b/contrib/tools/bison/gnulib/src/vasnprintf.c
index 4de22819fa..7131504a9c 100644
--- a/contrib/tools/bison/gnulib/src/vasnprintf.c
+++ b/contrib/tools/bison/gnulib/src/vasnprintf.c
@@ -5575,10 +5575,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
if (buf_malloced != NULL)
free (buf_malloced);
CLEANUP ();
-#if (defined _MSC_VER) && (_MSC_VER < 1800)
-#else
+#if (defined _MSC_VER) && (_MSC_VER < 1800)
+#else
errno = EOVERFLOW;
-#endif
+#endif
return NULL;
#endif
diff --git a/contrib/tools/bison/gnulib/src/vasprintf.c b/contrib/tools/bison/gnulib/src/vasprintf.c
index afc8056194..4382cacd5c 100644
--- a/contrib/tools/bison/gnulib/src/vasprintf.c
+++ b/contrib/tools/bison/gnulib/src/vasprintf.c
@@ -40,10 +40,10 @@ vasprintf (char **resultp, const char *format, va_list args)
if (length > INT_MAX)
{
free (result);
-#if (defined _MSC_VER) && (_MSC_VER < 1800)
-#else
+#if (defined _MSC_VER) && (_MSC_VER < 1800)
+#else
errno = EOVERFLOW;
-#endif
+#endif
return -1;
}
diff --git a/contrib/tools/bison/gnulib/src/xvasprintf.c b/contrib/tools/bison/gnulib/src/xvasprintf.c
index 9c93492b80..ba1a157293 100644
--- a/contrib/tools/bison/gnulib/src/xvasprintf.c
+++ b/contrib/tools/bison/gnulib/src/xvasprintf.c
@@ -53,10 +53,10 @@ xstrcat (size_t argcount, va_list args)
vasprintf(). */
if (totalsize == SIZE_MAX || totalsize > INT_MAX)
{
-#if (defined _MSC_VER) && (_MSC_VER < 1800)
-#else
+#if (defined _MSC_VER) && (_MSC_VER < 1800)
+#else
errno = EOVERFLOW;
-#endif
+#endif
return NULL;
}
diff --git a/contrib/tools/bison/gnulib/ya.make b/contrib/tools/bison/gnulib/ya.make
index b674fd9ada..986ae6e4be 100644
--- a/contrib/tools/bison/gnulib/ya.make
+++ b/contrib/tools/bison/gnulib/ya.make
@@ -184,13 +184,13 @@ IF (NOT OS_LINUX)
ENDIF()
IF (NOT OS_WINDOWS)
- SRCS(
- src/stdio-write.c
- )
+ SRCS(
+ src/stdio-write.c
+ )
ENDIF()
-
+
IF (OS_WINDOWS)
- SRCS(
+ SRCS(
src/frexp.c
src/wcrtomb.c
src/perror.c
@@ -225,7 +225,7 @@ IF (OS_WINDOWS)
src/waitpid.c
src/wcwidth.c
src/uniwidth/width.c
- )
+ )
ENDIF()
IF (NOT OS_LINUX OR MUSL)
diff --git a/contrib/tools/ragel6/main.cpp b/contrib/tools/ragel6/main.cpp
index 1fd36c6f9d..966e3b085c 100644
--- a/contrib/tools/ragel6/main.cpp
+++ b/contrib/tools/ragel6/main.cpp
@@ -564,11 +564,11 @@ int main( int argc, const char **argv )
"\" is the same as the input file" << endp;
}
- for (char* p = (char*)id.inputFileName; *p != 0; p++) {
- if (*p == '\\')
- *p = '/';
- }
-
+ for (char* p = (char*)id.inputFileName; *p != 0; p++) {
+ if (*p == '\\')
+ *p = '/';
+ }
+
process( id );
return 0;
diff --git a/contrib/tools/ragel6/rlscan.cpp b/contrib/tools/ragel6/rlscan.cpp
index 5e2fc36645..049f53a004 100644
--- a/contrib/tools/ragel6/rlscan.cpp
+++ b/contrib/tools/ragel6/rlscan.cpp
@@ -805,7 +805,7 @@ void Scanner::endSection( )
bool isAbsolutePath( const char *path )
{
#ifdef _WIN32
- return isalpha( path[0] ) && path[1] == ':' && (path[2] == '\\' || path[2] == '/');
+ return isalpha( path[0] ) && path[1] == ':' && (path[2] == '\\' || path[2] == '/');
#else
return path[0] == '/';
#endif
@@ -823,8 +823,8 @@ inline char* resolvePath(const char* rel, const char* abs) {
strcpy(ret + l3, rel);
return ret;
-}
-
+}
+
char **Scanner::makeIncludePathChecks( const char *thisFileName,
const char *fileName, int fnlen )
{
@@ -844,7 +844,7 @@ char **Scanner::makeIncludePathChecks( const char *thisFileName,
checks = new char*[2 + id.includePaths.length()];
/* Search from the the location of the current file. */
- const char *lastSlash = strrchr( thisFileName, '/' );
+ const char *lastSlash = strrchr( thisFileName, '/' );
if ( lastSlash == 0 )
checks[nextCheck++] = data;
else {
@@ -857,7 +857,7 @@ char **Scanner::makeIncludePathChecks( const char *thisFileName,
long checkLen = pathLen + 1 + length;
char *check = new char[checkLen+1];
memcpy( check, *incp, pathLen );
- check[pathLen] = '/';
+ check[pathLen] = '/';
memcpy( check+pathLen+1, data, length );
check[checkLen] = 0;
checks[nextCheck++] = check;
diff --git a/contrib/tools/ragel6/rlscan.rl b/contrib/tools/ragel6/rlscan.rl
index c3217f1542..659cafc98b 100644
--- a/contrib/tools/ragel6/rlscan.rl
+++ b/contrib/tools/ragel6/rlscan.rl
@@ -542,7 +542,7 @@ void Scanner::endSection( )
bool isAbsolutePath( const char *path )
{
#ifdef _WIN32
- return isalpha( path[0] ) && path[1] == ':' && (path[2] == '\\' || path[2] == '/');
+ return isalpha( path[0] ) && path[1] == ':' && (path[2] == '\\' || path[2] == '/');
#else
return path[0] == '/';
#endif
@@ -560,8 +560,8 @@ inline char* resolvePath(const char* rel, const char* abs) {
strcpy(ret + l3, rel);
return ret;
-}
-
+}
+
char **Scanner::makeIncludePathChecks( const char *thisFileName,
const char *fileName, int fnlen )
{
@@ -581,7 +581,7 @@ char **Scanner::makeIncludePathChecks( const char *thisFileName,
checks = new char*[2 + id.includePaths.length()];
/* Search from the the location of the current file. */
- const char *lastSlash = strrchr( thisFileName, '/' );
+ const char *lastSlash = strrchr( thisFileName, '/' );
if ( lastSlash == 0 )
checks[nextCheck++] = data;
else {
@@ -594,7 +594,7 @@ char **Scanner::makeIncludePathChecks( const char *thisFileName,
long checkLen = pathLen + 1 + length;
char *check = new char[checkLen+1];
memcpy( check, *incp, pathLen );
- check[pathLen] = '/';
+ check[pathLen] = '/';
memcpy( check+pathLen+1, data, length );
check[checkLen] = 0;
checks[nextCheck++] = check;
diff --git a/library/cpp/actors/dnscachelib/dnscache.cpp b/library/cpp/actors/dnscachelib/dnscache.cpp
index 649339ddb2..ae64e1eea4 100644
--- a/library/cpp/actors/dnscachelib/dnscache.cpp
+++ b/library/cpp/actors/dnscachelib/dnscache.cpp
@@ -4,7 +4,7 @@
#include <contrib/libs/c-ares/ares.h>
#include <util/system/guard.h>
-#include <util/datetime/systime.h>
+#include <util/datetime/systime.h>
const TDnsCache::THost TDnsCache::NullHost;
diff --git a/library/cpp/archive/yarchive_ut.cpp b/library/cpp/archive/yarchive_ut.cpp
index 602a1cdbbd..a5ba9db26b 100644
--- a/library/cpp/archive/yarchive_ut.cpp
+++ b/library/cpp/archive/yarchive_ut.cpp
@@ -3,7 +3,7 @@
#include <library/cpp/testing/unittest/registar.h>
#include <util/string/cast.h>
-#include <util/stream/file.h>
+#include <util/stream/file.h>
#include <util/system/tempfile.h>
#include <util/memory/blob.h>
@@ -49,7 +49,7 @@ void TArchiveTest::TestCreate() {
void TArchiveTest::TestRead() {
CreateArchive();
TTempFile tmpFile(ARCHIVE);
- TBlob blob = TBlob::FromFileSingleThreaded(ARCHIVE);
+ TBlob blob = TBlob::FromFileSingleThreaded(ARCHIVE);
TArchiveReader r(blob);
UNIT_ASSERT_EQUAL(r.Count(), 1000);
diff --git a/library/cpp/blockcodecs/core/stream.h b/library/cpp/blockcodecs/core/stream.h
index fd44ef88f2..ad4220c6a7 100644
--- a/library/cpp/blockcodecs/core/stream.h
+++ b/library/cpp/blockcodecs/core/stream.h
@@ -7,7 +7,7 @@
#include <util/generic/buffer.h>
namespace NBlockCodecs {
- struct ICodec;
+ struct ICodec;
class TCodedOutput: public IOutputStream {
public:
diff --git a/library/cpp/charset/codepage.cpp b/library/cpp/charset/codepage.cpp
index 0431bef31b..b7205e903c 100644
--- a/library/cpp/charset/codepage.cpp
+++ b/library/cpp/charset/codepage.cpp
@@ -132,7 +132,7 @@ private:
TData Data;
TMemoryPool Pool;
-
+
private:
inline void AddNameWithCheck(const TString& name, ECharset code) {
if (Data.find(name.c_str()) == Data.end()) {
@@ -189,7 +189,7 @@ public:
return CODES_UNKNOWN;
return it->second;
- }
+ }
};
ECharset CharsetByName(TStringBuf name) {
diff --git a/library/cpp/charset/codepage.h b/library/cpp/charset/codepage.h
index 30a02a4610..2bad95ee4d 100644
--- a/library/cpp/charset/codepage.h
+++ b/library/cpp/charset/codepage.h
@@ -159,12 +159,12 @@ ECharset CharsetByName(TStringBuf name);
ECharset CharsetByNameOrDie(TStringBuf name);
inline ECharset CharsetByCodePage(const CodePage* CP) {
- return CP->CPEnum;
-}
+ return CP->CPEnum;
+}
inline const char* NameByCharset(ECharset e) {
return ::NCodepagePrivate::TCodepagesMap::Instance().NameByCharset(e);
-}
+}
inline const char* NameByCharsetSafe(ECharset e) {
if (CODES_UNKNOWN < e && e < CODES_MAX)
@@ -174,8 +174,8 @@ inline const char* NameByCharsetSafe(ECharset e) {
}
inline const char* NameByCodePage(const CodePage* CP) {
- return CP->Names[0];
-}
+ return CP->Names[0];
+}
inline const CodePage* CodePageByName(const char* name) {
ECharset code = CharsetByName(name);
diff --git a/library/cpp/charset/codepage_ut.cpp b/library/cpp/charset/codepage_ut.cpp
index c3ac3ac478..8d7fb4980a 100644
--- a/library/cpp/charset/codepage_ut.cpp
+++ b/library/cpp/charset/codepage_ut.cpp
@@ -9,8 +9,8 @@
#if defined(_MSC_VER)
#pragma warning(disable : 4309) /*truncation of constant value*/
-#endif
-
+#endif
+
namespace {
const char yandexUpperCase[] =
"\x81\x82\x83\x84\x85\x86\x87"
diff --git a/library/cpp/charset/doccodes.h b/library/cpp/charset/doccodes.h
index 75c87adf9e..ee5108b658 100644
--- a/library/cpp/charset/doccodes.h
+++ b/library/cpp/charset/doccodes.h
@@ -12,11 +12,11 @@ enum ECharset {
CODES_RESERVED_3, // reserved code: use it for new encodings before adding them to the end of the list
CODES_WIN_EAST, // [ 7] WINDOWS_1250 WIN PL
CODES_ISO_EAST, // [ 8] ISO_8859_2 ISO PL
- // our superset of subset of windows-1251
+ // our superset of subset of windows-1251
CODES_YANDEX, // [ 9] YANDEX
CODES_UTF_16BE, // [10] UTF_16BE
CODES_UTF_16LE, // [11] UTF_16LE
- // missing standard codepages
+ // missing standard codepages
CODES_IBM855, // [12] IBM_855
CODES_UTF8, // [13] UTF8
CODES_UNKNOWNPLANE, // [14] Unrecognized characters are mapped into the PUA: U+F000..U+F0FF
diff --git a/library/cpp/charset/recyr.hh b/library/cpp/charset/recyr.hh
index 5ec8734bcf..594451e164 100644
--- a/library/cpp/charset/recyr.hh
+++ b/library/cpp/charset/recyr.hh
@@ -1,6 +1,6 @@
#pragma once
-#include <cstdlib>
+#include <cstdlib>
#include <util/charset/recode_result.h>
#include <util/generic/ptr.h>
@@ -49,7 +49,7 @@ inline RECODE_RESULT RecodeFromUnicode(ECharset to, const TCharType* in, char* o
inline RECODE_RESULT RecodeFromUnicode(ECharset theEncoding, const wchar16* chars, size_t length,
char* bytes, size_t size, size_t* read = nullptr, size_t* written = nullptr) {
size_t w = 0, r = 0;
- RECODE_RESULT rc = ::RecodeFromUnicode(theEncoding, chars, bytes, length, size, r, w);
+ RECODE_RESULT rc = ::RecodeFromUnicode(theEncoding, chars, bytes, length, size, r, w);
if (read)
*read = r;
if (written)
@@ -93,8 +93,8 @@ inline RECODE_RESULT Recode(ECharset from, ECharset to, const char* in, char* ou
res = RecodeFromUnicode(to, wide.Get(), out, wideWritten, outSize, wideRead, outWritten);
return res;
-}
-
+}
+
inline RECODE_RESULT Recode(ECharset from, ECharset to, const char* in, char* out, size_t inSize, size_t outSize) {
size_t inRead = 0;
size_t outWritten = 0;
@@ -156,7 +156,7 @@ inline TString RecodeToHTMLEntities(ECharset from, const TString& in) {
res = NCodepagePrivate::_recodeToHTMLEntities(from, in.c_str(), out.begin(), in.length(), out.length(), inRead, outWritten);
}
if (res != RECODE_OK) {
- ythrow yexception() << "Recode to HTML entities failed";
+ ythrow yexception() << "Recode to HTML entities failed";
}
out.resize(outWritten - 1);
diff --git a/library/cpp/charset/ya.make b/library/cpp/charset/ya.make
index 7565566bf0..fff2d160ed 100644
--- a/library/cpp/charset/ya.make
+++ b/library/cpp/charset/ya.make
@@ -9,8 +9,8 @@ SRCS(
cp_encrec.cpp
doccodes.cpp
iconv.cpp
- recyr.hh
- recyr_int.hh
+ recyr.hh
+ recyr_int.hh
ci_string.cpp
wide.cpp
)
diff --git a/library/cpp/codecs/greedy_dict/ut/greedy_dict_ut.cpp b/library/cpp/codecs/greedy_dict/ut/greedy_dict_ut.cpp
index 679089a11b..296449710d 100644
--- a/library/cpp/codecs/greedy_dict/ut/greedy_dict_ut.cpp
+++ b/library/cpp/codecs/greedy_dict/ut/greedy_dict_ut.cpp
@@ -3,7 +3,7 @@
#include <library/cpp/testing/unittest/registar.h>
#include <library/cpp/string_utils/relaxed_escaper/relaxed_escaper.h>
#include <util/string/printf.h>
-#include <util/generic/ymath.h>
+#include <util/generic/ymath.h>
class TGreedyDictTest: public TTestBase {
UNIT_TEST_SUITE(TGreedyDictTest);
diff --git a/library/cpp/containers/2d_array/2d_array.h b/library/cpp/containers/2d_array/2d_array.h
index 9e24650637..090a8aff57 100644
--- a/library/cpp/containers/2d_array/2d_array.h
+++ b/library/cpp/containers/2d_array/2d_array.h
@@ -1,110 +1,110 @@
#pragma once
#include <util/system/yassert.h>
-#include <util/generic/algorithm.h>
+#include <util/generic/algorithm.h>
-#ifdef _DEBUG
-template <class T>
-struct TBoundCheck {
- T* Data;
+#ifdef _DEBUG
+template <class T>
+struct TBoundCheck {
+ T* Data;
size_t Size;
TBoundCheck(T* d, size_t s) {
- Data = d;
- Size = s;
- }
+ Data = d;
+ Size = s;
+ }
T& operator[](size_t i) const {
Y_ASSERT(i >= 0 && i < Size);
- return Data[i];
- }
+ return Data[i];
+ }
};
-#endif
+#endif
template <class T>
-class TArray2D {
-private:
- typedef T* PT;
- T* Data;
- T** PData;
+class TArray2D {
+private:
+ typedef T* PT;
+ T* Data;
+ T** PData;
size_t XSize;
size_t YSize;
-private:
+private:
void Copy(const TArray2D& a) {
- XSize = a.XSize;
- YSize = a.YSize;
- Create();
+ XSize = a.XSize;
+ YSize = a.YSize;
+ Create();
for (size_t i = 0; i < XSize * YSize; i++)
- Data[i] = a.Data[i];
- }
- void Destroy() {
- delete[] Data;
- delete[] PData;
- }
- void Create() {
- Data = new T[XSize * YSize];
- PData = new PT[YSize];
+ Data[i] = a.Data[i];
+ }
+ void Destroy() {
+ delete[] Data;
+ delete[] PData;
+ }
+ void Create() {
+ Data = new T[XSize * YSize];
+ PData = new PT[YSize];
for (size_t i = 0; i < YSize; i++)
- PData[i] = Data + i * XSize;
- }
+ PData[i] = Data + i * XSize;
+ }
public:
TArray2D(size_t xsize = 1, size_t ysize = 1) {
- XSize = xsize;
- YSize = ysize;
- Create();
- }
+ XSize = xsize;
+ YSize = ysize;
+ Create();
+ }
TArray2D(const TArray2D& a) {
- Copy(a);
- }
+ Copy(a);
+ }
TArray2D& operator=(const TArray2D& a) {
- Destroy();
- Copy(a);
- return *this;
- }
- ~TArray2D() {
- Destroy();
- }
+ Destroy();
+ Copy(a);
+ return *this;
+ }
+ ~TArray2D() {
+ Destroy();
+ }
void SetSizes(size_t xsize, size_t ysize) {
- if (XSize == xsize && YSize == ysize)
- return;
- Destroy();
- XSize = xsize;
- YSize = ysize;
- Create();
- }
- void Clear() {
+ if (XSize == xsize && YSize == ysize)
+ return;
+ Destroy();
+ XSize = xsize;
+ YSize = ysize;
+ Create();
+ }
+ void Clear() {
SetSizes(1, 1);
- }
+ }
#ifdef _DEBUG
TBoundCheck<T> operator[](size_t i) const {
Y_ASSERT(i < YSize);
- return TBoundCheck<T>(PData[i], XSize);
- }
+ return TBoundCheck<T>(PData[i], XSize);
+ }
#else
T* operator[](size_t i) const {
Y_ASSERT(i < YSize);
- return PData[i];
- }
+ return PData[i];
+ }
#endif
size_t GetXSize() const {
- return XSize;
- }
+ return XSize;
+ }
size_t GetYSize() const {
- return YSize;
- }
- void FillZero() {
- memset(Data, 0, sizeof(T) * XSize * YSize);
- }
- void FillEvery(const T& a) {
+ return YSize;
+ }
+ void FillZero() {
+ memset(Data, 0, sizeof(T) * XSize * YSize);
+ }
+ void FillEvery(const T& a) {
for (size_t i = 0; i < XSize * YSize; i++)
- Data[i] = a;
- }
- void Swap(TArray2D& a) {
- std::swap(Data, a.Data);
- std::swap(PData, a.PData);
- std::swap(XSize, a.XSize);
- std::swap(YSize, a.YSize);
- }
+ Data[i] = a;
+ }
+ void Swap(TArray2D& a) {
+ std::swap(Data, a.Data);
+ std::swap(PData, a.PData);
+ std::swap(XSize, a.XSize);
+ std::swap(YSize, a.YSize);
+ }
};
template <class T>
@@ -121,5 +121,5 @@ inline bool operator==(const TArray2D<T>& a, const TArray2D<T>& b) {
template <class T>
inline bool operator!=(const TArray2D<T>& a, const TArray2D<T>& b) {
- return !(a == b);
-}
+ return !(a == b);
+}
diff --git a/library/cpp/containers/atomizer/atomizer.h b/library/cpp/containers/atomizer/atomizer.h
index 5e40f47ab9..f18397c24e 100644
--- a/library/cpp/containers/atomizer/atomizer.h
+++ b/library/cpp/containers/atomizer/atomizer.h
@@ -16,7 +16,7 @@ class super_atomizer;
template <class HashFcn, class EqualTo>
class atomizer: public string_hash<ui32, HashFcn, EqualTo> {
-private:
+private:
TVector<const char*> order;
public:
@@ -36,7 +36,7 @@ public:
atomizer() {
order.reserve(HASH_SIZE_DEFAULT);
}
- atomizer(size_type hash_size, pool_size_type pool_size)
+ atomizer(size_type hash_size, pool_size_type pool_size)
: string_hash<ui32, HashFcn, EqualTo>(hash_size, pool_size)
{
order.reserve(hash_size);
@@ -80,63 +80,63 @@ public:
order.clear();
}
void SaveC2N(FILE* f) const { // we write sorted file
- for (ui32 i = 0; i < order.size(); i++)
- if (order[i])
+ for (ui32 i = 0; i < order.size(); i++)
+ if (order[i])
fprintf(f, "%d\t%s\n", i + 1, order[i]);
- }
+ }
void LoadC2N(FILE* f) { // but can read unsorted one
- long k, km = 0;
- char buf[1000];
+ long k, km = 0;
+ char buf[1000];
char* s;
- while (fgets(buf, 1000, f)) {
- k = strtol(buf, &s, 10);
+ while (fgets(buf, 1000, f)) {
+ k = strtol(buf, &s, 10);
char* endl = strchr(s, '\n');
- if (endl)
- *endl = 0;
- if (k > 0 && k != LONG_MAX) {
+ if (endl)
+ *endl = 0;
+ if (k > 0 && k != LONG_MAX) {
km = Max(km, k);
- insert_copy(++s, ui32(k));
- }
- }
- order.resize(km);
+ insert_copy(++s, ui32(k));
+ }
+ }
+ order.resize(km);
memset(&order[0], 0, order.size()); // if some atoms are absent
for (const_iterator I = this->begin(); I != end(); ++I)
- order[(*I).second - 1] = (*I).first;
- }
-};
+ order[(*I).second - 1] = (*I).first;
+ }
+};
-template <class T, class HashFcn, class EqualTo>
+template <class T, class HashFcn, class EqualTo>
class super_atomizer: public string_hash<ui32, HashFcn, EqualTo> {
-private:
+private:
using TOrder = TVector<std::pair<const char*, T>>;
- TOrder order;
+ TOrder order;
-public:
+public:
using iterator = typename string_hash<ui32, HashFcn, EqualTo>::iterator;
using const_iterator = typename string_hash<ui32, HashFcn, EqualTo>::const_iterator;
using value_type = typename string_hash<ui32, HashFcn, EqualTo>::value_type;
using size_type = typename string_hash<ui32, HashFcn, EqualTo>::size_type;
using pool_size_type = typename string_hash<ui32, HashFcn, EqualTo>::pool_size_type;
-
+
using o_iterator = typename TOrder::iterator;
using o_const_iterator = typename TOrder::const_iterator;
using o_value_type = typename TOrder::value_type;
-
- using string_hash<ui32, HashFcn, EqualTo>::pool;
- using string_hash<ui32, HashFcn, EqualTo>::size;
- using string_hash<ui32, HashFcn, EqualTo>::find;
- using string_hash<ui32, HashFcn, EqualTo>::end;
- using string_hash<ui32, HashFcn, EqualTo>::insert_copy;
- using string_hash<ui32, HashFcn, EqualTo>::clear_hash;
-
+
+ using string_hash<ui32, HashFcn, EqualTo>::pool;
+ using string_hash<ui32, HashFcn, EqualTo>::size;
+ using string_hash<ui32, HashFcn, EqualTo>::find;
+ using string_hash<ui32, HashFcn, EqualTo>::end;
+ using string_hash<ui32, HashFcn, EqualTo>::insert_copy;
+ using string_hash<ui32, HashFcn, EqualTo>::clear_hash;
+
super_atomizer() {
- order.reserve(HASH_SIZE_DEFAULT);
- }
- super_atomizer(size_type hash_size, pool_size_type pool_size)
+ order.reserve(HASH_SIZE_DEFAULT);
+ }
+ super_atomizer(size_type hash_size, pool_size_type pool_size)
: string_hash<ui32, HashFcn, EqualTo>(hash_size, pool_size)
- {
- order.reserve(hash_size);
- }
+ {
+ order.reserve(hash_size);
+ }
~super_atomizer() = default;
ui32 string_to_atom(const char* key, const T* atom_data = NULL) {
const char* old_begin = pool.Begin();
@@ -145,56 +145,56 @@ public:
if (ins.second) { // new?
if (pool.Begin() != old_begin) // repoint?
for (typename TOrder::iterator ptr = order.begin(); ptr != order.end(); ++ptr)
- if (old_begin <= (*ptr).first && (*ptr).first < old_end) // from old pool?
+ if (old_begin <= (*ptr).first && (*ptr).first < old_end) // from old pool?
(*ptr).first += pool.Begin() - old_begin;
order.push_back(std::pair<const char*, T>((*ins.first).first, atom_data ? *atom_data : T()));
- }
- return (*ins.first).second;
- }
-
+ }
+ return (*ins.first).second;
+ }
+
ui32 perm_string_to_atom(const char* key, const T* atom_data = NULL) {
value_type val(key, ui32(size() + 1));
std::pair<iterator, bool> ins = this->insert(val);
- if (ins.second)
+ if (ins.second)
order.push_back(std::pair<const char*, T>((*ins.first).first, atom_data ? *atom_data : T()));
- return (*ins.first).second; // == size()+1
- }
+ return (*ins.first).second; // == size()+1
+ }
ui32 find_atom(const char* key) const {
- const_iterator it = find(key);
- if (it == end())
- return 0; // INVALID_ATOM
- else
- return (*it).second;
- }
+ const_iterator it = find(key);
+ if (it == end())
+ return 0; // INVALID_ATOM
+ else
+ return (*it).second;
+ }
const char* get_atom_name(ui32 atom) const {
- if (atom && atom <= size())
+ if (atom && atom <= size())
return order[atom - 1].first;
return nullptr;
- }
- const T* get_atom_data(ui32 atom) const {
- if (atom && atom <= size())
+ }
+ const T* get_atom_data(ui32 atom) const {
+ if (atom && atom <= size())
return &order[atom - 1].second;
- return NULL;
- }
- T* get_atom_data(ui32 atom) {
- if (atom && atom <= size())
+ return NULL;
+ }
+ T* get_atom_data(ui32 atom) {
+ if (atom && atom <= size())
return &order[atom - 1].second;
- return NULL;
- }
- o_iterator o_begin() {
- return order.begin();
- }
- o_iterator o_end() {
- return order.end();
- }
- o_const_iterator o_begin() const {
- return order.begin();
- }
- o_const_iterator o_end() const {
- return order.end();
- }
+ return NULL;
+ }
+ o_iterator o_begin() {
+ return order.begin();
+ }
+ o_iterator o_end() {
+ return order.end();
+ }
+ o_const_iterator o_begin() const {
+ return order.begin();
+ }
+ o_const_iterator o_end() const {
+ return order.end();
+ }
void clear_atomizer() {
- clear_hash();
- order.clear();
- }
+ clear_hash();
+ order.clear();
+ }
};
diff --git a/library/cpp/containers/comptrie/comptrie_builder.inl b/library/cpp/containers/comptrie/comptrie_builder.inl
index f273fa6571..a7da790348 100644
--- a/library/cpp/containers/comptrie/comptrie_builder.inl
+++ b/library/cpp/containers/comptrie/comptrie_builder.inl
@@ -508,7 +508,7 @@ void TCompactTrieBuilder<T, D, S>::TCompactTrieBuilderImpl::ConvertSymbolArrayTo
for (size_t i = 0; i < keylen; ++i) {
TSymbol label = key[i];
- for (int j = (int)NCompactTrie::ExtraBits<TSymbol>(); j >= 0; j -= 8) {
+ for (int j = (int)NCompactTrie::ExtraBits<TSymbol>(); j >= 0; j -= 8) {
Y_ASSERT(ckeyptr < buf.Data() + buflen);
*(ckeyptr++) = (char)(label >> j);
}
diff --git a/library/cpp/containers/str_map/str_map.h b/library/cpp/containers/str_map/str_map.h
index 31b00d1b99..997da8d4a0 100644
--- a/library/cpp/containers/str_map/str_map.h
+++ b/library/cpp/containers/str_map/str_map.h
@@ -31,9 +31,9 @@ pool_insert(Map* m, const char* key, const typename Map::mapped_type& data, TBuf
return ins;
}
-#define HASH_SIZE_DEFAULT 100
+#define HASH_SIZE_DEFAULT 100
#define AVERAGEWORD_BUF 10
-
+
template <class T, class HashFcn, class EqualTo, class Alloc>
class string_hash: public THashMap<const char*, T, HashFcn, EqualTo, Alloc> {
protected:
@@ -49,7 +49,7 @@ public:
string_hash() {
pool.Reserve(HASH_SIZE_DEFAULT * AVERAGEWORD_BUF); // reserve here
}
- string_hash(size_type hash_size, pool_size_type pool_size)
+ string_hash(size_type hash_size, pool_size_type pool_size)
: THashMap<const char*, T, HashFcn, EqualTo, Alloc>(hash_size)
{
pool.Reserve(pool_size); // reserve here
@@ -66,46 +66,46 @@ public:
pool_size_type pool_size() const {
return pool.Size();
}
-
- string_hash(const string_hash& sh)
+
+ string_hash(const string_hash& sh)
: THashMap<const char*, T, HashFcn, EqualTo, Alloc>()
- {
- for (const_iterator i = sh.begin(); i != sh.end(); ++i)
- insert_copy((*i).first, (*i).second);
- }
- /* May be faster?
- string_hash(const string_hash& sh)
+ {
+ for (const_iterator i = sh.begin(); i != sh.end(); ++i)
+ insert_copy((*i).first, (*i).second);
+ }
+ /* May be faster?
+ string_hash(const string_hash& sh)
: THashMap<const char *, T, HashFcn, EqualTo>(sh)
- {
- pool = sh.pool;
- size_t delta = pool.begin() - sh.pool.begin();
- for (iterator i = begin(); i != end(); ++i)
- (const char*&)(*i).first += delta;
- }
- */
+ {
+ pool = sh.pool;
+ size_t delta = pool.begin() - sh.pool.begin();
+ for (iterator i = begin(); i != end(); ++i)
+ (const char*&)(*i).first += delta;
+ }
+ */
string_hash& operator=(const string_hash& sh) {
- if (&sh != this) {
- clear_hash();
- for (const_iterator i = sh.begin(); i != sh.end(); ++i)
- insert_copy((*i).first, (*i).second);
- }
- return *this;
- }
-
+ if (&sh != this) {
+ clear_hash();
+ for (const_iterator i = sh.begin(); i != sh.end(); ++i)
+ insert_copy((*i).first, (*i).second);
+ }
+ return *this;
+ }
+
mapped_type& operator[](const char* key) {
iterator I = yh::find(key);
if (I == yh::end())
- I = insert_copy(key, mapped_type()).first;
- return (*I).second;
- }
+ I = insert_copy(key, mapped_type()).first;
+ return (*I).second;
+ }
};
-template <class C, class T, class HashFcn, class EqualTo>
+template <class C, class T, class HashFcn, class EqualTo>
class THashWithSegmentedPoolForKeys: protected THashMap<const C*, T, HashFcn, EqualTo>, TNonCopyable {
-protected:
- segmented_pool<C> pool;
+protected:
+ segmented_pool<C> pool;
-public:
+public:
using yh = THashMap<const C*, T, HashFcn, EqualTo>;
using iterator = typename yh::iterator;
using const_iterator = typename yh::const_iterator;
@@ -114,68 +114,68 @@ public:
using key_type = typename yh::key_type;
using value_type = typename yh::value_type;
- THashWithSegmentedPoolForKeys(size_type hash_size = HASH_SIZE_DEFAULT, size_t segsize = HASH_SIZE_DEFAULT * AVERAGEWORD_BUF, bool afs = false)
- : yh(hash_size)
- , pool(segsize)
- {
- if (afs)
- pool.alloc_first_seg();
- }
-
+ THashWithSegmentedPoolForKeys(size_type hash_size = HASH_SIZE_DEFAULT, size_t segsize = HASH_SIZE_DEFAULT * AVERAGEWORD_BUF, bool afs = false)
+ : yh(hash_size)
+ , pool(segsize)
+ {
+ if (afs)
+ pool.alloc_first_seg();
+ }
+
std::pair<iterator, bool> insert_copy(const C* key, size_t keylen, const mapped_type& data) {
std::pair<iterator, bool> ins = this->insert(value_type(key, data));
- if (ins.second) // new?
- (const C*&)(*ins.first).first = pool.append(key, keylen);
- return ins;
- }
-
- void clear_hash() {
- yh::clear();
- pool.restart();
- }
-
- size_t pool_size() const {
- return pool.size();
- }
-
- size_t size() const {
- return yh::size();
- }
-
- bool empty() const {
- return yh::empty();
- }
-
- iterator begin() {
- return yh::begin();
- }
-
- iterator end() {
- return yh::end();
- }
-
- const_iterator begin() const {
- return yh::begin();
- }
-
- const_iterator end() const {
- return yh::end();
- }
-
- iterator find(const key_type& key) {
- return yh::find(key);
- }
-
- const_iterator find(const key_type& key) const {
- return yh::find(key);
- }
-
+ if (ins.second) // new?
+ (const C*&)(*ins.first).first = pool.append(key, keylen);
+ return ins;
+ }
+
+ void clear_hash() {
+ yh::clear();
+ pool.restart();
+ }
+
+ size_t pool_size() const {
+ return pool.size();
+ }
+
+ size_t size() const {
+ return yh::size();
+ }
+
+ bool empty() const {
+ return yh::empty();
+ }
+
+ iterator begin() {
+ return yh::begin();
+ }
+
+ iterator end() {
+ return yh::end();
+ }
+
+ const_iterator begin() const {
+ return yh::begin();
+ }
+
+ const_iterator end() const {
+ return yh::end();
+ }
+
+ iterator find(const key_type& key) {
+ return yh::find(key);
+ }
+
+ const_iterator find(const key_type& key) const {
+ return yh::find(key);
+ }
+
const yh& get_THashMap() const {
return static_cast<const yh&>(*this);
}
-};
-
-template <class T, class HashFcn, class EqualTo>
+};
+
+template <class T, class HashFcn, class EqualTo>
class segmented_string_hash: public THashWithSegmentedPoolForKeys<char, T, HashFcn, EqualTo> {
public:
using Base = THashWithSegmentedPoolForKeys<char, T, HashFcn, EqualTo>;
@@ -186,20 +186,20 @@ public:
using key_type = typename Base::key_type;
using value_type = typename Base::value_type;
-public:
- segmented_string_hash(size_type hash_size = HASH_SIZE_DEFAULT, size_t segsize = HASH_SIZE_DEFAULT * AVERAGEWORD_BUF, bool afs = false)
+public:
+ segmented_string_hash(size_type hash_size = HASH_SIZE_DEFAULT, size_t segsize = HASH_SIZE_DEFAULT * AVERAGEWORD_BUF, bool afs = false)
: Base(hash_size, segsize, afs)
{
}
-
+
std::pair<iterator, bool> insert_copy(const char* key, const mapped_type& data) {
- return Base::insert_copy(key, strlen(key) + 1, data);
- }
-
- mapped_type& operator[](const char* key) {
- iterator I = Base::find(key);
- if (I == Base::end())
- I = insert_copy(key, mapped_type()).first;
- return (*I).second;
+ return Base::insert_copy(key, strlen(key) + 1, data);
+ }
+
+ mapped_type& operator[](const char* key) {
+ iterator I = Base::find(key);
+ if (I == Base::end())
+ I = insert_copy(key, mapped_type()).first;
+ return (*I).second;
}
};
diff --git a/library/cpp/coroutine/engine/coroutine_ut.cpp b/library/cpp/coroutine/engine/coroutine_ut.cpp
index 8b372496a2..d03b157fdf 100644
--- a/library/cpp/coroutine/engine/coroutine_ut.cpp
+++ b/library/cpp/coroutine/engine/coroutine_ut.cpp
@@ -282,7 +282,7 @@ void TCoroTest::TestMutex() {
TContExecutor e(32000);
e.Execute(CoMutexTest);
UNIT_ASSERT_EQUAL(res, "1212");
- res.clear();
+ res.clear();
}
static TContMutex m1;
@@ -322,7 +322,7 @@ void TCoroTest::TestCondVar() {
TContExecutor e(32000);
e.Execute(CoCondVarTest);
UNIT_ASSERT_EQUAL(res, "0^1234561^1234562^123456");
- res.clear();
+ res.clear();
}
namespace NCoroTestJoin {
diff --git a/library/cpp/coroutine/engine/poller.h b/library/cpp/coroutine/engine/poller.h
index 8ea012c0fc..345bc22888 100644
--- a/library/cpp/coroutine/engine/poller.h
+++ b/library/cpp/coroutine/engine/poller.h
@@ -18,7 +18,7 @@ enum class EContPoller {
class IPollerFace {
public:
struct TChange {
- SOCKET Fd;
+ SOCKET Fd;
void* Data;
ui16 Flags;
};
diff --git a/library/cpp/coroutine/listener/listen.h b/library/cpp/coroutine/listener/listen.h
index 3a89cd3ecc..1089cec411 100644
--- a/library/cpp/coroutine/listener/listen.h
+++ b/library/cpp/coroutine/listener/listen.h
@@ -3,7 +3,7 @@
#include <util/generic/ptr.h>
#include <util/generic/ylimits.h>
-struct TIpAddress;
+struct TIpAddress;
class TContExecutor;
class TSocketHolder;
class TNetworkAddress;
@@ -110,7 +110,7 @@ public:
void Stop() noexcept;
void StopListenAddr(const NAddr::IRemoteAddr& addr);
- void StopListenAddr(const TIpAddress& addr);
+ void StopListenAddr(const TIpAddress& addr);
void StopListenAddr(const TNetworkAddress& addr);
template <class T>
diff --git a/library/cpp/deprecated/mapped_file/mapped_file.cpp b/library/cpp/deprecated/mapped_file/mapped_file.cpp
index b0e4511299..1239b9edca 100644
--- a/library/cpp/deprecated/mapped_file/mapped_file.cpp
+++ b/library/cpp/deprecated/mapped_file/mapped_file.cpp
@@ -1,6 +1,6 @@
#include "mapped_file.h"
-#include <util/generic/yexception.h>
+#include <util/generic/yexception.h>
#include <util/system/defaults.h>
#include <util/system/hi_lo.h>
#include <util/system/filemap.h>
@@ -57,8 +57,8 @@ void TMappedFile::init(const TString& name, TFileMap::EOpenMode om) {
Y_UNUSED(map.Release());
newFile.swap(*this);
newFile.term();
-}
-
+}
+
void TMappedFile::flush() {
Map_->Flush();
}
diff --git a/library/cpp/deprecated/mapped_file/mapped_file.h b/library/cpp/deprecated/mapped_file/mapped_file.h
index 45859ed65a..4da8aacf55 100644
--- a/library/cpp/deprecated/mapped_file/mapped_file.h
+++ b/library/cpp/deprecated/mapped_file/mapped_file.h
@@ -4,7 +4,7 @@
#include <util/generic/ptr.h>
#include <util/generic/string.h>
#include <util/generic/utility.h>
-#include <util/generic/yexception.h>
+#include <util/generic/yexception.h>
#include <util/system/align.h>
#include <util/system/file.h>
#include <util/system/filemap.h>
@@ -15,25 +15,25 @@
/// Deprecated (by pg@), use TFileMap or TMemoryMap instead
class TMappedFile {
-private:
+private:
TFileMap* Map_;
private:
TMappedFile(TFileMap* map, const char* dbgName);
-public:
+public:
TMappedFile() {
Map_ = nullptr;
- }
+ }
~TMappedFile() {
- term();
- }
+ term();
+ }
explicit TMappedFile(const TString& name) {
Map_ = nullptr;
init(name, TFileMap::oRdOnly);
- }
+ }
TMappedFile(const TFile& file, TFileMap::EOpenMode om = TFileMap::oRdOnly, const char* dbgName = "unknown");
@@ -52,8 +52,8 @@ public:
Map_->Unmap();
delete Map_;
Map_ = nullptr;
- }
- }
+ }
+ }
size_t getSize() const {
return (Map_ ? Map_->MappedSize() : 0);
@@ -69,4 +69,4 @@ public:
void swap(TMappedFile& file) noexcept {
DoSwap(Map_, file.Map_);
}
-};
+};
diff --git a/library/cpp/digest/md5/md5.cpp b/library/cpp/digest/md5/md5.cpp
index 24a5b69eef..4d6168c4e8 100644
--- a/library/cpp/digest/md5/md5.cpp
+++ b/library/cpp/digest/md5/md5.cpp
@@ -5,7 +5,7 @@
#include <util/stream/input.h>
#include <util/stream/file.h>
#include <util/string/hex.h>
-
+
#include <contrib/libs/nayuki_md5/md5.h>
namespace {
@@ -42,11 +42,11 @@ char* MD5::File(const char* filename, char* buf) {
return Stream(&fi, buf);
} catch (...) {
- }
+ }
return nullptr;
-}
-
+}
+
TString MD5::File(const TString& filename) {
TString buf;
buf.ReserveAndResize(MD5_HEX_DIGEST_LENGTH);
@@ -63,8 +63,8 @@ char* MD5::Data(const TArrayRef<const ui8>& data, char* buf) {
char* MD5::Data(const void* data, size_t len, char* buf) {
return Data(MakeUnsignedArrayRef(data, len), buf);
-}
-
+}
+
TString MD5::Data(const TArrayRef<const ui8>& data) {
TString buf;
buf.ReserveAndResize(MD5_HEX_DIGEST_LENGTH);
@@ -92,25 +92,25 @@ static const ui8 PADDING[MD5_BLOCK_LENGTH] = {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
-
-/* MD5 initialization. Begins an MD5 operation, writing a new context. */
-
+
+/* MD5 initialization. Begins an MD5 operation, writing a new context. */
+
void MD5::Init() {
BufferSize = 0;
StreamSize = 0;
- /* Load magic initialization constants. */
+ /* Load magic initialization constants. */
State[0] = 0x67452301;
State[1] = 0xefcdab89;
State[2] = 0x98badcfe;
State[3] = 0x10325476;
-}
-
+}
+
/*
- * MD5 block update operation. Continues an MD5 message-digest
- * operation, processing another message block, and updating the
- * context.
- */
-
+ * MD5 block update operation. Continues an MD5 message-digest
+ * operation, processing another message block, and updating the
+ * context.
+ */
+
void MD5::UpdatePart(TArrayRef<const ui8> data) {
/* Count input bytes */
StreamSize += data.size();
@@ -135,12 +135,12 @@ void MD5::UpdatePart(TArrayRef<const ui8> data) {
/* Save remaining input in buffer */
memcpy(Buffer, data.data(), data.size());
BufferSize += data.size();
-}
-
-/*
- * MD5 padding. Adds padding followed by original length.
- */
-
+}
+
+/*
+ * MD5 padding. Adds padding followed by original length.
+ */
+
void MD5::Pad() {
size_t streamSize = StreamSize;
@@ -155,40 +155,40 @@ void MD5::Pad() {
Buffer[MD5_PADDING_SHIFT + i] = static_cast<ui8>(streamSize & 0xFFU);
}
md5_compress(State, Buffer);
-}
-
-/*
- * MD5 finalization. Ends an MD5 message-digest operation, writing the
- * the message digest and zeroizing the context.
- */
-
+}
+
+/*
+ * MD5 finalization. Ends an MD5 message-digest operation, writing the
+ * the message digest and zeroizing the context.
+ */
+
ui8* MD5::Final(ui8 digest[16]) {
- /* Do padding. */
- Pad();
- /* Store state in digest */
+ /* Do padding. */
+ Pad();
+ /* Store state in digest */
memcpy(digest, State, 16);
- /* Zeroize sensitive information. */
+ /* Zeroize sensitive information. */
Init();
return digest;
-}
-
+}
+
char* MD5::End(char* buf) {
static const char hex[] = "0123456789abcdef";
ui8 digest[16];
if (!buf)
- buf = (char*)malloc(33);
+ buf = (char*)malloc(33);
if (!buf)
return nullptr;
- Final(digest);
+ Final(digest);
for (ui8 i = 0; i < MD5_HEX_DIGEST_LENGTH / 2; i++) {
buf[i * 2] = hex[digest[i] >> 4];
buf[i * 2 + 1] = hex[digest[i] & 0x0f];
- }
+ }
buf[32] = '\0';
- return buf;
-}
-
+ return buf;
+}
+
char* MD5::End_b64(char* buf) {
ui8 digest[16];
if (!buf)
diff --git a/library/cpp/digest/md5/md5.h b/library/cpp/digest/md5/md5.h
index 2c17aa0518..ead7158a6e 100644
--- a/library/cpp/digest/md5/md5.h
+++ b/library/cpp/digest/md5/md5.h
@@ -1,8 +1,8 @@
#pragma once
-
+
#include <util/generic/array_ref.h>
#include <util/generic/strbuf.h>
-
+
class IInputStream;
class MD5 {
@@ -74,4 +74,4 @@ private:
ui8 Buffer[64]; /* input buffer */
ui32 State[4]; /* state (ABCD) */
ui64 StreamSize; /* total bytes in input stream */
-};
+};
diff --git a/library/cpp/digest/old_crc/crc.h b/library/cpp/digest/old_crc/crc.h
index 4a3ce6d05e..a737f2e8b7 100644
--- a/library/cpp/digest/old_crc/crc.h
+++ b/library/cpp/digest/old_crc/crc.h
@@ -46,8 +46,8 @@ inline ui32 crc32(const char* buf, size_t buflen, ui32 crcinit = CRC32INIT) {
inline ui32 crc32(const void* buf, size_t buflen, ui32 crcinit = CRC32INIT) {
return crc32((const char*)buf, buflen, crcinit);
-}
-
+}
+
// Copyright (C) Sewell Development Corporation, 1994 - 1998.
inline ui64 crc64(const void* buf, size_t buflen, ui64 crcinit = CRC64INIT) {
const unsigned char* ptr = (const unsigned char*)buf;
diff --git a/library/cpp/digest/old_crc/gencrc/main.cpp b/library/cpp/digest/old_crc/gencrc/main.cpp
index d5821304ce..a7e3c25561 100644
--- a/library/cpp/digest/old_crc/gencrc/main.cpp
+++ b/library/cpp/digest/old_crc/gencrc/main.cpp
@@ -2,7 +2,7 @@
#define POLY_16 0x1021
#define POLY_32 0xEDB88320UL
-#define POLY_64 ULL(0xE543279765927881)
+#define POLY_64 ULL(0xE543279765927881)
static void crc16init() {
ui32 CRCTAB16[256];
diff --git a/library/cpp/digest/sfh/sfh.h b/library/cpp/digest/sfh/sfh.h
index 372938654c..aa48f3ceeb 100644
--- a/library/cpp/digest/sfh/sfh.h
+++ b/library/cpp/digest/sfh/sfh.h
@@ -6,9 +6,9 @@
inline ui32 SuperFastHash(const void* d, size_t l) noexcept {
ui32 hash = (ui32)l;
ui32 tmp;
-
+
if (!l || !d)
- return 0;
+ return 0;
TUnalignedMemoryIterator<ui16, 4> iter(d, l);
diff --git a/library/cpp/getopt/small/opt.cpp b/library/cpp/getopt/small/opt.cpp
index 744501765c..f54e008f79 100644
--- a/library/cpp/getopt/small/opt.cpp
+++ b/library/cpp/getopt/small/opt.cpp
@@ -63,7 +63,7 @@ int Opt::Get(int* longOptionIndex) {
try {
bool r = OptsParser_->Next();
- Ind = (int)OptsParser_->Pos_;
+ Ind = (int)OptsParser_->Pos_;
if (!r) {
return EOF;
} else {
@@ -74,7 +74,7 @@ int Opt::Get(int* longOptionIndex) {
} else {
const Ion* ion = (const Ion*)OptsParser_->CurOpt()->UserValue();
if (longOptionIndex) {
- *longOptionIndex = int(ion - Ions_);
+ *longOptionIndex = int(ion - Ions_);
}
char c = OptsParser_->CurOpt()->GetCharOr0();
return c != 0 ? c : ion->val;
@@ -93,7 +93,7 @@ void Opt::DummyHelp(IOutputStream& os) {
}
int Opt::GetArgC() const {
- return (int)OptsParser_->Argc_;
+ return (int)OptsParser_->Argc_;
}
const char** Opt::GetArgV() const {
diff --git a/library/cpp/getopt/small/opt2.cpp b/library/cpp/getopt/small/opt2.cpp
index 0cdc774e78..0f6eb6d179 100644
--- a/library/cpp/getopt/small/opt2.cpp
+++ b/library/cpp/getopt/small/opt2.cpp
@@ -45,7 +45,7 @@ void Opt2::EatArgv(const char* optspec, const char* long_alias) {
if (*s == '?' || *s == '-')
ythrow yexception() << "Opt2: Symbol '" << *s << "' can not be used in optspec because it is reserved";
Specs.push_back(Opt2Param());
- SpecsMap[(ui8)*s] = (ui8)Specs.size(); // actual index + 1
+ SpecsMap[(ui8)*s] = (ui8)Specs.size(); // actual index + 1
Specs.back().opt = *s;
if (s[1] == ':') {
Specs.back().HasArg = true;
diff --git a/library/cpp/getopt/small/posix_getopt.cpp b/library/cpp/getopt/small/posix_getopt.cpp
index bd06f3499f..c8cab678ac 100644
--- a/library/cpp/getopt/small/posix_getopt.cpp
+++ b/library/cpp/getopt/small/posix_getopt.cpp
@@ -48,7 +48,7 @@ namespace NLastGetopt {
return -1;
} else {
optarg = (char*)OptsParser->CurVal();
- optind = (int)OptsParser->Pos_;
+ optind = (int)OptsParser->Pos_;
if (longindex && OptsParser->CurOpt())
*longindex = (int)Opts->IndexOf(OptsParser->CurOpt());
return OptsParser->CurOpt() ? OptsParser->CurOpt()->GetCharOr0() : 1;
diff --git a/library/cpp/getopt/ut/opt2_ut.cpp b/library/cpp/getopt/ut/opt2_ut.cpp
index 0e7464747c..4f6ac64e29 100644
--- a/library/cpp/getopt/ut/opt2_ut.cpp
+++ b/library/cpp/getopt/ut/opt2_ut.cpp
@@ -36,9 +36,9 @@ Y_UNIT_TEST_SUITE(Opt2Test) {
UNIT_ASSERT_VALUES_EQUAL((void*)edef, e);
UNIT_ASSERT_VALUES_EQUAL(2u, opt.Pos.size());
- UNIT_ASSERT_STRINGS_EQUAL("zz", opt.Pos.at(0));
+ UNIT_ASSERT_STRINGS_EQUAL("zz", opt.Pos.at(0));
UNIT_ASSERT_VALUES_EQUAL((void*)argv[2], opt.Pos.at(0));
- UNIT_ASSERT_STRINGS_EQUAL("ww", opt.Pos.at(1));
+ UNIT_ASSERT_STRINGS_EQUAL("ww", opt.Pos.at(1));
UNIT_ASSERT_STRINGS_EQUAL("1", x.at(0));
UNIT_ASSERT_STRINGS_EQUAL("2", x.at(1));
}
diff --git a/library/cpp/http/fetch/exthttpcodes.cpp b/library/cpp/http/fetch/exthttpcodes.cpp
index acc05650c8..ac0d3b359d 100644
--- a/library/cpp/http/fetch/exthttpcodes.cpp
+++ b/library/cpp/http/fetch/exthttpcodes.cpp
@@ -1,18 +1,18 @@
#include "exthttpcodes.h"
-#include <cstring>
-
+#include <cstring>
+
const ui16 CrazyServer = ShouldDelete | MarkSuspect;
-
+
struct http_flag {
ui16 http;
ui16 flag;
};
-static http_flag HTTP_FLAG[] = {
+static http_flag HTTP_FLAG[] = {
{HTTP_CONTINUE, MarkSuspect}, // 100
{HTTP_SWITCHING_PROTOCOLS, CrazyServer}, // 101
{HTTP_PROCESSING, CrazyServer}, // 102
-
+
{HTTP_OK, ShouldReindex}, // 200
{HTTP_CREATED, CrazyServer}, // 201
{HTTP_ACCEPTED, ShouldDelete}, // 202
@@ -23,7 +23,7 @@ static http_flag HTTP_FLAG[] = {
{HTTP_MULTI_STATUS, CrazyServer}, // 207
{HTTP_ALREADY_REPORTED, CrazyServer}, // 208
{HTTP_IM_USED, CrazyServer}, // 226
-
+
{HTTP_MULTIPLE_CHOICES, CheckLinks | ShouldDelete}, // 300
{HTTP_MOVED_PERMANENTLY, CheckLocation | ShouldDelete | MoveRedir}, // 301
{HTTP_FOUND, CheckLocation | ShouldDelete | MoveRedir}, // 302
@@ -32,7 +32,7 @@ static http_flag HTTP_FLAG[] = {
{HTTP_USE_PROXY, ShouldDelete}, // 305
{HTTP_TEMPORARY_REDIRECT, CheckLocation | ShouldDelete | MoveRedir}, // 307
{HTTP_PERMANENT_REDIRECT, CheckLocation | ShouldDelete | MoveRedir}, // 308
-
+
{HTTP_BAD_REQUEST, CrazyServer}, // 400
{HTTP_UNAUTHORIZED, ShouldDelete}, // 401
{HTTP_PAYMENT_REQUIRED, ShouldDelete}, // 402
@@ -53,7 +53,7 @@ static http_flag HTTP_FLAG[] = {
{HTTP_EXPECTATION_FAILED, ShouldDelete}, // 417
{HTTP_I_AM_A_TEAPOT, CrazyServer}, // 418
{HTTP_AUTHENTICATION_TIMEOUT, ShouldDelete}, // 419
-
+
{HTTP_MISDIRECTED_REQUEST, CrazyServer}, // 421
{HTTP_UNPROCESSABLE_ENTITY, CrazyServer}, // 422
{HTTP_LOCKED, ShouldDelete}, // 423
@@ -62,7 +62,7 @@ static http_flag HTTP_FLAG[] = {
{HTTP_PRECONDITION_REQUIRED, ShouldDelete}, // 428
{HTTP_TOO_MANY_REQUESTS, ShouldDisconnect | ShouldRetry | MarkSuspect}, // 429
{HTTP_UNAVAILABLE_FOR_LEGAL_REASONS, ShouldDelete}, // 451
-
+
{HTTP_INTERNAL_SERVER_ERROR, MarkSuspect}, // 500
{HTTP_NOT_IMPLEMENTED, ShouldDelete | ShouldDisconnect}, // 501
{HTTP_BAD_GATEWAY, MarkSuspect}, // 502
@@ -116,7 +116,7 @@ static http_flag HTTP_FLAG[] = {
{HTTP_FETCHER_BAD_RESPONSE, 0}, // 1040
{HTTP_FETCHER_MB_ERROR, 0}, // 1041
{HTTP_SSL_CERT_ERROR, 0}, // 1042
-
+
// Custom (replace HTTP 200/304)
{EXT_HTTP_MIRRMOVE, 0}, // 2000
{EXT_HTTP_MANUAL_DELETE, ShouldDelete}, // 2001
@@ -142,34 +142,34 @@ static http_flag HTTP_FLAG[] = {
{EXT_HTTP_EMPTY_RESPONSE, ShouldDelete}, // 2024
{EXT_HTTP_REL_CANONICAL, ShouldDelete | CheckLinks | MoveRedir}, // 2025
{0, 0}};
-
+
static ui16* prepare_flags(http_flag* arg) {
- static ui16 flags[EXT_HTTP_CODE_MAX];
+ static ui16 flags[EXT_HTTP_CODE_MAX];
http_flag* ptr;
- size_t i;
-
+ size_t i;
+
// устанавливаем значение по умолчанию для кодов не перечисленных в таблице выше
for (i = 0; i < EXT_HTTP_CODE_MAX; ++i)
- flags[i] = CrazyServer;
-
+ flags[i] = CrazyServer;
+
// устанавливаем флаги для перечисленных кодов
for (ptr = arg; ptr->http; ++ptr)
flags[ptr->http & (EXT_HTTP_CODE_MAX - 1)] = ptr->flag;
-
+
// для стандартных кодов ошибок берем флаги из первого кода каждой группы и проставляем их
// всем кодам не перечисленным в таблице выше
for (size_t group = 0; group < 1000; group += 100)
for (size_t j = group + 1; j < group + 100; ++j)
flags[j] = flags[group];
-
+
// предыдущий цикл затер некоторые флаги перечисленные в таблице выше
// восстанавливаем их
for (ptr = arg; ptr->http; ++ptr)
flags[ptr->http & (EXT_HTTP_CODE_MAX - 1)] = ptr->flag;
-
- return flags;
-}
-
+
+ return flags;
+}
+
ui16* http2status = prepare_flags(HTTP_FLAG);
TStringBuf ExtHttpCodeStr(int code) noexcept {
diff --git a/library/cpp/http/fetch/exthttpcodes.h b/library/cpp/http/fetch/exthttpcodes.h
index 6b525052cd..88bfe8d829 100644
--- a/library/cpp/http/fetch/exthttpcodes.h
+++ b/library/cpp/http/fetch/exthttpcodes.h
@@ -1,9 +1,9 @@
#pragma once
-
-#include <util/system/defaults.h>
+
+#include <util/system/defaults.h>
#include <library/cpp/http/misc/httpcodes.h>
-
-enum ExtHttpCodes {
+
+enum ExtHttpCodes {
// Custom
HTTP_EXTENDED = 1000,
HTTP_BAD_RESPONSE_HEADER = 1000,
@@ -50,8 +50,8 @@ enum ExtHttpCodes {
HTTP_FETCHER_MB_ERROR = 1041,
HTTP_SSL_CERT_ERROR = 1042,
HTTP_PROXY_REQUEST_CANCELED = 1051,
-
- // Custom (replace HTTP 200/304)
+
+ // Custom (replace HTTP 200/304)
EXT_HTTP_EXT_SUCCESS_BEGIN = 2000, // to check if code variable is in success interval
EXT_HTTP_MIRRMOVE = 2000,
EXT_HTTP_MANUAL_DELETE = 2001,
@@ -104,22 +104,22 @@ enum ExtHttpCodes {
EXT_HTTP_WRONGMULTILANG = 3023,
EXT_HTTP_SOFTMIRRORS = 3024,
EXT_HTTP_BIGLEVEL = 3025,
-
- // fast robot codes
-
+
+ // fast robot codes
+
EXT_HTTP_FASTHOPS = 4000,
EXT_HTTP_NODOC = 4001,
EXT_HTTP_MAX
-};
-
-enum HttpFlags {
- // connection
- ShouldDisconnect = 1,
+};
+
+enum HttpFlags {
+ // connection
+ ShouldDisconnect = 1,
ShouldRetry = 2,
// UNUSED 4
-
- // indexer
+
+ // indexer
ShouldReindex = 8,
ShouldDelete = 16,
CheckLocation = 32,
@@ -129,13 +129,13 @@ enum HttpFlags {
// UNUSED 512
MoveRedir = 1024,
CanBeFake = 2048,
-};
-
+};
+
const size_t EXT_HTTP_CODE_MAX = 1 << 12;
-
-static inline int Http2Status(int code) {
+
+static inline int Http2Status(int code) {
extern ui16* http2status;
return http2status[code & (EXT_HTTP_CODE_MAX - 1)];
-}
+}
TStringBuf ExtHttpCodeStr(int code) noexcept;
diff --git a/library/cpp/http/fetch/http_digest.cpp b/library/cpp/http/fetch/http_digest.cpp
index 1eaa02b7f2..1c8bc6f449 100644
--- a/library/cpp/http/fetch/http_digest.cpp
+++ b/library/cpp/http/fetch/http_digest.cpp
@@ -3,204 +3,204 @@
#include <library/cpp/digest/md5/md5.h>
#include <util/stream/output.h>
#include <util/stream/str.h>
-
-/************************************************************/
-/************************************************************/
-static const char* WWW_PREFIX = "Authorization: Digest ";
-
-/************************************************************/
+
+/************************************************************/
+/************************************************************/
+static const char* WWW_PREFIX = "Authorization: Digest ";
+
+/************************************************************/
httpDigestHandler::httpDigestHandler()
: User_(nullptr)
, Password_(nullptr)
, Nonce_(nullptr)
, NonceCount_(0)
, HeaderInstruction_(nullptr)
-{
-}
-
-/************************************************************/
+{
+}
+
+/************************************************************/
httpDigestHandler::~httpDigestHandler() {
- clear();
-}
-
-/************************************************************/
+ clear();
+}
+
+/************************************************************/
void httpDigestHandler::clear() {
free(Nonce_);
free(HeaderInstruction_);
User_ = Password_ = nullptr;
Nonce_ = HeaderInstruction_ = nullptr;
NonceCount_ = 0;
-}
-
-/************************************************************/
+}
+
+/************************************************************/
void httpDigestHandler::setAuthorization(const char* user, const char* password) {
- clear();
+ clear();
if (user && password) {
User_ = user;
Password_ = password;
- }
-}
-
-/************************************************************/
+ }
+}
+
+/************************************************************/
const char* httpDigestHandler::getHeaderInstruction() const {
return HeaderInstruction_;
-}
-
-/************************************************************/
+}
+
+/************************************************************/
void httpDigestHandler::generateCNonce(char* outCNonce) {
- if (!*outCNonce)
+ if (!*outCNonce)
sprintf(outCNonce, "%ld", (long)time(nullptr));
-}
-
-/************************************************************/
+}
+
+/************************************************************/
inline void addMD5(MD5& ctx, const char* value) {
- ctx.Update((const unsigned char*)(value), strlen(value));
-}
-
+ ctx.Update((const unsigned char*)(value), strlen(value));
+}
+
inline void addMD5(MD5& ctx, const char* value, int len) {
- ctx.Update((const unsigned char*)(value), len);
-}
-
+ ctx.Update((const unsigned char*)(value), len);
+}
+
inline void addMD5Sep(MD5& ctx) {
- addMD5(ctx, ":", 1);
-}
-
-/************************************************************/
-/* calculate H(A1) as per spec */
+ addMD5(ctx, ":", 1);
+}
+
+/************************************************************/
+/* calculate H(A1) as per spec */
void httpDigestHandler::digestCalcHA1(const THttpAuthHeader& hd,
char* outSessionKey,
char* outCNonce) {
- MD5 ctx;
- ctx.Init();
+ MD5 ctx;
+ ctx.Init();
addMD5(ctx, User_);
addMD5Sep(ctx);
addMD5(ctx, hd.realm);
addMD5Sep(ctx);
addMD5(ctx, Password_);
-
+
if (hd.algorithm == 1) { //MD5-sess
- unsigned char digest[16];
- ctx.Final(digest);
-
- generateCNonce(outCNonce);
-
- ctx.Init();
- ctx.Update(digest, 16);
+ unsigned char digest[16];
+ ctx.Final(digest);
+
+ generateCNonce(outCNonce);
+
+ ctx.Init();
+ ctx.Update(digest, 16);
addMD5Sep(ctx);
addMD5(ctx, hd.nonce);
addMD5Sep(ctx);
addMD5(ctx, outCNonce);
- ctx.End(outSessionKey);
- }
-
+ ctx.End(outSessionKey);
+ }
+
ctx.End(outSessionKey);
-};
-
-/************************************************************/
-/* calculate request-digest/response-digest as per HTTP Digest spec */
+};
+
+/************************************************************/
+/* calculate request-digest/response-digest as per HTTP Digest spec */
void httpDigestHandler::digestCalcResponse(const THttpAuthHeader& hd,
const char* path,
const char* method,
const char* nonceCount,
char* outResponse,
char* outCNonce) {
- char HA1[33];
- digestCalcHA1(hd, HA1, outCNonce);
-
- char HA2[33];
- MD5 ctx;
- ctx.Init();
+ char HA1[33];
+ digestCalcHA1(hd, HA1, outCNonce);
+
+ char HA2[33];
+ MD5 ctx;
+ ctx.Init();
addMD5(ctx, method);
addMD5Sep(ctx);
addMD5(ctx, path);
- //ignore auth-int
- ctx.End(HA2);
-
- ctx.Init();
+ //ignore auth-int
+ ctx.End(HA2);
+
+ ctx.Init();
addMD5(ctx, HA1, 32);
addMD5Sep(ctx);
addMD5(ctx, Nonce_);
addMD5Sep(ctx);
-
+
if (hd.qop_auth) {
- if (!*outCNonce)
- generateCNonce(outCNonce);
-
+ if (!*outCNonce)
+ generateCNonce(outCNonce);
+
addMD5(ctx, nonceCount, 8);
addMD5Sep(ctx);
addMD5(ctx, outCNonce);
addMD5Sep(ctx);
addMD5(ctx, "auth", 4);
addMD5Sep(ctx);
- }
+ }
addMD5(ctx, HA2, 32);
- ctx.End(outResponse);
-}
-
-/************************************************************/
+ ctx.End(outResponse);
+}
+
+/************************************************************/
bool httpDigestHandler::processHeader(const THttpAuthHeader* header,
const char* path,
const char* method,
const char* cnonce) {
if (!User_ || !header || !header->use_auth || !header->realm || !header->nonce)
- return false;
-
+ return false;
+
if (Nonce_) {
if (strcmp(Nonce_, header->nonce)) {
free(Nonce_);
Nonce_ = nullptr;
NonceCount_ = 0;
- }
- }
+ }
+ }
if (!Nonce_) {
Nonce_ = strdup(header->nonce);
NonceCount_ = 0;
- }
+ }
free(HeaderInstruction_);
HeaderInstruction_ = nullptr;
NonceCount_++;
-
- char nonceCount[20];
+
+ char nonceCount[20];
sprintf(nonceCount, "%08d", NonceCount_);
-
- char CNonce[50];
- if (cnonce)
- strcpy(CNonce, cnonce);
- else
+
+ char CNonce[50];
+ if (cnonce)
+ strcpy(CNonce, cnonce);
+ else
CNonce[0] = 0;
-
- char response[33];
+
+ char response[33];
digestCalcResponse(*header, path, method, nonceCount, response, CNonce);
-
- //digest-response = 1#( username | realm | nonce | digest-uri
- // | response | [ algorithm ] | [cnonce] |
- // [opaque] | [message-qop] |
- // [nonce-count] | [auth-param] )
-
- TStringStream out;
+
+ //digest-response = 1#( username | realm | nonce | digest-uri
+ // | response | [ algorithm ] | [cnonce] |
+ // [opaque] | [message-qop] |
+ // [nonce-count] | [auth-param] )
+
+ TStringStream out;
out << WWW_PREFIX << "username=\"" << User_ << "\"";
- out << ", realm=\"" << header->realm << "\"";
- out << ", nonce=\"" << header->nonce << "\"";
- out << ", uri=\"" << path << "\"";
+ out << ", realm=\"" << header->realm << "\"";
+ out << ", nonce=\"" << header->nonce << "\"";
+ out << ", uri=\"" << path << "\"";
if (header->algorithm == 1)
- out << ", algorithm=MD5-sess";
- else
- out << ", algorithm=MD5";
- if (header->qop_auth)
- out << ", qop=auth";
- out << ", nc=" << nonceCount;
- if (CNonce[0])
- out << ", cnonce=\"" << CNonce << "\"";
- out << ", response=\"" << response << "\"";
- if (header->opaque)
- out << ", opaque=\"" << header->opaque << "\"";
- out << "\r\n";
-
+ out << ", algorithm=MD5-sess";
+ else
+ out << ", algorithm=MD5";
+ if (header->qop_auth)
+ out << ", qop=auth";
+ out << ", nc=" << nonceCount;
+ if (CNonce[0])
+ out << ", cnonce=\"" << CNonce << "\"";
+ out << ", response=\"" << response << "\"";
+ if (header->opaque)
+ out << ", opaque=\"" << header->opaque << "\"";
+ out << "\r\n";
+
TString s_out = out.Str();
HeaderInstruction_ = strdup(s_out.c_str());
-
- return true;
-}
-
-/************************************************************/
-/************************************************************/
+
+ return true;
+}
+
+/************************************************************/
+/************************************************************/
diff --git a/library/cpp/http/fetch/http_digest.h b/library/cpp/http/fetch/http_digest.h
index 3b1872d70b..018107c2e4 100644
--- a/library/cpp/http/fetch/http_digest.h
+++ b/library/cpp/http/fetch/http_digest.h
@@ -1,10 +1,10 @@
#pragma once
-
+
#include "httpheader.h"
-#include <util/system/compat.h>
+#include <util/system/compat.h>
#include <library/cpp/http/misc/httpcodes.h>
-
+
class httpDigestHandler {
protected:
const char* User_;
@@ -12,36 +12,36 @@ protected:
char* Nonce_;
int NonceCount_;
char* HeaderInstruction_;
-
- void clear();
-
+
+ void clear();
+
void generateCNonce(char* outCNonce);
-
+
void digestCalcHA1(const THttpAuthHeader& hd,
char* outSessionKey,
char* outCNonce);
-
+
void digestCalcResponse(const THttpAuthHeader& hd,
const char* method,
const char* path,
const char* nonceCount,
char* outResponse,
char* outCNonce);
-
+
public:
- httpDigestHandler();
- ~httpDigestHandler();
-
+ httpDigestHandler();
+ ~httpDigestHandler();
+
void setAuthorization(const char* user,
const char* password);
bool processHeader(const THttpAuthHeader* header,
const char* path,
const char* method,
const char* cnonce = nullptr);
-
+
bool empty() const {
return (!User_);
- }
-
+ }
+
const char* getHeaderInstruction() const;
-};
+};
diff --git a/library/cpp/http/fetch/http_socket.cpp b/library/cpp/http/fetch/http_socket.cpp
index 1524ef04a8..870d927489 100644
--- a/library/cpp/http/fetch/http_socket.cpp
+++ b/library/cpp/http/fetch/http_socket.cpp
@@ -1,30 +1,30 @@
-#include "httpload.h"
-#include "http_digest.h"
-
-/************************************************************/
-
-#ifdef USE_GNUTLS
-
-#include <gcrypt.h>
-#include <gnutls/gnutls.h>
+#include "httpload.h"
+#include "http_digest.h"
+
+/************************************************************/
+
+#ifdef USE_GNUTLS
+
+#include <gcrypt.h>
+#include <gnutls/gnutls.h>
#include <util/network/init.h>
-#include <util/network/socket.h>
-#include <util/system/mutex.h>
-
-/********************************************************/
-// HTTPS handler is used as implementation of
-// socketAbstractHandler for work through HTTPS protocol
-
+#include <util/network/socket.h>
+#include <util/system/mutex.h>
+
+/********************************************************/
+// HTTPS handler is used as implementation of
+// socketAbstractHandler for work through HTTPS protocol
+
class socketSecureHandler: public socketRegularHandler {
protected:
bool IsValid_;
gnutls_session Session_;
gnutls_certificate_credentials Credits_;
-
+
public:
socketSecureHandler();
virtual ~socketSecureHandler();
-
+
virtual bool Good();
virtual int Connect(const TAddrList& addrs, TDuration Timeout);
virtual void Disconnect();
@@ -32,175 +32,175 @@ public:
virtual bool send(const char* message, ssize_t messlen);
virtual bool peek();
virtual ssize_t read(void* buffer, ssize_t buflen);
-};
-
-/********************************************************/
-/********************************************************/
+};
+
+/********************************************************/
+/********************************************************/
static int gcry_pthread_mutex_init(void** priv) {
- int err = 0;
-
- try {
+ int err = 0;
+
+ try {
TMutex* lock = new TMutex;
- *priv = lock;
+ *priv = lock;
} catch (...) {
- err = -1;
- }
-
- return err;
-}
-
+ err = -1;
+ }
+
+ return err;
+}
+
static int gcry_pthread_mutex_destroy(void** lock) {
delete static_cast<TMutex*>(*lock);
- return 0;
-}
-
+ return 0;
+}
+
static int gcry_pthread_mutex_lock(void** lock) {
static_cast<TMutex*>(*lock)->Acquire();
-
- return 0;
-}
-
+
+ return 0;
+}
+
static int gcry_pthread_mutex_unlock(void** lock) {
static_cast<TMutex*>(*lock)->Release();
-
- return 0;
-}
-
-static struct gcry_thread_cbs gcry_threads_pthread =
+
+ return 0;
+}
+
+static struct gcry_thread_cbs gcry_threads_pthread =
{
GCRY_THREAD_OPTION_PTHREAD, NULL,
gcry_pthread_mutex_init, gcry_pthread_mutex_destroy,
gcry_pthread_mutex_lock, gcry_pthread_mutex_unlock,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL};
-
-/********************************************************/
+
+/********************************************************/
struct https_initor {
https_initor() {
gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
- gnutls_global_init();
+ gnutls_global_init();
InitNetworkSubSystem();
- }
-
+ }
+
~https_initor() {
- gnutls_global_deinit();
- }
-};
-
-static https_initor _initor;
-
-/********************************************************/
+ gnutls_global_deinit();
+ }
+};
+
+static https_initor _initor;
+
+/********************************************************/
socketSecureHandler::socketSecureHandler()
: socketRegularHandler()
, IsValid_(false)
, Session_()
, Credits_()
-{
-}
-
-/********************************************************/
+{
+}
+
+/********************************************************/
socketSecureHandler::~socketSecureHandler() {
if (IsValid_)
- Disconnect();
-}
-
-/********************************************************/
+ Disconnect();
+}
+
+/********************************************************/
bool socketSecureHandler::Good() {
return Socket_.Good() && IsValid_;
-}
-
-/********************************************************/
+}
+
+/********************************************************/
int socketSecureHandler::Connect(const TAddrList& addrs, TDuration Timeout) {
IsValid_ = false;
-
+
int ret = socketRegularHandler::Connect(addrs, Timeout);
- if (ret)
- return ret;
-
+ if (ret)
+ return ret;
+
gnutls_certificate_allocate_credentials(&Credits_);
gnutls_init(&Session_, GNUTLS_CLIENT);
gnutls_set_default_priority(Session_);
gnutls_credentials_set(Session_, GNUTLS_CRD_CERTIFICATE, Credits_);
-
+
SOCKET fd = Socket_;
gnutls_transport_set_ptr(Session_, (gnutls_transport_ptr)fd);
-
+
ret = gnutls_handshake(Session_);
-
+
if (ret < 0) {
- fprintf(stderr, "*** Handshake failed\n");
- gnutls_perror(ret);
-
+ fprintf(stderr, "*** Handshake failed\n");
+ gnutls_perror(ret);
+
gnutls_deinit(Session_);
if (Credits_) {
gnutls_certificate_free_credentials(Credits_);
Credits_ = 0;
- }
- return 1;
- }
-
+ }
+ return 1;
+ }
+
IsValid_ = true;
return !IsValid_;
-}
-
-/********************************************************/
+}
+
+/********************************************************/
void socketSecureHandler::Disconnect() {
if (IsValid_) {
gnutls_bye(Session_, GNUTLS_SHUT_RDWR);
IsValid_ = false;
gnutls_deinit(Session_);
- }
-
+ }
+
if (Credits_) {
gnutls_certificate_free_credentials(Credits_);
Credits_ = 0;
- }
-
- socketRegularHandler::Disconnect();
-}
-
-/********************************************************/
+ }
+
+ socketRegularHandler::Disconnect();
+}
+
+/********************************************************/
void socketSecureHandler::shutdown() {
-}
-
-/********************************************************/
+}
+
+/********************************************************/
bool socketSecureHandler::send(const char* message, ssize_t messlen) {
if (!IsValid_)
- return false;
+ return false;
ssize_t rv = gnutls_record_send(Session_, message, messlen);
- return rv >= 0;
-}
-
-/********************************************************/
+ return rv >= 0;
+}
+
+/********************************************************/
bool socketSecureHandler::peek() {
- //ssize_t rv = gnutls_record_check_pending(mSession);
- //return rv>0;
- return true;
-}
-
-/********************************************************/
+ //ssize_t rv = gnutls_record_check_pending(mSession);
+ //return rv>0;
+ return true;
+}
+
+/********************************************************/
ssize_t socketSecureHandler::read(void* buffer, ssize_t buflen) {
if (!IsValid_)
- return false;
+ return false;
return gnutls_record_recv(Session_, (char*)buffer, buflen);
-}
-
-#endif
-
-/************************************************************/
+}
+
+#endif
+
+/************************************************************/
socketAbstractHandler* socketHandlerFactory::chooseHandler(const THttpURL& url) {
if (url.IsValidGlobal() && url.GetScheme() == THttpURL::SchemeHTTP)
- return new socketRegularHandler;
-
+ return new socketRegularHandler;
+
#ifdef USE_GNUTLS
if (url.IsValidGlobal() && url.GetScheme() == THttpURL::SchemeHTTPS)
- return new socketSecureHandler;
+ return new socketSecureHandler;
#endif
-
+
return nullptr;
-}
-
-/************************************************************/
-socketHandlerFactory socketHandlerFactory::sInstance;
-/************************************************************/
+}
+
+/************************************************************/
+socketHandlerFactory socketHandlerFactory::sInstance;
+/************************************************************/
diff --git a/library/cpp/http/fetch/httpfetcher.h b/library/cpp/http/fetch/httpfetcher.h
index 7fc251afd2..1c5b94a678 100644
--- a/library/cpp/http/fetch/httpfetcher.h
+++ b/library/cpp/http/fetch/httpfetcher.h
@@ -1,22 +1,22 @@
#pragma once
-
-#ifdef _MSC_VER
+
+#ifdef _MSC_VER
#include <io.h>
-#endif
-
+#endif
+
#include <library/cpp/http/misc/httpdate.h>
-
-#include "httpagent.h"
-#include "httpparser.h"
-
-struct TFakeBackup {
+
+#include "httpagent.h"
+#include "httpparser.h"
+
+struct TFakeBackup {
int Write(void* /*buf*/, size_t /*size*/) {
return 0;
}
-};
-
-template <size_t bufsize = 5000>
-struct TFakeAlloc {
+};
+
+template <size_t bufsize = 5000>
+struct TFakeAlloc {
void Shrink(void* /*buf*/, size_t /*size*/) {
}
void* Grab(size_t /*min*/, size_t* real) {
@@ -24,17 +24,17 @@ struct TFakeAlloc {
return buf;
}
char buf[bufsize];
-};
-
+};
+
template <typename TAlloc = TFakeAlloc<>,
typename TCheck = TFakeCheck<>,
- typename TWriter = TFakeBackup,
+ typename TWriter = TFakeBackup,
typename TAgent = THttpAgent<>>
class THttpFetcher: public THttpParser<TCheck>, public TAlloc, public TWriter, public TAgent {
-public:
- static const size_t TCP_MIN = 1500;
- static int TerminateNow;
-
+public:
+ static const size_t TCP_MIN = 1500;
+ static int TerminateNow;
+
THttpFetcher()
: THttpParser<TCheck>()
, TAlloc()
@@ -47,54 +47,54 @@ public:
}
int Fetch(THttpHeader* header, const char* path, const char* const* headers, int persistent, bool head_request = false) {
- int ret = 0;
- int fetcherr = 0;
-
- THttpParser<TCheck>::Init(header, head_request);
+ int ret = 0;
+ int fetcherr = 0;
+
+ THttpParser<TCheck>::Init(header, head_request);
const char* scheme = HttpUrlSchemeKindToString((THttpURL::TSchemeKind)TAgent::GetScheme());
size_t schemelen = strlen(scheme);
- if (*path == '/') {
+ if (*path == '/') {
header->base = TStringBuf(scheme, schemelen);
header->base += TStringBuf("://", 3);
header->base += TStringBuf(TAgent::pHostBeg, TAgent::pHostEnd - TAgent::pHostBeg);
header->base += path;
- } else {
+ } else {
if (strlen(path) >= FETCHER_URL_MAX) {
header->error = HTTP_URL_TOO_LARGE;
return 0;
}
header->base = path;
- }
-
- if ((ret = TAgent::RequestGet(path, headers, persistent, head_request))) {
- header->error = (i16)ret;
- return 0;
- }
-
- bool inheader = 1;
+ }
+
+ if ((ret = TAgent::RequestGet(path, headers, persistent, head_request))) {
+ header->error = (i16)ret;
+ return 0;
+ }
+
+ bool inheader = 1;
void *bufptr = nullptr, *buf = nullptr, *parsebuf = nullptr;
- ssize_t got;
- size_t buffree = 0, bufsize = 0, buflen = 0;
- size_t maxsize = TCheck::GetMaxHeaderSize();
- do {
- if (buffree < TCP_MIN) {
- if (buf) {
- TAlloc::Shrink(buf, buflen - buffree);
- if (TWriter::Write(buf, buflen - buffree) < 0) {
+ ssize_t got;
+ size_t buffree = 0, bufsize = 0, buflen = 0;
+ size_t maxsize = TCheck::GetMaxHeaderSize();
+ do {
+ if (buffree < TCP_MIN) {
+ if (buf) {
+ TAlloc::Shrink(buf, buflen - buffree);
+ if (TWriter::Write(buf, buflen - buffree) < 0) {
buf = nullptr;
- ret = EIO;
- break;
- }
- }
- if (!(buf = TAlloc::Grab(TCP_MIN, &buflen))) {
- ret = ENOMEM;
- break;
- }
- bufptr = buf;
- buffree = buflen;
- }
- if ((got = TAgent::read(bufptr, buffree)) < 0) {
- fetcherr = errno;
+ ret = EIO;
+ break;
+ }
+ }
+ if (!(buf = TAlloc::Grab(TCP_MIN, &buflen))) {
+ ret = ENOMEM;
+ break;
+ }
+ bufptr = buf;
+ buffree = buflen;
+ }
+ if ((got = TAgent::read(bufptr, buffree)) < 0) {
+ fetcherr = errno;
if (errno == EINTR)
header->error = HTTP_INTERRUPTED;
else if (errno == ETIMEDOUT)
@@ -102,43 +102,43 @@ public:
else
header->error = HTTP_CONNECTION_LOST;
- break;
- }
-
- parsebuf = bufptr;
- bufptr = (char*)bufptr + got;
- bufsize += got;
- buffree -= got;
-
- THttpParser<TCheck>::Parse(parsebuf, got);
-
- if (header->error)
+ break;
+ }
+
+ parsebuf = bufptr;
+ bufptr = (char*)bufptr + got;
+ bufsize += got;
+ buffree -= got;
+
+ THttpParser<TCheck>::Parse(parsebuf, got);
+
+ if (header->error)
break; //if ANY error ocurred we will stop download that file or will have unprognosed stream position until MAX size reached
-
- if (inheader && THttpParser<TCheck>::GetState() != THttpParser<TCheck>::hp_in_header) {
- inheader = 0;
- if (TCheck::Check(header))
- break;
- if (header->header_size > (long)maxsize) {
- header->error = HTTP_HEADER_TOO_LARGE;
- break;
- }
+
+ if (inheader && THttpParser<TCheck>::GetState() != THttpParser<TCheck>::hp_in_header) {
+ inheader = 0;
+ if (TCheck::Check(header))
+ break;
+ if (header->header_size > (long)maxsize) {
+ header->error = HTTP_HEADER_TOO_LARGE;
+ break;
+ }
}
if (!inheader) {
- maxsize = TCheck::GetMaxBodySize(header);
- }
- if (header->http_status >= HTTP_EXTENDED)
- break;
- if (bufsize > maxsize) {
- header->error = inheader ? HTTP_HEADER_TOO_LARGE : HTTP_BODY_TOO_LARGE;
- break;
- }
- if (TerminateNow) {
- header->error = HTTP_INTERRUPTED;
- break;
- }
- } while (THttpParser<TCheck>::GetState() > THttpParser<TCheck>::hp_eof);
-
+ maxsize = TCheck::GetMaxBodySize(header);
+ }
+ if (header->http_status >= HTTP_EXTENDED)
+ break;
+ if (bufsize > maxsize) {
+ header->error = inheader ? HTTP_HEADER_TOO_LARGE : HTTP_BODY_TOO_LARGE;
+ break;
+ }
+ if (TerminateNow) {
+ header->error = HTTP_INTERRUPTED;
+ break;
+ }
+ } while (THttpParser<TCheck>::GetState() > THttpParser<TCheck>::hp_eof);
+
i64 Adjustment = 0;
if (!header->error) {
if (header->transfer_chunked) {
@@ -150,22 +150,22 @@ public:
Adjustment = 0;
}
- if (buf) {
+ if (buf) {
TAlloc::Shrink(buf, buflen - buffree + Adjustment);
- if (TWriter::Write(buf, buflen - buffree) < 0)
- ret = EIO;
- }
- TCheck::CheckEndDoc(header);
- if (ret || header->error || header->http_status >= HTTP_EXTENDED || header->connection_closed) {
- TAgent::Disconnect();
- if (!fetcherr)
- fetcherr = errno;
- }
- errno = fetcherr;
- return ret;
- }
-};
-
-template <typename TAlloc, typename TCheck, typename TWriter, typename TAgent>
-int THttpFetcher<TAlloc, TCheck, TWriter, TAgent>::TerminateNow = 0;
+ if (TWriter::Write(buf, buflen - buffree) < 0)
+ ret = EIO;
+ }
+ TCheck::CheckEndDoc(header);
+ if (ret || header->error || header->http_status >= HTTP_EXTENDED || header->connection_closed) {
+ TAgent::Disconnect();
+ if (!fetcherr)
+ fetcherr = errno;
+ }
+ errno = fetcherr;
+ return ret;
+ }
+};
+
+template <typename TAlloc, typename TCheck, typename TWriter, typename TAgent>
+int THttpFetcher<TAlloc, TCheck, TWriter, TAgent>::TerminateNow = 0;
diff --git a/library/cpp/http/fetch/httpfsm.h b/library/cpp/http/fetch/httpfsm.h
index c4abdcd0d2..62a27b6561 100644
--- a/library/cpp/http/fetch/httpfsm.h
+++ b/library/cpp/http/fetch/httpfsm.h
@@ -1,13 +1,13 @@
#pragma once
-
+
#include "httpheader.h"
-#include <util/system/maxlen.h>
+#include <util/system/maxlen.h>
#include <util/datetime/parser.h>
-
+
#include <time.h>
-struct THttpHeaderParser {
+struct THttpHeaderParser {
static constexpr int ErrFirstlineTypeMismatch = -3;
static constexpr int ErrHeader = -2;
static constexpr int Err = -1;
@@ -16,34 +16,34 @@ struct THttpHeaderParser {
static constexpr int Accepted = 2;
int Execute(const void* inBuf, size_t len) {
- return execute((unsigned char*)inBuf, (int)len);
- }
-
+ return execute((unsigned char*)inBuf, (int)len);
+ }
+
int Execute(TStringBuf str) {
return Execute(str.data(), str.size());
}
int Init(THttpHeader* h) {
int ret = Init((THttpBaseHeader*)(h));
- hd = h;
- hd->Init();
+ hd = h;
+ hd->Init();
hreflangpos = hd->hreflangs;
hreflangspace = HREFLANG_MAX;
return ret;
- }
-
+ }
+
int Init(THttpAuthHeader* h) {
- int ret = Init((THttpHeader*)(h));
- auth_hd = h;
- return ret;
- }
+ int ret = Init((THttpHeader*)(h));
+ auth_hd = h;
+ return ret;
+ }
int Init(THttpRequestHeader* h) {
int ret = Init((THttpBaseHeader*)(h));
request_hd = h;
request_hd->Init();
return ret;
}
-
+
THttpHeader* hd;
long I;
int Dc;
@@ -51,7 +51,7 @@ struct THttpHeaderParser {
char buf[FETCHER_URL_MAX];
size_t buflen;
char* lastchar;
-
+
const unsigned char* langstart;
size_t langlen;
@@ -62,10 +62,10 @@ struct THttpHeaderParser {
THttpAuthHeader* auth_hd;
THttpRequestHeader* request_hd;
-
-private:
+
+private:
THttpBaseHeader* base_hd;
- int cs;
+ int cs;
private:
int Init(THttpBaseHeader* header) {
@@ -78,27 +78,27 @@ private:
}
int execute(unsigned char* inBuf, int len);
- void init();
-};
-
-struct THttpChunkParser {
+ void init();
+};
+
+struct THttpChunkParser {
int Execute(const void* inBuf, int len) {
- return execute((unsigned char*)inBuf, len);
- }
-
- int Init() {
- init();
- return 0;
- }
-
+ return execute((unsigned char*)inBuf, len);
+ }
+
+ int Init() {
+ init();
+ return 0;
+ }
+
int chunk_length;
char* lastchar;
long I;
int Dc;
i64 cnt64;
-
-private:
- int cs;
+
+private:
+ int cs;
int execute(unsigned char* inBuf, int len);
- void init();
-};
+ void init();
+};
diff --git a/library/cpp/http/fetch/httpfsm.rl6 b/library/cpp/http/fetch/httpfsm.rl6
index eab0328b18..83557b144e 100644
--- a/library/cpp/http/fetch/httpfsm.rl6
+++ b/library/cpp/http/fetch/httpfsm.rl6
@@ -1,70 +1,70 @@
-#include <stdio.h>
-#include <time.h>
-
+#include <stdio.h>
+#include <time.h>
+
#include <library/cpp/charset/doccodes.h>
#include <library/cpp/charset/codepage.h>
#include <library/cpp/http/misc/httpcodes.h>
#include <util/datetime/base.h>
#include <util/generic/ylimits.h>
#include <algorithm> // max
-
+
#include <library/cpp/http/fetch/httpheader.h>
#include <library/cpp/http/fetch/httpfsm.h>
-
+
#ifdef _MSC_VER
#pragma warning(disable: 4702) // unreachable code
#endif
#define c(i) I = i;
#define m(i) I = std::max(I, (long)i);
-
-static inline int X(unsigned char c) {
- return (c >= 'A' ? ((c & 0xdf) - 'A' + 10) : (c - '0'));
-}
-
-template <typename x>
-static inline void guard(x &val) {
- val = (val >= -1) ? -4 - val : -2; // f(-2) = -2
-}
-
-template <typename x>
-static inline void setguarded(x &val, long cnt) {
- val = (val == -4 - -1 || cnt == -4 -val) ? cnt : -2;
-}
-
-////////////////////////////////////////////////////////////////////
-/// HTTP PARSER
-////////////////////////////////////////////////////////////////////
-
-%%{
-machine http_header_parser;
-
+
+static inline int X(unsigned char c) {
+ return (c >= 'A' ? ((c & 0xdf) - 'A' + 10) : (c - '0'));
+}
+
+template <typename x>
+static inline void guard(x &val) {
+ val = (val >= -1) ? -4 - val : -2; // f(-2) = -2
+}
+
+template <typename x>
+static inline void setguarded(x &val, long cnt) {
+ val = (val == -4 - -1 || cnt == -4 -val) ? cnt : -2;
+}
+
+////////////////////////////////////////////////////////////////////
+/// HTTP PARSER
+////////////////////////////////////////////////////////////////////
+
+%%{
+machine http_header_parser;
+
include HttpDateTimeParser "../../../../util/datetime/parser.rl6";
-alphtype unsigned char;
-
-################# 2.2 Basic Rules #################
-eol = '\r'? '\n';
-ws = [ \t];
-lw = '\r'? '\n'? ws;
+alphtype unsigned char;
+
+################# 2.2 Basic Rules #################
+eol = '\r'? '\n';
+ws = [ \t];
+lw = '\r'? '\n'? ws;
separator = [()<>@,;:\\"/\[\]?={}];
-token_char = [!-~] - separator; # http tokens chars
-url_char = [!-~] - ["<>\[\]\\^`{}|]; # uric chars
-text_char = ws | 33..126 | 128..255;
-any_text_char = any - [\r\n];
-
-lws = lw*;
-eoh = lws eol;
-token = token_char+;
-ex_token = (token_char | ws)* token_char;
-text = (text_char | lw)*;
-any_text = (any_text_char | lw)*;
-def = lws ':' lws;
-
+token_char = [!-~] - separator; # http tokens chars
+url_char = [!-~] - ["<>\[\]\\^`{}|]; # uric chars
+text_char = ws | 33..126 | 128..255;
+any_text_char = any - [\r\n];
+
+lws = lw*;
+eoh = lws eol;
+token = token_char+;
+ex_token = (token_char | ws)* token_char;
+text = (text_char | lw)*;
+any_text = (any_text_char | lw)*;
+def = lws ':' lws;
+
action clear_buf { buflen = 0; }
action update_buf { if (buflen < sizeof(buf)) buf[buflen++] = fc; }
-
-###################################################
+
+###################################################
############ response status line #################
action set_minor { base_hd->http_minor = I; }
action set_status {
@@ -75,14 +75,14 @@ action set_status {
return -3;
}
}
-
+
status_code = int3;
http_major = int;
http_minor = int;
reason_phrase = ws+ text_char*;
http_version = "http/"i http_major '.' http_minor %set_minor;
response_status_line = http_version ws+ status_code reason_phrase? eol %set_status;
-
+
############ request status line #################
action set_request_uri {
if (request_hd && buflen < FETCHER_URL_MAX) {
@@ -116,44 +116,44 @@ request_uri = (token_char | separator)+ >clear_buf $update_buf
%set_request_uri;
request_status_line = http_method ws+ request_uri ws+ http_version eoh;
-################# connection ######################
+################# connection ######################
action beg_connection { guard(base_hd->connection_closed); I = -1; }
action set_connection { setguarded(base_hd->connection_closed, I); }
-
-c_token = "close"i %{m(1)}
- | "keep-alive"i %{m(0)};
-c_tokenlist = c_token (lws ',' lws c_token)?;
+
+c_token = "close"i %{m(1)}
+ | "keep-alive"i %{m(0)};
+c_tokenlist = c_token (lws ',' lws c_token)?;
connection = "connection"i def %beg_connection c_tokenlist eoh %set_connection;
-
-################# content-encoding ################
+
+################# content-encoding ################
action beg_content_encoding { I = HTTP_COMPRESSION_ERROR; }
action set_content_encoding { base_hd->compression_method =
((base_hd->compression_method == HTTP_COMPRESSION_UNSET ||
base_hd->compression_method == I) ?
I : (int)HTTP_COMPRESSION_ERROR); }
-
-ce_tokenlist = "identity"i %{c(HTTP_COMPRESSION_IDENTITY)}
- | "gzip"i %{c(HTTP_COMPRESSION_GZIP)}
- | "x-gzip"i %{c(HTTP_COMPRESSION_GZIP)}
- | "deflate"i %{c(HTTP_COMPRESSION_DEFLATE)}
- | "compress"i %{c(HTTP_COMPRESSION_COMPRESS)}
- | "x-compress"i %{c(HTTP_COMPRESSION_COMPRESS)};
+
+ce_tokenlist = "identity"i %{c(HTTP_COMPRESSION_IDENTITY)}
+ | "gzip"i %{c(HTTP_COMPRESSION_GZIP)}
+ | "x-gzip"i %{c(HTTP_COMPRESSION_GZIP)}
+ | "deflate"i %{c(HTTP_COMPRESSION_DEFLATE)}
+ | "compress"i %{c(HTTP_COMPRESSION_COMPRESS)}
+ | "x-compress"i %{c(HTTP_COMPRESSION_COMPRESS)};
content_encoding = "content-encoding"i def %beg_content_encoding ce_tokenlist eoh %set_content_encoding;
-
-################# transfer-encoding ###############
+
+################# transfer-encoding ###############
action beg_encoding { guard(base_hd->transfer_chunked); }
action set_encoding { setguarded(base_hd->transfer_chunked, I); }
-
-e_tokenlist = "identity"i %{c(0)}
- | "chunked"i %{c(1)};
+
+e_tokenlist = "identity"i %{c(0)}
+ | "chunked"i %{c(1)};
transfer_encoding = "transfer-encoding"i def %beg_encoding e_tokenlist eoh %set_encoding;
-
-################# content-length ##################
+
+################# content-length ##################
action beg_content_length { guard(base_hd->content_length); }
action set_content_length { setguarded(base_hd->content_length, I); }
-
+
content_length = "content-length"i def %beg_content_length int eoh %set_content_length;
-
+
################# content-range ###################
action beg_content_range_start { guard(base_hd->content_range_start); I = -1; }
action set_content_range_start { setguarded(base_hd->content_range_start, I); }
@@ -166,7 +166,7 @@ content_range = "content-range"i def "bytes"i sp %beg_content_range_start int
%beg_content_range_end int '/' %set_content_range_end
%beg_content_range_el int eoh %set_content_range_el;
-################# accept-ranges ###################
+################# accept-ranges ###################
action beg_accept_ranges {
if (hd) {
guard(hd->accept_ranges);
@@ -174,21 +174,21 @@ action beg_accept_ranges {
}
}
action set_accept_ranges { if (hd) setguarded(hd->accept_ranges, I); }
-
-ar_tokenlist = "bytes"i %{c(1)}
- | "none"i %{c(0)};
+
+ar_tokenlist = "bytes"i %{c(1)}
+ | "none"i %{c(0)};
accept_ranges = "accept-ranges"i def %beg_accept_ranges ar_tokenlist eoh %set_accept_ranges;
-
-################# content-type ####################
+
+################# content-type ####################
action beg_mime { guard(base_hd->mime_type); }
action set_mime { setguarded(base_hd->mime_type, I); }
action set_charset {
if (buflen < FETCHER_URL_MAX) {
- buf[buflen++] = 0;
+ buf[buflen++] = 0;
base_hd->charset = EncodingHintByName((const char*)buf);
- }
-}
-
+ }
+}
+
mime_type = "text/plain"i %{c(MIME_TEXT)}
| "text/html"i %{c(MIME_HTML)}
| "application/pdf"i %{c(MIME_PDF)}
@@ -234,36 +234,36 @@ mime_type = "text/plain"i %{c(MIME_TEXT)}
charset_name = token_char+ >clear_buf $update_buf;
mime_param = "charset"i ws* '=' ws* '"'? charset_name '"'? %set_charset @2
- | token ws* '=' ws* '"'? token '"'? @1
- | text $0;
-mime_parms = (lws ';' lws mime_param)*;
+ | token ws* '=' ws* '"'? token '"'? @1
+ | text $0;
+mime_parms = (lws ';' lws mime_param)*;
content_type = "content-type"i def %beg_mime mime_type mime_parms eoh %set_mime;
-
-################# last modified ###################
+
+################# last modified ###################
action beg_modtime { guard(base_hd->http_time); }
action set_modtime {
setguarded(base_hd->http_time, DateTimeFields.ToTimeT(-1));
}
-
+
last_modified = "last-modified"i def %beg_modtime http_date eoh %set_modtime;
-
-################# location ########################
+
+################# location ########################
action set_location {
while (buflen > 0 && (buf[buflen - 1] == ' ' || buf[buflen - 1] == '\t')) {
buflen --;
}
if (hd && buflen < FETCHER_URL_MAX) {
hd->location = TStringBuf(buf, buflen);
- }
-}
-
+ }
+}
+
action set_status_303{ if (hd) hd->http_status = 303; }
-
+
url = url_char+ >clear_buf $update_buf;
loc_url = any_text_char+ >clear_buf $update_buf;
location = "location"i def loc_url eoh %set_location;
refresh = "refresh"i def int ';' lws "url="i loc_url eoh %set_location;
-
+
################# x-robots-tag ################
action set_x_robots {
if (hd && AcceptingXRobots) {
@@ -349,56 +349,56 @@ action set_squid_error {
squid_error = "X-Yandex-Squid-Error"i def any_text eoh %set_squid_error;
-################# auth ########################
+################# auth ########################
action init_auth {
- if (auth_hd)
- auth_hd->use_auth=true;
-}
-
+ if (auth_hd)
+ auth_hd->use_auth=true;
+}
+
action update_auth_buf
- { if (auth_hd && buflen < sizeof(buf)) buf[buflen++] = *fpc; }
-
-quoted_str = /"/ (text_char - /"/)* /"/ >2;
+ { if (auth_hd && buflen < sizeof(buf)) buf[buflen++] = *fpc; }
+
+quoted_str = /"/ (text_char - /"/)* /"/ >2;
auth_quoted_str = ( /"/ ( ( text_char - /"/ )* >clear_buf $update_auth_buf ) /"/ ) > 2;
-
-# do not support auth-int, too heavy procedure
-
-qop_auth_option = "auth"i @1 %{if(auth_hd) auth_hd->qop_auth = true; };
-
-qop_option = ( qop_auth_option @1 ) | (( token-"auth"i) $0 );
-
-auth_good_param = ( "nonce"i /=/ auth_quoted_str )
+
+# do not support auth-int, too heavy procedure
+
+qop_auth_option = "auth"i @1 %{if(auth_hd) auth_hd->qop_auth = true; };
+
+qop_option = ( qop_auth_option @1 ) | (( token-"auth"i) $0 );
+
+auth_good_param = ( "nonce"i /=/ auth_quoted_str )
%{if (auth_hd && buflen < FETCHER_URL_MAX-1) {
- buf[buflen++] = 0;
- auth_hd->nonce = strdup((const char*)buf);
- }}
- | ( "realm"i /=/ auth_quoted_str )
+ buf[buflen++] = 0;
+ auth_hd->nonce = strdup((const char*)buf);
+ }}
+ | ( "realm"i /=/ auth_quoted_str )
%{if (auth_hd && buflen < FETCHER_URL_MAX-1) {
- buf[buflen++] = 0;
- auth_hd->realm = strdup((const char*)buf);
- }}
- | ( "opaque"i /=/ auth_quoted_str )
+ buf[buflen++] = 0;
+ auth_hd->realm = strdup((const char*)buf);
+ }}
+ | ( "opaque"i /=/ auth_quoted_str )
%{if (auth_hd && buflen < FETCHER_URL_MAX-1) {
- buf[buflen++] = 0;
- auth_hd->opaque = strdup((const char*)buf);
- }}
- | "stale"i /=/ "true"i
- %{if (auth_hd) auth_hd->stale = true; }
- | "algorithm"i /=/ "md5"i /-/ "sess"i
- %{if (auth_hd) auth_hd->algorithm = 1; }
- | ( "qop"i /="/ qop_option (ws* "," ws* qop_option)* /"/);
-
-auth_param = auth_good_param @1 |
- ( (token - ( "nonce"i | "opaque"i | "realm"i | "qop"i ) )
- /=/ (token | quoted_str ) ) $0;
-
-auth_params = auth_param ( ws* /,/ ws* auth_param )*;
-
+ buf[buflen++] = 0;
+ auth_hd->opaque = strdup((const char*)buf);
+ }}
+ | "stale"i /=/ "true"i
+ %{if (auth_hd) auth_hd->stale = true; }
+ | "algorithm"i /=/ "md5"i /-/ "sess"i
+ %{if (auth_hd) auth_hd->algorithm = 1; }
+ | ( "qop"i /="/ qop_option (ws* "," ws* qop_option)* /"/);
+
+auth_param = auth_good_param @1 |
+ ( (token - ( "nonce"i | "opaque"i | "realm"i | "qop"i ) )
+ /=/ (token | quoted_str ) ) $0;
+
+auth_params = auth_param ( ws* /,/ ws* auth_param )*;
+
digest_challenge = ("digest"i %init_auth ws+ auth_params) |
- ((token-"digest"i) text);
-
-auth = "www-authenticate"i def digest_challenge eoh;
-
+ ((token-"digest"i) text);
+
+auth = "www-authenticate"i def digest_challenge eoh;
+
###################### host #######################
action set_host {
if (request_hd && buflen < HOST_MAX) {
@@ -562,8 +562,8 @@ action set_request_priority {
request_priority = "x-yandex-request-priority"i def int eoh
%set_request_priority;
-################# message header ##################
-other_header = ( ex_token - "www-authenticate"i ) def any_text eoh;
+################# message header ##################
+other_header = ( ex_token - "www-authenticate"i ) def any_text eoh;
message_header = other_header $0
| connection @1
| content_encoding @1
@@ -595,90 +595,90 @@ request_header = message_header $0
| request_cache_control @1
| response_timeout @1
| request_priority @1;
-
-################# main ############################
+
+################# main ############################
action accepted { lastchar = (char*)fpc; return 2; }
-
+
main := ((response_status_line ('\r'? response_header)*)
| (request_status_line ('\r' ? request_header)*))
eol @accepted;
-
-}%%
-
-%% write data;
-
-int THttpHeaderParser::execute(unsigned char *inBuf, int len) {
- const unsigned char *p = inBuf;
- const unsigned char *pe = p + len;
- %% write exec;
- if (cs == http_header_parser_error)
- return -1;
- else if (cs == http_header_parser_first_final)
- return 0;
- else
- return 1;
-}
-
-void THttpHeaderParser::init() {
- %% write init;
-}
-
-%%{
-machine http_chunk_parser;
-
-alphtype unsigned char;
-
+
+}%%
+
+%% write data;
+
+int THttpHeaderParser::execute(unsigned char *inBuf, int len) {
+ const unsigned char *p = inBuf;
+ const unsigned char *pe = p + len;
+ %% write exec;
+ if (cs == http_header_parser_error)
+ return -1;
+ else if (cs == http_header_parser_first_final)
+ return 0;
+ else
+ return 1;
+}
+
+void THttpHeaderParser::init() {
+ %% write init;
+}
+
+%%{
+machine http_chunk_parser;
+
+alphtype unsigned char;
+
action clear_hex { cnt64 = 0; }
action update_hex { cnt64 = 16 * cnt64 + X(fc); if(cnt64 > Max<int>()) return -2; }
action set_chunk { chunk_length = static_cast<int>(cnt64); }
action accepted { lastchar = (char*)fpc; return 2; }
-
-eol = '\r'? '\n';
-ws = [ \t];
-sp = ' ';
-lw = '\r'? '\n'? ws;
-separator = [()<>@,;:\\"/\[\]?={}];
-token_char = [!-~] - separator; # http tokens chars
-url_char = [!-~] - ["<>\[\]\\^`{}|]; # uric chars
-text_char = ws | 33..127 | 160..255;
-
-lws = lw*;
-eoh = lws eol;
-token = token_char+;
-text = (text_char | lw)*;
-def = lws ':' lws;
-
+
+eol = '\r'? '\n';
+ws = [ \t];
+sp = ' ';
+lw = '\r'? '\n'? ws;
+separator = [()<>@,;:\\"/\[\]?={}];
+token_char = [!-~] - separator; # http tokens chars
+url_char = [!-~] - ["<>\[\]\\^`{}|]; # uric chars
+text_char = ws | 33..127 | 160..255;
+
+lws = lw*;
+eoh = lws eol;
+token = token_char+;
+text = (text_char | lw)*;
+def = lws ':' lws;
+
hex = (xdigit+) >clear_hex $update_hex;
-quoted_string = '"' ((text_char - '"') $0 | '\\"' @1)* '"';
-
-chunk_ext_val = token | quoted_string;
-chunk_ext_name = token;
-chunk_extension = ws* (';' chunk_ext_name ws* '=' ws* chunk_ext_val ws*)*;
-
-entity_header = token def text eoh;
-trailer = entity_header*;
-
+quoted_string = '"' ((text_char - '"') $0 | '\\"' @1)* '"';
+
+chunk_ext_val = token | quoted_string;
+chunk_ext_name = token;
+chunk_extension = ws* (';' chunk_ext_name ws* '=' ws* chunk_ext_val ws*)*;
+
+entity_header = token def text eoh;
+trailer = entity_header*;
+
chunk = (hex - '0'+) chunk_extension? %set_chunk;
-last_chunk = '0'+ chunk_extension? eol trailer;
+last_chunk = '0'+ chunk_extension? eol trailer;
main := eol (chunk $0 | last_chunk @1) eol @accepted;
-
-}%%
-
-%% write data;
-
-int THttpChunkParser::execute(unsigned char *inBuf, int len) {
- const unsigned char *p = inBuf;
- const unsigned char *pe = p + len;
- %% write exec;
- if (cs == http_chunk_parser_error)
- return -1;
- else if (cs == http_chunk_parser_first_final)
- return 0;
- else
- return 1;
-}
-
-void THttpChunkParser::init() {
- chunk_length = 0;
- %% write init;
-}
+
+}%%
+
+%% write data;
+
+int THttpChunkParser::execute(unsigned char *inBuf, int len) {
+ const unsigned char *p = inBuf;
+ const unsigned char *pe = p + len;
+ %% write exec;
+ if (cs == http_chunk_parser_error)
+ return -1;
+ else if (cs == http_chunk_parser_first_final)
+ return 0;
+ else
+ return 1;
+}
+
+void THttpChunkParser::init() {
+ chunk_length = 0;
+ %% write init;
+}
diff --git a/library/cpp/http/fetch/httpheader.h b/library/cpp/http/fetch/httpheader.h
index b2810bbd41..20f8e0956b 100644
--- a/library/cpp/http/fetch/httpheader.h
+++ b/library/cpp/http/fetch/httpheader.h
@@ -1,5 +1,5 @@
#pragma once
-
+
#include "exthttpcodes.h"
#include <library/cpp/mime/types/mime.h>
@@ -11,11 +11,11 @@
#include <util/system/maxlen.h>
#include <ctime>
-#include <cstdio>
-#include <cstdlib>
-#include <cstring>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
#include <algorithm>
-
+
// This is ugly solution but here a lot of work to do it the right way.
#define FETCHER_URL_MAX 8192
@@ -29,16 +29,16 @@ extern const i32 DEFAULT_RESPONSE_TIMEOUT; /// == -1
#define MAX_LANGREGION_LEN 4
#define MAXWORD_LEN 55
-enum HTTP_COMPRESSION {
+enum HTTP_COMPRESSION {
HTTP_COMPRESSION_UNSET = 0,
HTTP_COMPRESSION_ERROR = 1,
- HTTP_COMPRESSION_IDENTITY = 2,
+ HTTP_COMPRESSION_IDENTITY = 2,
HTTP_COMPRESSION_GZIP = 3,
HTTP_COMPRESSION_DEFLATE = 4,
- HTTP_COMPRESSION_COMPRESS = 5,
+ HTTP_COMPRESSION_COMPRESS = 5,
HTTP_COMPRESSION_MAX = 6
-};
-
+};
+
enum HTTP_METHOD {
HTTP_METHOD_UNDEFINED = -1,
HTTP_METHOD_OPTIONS,
@@ -78,25 +78,25 @@ public:
TString base;
public:
- void Init() {
+ void Init() {
error = 0;
- header_size = 0;
- entity_size = 0;
- content_length = -1;
- http_time = -1;
- http_minor = -1;
- mime_type = -1;
- charset = -1;
- compression_method = HTTP_COMPRESSION_UNSET;
- transfer_chunked = -1;
+ header_size = 0;
+ entity_size = 0;
+ content_length = -1;
+ http_time = -1;
+ http_minor = -1;
+ mime_type = -1;
+ charset = -1;
+ compression_method = HTTP_COMPRESSION_UNSET;
+ transfer_chunked = -1;
connection_closed = HTTP_CONNECTION_UNDEFINED;
content_range_start = -1;
content_range_end = -1;
content_range_entity_length = -1;
base.clear();
- }
-
- void Print() const {
+ }
+
+ void Print() const {
printf("content_length: %" PRIi64 "\n", content_length);
printf("http_time: %" PRIi64 "\n", http_time);
printf("http_minor: %" PRIi8 "\n", http_minor);
@@ -110,22 +110,22 @@ public:
printf("content_range_entity_length: %" PRIi64 "\n", content_range_entity_length);
printf("base: \"%s\"\n", base.c_str());
printf("error: %" PRIi16 "\n", error);
- }
-
- int SetBase(const char* path,
+ }
+
+ int SetBase(const char* path,
const char* hostNamePtr = nullptr,
int hostNameLength = 0) {
if (*path == '/') {
base = "http://";
base += TStringBuf(hostNamePtr, hostNameLength);
base += path;
- } else {
+ } else {
base = path;
- }
- return error;
- }
-};
-
+ }
+ return error;
+ }
+};
+
enum { HREFLANG_MAX = FETCHER_URL_MAX * 2 };
/// Class represents Http Response Header.
struct THttpHeader: public THttpBaseHeader {
@@ -165,7 +165,7 @@ public:
};
struct THttpRequestHeader: public THttpBaseHeader {
-public:
+public:
TString request_uri;
char host[HOST_MAX];
char from[MAXWORD_LEN];
@@ -184,7 +184,7 @@ public:
THttpRequestHeader() {
Init();
}
-
+
void Init() {
request_uri.clear();
host[0] = 0;
@@ -201,7 +201,7 @@ public:
if_modified_since = DEFAULT_IF_MODIFIED_SINCE;
THttpBaseHeader::Init();
}
-
+
void Print() const {
THttpBaseHeader::Print();
printf("request_uri: \"%s\"\n", request_uri.c_str());
@@ -213,7 +213,7 @@ public:
printf("max_age: %" PRIi32 "\n", max_age);
printf("if_modified_since: %" PRIi64 "\n", if_modified_since);
}
-
+
/// It doesn't care about errors in request or headers, where
/// request_uri equals to '*'.
/// This returns copy of the string, which you have to delete.
@@ -225,20 +225,20 @@ public:
url = HTTP_PREFIX;
url += host;
url += request_uri;
- }
+ }
return url;
}
-
+
char* GetUrl(char* buffer, size_t size) {
if (host[0] == 0 || !strcmp(host, "")) {
strlcpy(buffer, request_uri.c_str(), size);
} else {
snprintf(buffer, size, "http://%s%s", host, request_uri.c_str());
- }
+ }
return buffer;
}
};
-
+
class THttpAuthHeader: public THttpHeader {
public:
char* realm;
@@ -282,6 +282,6 @@ public:
printf("stale: %d\n", stale);
printf("algorithm: %d\n", algorithm);
printf("qop_auth: %d\n", qop_auth);
- }
+ }
}
-};
+};
diff --git a/library/cpp/http/fetch/httpload.cpp b/library/cpp/http/fetch/httpload.cpp
index 82ea8900b5..f944d7906a 100644
--- a/library/cpp/http/fetch/httpload.cpp
+++ b/library/cpp/http/fetch/httpload.cpp
@@ -1,7 +1,7 @@
-#include "httpload.h"
-
-/************************************************************/
-/************************************************************/
+#include "httpload.h"
+
+/************************************************************/
+/************************************************************/
httpAgentReader::httpAgentReader(httpSpecialAgent& agent,
const char* baseUrl,
bool assumeConnectionClosed,
@@ -13,109 +13,109 @@ httpAgentReader::httpAgentReader(httpSpecialAgent& agent,
, BufPtr_(Buffer_)
, BufSize_(bufSize)
, BufRest_(0)
-{
- HeadRequest = false;
+{
+ HeadRequest = false;
Header = &Header_;
- if (use_auth)
+ if (use_auth)
HeaderParser.Init(&Header_);
- else
- HeaderParser.Init(Header);
+ else
+ HeaderParser.Init(Header);
setAssumeConnectionClosed(assumeConnectionClosed ? 1 : 0);
Header_.SetBase(baseUrl);
-
+
if (Header_.error)
- State = hp_error;
- else
- State = hp_in_header;
-}
-
-/************************************************************/
+ State = hp_error;
+ else
+ State = hp_in_header;
+}
+
+/************************************************************/
httpAgentReader::~httpAgentReader() {
delete[] Buffer_;
-}
-
-/************************************************************/
+}
+
+/************************************************************/
void httpAgentReader::readBuf() {
assert(BufRest_ == 0);
if (!BufPtr_) {
BufRest_ = -1;
- return;
- }
-
+ return;
+ }
+
BufRest_ = Agent_.read(Buffer_, BufSize_);
if (BufRest_ <= 0) {
BufRest_ = -1;
BufPtr_ = nullptr;
- } else {
+ } else {
BufPtr_ = Buffer_;
- //cout << "BUF: " << mBuffer << endl << endl;
- }
-}
-
-/************************************************************/
+ //cout << "BUF: " << mBuffer << endl << endl;
+ }
+}
+
+/************************************************************/
const THttpHeader* httpAgentReader::readHeader() {
while (State == hp_in_header) {
if (!step()) {
Header_.error = HTTP_CONNECTION_LOST;
return nullptr;
- }
+ }
ParseGeneric(BufPtr_, BufRest_);
- }
+ }
if (State == hp_eof || State == hp_error) {
BufPtr_ = nullptr;
BufRest_ = -1;
- }
+ }
if (State == hp_error || Header_.error)
return nullptr;
return &Header_;
-}
-
-/************************************************************/
+}
+
+/************************************************************/
long httpAgentReader::readPortion(void*& buf) {
assert(State != hp_in_header);
-
- long Chunk = 0;
+
+ long Chunk = 0;
do {
if (BufSize_ == 0 && !BufPtr_)
- return 0;
-
- if (!step())
- return 0;
-
+ return 0;
+
+ if (!step())
+ return 0;
+
Chunk = ParseGeneric(BufPtr_, BufRest_);
buf = BufPtr_;
-
+
if (State == hp_error && Header_.entity_size > Header_.content_length) {
Chunk -= (Header_.entity_size - Header_.content_length);
BufPtr_ = (char*)BufPtr_ + Chunk;
BufRest_ = 0;
State = hp_eof;
Header_.error = 0;
- break;
- }
-
+ break;
+ }
+
BufPtr_ = (char*)BufPtr_ + Chunk;
BufRest_ -= Chunk;
-
+
if (State == hp_eof || State == hp_error) {
BufRest_ = -1;
BufPtr_ = nullptr;
- }
- } while (!Chunk);
- return Chunk;
-}
-
-/************************************************************/
+ }
+ } while (!Chunk);
+ return Chunk;
+}
+
+/************************************************************/
bool httpAgentReader::skipTheRest() {
void* b;
- while (!eof())
- readPortion(b);
+ while (!eof())
+ readPortion(b);
return (State == hp_eof);
-}
-
-/************************************************************/
-/************************************************************/
+}
+
+/************************************************************/
+/************************************************************/
httpLoadAgent::httpLoadAgent(bool handleAuthorization,
socketHandlerFactory& factory)
: Factory_(factory)
@@ -126,82 +126,82 @@ httpLoadAgent::httpLoadAgent(bool handleAuthorization,
, Headers_()
, ErrCode_(0)
, RealHost_(nullptr)
-{
-}
-
-/************************************************************/
+{
+}
+
+/************************************************************/
httpLoadAgent::~httpLoadAgent() {
delete Reader_;
free(RealHost_);
-}
-
-/************************************************************/
+}
+
+/************************************************************/
void httpLoadAgent::clearReader() {
if (Reader_) {
- bool opened = false;
+ bool opened = false;
if (PersistentConn_) {
const THttpHeader* H = Reader_->readHeader();
if (H && !H->connection_closed) {
Reader_->skipTheRest();
- opened = true;
- }
- }
- if (!opened)
- Disconnect();
+ opened = true;
+ }
+ }
+ if (!opened)
+ Disconnect();
delete Reader_;
Reader_ = nullptr;
- }
+ }
ErrCode_ = 0;
-}
-/************************************************************/
+}
+/************************************************************/
void httpLoadAgent::setRealHost(const char* hostname) {
free(RealHost_);
- if (hostname)
+ if (hostname)
RealHost_ = strdup(hostname);
- else
+ else
RealHost_ = nullptr;
ErrCode_ = 0;
-}
-
-/************************************************************/
+}
+
+/************************************************************/
void httpLoadAgent::setIMS(const char* ifModifiedSince) {
- char ims_buf[100];
- snprintf(ims_buf, 100, "If-Modified-Since: %s\r\n",
- ifModifiedSince);
+ char ims_buf[100];
+ snprintf(ims_buf, 100, "If-Modified-Since: %s\r\n",
+ ifModifiedSince);
Headers_.push_back(ims_buf);
-}
-
-/************************************************************/
+}
+
+/************************************************************/
void httpLoadAgent::addHeaderInstruction(const char* instr) {
Headers_.push_back(instr);
-}
-
-/************************************************************/
+}
+
+/************************************************************/
void httpLoadAgent::dropHeaderInstructions() {
Headers_.clear();
-}
-
-/************************************************************/
+}
+
+/************************************************************/
bool httpLoadAgent::startRequest(const THttpURL& url,
bool persistent,
const TAddrList& addrs)
-{
- clearReader();
+{
+ clearReader();
ErrCode_ = 0;
-
+
URL_.Clear();
URL_ = url;
PersistentConn_ = persistent;
if (!URL_.IsValidAbs())
- return false;
+ return false;
if (!HandleAuthorization_ && !URL_.IsNull(THttpURL::FlagAuth))
- return false;
-
+ return false;
+
return doSetHost(addrs) && doStartRequest();
-}
-
-/************************************************************/
+}
+
+/************************************************************/
bool httpLoadAgent::startRequest(const char* url,
const char* url_to_merge,
bool persistent,
@@ -226,148 +226,148 @@ bool httpLoadAgent::startRequest(const char* url,
const char* url_to_merge,
bool persistent,
ui32 ip) {
- clearReader();
-
+ clearReader();
+
URL_.Clear();
PersistentConn_ = persistent;
-
- long flags = THttpURL::FeatureSchemeKnown | THttpURL::FeaturesNormalizeSet;
+
+ long flags = THttpURL::FeatureSchemeKnown | THttpURL::FeaturesNormalizeSet;
if (HandleAuthorization_)
- flags |= THttpURL::FeatureAuthSupported;
-
+ flags |= THttpURL::FeatureAuthSupported;
+
if (URL_.Parse(url, flags, url_to_merge) || !URL_.IsValidGlobal())
- return false;
-
+ return false;
+
return doSetHost(TAddrList::MakeV4Addr(ip, URL_.GetPort())) && doStartRequest();
-}
-
-/************************************************************/
+}
+
+/************************************************************/
bool httpLoadAgent::doSetHost(const TAddrList& addrs) {
socketAbstractHandler* h = Factory_.chooseHandler(URL_);
- if (!h)
- return false;
- Socket.setHandler(h);
-
+ if (!h)
+ return false;
+ Socket.setHandler(h);
+
if (addrs.size()) {
ErrCode_ = SetHost(URL_.Get(THttpURL::FieldHost),
URL_.GetPort(), addrs);
- } else {
+ } else {
ErrCode_ = SetHost(URL_.Get(THttpURL::FieldHost),
URL_.GetPort());
- }
+ }
if (ErrCode_)
- return false;
-
+ return false;
+
if (RealHost_) {
- free(Hostheader);
+ free(Hostheader);
Hostheader = (char*)malloc(strlen(RealHost_) + 20);
sprintf(Hostheader, "Host: %s\r\n", RealHost_);
- }
-
+ }
+
if (!URL_.IsNull(THttpURL::FlagAuth)) {
if (!HandleAuthorization_) {
ErrCode_ = HTTP_UNAUTHORIZED;
- return false;
- }
-
+ return false;
+ }
+
Digest_.setAuthorization(URL_.Get(THttpURL::FieldUsername),
URL_.Get(THttpURL::FieldPassword));
- }
-
- return true;
-}
-
-/************************************************************/
+ }
+
+ return true;
+}
+
+/************************************************************/
bool httpLoadAgent::setHost(const char* host_url,
const TAddrList& addrs) {
- clearReader();
-
+ clearReader();
+
URL_.Clear();
PersistentConn_ = true;
-
- long flags = THttpURL::FeatureSchemeKnown | THttpURL::FeaturesNormalizeSet;
+
+ long flags = THttpURL::FeatureSchemeKnown | THttpURL::FeaturesNormalizeSet;
if (HandleAuthorization_)
- flags |= THttpURL::FeatureAuthSupported;
-
+ flags |= THttpURL::FeatureAuthSupported;
+
if (URL_.Parse(host_url, flags) || !URL_.IsValidGlobal())
- return false;
-
+ return false;
+
return doSetHost(addrs);
-}
-
-/************************************************************/
+}
+
+/************************************************************/
bool httpLoadAgent::startOneRequest(const char* local_url) {
- clearReader();
-
- THttpURL lURL;
+ clearReader();
+
+ THttpURL lURL;
if (lURL.Parse(local_url, THttpURL::FeaturesNormalizeSet) || lURL.IsValidGlobal())
- return false;
-
+ return false;
+
URL_.SetInMemory(THttpURL::FieldPath, lURL.Get(THttpURL::FieldPath));
URL_.SetInMemory(THttpURL::FieldQuery, lURL.Get(THttpURL::FieldQuery));
URL_.Rewrite();
-
- return doStartRequest();
-}
-
-/************************************************************/
+
+ return doStartRequest();
+}
+
+/************************************************************/
bool httpLoadAgent::doStartRequest() {
TString urlStr = URL_.PrintS(THttpURL::FlagPath | THttpURL::FlagQuery);
- if (!urlStr)
- urlStr = "/";
-
+ if (!urlStr)
+ urlStr = "/";
+
for (int step = 0; step < 10; step++) {
const char* digestHeader = Digest_.getHeaderInstruction();
-
+
unsigned i = (digestHeader) ? 2 : 1;
- const char** headers =
+ const char** headers =
(const char**)(alloca((i + Headers_.size()) * sizeof(char*)));
-
+
for (i = 0; i < Headers_.size(); i++)
headers[i] = Headers_[i].c_str();
- if (digestHeader)
- headers[i++] = digestHeader;
+ if (digestHeader)
+ headers[i++] = digestHeader;
headers[i] = nullptr;
-
+
ErrCode_ = RequestGet(urlStr.c_str(), headers, PersistentConn_);
-
+
if (ErrCode_) {
- Disconnect();
- return false;
- }
-
+ Disconnect();
+ return false;
+ }
+
TString urlBaseStr = URL_.PrintS(THttpURL::FlagNoFrag);
-
- clearReader();
+
+ clearReader();
Reader_ = new httpAgentReader(*this, urlBaseStr.c_str(),
!PersistentConn_, !Digest_.empty());
-
+
if (Reader_->readHeader()) {
- //mReader->getHeader()->Print();
+ //mReader->getHeader()->Print();
if (getHeader()->http_status == HTTP_UNAUTHORIZED &&
step < 1 &&
Digest_.processHeader(getAuthHeader(),
urlStr.c_str(),
"GET")) {
- //mReader->skipTheRest();
+ //mReader->skipTheRest();
delete Reader_;
Reader_ = nullptr;
ErrCode_ = 0;
- Disconnect();
- continue;
- }
-
- return true;
- }
- Disconnect();
- clearReader();
-
- return false;
- }
-
+ Disconnect();
+ continue;
+ }
+
+ return true;
+ }
+ Disconnect();
+ clearReader();
+
+ return false;
+ }
+
ErrCode_ = HTTP_UNAUTHORIZED;
- return false;
-}
-
-/************************************************************/
-/************************************************************/
+ return false;
+}
+
+/************************************************************/
+/************************************************************/
diff --git a/library/cpp/http/fetch/httpload.h b/library/cpp/http/fetch/httpload.h
index e22e4b809e..1441dd27b5 100644
--- a/library/cpp/http/fetch/httpload.h
+++ b/library/cpp/http/fetch/httpload.h
@@ -1,226 +1,226 @@
#pragma once
-
+
#include "httpagent.h"
#include "httpparser.h"
#include "http_digest.h"
-#include <util/system/compat.h>
-#include <util/string/vector.h>
+#include <util/system/compat.h>
+#include <util/string/vector.h>
#include <util/network/ip.h>
#include <library/cpp/uri/http_url.h>
#include <library/cpp/http/misc/httpcodes.h>
-
-/********************************************************/
-// Section 1: socket handlers
-/********************************************************/
-// The following classes allows to adopt template scheme
-// THttpAgent for work with socket by flexible
-// object-style scheme.
-
-/********************************************************/
-// This class is used as a base one for flexible
-// socket handling
+
+/********************************************************/
+// Section 1: socket handlers
+/********************************************************/
+// The following classes allows to adopt template scheme
+// THttpAgent for work with socket by flexible
+// object-style scheme.
+
+/********************************************************/
+// This class is used as a base one for flexible
+// socket handling
class socketAbstractHandler {
-public:
- virtual bool Good() = 0;
-
+public:
+ virtual bool Good() = 0;
+
virtual int Connect(const TAddrList& addrs, TDuration Timeout) = 0;
-
- virtual void Disconnect() = 0;
-
- virtual void shutdown() = 0;
-
- virtual bool send(const char* message, ssize_t messlen) = 0;
-
- virtual bool peek() = 0;
-
- virtual ssize_t read(void* buffer, ssize_t buflen) = 0;
-
+
+ virtual void Disconnect() = 0;
+
+ virtual void shutdown() = 0;
+
+ virtual bool send(const char* message, ssize_t messlen) = 0;
+
+ virtual bool peek() = 0;
+
+ virtual ssize_t read(void* buffer, ssize_t buflen) = 0;
+
virtual ~socketAbstractHandler() {
}
-
-protected:
+
+protected:
socketAbstractHandler() {
}
-};
-
-/********************************************************/
-// This class is used as a proxy between THttpAgent and
-// socketAbstractHandler
-// (it is used by template scheme,
-// so it does not have virtual methods)
+};
+
+/********************************************************/
+// This class is used as a proxy between THttpAgent and
+// socketAbstractHandler
+// (it is used by template scheme,
+// so it does not have virtual methods)
class TSocketHandlerPtr {
-protected:
+protected:
socketAbstractHandler* Handler_;
-
-public:
+
+public:
TSocketHandlerPtr()
: Handler_(nullptr)
{
}
-
+
virtual ~TSocketHandlerPtr() {
delete Handler_;
}
-
+
int Good() {
return (Handler_ && Handler_->Good());
}
-
+
int Connect(const TAddrList& addrs, TDuration Timeout) {
return (Handler_) ? Handler_->Connect(addrs, Timeout) : 1;
- }
-
+ }
+
void Disconnect() {
if (Handler_)
Handler_->Disconnect();
- }
-
+ }
+
void shutdown() {
if (Handler_)
Handler_->shutdown();
- }
-
+ }
+
bool send(const char* message, ssize_t messlen) {
return (Handler_) ? Handler_->send(message, messlen) : false;
- }
-
+ }
+
virtual bool peek() {
return (Handler_) ? Handler_->peek() : false;
- }
-
+ }
+
virtual ssize_t read(void* buffer, ssize_t buflen) {
return (Handler_) ? Handler_->read(buffer, buflen) : 0;
- }
-
+ }
+
void setHandler(socketAbstractHandler* handler) {
if (Handler_)
delete Handler_;
Handler_ = handler;
- }
-};
-
-/********************************************************/
-// Here is httpAgent that uses socketAbstractHandler class
-// ant its derivatives
+ }
+};
+
+/********************************************************/
+// Here is httpAgent that uses socketAbstractHandler class
+// ant its derivatives
using httpSpecialAgent = THttpAgent<TSocketHandlerPtr>;
-
-/********************************************************/
-// Regular handler is used as implementation of
-// socketAbstractHandler for work through HTTP protocol
+
+/********************************************************/
+// Regular handler is used as implementation of
+// socketAbstractHandler for work through HTTP protocol
class socketRegularHandler: public socketAbstractHandler {
protected:
TSimpleSocketHandler Socket_;
-
+
public:
socketRegularHandler()
: Socket_()
{
}
-
+
bool Good() override {
return Socket_.Good();
- }
-
+ }
+
int Connect(const TAddrList& addrs, TDuration Timeout) override {
return Socket_.Connect(addrs, Timeout);
- }
-
+ }
+
void Disconnect() override {
Socket_.Disconnect();
- }
-
+ }
+
void shutdown() override {
- //Do not block writing to socket
- //There are servers that works in a bad way with this
- //mSocket.shutdown();
- }
-
+ //Do not block writing to socket
+ //There are servers that works in a bad way with this
+ //mSocket.shutdown();
+ }
+
bool send(const char* message, ssize_t messlen) override {
return Socket_.send(message, messlen);
- }
-
+ }
+
bool peek() override {
return Socket_.peek();
- }
-
+ }
+
ssize_t read(void* buffer, ssize_t buflen) override {
return Socket_.read(buffer, buflen);
- }
-};
-
-/********************************************************/
-// The base factory that allows to choose an appropriate
-// socketAbstractHandler implementation by url schema
+ }
+};
+
+/********************************************************/
+// The base factory that allows to choose an appropriate
+// socketAbstractHandler implementation by url schema
class socketHandlerFactory {
public:
virtual ~socketHandlerFactory() {
}
-
- //returns mHandler_HTTP for correct HTTP-based url
+
+ //returns mHandler_HTTP for correct HTTP-based url
virtual socketAbstractHandler* chooseHandler(const THttpURL& url);
-
- static socketHandlerFactory sInstance;
-};
-
-/********************************************************/
-// Section 2: the configurates tool to parse an HTTP-response
-/********************************************************/
-
+
+ static socketHandlerFactory sInstance;
+};
+
+/********************************************************/
+// Section 2: the configurates tool to parse an HTTP-response
+/********************************************************/
+
class httpAgentReader: public THttpParserGeneric<1> {
protected:
THttpAuthHeader Header_;
httpSpecialAgent& Agent_;
-
+
char* Buffer_;
void* BufPtr_;
int BufSize_;
long BufRest_;
-
- void readBuf();
-
+
+ void readBuf();
+
bool step() {
if (BufRest_ == 0)
- readBuf();
- if (eof())
- return false;
- return true;
- }
-
+ readBuf();
+ if (eof())
+ return false;
+ return true;
+ }
+
public:
httpAgentReader(httpSpecialAgent& agent,
const char* baseUrl,
bool assumeConnectionClosed,
bool use_auth = false,
int bufSize = 0x1000);
-
- ~httpAgentReader();
-
+
+ ~httpAgentReader();
+
bool eof() {
return BufRest_ < 0;
- }
-
+ }
+
int error() {
return Header_.error;
- }
-
+ }
+
void setError(int errCode) {
Header_.error = errCode;
- }
-
+ }
+
const THttpAuthHeader* getAuthHeader() {
return &Header_;
- }
-
+ }
+
const THttpHeader* readHeader();
long readPortion(void*& buf);
bool skipTheRest();
-};
-
-/********************************************************/
-// Section 3: the main class
-/********************************************************/
+};
+
+/********************************************************/
+// Section 3: the main class
+/********************************************************/
class httpLoadAgent: public httpSpecialAgent {
protected:
socketHandlerFactory& Factory_;
@@ -232,76 +232,76 @@ protected:
int ErrCode_;
char* RealHost_;
httpDigestHandler Digest_;
-
- void clearReader();
+
+ void clearReader();
bool doSetHost(const TAddrList& addrs);
- bool doStartRequest();
-
+ bool doStartRequest();
+
public:
httpLoadAgent(bool handleAuthorization = false,
socketHandlerFactory& factory = socketHandlerFactory::sInstance);
- ~httpLoadAgent();
-
- void setRealHost(const char* host);
+ ~httpLoadAgent();
+
+ void setRealHost(const char* host);
void setIMS(const char* ifModifiedSince);
- void addHeaderInstruction(const char* instr);
- void dropHeaderInstructions();
-
- bool startRequest(const char* url,
+ void addHeaderInstruction(const char* instr);
+ void dropHeaderInstructions();
+
+ bool startRequest(const char* url,
const char* url_to_merge = nullptr,
bool persistent = false,
const TAddrList& addrs = TAddrList());
-
+
// deprecated v4-only
bool startRequest(const char* url,
const char* url_to_merge,
bool persistent,
ui32 ip);
- bool startRequest(const THttpURL& url,
+ bool startRequest(const THttpURL& url,
bool persistent = false,
const TAddrList& addrs = TAddrList());
-
+
bool setHost(const char* host_url,
const TAddrList& addrs = TAddrList());
-
- bool startOneRequest(const char* local_url);
-
+
+ bool startOneRequest(const char* local_url);
+
const THttpAuthHeader* getAuthHeader() {
if (Reader_ && Reader_->getAuthHeader()->use_auth)
return Reader_->getAuthHeader();
return nullptr;
- }
-
+ }
+
const THttpHeader* getHeader() {
if (Reader_)
return Reader_->getAuthHeader();
return nullptr;
- }
-
+ }
+
const THttpURL& getURL() {
return URL_;
- }
-
+ }
+
bool eof() {
if (Reader_)
return Reader_->eof();
- return true;
- }
-
+ return true;
+ }
+
int error() {
if (ErrCode_)
return ErrCode_;
if (Reader_)
return Reader_->error();
- return HTTP_BAD_URL;
- }
-
+ return HTTP_BAD_URL;
+ }
+
long readPortion(void*& buf) {
if (Reader_)
return Reader_->readPortion(buf);
- return -1;
- }
-};
-
-/********************************************************/
+ return -1;
+ }
+};
+
+/********************************************************/
diff --git a/library/cpp/http/fetch/httpparser.h b/library/cpp/http/fetch/httpparser.h
index 769828e4ae..b666707038 100644
--- a/library/cpp/http/fetch/httpparser.h
+++ b/library/cpp/http/fetch/httpparser.h
@@ -1,14 +1,14 @@
#pragma once
-
-#include "httpfsm.h"
-#include "httpheader.h"
-
+
+#include "httpfsm.h"
+#include "httpheader.h"
+
#include <library/cpp/mime/types/mime.h>
#include <util/system/yassert.h>
#include <library/cpp/http/misc/httpcodes.h>
template <size_t headermax = 100 << 10, size_t bodymax = 1 << 20>
-struct TFakeCheck {
+struct TFakeCheck {
bool Check(THttpHeader* /*header*/) {
return false;
}
@@ -22,351 +22,351 @@ struct TFakeCheck {
size_t GetMaxBodySize(THttpHeader*) {
return bodymax;
}
-};
-
-class THttpParserBase {
-public:
- enum States {
- hp_error,
- hp_eof,
- hp_in_header,
- hp_read_alive,
- hp_read_closed,
- hp_begin_chunk_header,
- hp_chunk_header,
- hp_read_chunk
- };
-
+};
+
+class THttpParserBase {
+public:
+ enum States {
+ hp_error,
+ hp_eof,
+ hp_in_header,
+ hp_read_alive,
+ hp_read_closed,
+ hp_begin_chunk_header,
+ hp_chunk_header,
+ hp_read_chunk
+ };
+
States GetState() {
return State;
}
-
+
void setAssumeConnectionClosed(int value) {
- AssumeConnectionClosed = value;
- }
-
+ AssumeConnectionClosed = value;
+ }
+
THttpHeader* GetHttpHeader() const {
return Header;
}
-
-protected:
- int CheckHeaders() {
+
+protected:
+ int CheckHeaders() {
if (Header->http_status < HTTP_OK || Header->http_status == HTTP_NO_CONTENT || Header->http_status == HTTP_NOT_MODIFIED) {
- Header->content_length = 0;
- Header->transfer_chunked = 0;
- }
- if (Header->transfer_chunked < -1) {
- Header->error = HTTP_BAD_ENCODING;
- return 1;
- } else if (Header->transfer_chunked == -1) {
- Header->transfer_chunked = 0;
- }
- if (!Header->transfer_chunked && Header->content_length < -1) {
- Header->error = HTTP_BAD_CONTENT_LENGTH;
- return 1;
- }
+ Header->content_length = 0;
+ Header->transfer_chunked = 0;
+ }
+ if (Header->transfer_chunked < -1) {
+ Header->error = HTTP_BAD_ENCODING;
+ return 1;
+ } else if (Header->transfer_chunked == -1) {
+ Header->transfer_chunked = 0;
+ }
+ if (!Header->transfer_chunked && Header->content_length < -1) {
+ Header->error = HTTP_BAD_CONTENT_LENGTH;
+ return 1;
+ }
if (Header->http_status == HTTP_OK) {
- if (Header->compression_method != HTTP_COMPRESSION_UNSET &&
- Header->compression_method != HTTP_COMPRESSION_IDENTITY &&
- Header->compression_method != HTTP_COMPRESSION_GZIP &&
+ if (Header->compression_method != HTTP_COMPRESSION_UNSET &&
+ Header->compression_method != HTTP_COMPRESSION_IDENTITY &&
+ Header->compression_method != HTTP_COMPRESSION_GZIP &&
Header->compression_method != HTTP_COMPRESSION_DEFLATE)
{
- Header->error = HTTP_BAD_CONTENT_ENCODING;
- return 1;
- }
- }
- if (Header->connection_closed == -1)
- Header->connection_closed = (Header->http_minor == 0 ||
- AssumeConnectionClosed);
+ Header->error = HTTP_BAD_CONTENT_ENCODING;
+ return 1;
+ }
+ }
+ if (Header->connection_closed == -1)
+ Header->connection_closed = (Header->http_minor == 0 ||
+ AssumeConnectionClosed);
if (!Header->transfer_chunked && !Header->connection_closed && Header->content_length < 0 && !HeadRequest) {
- Header->error = HTTP_LENGTH_UNKNOWN;
- return 1;
- }
- if (Header->http_time < 0)
- Header->http_time = 0;
- if (Header->mime_type < 0)
- Header->mime_type = MIME_UNKNOWN;
- return 0;
- }
-
- THttpHeaderParser HeaderParser;
- THttpChunkParser ChunkParser;
- States State;
- long ChunkSize;
+ Header->error = HTTP_LENGTH_UNKNOWN;
+ return 1;
+ }
+ if (Header->http_time < 0)
+ Header->http_time = 0;
+ if (Header->mime_type < 0)
+ Header->mime_type = MIME_UNKNOWN;
+ return 0;
+ }
+
+ THttpHeaderParser HeaderParser;
+ THttpChunkParser ChunkParser;
+ States State;
+ long ChunkSize;
THttpHeader* Header;
- int AssumeConnectionClosed;
- bool HeadRequest;
-};
-
+ int AssumeConnectionClosed;
+ bool HeadRequest;
+};
+
template <int isReader, typename TCheck = TFakeCheck<>>
-class THttpParserGeneric: public THttpParserBase, public TCheck {
-protected:
+class THttpParserGeneric: public THttpParserBase, public TCheck {
+protected:
long ParseGeneric(void*& buf, long& size) {
- if (!size) {
- switch (State) {
- case hp_error:
- case hp_eof:
- break;
- case hp_read_closed:
- State = hp_eof;
- break;
- case hp_in_header:
- Header->error = HTTP_HEADER_EOF;
- State = hp_error;
- break;
- case hp_read_alive:
- case hp_read_chunk:
- if (HeadRequest)
- State = hp_eof;
- else {
- Header->error = HTTP_MESSAGE_EOF;
- State = hp_error;
- }
- break;
- case hp_begin_chunk_header:
- case hp_chunk_header:
- if (HeadRequest)
- State = hp_eof;
- else {
- Header->error = HTTP_CHUNK_EOF;
- State = hp_error;
- }
- break;
- }
- return 0;
- }
- while (size) {
- int ret;
-
- switch (State) {
- case hp_error:
- return 0;
-
- case hp_eof:
- return 0;
-
- case hp_in_header:
- if ((ret = HeaderParser.Execute(buf, size)) < 0) {
- Header->error = HTTP_BAD_HEADER_STRING;
- State = hp_error;
- return 0;
- } else if (ret == 2) {
- Header->header_size += i32(HeaderParser.lastchar - (char*)buf + 1);
- size -= long(HeaderParser.lastchar - (char*)buf + 1);
- buf = HeaderParser.lastchar + 1;
- State = CheckHeaders() ? hp_error
+ if (!size) {
+ switch (State) {
+ case hp_error:
+ case hp_eof:
+ break;
+ case hp_read_closed:
+ State = hp_eof;
+ break;
+ case hp_in_header:
+ Header->error = HTTP_HEADER_EOF;
+ State = hp_error;
+ break;
+ case hp_read_alive:
+ case hp_read_chunk:
+ if (HeadRequest)
+ State = hp_eof;
+ else {
+ Header->error = HTTP_MESSAGE_EOF;
+ State = hp_error;
+ }
+ break;
+ case hp_begin_chunk_header:
+ case hp_chunk_header:
+ if (HeadRequest)
+ State = hp_eof;
+ else {
+ Header->error = HTTP_CHUNK_EOF;
+ State = hp_error;
+ }
+ break;
+ }
+ return 0;
+ }
+ while (size) {
+ int ret;
+
+ switch (State) {
+ case hp_error:
+ return 0;
+
+ case hp_eof:
+ return 0;
+
+ case hp_in_header:
+ if ((ret = HeaderParser.Execute(buf, size)) < 0) {
+ Header->error = HTTP_BAD_HEADER_STRING;
+ State = hp_error;
+ return 0;
+ } else if (ret == 2) {
+ Header->header_size += i32(HeaderParser.lastchar - (char*)buf + 1);
+ size -= long(HeaderParser.lastchar - (char*)buf + 1);
+ buf = HeaderParser.lastchar + 1;
+ State = CheckHeaders() ? hp_error
: Header->transfer_chunked ? hp_begin_chunk_header
: Header->content_length == 0 ? hp_eof
: Header->content_length > 0 ? hp_read_alive
: hp_read_closed;
- if (State == hp_begin_chunk_header) {
- // unget \n for chunk reader
+ if (State == hp_begin_chunk_header) {
+ // unget \n for chunk reader
buf = (char*)buf - 1;
- size++;
- }
- if (isReader)
- return size;
- } else {
- Header->header_size += size;
- size = 0;
- }
- break;
-
- case hp_read_alive:
- Header->entity_size += size;
+ size++;
+ }
+ if (isReader)
+ return size;
+ } else {
+ Header->header_size += size;
+ size = 0;
+ }
+ break;
+
+ case hp_read_alive:
+ Header->entity_size += size;
if (Header->entity_size >= Header->content_length) {
- State = hp_eof;
- }
+ State = hp_eof;
+ }
- TCheck::CheckDocPart(buf, size, Header);
- if (isReader)
- return size;
- size = 0;
- break;
-
- case hp_read_closed:
- Header->entity_size += size;
- TCheck::CheckDocPart(buf, size, Header);
- if (isReader)
- return size;
- size = 0;
- break;
-
- case hp_begin_chunk_header:
- ChunkParser.Init();
- State = hp_chunk_header;
+ TCheck::CheckDocPart(buf, size, Header);
+ if (isReader)
+ return size;
+ size = 0;
+ break;
+
+ case hp_read_closed:
+ Header->entity_size += size;
+ TCheck::CheckDocPart(buf, size, Header);
+ if (isReader)
+ return size;
+ size = 0;
+ break;
+
+ case hp_begin_chunk_header:
+ ChunkParser.Init();
+ State = hp_chunk_header;
[[fallthrough]];
-
- case hp_chunk_header:
- if ((ret = ChunkParser.Execute(buf, size)) < 0) {
- Header->error = i16(ret == -2 ? HTTP_CHUNK_TOO_LARGE : HTTP_BAD_CHUNK);
- State = hp_error;
- return 0;
- } else if (ret == 2) {
- Header->entity_size += i32(ChunkParser.lastchar - (char*)buf + 1);
- size -= long(ChunkParser.lastchar - (char*)buf + 1);
- buf = ChunkParser.lastchar + 1;
- ChunkSize = ChunkParser.chunk_length;
+
+ case hp_chunk_header:
+ if ((ret = ChunkParser.Execute(buf, size)) < 0) {
+ Header->error = i16(ret == -2 ? HTTP_CHUNK_TOO_LARGE : HTTP_BAD_CHUNK);
+ State = hp_error;
+ return 0;
+ } else if (ret == 2) {
+ Header->entity_size += i32(ChunkParser.lastchar - (char*)buf + 1);
+ size -= long(ChunkParser.lastchar - (char*)buf + 1);
+ buf = ChunkParser.lastchar + 1;
+ ChunkSize = ChunkParser.chunk_length;
Y_ASSERT(ChunkSize >= 0);
- State = ChunkSize ? hp_read_chunk : hp_eof;
- } else {
- Header->entity_size += size;
- size = 0;
- }
- break;
-
- case hp_read_chunk:
- if (size >= ChunkSize) {
- Header->entity_size += ChunkSize;
- State = hp_begin_chunk_header;
- TCheck::CheckDocPart(buf, ChunkSize, Header);
- if (isReader)
- return ChunkSize;
- size -= ChunkSize;
+ State = ChunkSize ? hp_read_chunk : hp_eof;
+ } else {
+ Header->entity_size += size;
+ size = 0;
+ }
+ break;
+
+ case hp_read_chunk:
+ if (size >= ChunkSize) {
+ Header->entity_size += ChunkSize;
+ State = hp_begin_chunk_header;
+ TCheck::CheckDocPart(buf, ChunkSize, Header);
+ if (isReader)
+ return ChunkSize;
+ size -= ChunkSize;
buf = (char*)buf + ChunkSize;
- } else {
- Header->entity_size += size;
- ChunkSize -= size;
- TCheck::CheckDocPart(buf, size, Header);
- if (isReader)
- return size;
- size = 0;
- }
+ } else {
+ Header->entity_size += size;
+ ChunkSize -= size;
+ TCheck::CheckDocPart(buf, size, Header);
+ if (isReader)
+ return size;
+ size = 0;
+ }
break;
- }
- }
- return size;
- }
-};
-
+ }
+ }
+ return size;
+ }
+};
+
template <class TCheck = TFakeCheck<>>
-class THttpParser: public THttpParserGeneric<0, TCheck> {
- typedef THttpParserGeneric<0, TCheck> TBaseT; //sorry avoiding gcc 3.4.6 BUG!
-public:
+class THttpParser: public THttpParserGeneric<0, TCheck> {
+ typedef THttpParserGeneric<0, TCheck> TBaseT; //sorry avoiding gcc 3.4.6 BUG!
+public:
void Init(THttpHeader* H, bool head_request = false) {
- TBaseT::Header = H;
- TBaseT::HeaderParser.Init(TBaseT::Header);
- TBaseT::State = TBaseT::hp_in_header;
- TBaseT::AssumeConnectionClosed = 0;
- TBaseT::HeadRequest = head_request;
- }
-
+ TBaseT::Header = H;
+ TBaseT::HeaderParser.Init(TBaseT::Header);
+ TBaseT::State = TBaseT::hp_in_header;
+ TBaseT::AssumeConnectionClosed = 0;
+ TBaseT::HeadRequest = head_request;
+ }
+
void Parse(void* buf, long size) {
TBaseT::ParseGeneric(buf, size);
- }
-};
-
-class TMemoReader {
-public:
+ }
+};
+
+class TMemoReader {
+public:
int Init(void* buf, long bufsize) {
- Buf = buf;
- Bufsize = bufsize;
- return 0;
- }
+ Buf = buf;
+ Bufsize = bufsize;
+ return 0;
+ }
long Read(void*& buf) {
Y_ASSERT(Bufsize >= 0);
- if (!Bufsize) {
- Bufsize = -1;
- return 0;
- }
- buf = Buf;
- long ret = Bufsize;
- Bufsize = 0;
- return ret;
- }
-
-protected:
- long Bufsize;
+ if (!Bufsize) {
+ Bufsize = -1;
+ return 0;
+ }
+ buf = Buf;
+ long ret = Bufsize;
+ Bufsize = 0;
+ return ret;
+ }
+
+protected:
+ long Bufsize;
void* Buf;
-};
-
-template <class Reader>
-class THttpReader: public THttpParserGeneric<1>, public Reader {
- typedef THttpParserGeneric<1> TBaseT;
+};
+
+template <class Reader>
+class THttpReader: public THttpParserGeneric<1>, public Reader {
+ typedef THttpParserGeneric<1> TBaseT;
-public:
+public:
using TBaseT::AssumeConnectionClosed;
- using TBaseT::Header;
- using TBaseT::ParseGeneric;
- using TBaseT::State;
-
+ using TBaseT::Header;
+ using TBaseT::ParseGeneric;
+ using TBaseT::State;
+
int Init(THttpHeader* H, int parsHeader, int assumeConnectionClosed = 0, bool headRequest = false) {
- Header = H;
- Eoferr = 1;
- Size = 0;
+ Header = H;
+ Eoferr = 1;
+ Size = 0;
AssumeConnectionClosed = assumeConnectionClosed;
HeadRequest = headRequest;
- return parsHeader ? ParseHeader() : SkipHeader();
- }
-
+ return parsHeader ? ParseHeader() : SkipHeader();
+ }
+
long Read(void*& buf) {
- long Chunk;
- do {
- if (!Size) {
- if (Eoferr != 1)
- return Eoferr;
- else if ((Size = (long)Reader::Read(Ptr)) < 0) {
- Header->error = HTTP_CONNECTION_LOST;
- return Eoferr = -1;
- }
- }
+ long Chunk;
+ do {
+ if (!Size) {
+ if (Eoferr != 1)
+ return Eoferr;
+ else if ((Size = (long)Reader::Read(Ptr)) < 0) {
+ Header->error = HTTP_CONNECTION_LOST;
+ return Eoferr = -1;
+ }
+ }
Chunk = ParseGeneric(Ptr, Size);
- buf = Ptr;
- Ptr = (char*)Ptr + Chunk;
- Size -= Chunk;
+ buf = Ptr;
+ Ptr = (char*)Ptr + Chunk;
+ Size -= Chunk;
if (State == hp_eof) {
Size = 0;
- Eoferr = 0;
+ Eoferr = 0;
} else if (State == hp_error)
- return Eoferr = -1;
- } while (!Chunk);
- return Chunk;
- }
-
-protected:
- int ParseHeader() {
- HeaderParser.Init(Header);
- State = hp_in_header;
- while (State == hp_in_header) {
- if ((Size = (long)Reader::Read(Ptr)) < 0)
- return Eoferr = -1;
+ return Eoferr = -1;
+ } while (!Chunk);
+ return Chunk;
+ }
+
+protected:
+ int ParseHeader() {
+ HeaderParser.Init(Header);
+ State = hp_in_header;
+ while (State == hp_in_header) {
+ if ((Size = (long)Reader::Read(Ptr)) < 0)
+ return Eoferr = -1;
ParseGeneric(Ptr, Size);
- }
- if (State == hp_error)
- return Eoferr = -1;
- if (State == hp_eof)
- Eoferr = 0;
- return 0;
- }
-
- int SkipHeader() {
- long hdrsize = Header->header_size;
- while (hdrsize) {
- if ((Size = (long)Reader::Read(Ptr)) <= 0)
- return Eoferr = -1;
- if (Size >= hdrsize) {
- Size -= hdrsize;
- Ptr = (char*)Ptr + hdrsize;
- break;
- }
- hdrsize -= Size;
- }
- State = Header->transfer_chunked ? hp_begin_chunk_header
+ }
+ if (State == hp_error)
+ return Eoferr = -1;
+ if (State == hp_eof)
+ Eoferr = 0;
+ return 0;
+ }
+
+ int SkipHeader() {
+ long hdrsize = Header->header_size;
+ while (hdrsize) {
+ if ((Size = (long)Reader::Read(Ptr)) <= 0)
+ return Eoferr = -1;
+ if (Size >= hdrsize) {
+ Size -= hdrsize;
+ Ptr = (char*)Ptr + hdrsize;
+ break;
+ }
+ hdrsize -= Size;
+ }
+ State = Header->transfer_chunked ? hp_begin_chunk_header
: Header->content_length == 0 ? hp_eof
: Header->content_length > 0 ? hp_read_alive
: hp_read_closed;
- Header->entity_size = 0;
- if (State == hp_eof)
- Eoferr = 0;
- else if (State == hp_begin_chunk_header) {
- // unget \n for chunk reader
- Ptr = (char*)Ptr - 1;
- ++Size;
- }
- return 0;
- }
-
+ Header->entity_size = 0;
+ if (State == hp_eof)
+ Eoferr = 0;
+ else if (State == hp_begin_chunk_header) {
+ // unget \n for chunk reader
+ Ptr = (char*)Ptr - 1;
+ ++Size;
+ }
+ return 0;
+ }
+
void* Ptr;
- long Size;
+ long Size;
int Eoferr;
-};
+};
diff --git a/library/cpp/http/fetch/httpzreader.h b/library/cpp/http/fetch/httpzreader.h
index 68eb00853d..d951d21e9a 100644
--- a/library/cpp/http/fetch/httpzreader.h
+++ b/library/cpp/http/fetch/httpzreader.h
@@ -1,55 +1,55 @@
#pragma once
-
+
#include "httpheader.h"
#include "httpparser.h"
#include "exthttpcodes.h"
-
+
#include <util/system/defaults.h>
#include <util/generic/yexception.h>
-#include <contrib/libs/zlib/zlib.h>
-
+#include <contrib/libs/zlib/zlib.h>
+
#include <errno.h>
-#ifndef ENOTSUP
+#ifndef ENOTSUP
#define ENOTSUP 45
-#endif
-
-template <class Reader>
-class TCompressedHttpReader: public THttpReader<Reader> {
- typedef THttpReader<Reader> TBase;
+#endif
+
+template <class Reader>
+class TCompressedHttpReader: public THttpReader<Reader> {
+ typedef THttpReader<Reader> TBase;
-public:
+public:
using TBase::AssumeConnectionClosed;
- using TBase::Header;
- using TBase::ParseGeneric;
- using TBase::State;
-
+ using TBase::Header;
+ using TBase::ParseGeneric;
+ using TBase::State;
+
static constexpr size_t DefaultBufSize = 64 << 10;
static constexpr unsigned int DefaultWinSize = 15;
- TCompressedHttpReader()
- : CompressedInput(false)
- , BufSize(0)
- , CurContSize(0)
- , MaxContSize(0)
+ TCompressedHttpReader()
+ : CompressedInput(false)
+ , BufSize(0)
+ , CurContSize(0)
+ , MaxContSize(0)
, Buf(nullptr)
- , ZErr(0)
+ , ZErr(0)
, ConnectionClosed(0)
, IgnoreTrailingGarbage(true)
- {
- memset(&Stream, 0, sizeof(Stream));
- }
-
- ~TCompressedHttpReader() {
- ClearStream();
-
- if (Buf) {
- free(Buf);
+ {
+ memset(&Stream, 0, sizeof(Stream));
+ }
+
+ ~TCompressedHttpReader() {
+ ClearStream();
+
+ if (Buf) {
+ free(Buf);
Buf = nullptr;
- }
- }
-
+ }
+ }
+
void SetConnectionClosed(int cc) {
ConnectionClosed = cc;
}
@@ -66,196 +66,196 @@ public:
const unsigned int winSize = DefaultWinSize,
bool headRequest = false)
{
- ZErr = 0;
- CurContSize = 0;
- MaxContSize = maxContSize;
-
+ ZErr = 0;
+ CurContSize = 0;
+ MaxContSize = maxContSize;
+
int ret = TBase::Init(H, parsHeader, ConnectionClosed, headRequest);
- if (ret)
- return ret;
-
- ret = SetCompression(H->compression_method, bufSize, winSize);
- return ret;
- }
-
+ if (ret)
+ return ret;
+
+ ret = SetCompression(H->compression_method, bufSize, winSize);
+ return ret;
+ }
+
long Read(void*& buf) {
- if (!CompressedInput) {
- long res = TBase::Read(buf);
- if (res > 0) {
- CurContSize += (size_t)res;
- if (CurContSize > MaxContSize) {
- ZErr = E2BIG;
- return -1;
- }
- }
- return res;
- }
-
- while (true) {
- if (Stream.avail_in == 0) {
+ if (!CompressedInput) {
+ long res = TBase::Read(buf);
+ if (res > 0) {
+ CurContSize += (size_t)res;
+ if (CurContSize > MaxContSize) {
+ ZErr = E2BIG;
+ return -1;
+ }
+ }
+ return res;
+ }
+
+ while (true) {
+ if (Stream.avail_in == 0) {
void* tmpin = Stream.next_in;
long res = TBase::Read(tmpin);
Stream.next_in = (Bytef*)tmpin;
if (res <= 0)
return res;
Stream.avail_in = (uInt)res;
- }
-
- Stream.next_out = Buf;
- Stream.avail_out = (uInt)BufSize;
- buf = Buf;
-
- int err = inflate(&Stream, Z_SYNC_FLUSH);
-
+ }
+
+ Stream.next_out = Buf;
+ Stream.avail_out = (uInt)BufSize;
+ buf = Buf;
+
+ int err = inflate(&Stream, Z_SYNC_FLUSH);
+
//Y_ASSERT(Stream.avail_in == 0);
-
- switch (err) {
- case Z_OK:
- // there is no data in next_out yet
- if (BufSize == Stream.avail_out)
- continue;
+
+ switch (err) {
+ case Z_OK:
+ // there is no data in next_out yet
+ if (BufSize == Stream.avail_out)
+ continue;
[[fallthrough]]; // don't break or return; continue with Z_STREAM_END case
-
- case Z_STREAM_END:
- if (Stream.total_out > MaxContSize) {
- ZErr = E2BIG;
- return -1;
- }
+
+ case Z_STREAM_END:
+ if (Stream.total_out > MaxContSize) {
+ ZErr = E2BIG;
+ return -1;
+ }
if (!IgnoreTrailingGarbage && BufSize == Stream.avail_out && Stream.avail_in > 0) {
Header->error = EXT_HTTP_GZIPERROR;
ZErr = EFAULT;
Stream.msg = (char*)"trailing garbage";
return -1;
}
- return long(BufSize - Stream.avail_out);
-
- case Z_NEED_DICT:
- case Z_DATA_ERROR:
- Header->error = EXT_HTTP_GZIPERROR;
- ZErr = EFAULT;
- return -1;
-
- case Z_MEM_ERROR:
- ZErr = ENOMEM;
- return -1;
-
- default:
- ZErr = EINVAL;
- return -1;
- }
- }
-
- return -1;
- }
-
+ return long(BufSize - Stream.avail_out);
+
+ case Z_NEED_DICT:
+ case Z_DATA_ERROR:
+ Header->error = EXT_HTTP_GZIPERROR;
+ ZErr = EFAULT;
+ return -1;
+
+ case Z_MEM_ERROR:
+ ZErr = ENOMEM;
+ return -1;
+
+ default:
+ ZErr = EINVAL;
+ return -1;
+ }
+ }
+
+ return -1;
+ }
+
const char* ZMsg() const {
- return Stream.msg;
- }
-
- int ZError() const {
- return ZErr;
- }
-
- size_t GetCurContSize() const {
- return CompressedInput ? Stream.total_out : CurContSize;
- }
-
-protected:
- int SetCompression(const int compression, const size_t bufSize,
- const unsigned int winSize) {
- ClearStream();
-
- int winsize = winSize;
- switch ((enum HTTP_COMPRESSION)compression) {
- case HTTP_COMPRESSION_UNSET:
- case HTTP_COMPRESSION_IDENTITY:
- CompressedInput = false;
- return 0;
- case HTTP_COMPRESSION_GZIP:
- CompressedInput = true;
+ return Stream.msg;
+ }
+
+ int ZError() const {
+ return ZErr;
+ }
+
+ size_t GetCurContSize() const {
+ return CompressedInput ? Stream.total_out : CurContSize;
+ }
+
+protected:
+ int SetCompression(const int compression, const size_t bufSize,
+ const unsigned int winSize) {
+ ClearStream();
+
+ int winsize = winSize;
+ switch ((enum HTTP_COMPRESSION)compression) {
+ case HTTP_COMPRESSION_UNSET:
+ case HTTP_COMPRESSION_IDENTITY:
+ CompressedInput = false;
+ return 0;
+ case HTTP_COMPRESSION_GZIP:
+ CompressedInput = true;
winsize += 16; // 16 indicates gzip, see zlib.h
- break;
- case HTTP_COMPRESSION_DEFLATE:
- CompressedInput = true;
- winsize = -winsize; // negative indicates raw deflate stream, see zlib.h
- break;
- case HTTP_COMPRESSION_COMPRESS:
- case HTTP_COMPRESSION_ERROR:
- default:
- CompressedInput = false;
- ZErr = ENOTSUP;
- return -1;
- }
-
- if (bufSize != BufSize) {
- if (Buf)
- free(Buf);
- Buf = (ui8*)malloc(bufSize);
- if (!Buf) {
- ZErr = ENOMEM;
- return -1;
- }
- BufSize = bufSize;
- }
-
- int err = inflateInit2(&Stream, winsize);
- switch (err) {
- case Z_OK:
- Stream.total_in = 0;
- Stream.total_out = 0;
- Stream.avail_in = 0;
- return 0;
-
- case Z_DATA_ERROR: // never happens, see zlib.h
- CompressedInput = false;
- ZErr = EFAULT;
- return -1;
-
- case Z_MEM_ERROR:
- CompressedInput = false;
- ZErr = ENOMEM;
- return -1;
-
- default:
- CompressedInput = false;
- ZErr = EINVAL;
- return -1;
- }
- }
-
- void ClearStream() {
- if (CompressedInput) {
- inflateEnd(&Stream);
- CompressedInput = false;
- }
- }
-
- z_stream Stream;
- bool CompressedInput;
- size_t BufSize;
- size_t CurContSize, MaxContSize;
- ui8* Buf;
- int ZErr;
+ break;
+ case HTTP_COMPRESSION_DEFLATE:
+ CompressedInput = true;
+ winsize = -winsize; // negative indicates raw deflate stream, see zlib.h
+ break;
+ case HTTP_COMPRESSION_COMPRESS:
+ case HTTP_COMPRESSION_ERROR:
+ default:
+ CompressedInput = false;
+ ZErr = ENOTSUP;
+ return -1;
+ }
+
+ if (bufSize != BufSize) {
+ if (Buf)
+ free(Buf);
+ Buf = (ui8*)malloc(bufSize);
+ if (!Buf) {
+ ZErr = ENOMEM;
+ return -1;
+ }
+ BufSize = bufSize;
+ }
+
+ int err = inflateInit2(&Stream, winsize);
+ switch (err) {
+ case Z_OK:
+ Stream.total_in = 0;
+ Stream.total_out = 0;
+ Stream.avail_in = 0;
+ return 0;
+
+ case Z_DATA_ERROR: // never happens, see zlib.h
+ CompressedInput = false;
+ ZErr = EFAULT;
+ return -1;
+
+ case Z_MEM_ERROR:
+ CompressedInput = false;
+ ZErr = ENOMEM;
+ return -1;
+
+ default:
+ CompressedInput = false;
+ ZErr = EINVAL;
+ return -1;
+ }
+ }
+
+ void ClearStream() {
+ if (CompressedInput) {
+ inflateEnd(&Stream);
+ CompressedInput = false;
+ }
+ }
+
+ z_stream Stream;
+ bool CompressedInput;
+ size_t BufSize;
+ size_t CurContSize, MaxContSize;
+ ui8* Buf;
+ int ZErr;
int ConnectionClosed;
bool IgnoreTrailingGarbage;
-};
-
+};
+
class zlib_exception: public yexception {
-};
-
-template <class Reader>
-class SCompressedHttpReader: public TCompressedHttpReader<Reader> {
- typedef TCompressedHttpReader<Reader> TBase;
-
-public:
- using TBase::ZError;
- using TBase::ZMsg;
-
- SCompressedHttpReader()
+};
+
+template <class Reader>
+class SCompressedHttpReader: public TCompressedHttpReader<Reader> {
+ typedef TCompressedHttpReader<Reader> TBase;
+
+public:
+ using TBase::ZError;
+ using TBase::ZMsg;
+
+ SCompressedHttpReader()
: TBase()
{
}
-
+
int Init(
THttpHeader* H,
int parsHeader,
@@ -265,31 +265,31 @@ public:
bool headRequest = false)
{
int ret = TBase::Init(H, parsHeader, maxContSize, bufSize, winSize, headRequest);
- return (int)HandleRetValue((long)ret);
- }
-
+ return (int)HandleRetValue((long)ret);
+ }
+
long Read(void*& buf) {
- long ret = TBase::Read(buf);
- return HandleRetValue(ret);
- }
-
-protected:
- long HandleRetValue(long ret) {
- switch (ZError()) {
- case 0:
- return ret;
- case ENOMEM:
+ long ret = TBase::Read(buf);
+ return HandleRetValue(ret);
+ }
+
+protected:
+ long HandleRetValue(long ret) {
+ switch (ZError()) {
+ case 0:
+ return ret;
+ case ENOMEM:
ythrow yexception() << "SCompressedHttpReader: not enough memory";
- case EINVAL:
+ case EINVAL:
ythrow yexception() << "SCompressedHttpReader: zlib error: " << ZMsg();
- case ENOTSUP:
+ case ENOTSUP:
ythrow yexception() << "SCompressedHttpReader: unsupported compression method";
- case EFAULT:
+ case EFAULT:
ythrow zlib_exception() << "SCompressedHttpReader: " << ZMsg();
- case E2BIG:
+ case E2BIG:
ythrow zlib_exception() << "SCompressedHttpReader: Content exceeds maximum length";
- default:
+ default:
ythrow yexception() << "SCompressedHttpReader: unknown error";
- }
- }
-};
+ }
+ }
+};
diff --git a/library/cpp/http/fetch/ya.make b/library/cpp/http/fetch/ya.make
index 7737127463..aa8b073a8c 100644
--- a/library/cpp/http/fetch/ya.make
+++ b/library/cpp/http/fetch/ya.make
@@ -1,5 +1,5 @@
LIBRARY()
-
+
OWNER(
g:zora
)
@@ -14,25 +14,25 @@ PEERDIR(
library/cpp/uri
)
-SRCS(
- http_digest.cpp
- http_socket.cpp
+SRCS(
+ http_digest.cpp
+ http_socket.cpp
httpheader.cpp
- httpload.cpp
- exthttpcodes.cpp
+ httpload.cpp
+ exthttpcodes.cpp
httpfsm.rl6
- httpagent.h
- httpfetcher.h
- httpheader.h
- httpparser.h
- httpzreader.h
+ httpagent.h
+ httpfetcher.h
+ httpheader.h
+ httpparser.h
+ httpzreader.h
sockhandler.h
-)
-
+)
+
GENERATE_ENUM_SERIALIZATION(httpheader.h)
SET(RAGEL6_FLAGS -CF1)
-END()
+END()
RECURSE_FOR_TESTS(ut)
diff --git a/library/cpp/http/io/chunk_ut.cpp b/library/cpp/http/io/chunk_ut.cpp
index da283f8568..5a365e23f7 100644
--- a/library/cpp/http/io/chunk_ut.cpp
+++ b/library/cpp/http/io/chunk_ut.cpp
@@ -2,7 +2,7 @@
#include <library/cpp/testing/unittest/registar.h>
-#include <util/stream/file.h>
+#include <util/stream/file.h>
#include <util/system/tempfile.h>
#include <util/stream/null.h>
diff --git a/library/cpp/http/io/compression_ut.cpp b/library/cpp/http/io/compression_ut.cpp
index 2f3d131f8c..1201cda877 100644
--- a/library/cpp/http/io/compression_ut.cpp
+++ b/library/cpp/http/io/compression_ut.cpp
@@ -24,7 +24,7 @@ Y_UNIT_TEST_SUITE(THttpCompressionTest) {
auto encodedStream = (*encoder)(&buffer);
encodedStream->Write(DATA);
}
-
+
TZLibDecompress decompressor(&buffer);
UNIT_ASSERT_EQUAL(decompressor.ReadAll(), DATA);
}
diff --git a/library/cpp/http/io/headers.cpp b/library/cpp/http/io/headers.cpp
index 4ec27a29e8..070bfbe127 100644
--- a/library/cpp/http/io/headers.cpp
+++ b/library/cpp/http/io/headers.cpp
@@ -81,7 +81,7 @@ void THttpHeaders::RemoveHeader(const TStringBuf header) {
}
}
-void THttpHeaders::AddOrReplaceHeader(const THttpInputHeader& header) {
+void THttpHeaders::AddOrReplaceHeader(const THttpInputHeader& header) {
for (auto& hdr : Headers_) {
if (AsciiCompareIgnoreCase(hdr.Name(), header.Name()) == 0) {
hdr = header;
diff --git a/library/cpp/http/io/headers.h b/library/cpp/http/io/headers.h
index a71793d1c6..9bfc0d0172 100644
--- a/library/cpp/http/io/headers.h
+++ b/library/cpp/http/io/headers.h
@@ -12,7 +12,7 @@ class IOutputStream;
/// @addtogroup Streams_HTTP
/// @{
/// Объект, содержащий информацию о HTTP-заголовке.
-class THttpInputHeader {
+class THttpInputHeader {
public:
/// @param[in] header - строка вида 'параметр: значение'.
THttpInputHeader(TStringBuf header);
diff --git a/library/cpp/http/io/stream.cpp b/library/cpp/http/io/stream.cpp
index 6689be684f..28aa8af048 100644
--- a/library/cpp/http/io/stream.cpp
+++ b/library/cpp/http/io/stream.cpp
@@ -971,14 +971,14 @@ unsigned ParseHttpRetCode(const TStringBuf& ret) {
return FromString<unsigned>(code.data(), code.size());
}
-
+
void SendMinimalHttpRequest(TSocket& s, const TStringBuf& host, const TStringBuf& request, const TStringBuf& agent, const TStringBuf& from) {
- TSocketOutput so(s);
- THttpOutput output(&so);
-
- output.EnableKeepAlive(false);
- output.EnableCompression(false);
-
+ TSocketOutput so(s);
+ THttpOutput output(&so);
+
+ output.EnableKeepAlive(false);
+ output.EnableCompression(false);
+
const IOutputStream::TPart parts[] = {
IOutputStream::TPart(TStringBuf("GET ")),
IOutputStream::TPart(request),
@@ -994,11 +994,11 @@ void SendMinimalHttpRequest(TSocket& s, const TStringBuf& host, const TStringBuf
IOutputStream::TPart(from),
IOutputStream::TPart::CrLf(),
IOutputStream::TPart::CrLf(),
- };
+ };
- output.Write(parts, sizeof(parts) / sizeof(*parts));
- output.Finish();
-}
+ output.Write(parts, sizeof(parts) / sizeof(*parts));
+ output.Finish();
+}
TArrayRef<const TStringBuf> SupportedCodings() {
return TCompressionCodecFactory::Instance().GetBestCodecs();
diff --git a/library/cpp/http/io/stream.h b/library/cpp/http/io/stream.h
index 78ca4fc814..7a2693427e 100644
--- a/library/cpp/http/io/stream.h
+++ b/library/cpp/http/io/stream.h
@@ -172,7 +172,7 @@ unsigned ParseHttpRetCode(const TStringBuf& ret);
/// Отправляет HTTP-серверу запрос с минимумом необходимых заголовков.
void SendMinimalHttpRequest(TSocket& s, const TStringBuf& host, const TStringBuf& request, const TStringBuf& agent = "YandexSomething/1.0", const TStringBuf& from = "webadmin@yandex.ru");
-
+
TArrayRef<const TStringBuf> SupportedCodings();
/// @}
diff --git a/library/cpp/http/io/stream_ut.cpp b/library/cpp/http/io/stream_ut.cpp
index 1ea35df675..5fe494335a 100644
--- a/library/cpp/http/io/stream_ut.cpp
+++ b/library/cpp/http/io/stream_ut.cpp
@@ -116,7 +116,7 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) {
output.Write(r.data(), r.size());
output.Finish();
}
-
+
{
TSocketInput si(s);
THttpInput input(&si);
@@ -253,7 +253,7 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) {
SendMinimalHttpRequest(s, "www.yandex.lo", "/");
- TSocketInput si(s);
+ TSocketInput si(s);
THttpInput input(&si);
unsigned httpCode = ParseHttpRetCode(input.FirstLine());
UNIT_ASSERT_VALUES_EQUAL(httpCode, 200u);
@@ -261,7 +261,7 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) {
TransferData(&input, &dbg);
server.Stop();
}
-
+
Y_UNIT_TEST(TestResponseWithBlanks) {
TString res = "qqqqqq\r\n\r\nsdasdsad\r\n";
TPortManager pm;
@@ -292,13 +292,13 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) {
TStringOutput strOut(str);
TBufferedOutput bufOut(&strOut, 8192);
THttpOutput httpOut(&bufOut);
-
+
httpOut.EnableKeepAlive(true);
httpOut.EnableCompression(true);
const char* header = "GET / HTTP/1.1\r\nHost: yandex.ru\r\n\r\n";
httpOut << header;
-
+
unsigned curLen = str.size();
const char* body = "<html>Hello</html>";
httpOut << body;
@@ -306,7 +306,7 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) {
httpOut.Flush();
UNIT_ASSERT_VALUES_EQUAL(curLen + strlen(body), str.size());
}
-
+
Y_UNIT_TEST(TestOutputPostFlush) {
TString str;
TString checkStr;
diff --git a/library/cpp/http/misc/httpdate.cpp b/library/cpp/http/misc/httpdate.cpp
index 4a3031bbf4..719f100451 100644
--- a/library/cpp/http/misc/httpdate.cpp
+++ b/library/cpp/http/misc/httpdate.cpp
@@ -26,14 +26,14 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
-#include <util/system/defaults.h>
+#include <util/system/defaults.h>
#include <sys/types.h>
-#include <cctype>
-#include <cstdio>
-#include <cstdlib>
-#include <cstring>
-#include <ctime>
+#include <cctype>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
#include <util/system/compat.h> /* stricmp */
#include <util/system/yassert.h>
diff --git a/library/cpp/http/misc/httpdate.h b/library/cpp/http/misc/httpdate.h
index 04876f38fe..e9583b4230 100644
--- a/library/cpp/http/misc/httpdate.h
+++ b/library/cpp/http/misc/httpdate.h
@@ -3,7 +3,7 @@
#include <util/datetime/base.h>
#include <util/generic/string.h>
-#include <ctime>
+#include <ctime>
#define BAD_DATE ((time_t)-1)
diff --git a/library/cpp/http/misc/httpreqdata.h b/library/cpp/http/misc/httpreqdata.h
index 16e59c4d78..ae2652ac42 100644
--- a/library/cpp/http/misc/httpreqdata.h
+++ b/library/cpp/http/misc/httpreqdata.h
@@ -1,5 +1,5 @@
#pragma once
-
+
#include <library/cpp/digest/lower_case/hash_ops.h>
#include <util/str_stl.h>
@@ -14,11 +14,11 @@
#include <util/generic/string.h>
#include <util/datetime/base.h>
#include <util/generic/buffer.h>
-
+
using THttpHeadersContainer = THashMap<TString, TString, TCIOps, TCIOps>;
class TBaseServerRequestData {
-public:
+public:
TBaseServerRequestData(SOCKET s = INVALID_SOCKET);
TBaseServerRequestData(const char* qs, SOCKET s = INVALID_SOCKET);
@@ -29,7 +29,7 @@ public:
const TString& ServerName() const {
return Host;
- }
+ }
NAddr::IRemoteAddrPtr ServerAddress() const {
return NAddr::GetSockAddr(Socket);
@@ -37,15 +37,15 @@ public:
const TString& ServerPort() const {
return Port;
- }
+ }
- const char* ScriptName() const {
- return Path;
- }
+ const char* ScriptName() const {
+ return Path;
+ }
- const char* QueryString() const {
- return Search;
- }
+ const char* QueryString() const {
+ return Search;
+ }
TStringBuf QueryStringBuf() const {
return TStringBuf(Search, SearchLength);
@@ -82,22 +82,22 @@ public:
}
void SetPath(const TString& path);
- const char* GetCurPage() const;
+ const char* GetCurPage() const;
bool Parse(const char* req);
void AddHeader(const TString& name, const TString& value);
-private:
+private:
TBuffer PathStorage;
mutable char* Addr;
TString Host;
TString Port;
- char* Path;
- char* Search;
+ char* Path;
+ char* Search;
size_t SearchLength; // length of Search
TStringBuf OrigSearch;
THttpHeadersContainer HeadersIn_;
mutable char AddrData[INET6_ADDRSTRLEN];
- SOCKET Socket;
+ SOCKET Socket;
ui64 BeginTime;
mutable TString CurPage;
TBuffer ParseBuf;
@@ -105,7 +105,7 @@ private:
};
class TServerRequestData: public TBaseServerRequestData {
-public:
+public:
TServerRequestData(SOCKET s = INVALID_SOCKET)
: TBaseServerRequestData(s)
{
@@ -122,4 +122,4 @@ public:
public:
TCgiParameters CgiParam;
-};
+};
diff --git a/library/cpp/http/server/http.cpp b/library/cpp/http/server/http.cpp
index 128583bdd7..8d1900ef9e 100644
--- a/library/cpp/http/server/http.cpp
+++ b/library/cpp/http/server/http.cpp
@@ -22,7 +22,7 @@
#include <cerrno>
#include <cstring>
#include <ctime>
-
+
#include <sys/stat.h>
#include <sys/types.h>
@@ -139,7 +139,7 @@ public:
try {
((TImpl*)param)->ListenSocket();
} catch (...) {
-
+
}
return nullptr;
@@ -149,7 +149,7 @@ public:
THolder<TClientRequest> obj(Cb_->CreateClient());
obj->Conn_.Reset(c.Release());
-
+
return obj;
}
@@ -171,7 +171,7 @@ public:
void SaveErrorCode() {
ErrorCode = WSAGetLastError();
}
-
+
int GetErrorCode() const {
return ErrorCode;
}
@@ -218,7 +218,7 @@ public:
ListenThread.Reset(nullptr);
}
}
-
+
void Stop() {
Shutdown();
@@ -309,7 +309,7 @@ public:
Server_->AddRequestFromSocket(s, TInstant::Now(), SockAddrRef_);
}
-
+
SOCKET GetSocket() const noexcept {
return S_;
}
@@ -338,13 +338,13 @@ public:
return;
}
-
+
Requests->Start(Options_.nThreads, Options_.MaxQueueSize);
FailRequests->Start(Options_.nFThreads, Options_.MaxFQueueSize);
Cb_->OnListenStart();
ListenerRunningOK = true;
ListenStartEvent.Signal();
-
+
TVector<void*> events;
events.resize(1);
@@ -378,7 +378,7 @@ public:
Cb_->OnException();
}
}
-
+
while (!Reqs.Empty()) {
THolder<TListenSocket> ls(Reqs.PopFront());
@@ -586,20 +586,20 @@ void TClientConnection::OnPollEvent(TInstant now) {
return;
}
- }
+ }
THolder<TClientRequest> obj(HttpServ_->CreateRequest(this_));
AcceptMoment = now;
HttpServ_->AddRequest(obj, Reject_);
-}
-
+}
+
void TClientConnection::Activate(TInstant now) noexcept {
HttpServ_->Connections->Erase(this, now);
LastUsed = now;
++ReceivedRequests;
-}
-
+}
+
void TClientConnection::DeActivate() {
HttpServ_->Connections->Add(this);
}
diff --git a/library/cpp/http/server/http.h b/library/cpp/http/server/http.h
index b292d38f27..7fb210397c 100644
--- a/library/cpp/http/server/http.h
+++ b/library/cpp/http/server/http.h
@@ -1,5 +1,5 @@
#pragma once
-
+
#include "conn.h"
#include "options.h"
@@ -97,8 +97,8 @@ private:
private:
THolder<TImpl> Impl_;
-};
-
+};
+
/**
* @deprecated Use TRequestReplier instead
*/
diff --git a/library/cpp/ipv6_address/ipv6_address.h b/library/cpp/ipv6_address/ipv6_address.h
index 1d7eb0b65f..458ba87122 100644
--- a/library/cpp/ipv6_address/ipv6_address.h
+++ b/library/cpp/ipv6_address/ipv6_address.h
@@ -19,8 +19,8 @@
namespace NAddr {
class IRemoteAddr;
}
-struct in6_addr;
-struct in_addr;
+struct in6_addr;
+struct in_addr;
struct sockaddr;
struct sockaddr_in;
struct sockaddr_in6;
diff --git a/library/cpp/lfalloc/ya.make b/library/cpp/lfalloc/ya.make
index cace05f9d8..05dad5c2af 100644
--- a/library/cpp/lfalloc/ya.make
+++ b/library/cpp/lfalloc/ya.make
@@ -20,6 +20,6 @@ PEERDIR(
library/cpp/malloc/api
)
-SET(IDE_FOLDER "util")
+SET(IDE_FOLDER "util")
END()
diff --git a/library/cpp/lfalloc/yt/ya.make b/library/cpp/lfalloc/yt/ya.make
index 8c1a4f8a72..fa5791fcf9 100644
--- a/library/cpp/lfalloc/yt/ya.make
+++ b/library/cpp/lfalloc/yt/ya.make
@@ -24,6 +24,6 @@ PEERDIR(
library/cpp/malloc/api
)
-SET(IDE_FOLDER "util")
+SET(IDE_FOLDER "util")
END()
diff --git a/library/cpp/logger/backend.h b/library/cpp/logger/backend.h
index d088726d6d..0b64a80be5 100644
--- a/library/cpp/logger/backend.h
+++ b/library/cpp/logger/backend.h
@@ -1,5 +1,5 @@
#pragma once
-
+
#include "priority.h"
#include <util/generic/noncopyable.h>
@@ -7,7 +7,7 @@
#include <cstddef>
struct TLogRecord;
-
+
// NOTE: be aware that all `TLogBackend`s are registred in singleton.
class TLogBackend: public TNonCopyable {
public:
diff --git a/library/cpp/logger/file.h b/library/cpp/logger/file.h
index 10b4cd0c20..9204d5ad60 100644
--- a/library/cpp/logger/file.h
+++ b/library/cpp/logger/file.h
@@ -1,5 +1,5 @@
#pragma once
-
+
#include "backend.h"
#include <util/generic/fwd.h>
@@ -16,4 +16,4 @@ public:
private:
class TImpl;
TAtomicSharedPtr<TImpl> Impl_;
-};
+};
diff --git a/library/cpp/logger/log.h b/library/cpp/logger/log.h
index 8be984ccc8..35896d6b1e 100644
--- a/library/cpp/logger/log.h
+++ b/library/cpp/logger/log.h
@@ -1,5 +1,5 @@
#pragma once
-
+
#include "backend.h"
#include "element.h"
#include "priority.h"
diff --git a/library/cpp/logger/log_ut.cpp b/library/cpp/logger/log_ut.cpp
index 8de46f17f5..a30ae0f0df 100644
--- a/library/cpp/logger/log_ut.cpp
+++ b/library/cpp/logger/log_ut.cpp
@@ -54,7 +54,7 @@ void TLogTest::TestFile() {
log.AddLog("some useful data %d, %u, %lf, %s\n", v1, v2, v3, v4);
}
- TBlob data = TBlob::FromFileSingleThreaded(LOGFILE);
+ TBlob data = TBlob::FromFileSingleThreaded(LOGFILE);
UNIT_ASSERT_EQUAL(TString((const char*)data.Begin(), data.Size()), "some useful data 12, 34, 3.000000, qwqwqw\n");
}
@@ -73,7 +73,7 @@ void TLogTest::TestThreaded() {
log.AddLog("some useful data %d, %u, %lf, %s\n", v1, v2, v3, v4);
}
- TBlob data = TBlob::FromFileSingleThreaded(LOGFILE);
+ TBlob data = TBlob::FromFileSingleThreaded(LOGFILE);
UNIT_ASSERT_EQUAL(TString((const char*)data.Begin(), data.Size()), "some useful data 12, 34, 3.000000, qwqwqw\n");
}
diff --git a/library/cpp/logger/null.h b/library/cpp/logger/null.h
index a02f250b00..3ec8c670d9 100644
--- a/library/cpp/logger/null.h
+++ b/library/cpp/logger/null.h
@@ -1,5 +1,5 @@
#pragma once
-
+
#include "backend.h"
class TNullLogBackend: public TLogBackend {
diff --git a/library/cpp/logger/priority.h b/library/cpp/logger/priority.h
index d2a9fa0a07..aafa74be8b 100644
--- a/library/cpp/logger/priority.h
+++ b/library/cpp/logger/priority.h
@@ -1,5 +1,5 @@
#pragma once
-
+
enum ELogPriority {
TLOG_EMERG = 0 /* "EMERG" */,
TLOG_ALERT = 1 /* "ALERT" */,
diff --git a/library/cpp/logger/record.h b/library/cpp/logger/record.h
index c28a7785fd..dd9d0d03a1 100644
--- a/library/cpp/logger/record.h
+++ b/library/cpp/logger/record.h
@@ -1,5 +1,5 @@
#pragma once
-
+
#include "priority.h"
#include <util/system/defaults.h>
@@ -8,7 +8,7 @@ struct TLogRecord {
const char* Data;
size_t Len;
ELogPriority Priority;
-
+
inline TLogRecord(ELogPriority priority, const char* data, size_t len) noexcept
: Data(data)
, Len(len)
diff --git a/library/cpp/logger/stream.h b/library/cpp/logger/stream.h
index feb240afcb..e57fcf55fd 100644
--- a/library/cpp/logger/stream.h
+++ b/library/cpp/logger/stream.h
@@ -1,5 +1,5 @@
#pragma once
-
+
#include "backend.h"
class IOutputStream;
diff --git a/library/cpp/logger/system.h b/library/cpp/logger/system.h
index b8c60b3023..5eeca896c6 100644
--- a/library/cpp/logger/system.h
+++ b/library/cpp/logger/system.h
@@ -1,5 +1,5 @@
#pragma once
-
+
#include "log.h"
#include "backend.h"
#include "priority.h"
diff --git a/library/cpp/logger/thread.h b/library/cpp/logger/thread.h
index 65f7a88e87..1ea222a0e6 100644
--- a/library/cpp/logger/thread.h
+++ b/library/cpp/logger/thread.h
@@ -1,5 +1,5 @@
#pragma once
-
+
#include "backend.h"
#include <util/generic/ptr.h>
diff --git a/library/cpp/messagebus/coreconn.cpp b/library/cpp/messagebus/coreconn.cpp
index d9411bb5db..d25f48930e 100644
--- a/library/cpp/messagebus/coreconn.cpp
+++ b/library/cpp/messagebus/coreconn.cpp
@@ -8,7 +8,7 @@
#include <util/string/util.h>
#include <util/system/thread.h>
-namespace NBus {
+namespace NBus {
TBusInstant Now() {
return millisec();
}
diff --git a/library/cpp/messagebus/coreconn.h b/library/cpp/messagebus/coreconn.h
index fca228d82e..7547c9aba6 100644
--- a/library/cpp/messagebus/coreconn.h
+++ b/library/cpp/messagebus/coreconn.h
@@ -27,10 +27,10 @@
#include <deque>
#include <utility>
-#ifdef NO_ERROR
+#ifdef NO_ERROR
#undef NO_ERROR
-#endif
-
+#endif
+
#define BUS_WORKER_CONDVAR
//#define BUS_WORKER_MIXED
@@ -63,5 +63,5 @@ namespace NBus {
POLL_READ,
POLL_WRITE
};
-
+
}
diff --git a/library/cpp/messagebus/handler.cpp b/library/cpp/messagebus/handler.cpp
index 333bd52934..3ad336c91d 100644
--- a/library/cpp/messagebus/handler.cpp
+++ b/library/cpp/messagebus/handler.cpp
@@ -1,7 +1,7 @@
#include "handler.h"
#include "remote_server_connection.h"
-#include "ybus.h"
+#include "ybus.h"
using namespace NBus;
using namespace NBus::NPrivate;
diff --git a/library/cpp/messagebus/locator.cpp b/library/cpp/messagebus/locator.cpp
index e38a35c426..11716e3cd5 100644
--- a/library/cpp/messagebus/locator.cpp
+++ b/library/cpp/messagebus/locator.cpp
@@ -9,7 +9,7 @@
#include <util/generic/hash_set.h>
#include <util/system/hostname.h>
-namespace NBus {
+namespace NBus {
using namespace NAddr;
static TIpPort GetAddrPort(const IRemoteAddr& addr) {
@@ -360,7 +360,7 @@ namespace NBus {
}
int TBusLocator::LocateKeys(TBusService service, TBusKeyVec& keys, bool onlyLocal) {
- TGuard<TMutex> G(Lock);
+ TGuard<TMutex> G(Lock);
Y_VERIFY(keys.empty(), "Non empty keys");
TServiceId serviceId = GetServiceId(service);
@@ -374,7 +374,7 @@ namespace NBus {
continue;
}
keys.push_back(std::make_pair(item.Start, item.End));
- }
+ }
return (int)keys.size();
}
diff --git a/library/cpp/messagebus/message.cpp b/library/cpp/messagebus/message.cpp
index bfa7ed8e9b..0fba16bc68 100644
--- a/library/cpp/messagebus/message.cpp
+++ b/library/cpp/messagebus/message.cpp
@@ -9,7 +9,7 @@
using namespace NBus;
-namespace NBus {
+namespace NBus {
using namespace NBus::NPrivate;
TBusIdentity::TBusIdentity()
@@ -156,7 +156,7 @@ namespace NBus {
ReplyTo = data.Connection->PeerAddrSocketAddr;
SetCompressed(compressed || IsCompressedResponse());
}
-
+
void TBusMessage::SetCompressed(bool v) {
if (v) {
GetHeader()->FlagsInternal |= MESSAGE_COMPRESS_INTERNAL;
diff --git a/library/cpp/messagebus/messqueue.cpp b/library/cpp/messagebus/messqueue.cpp
index 3474d62705..5de2c1a12c 100644
--- a/library/cpp/messagebus/messqueue.cpp
+++ b/library/cpp/messagebus/messqueue.cpp
@@ -24,17 +24,17 @@ TBusMessageQueuePtr NBus::CreateMessageQueue(const TBusQueueConfig& config, TBus
TBusMessageQueuePtr NBus::CreateMessageQueue(const TBusQueueConfig& config, const char* name) {
return CreateMessageQueue(config, new TBusLocator, name);
-}
-
+}
+
TBusMessageQueuePtr NBus::CreateMessageQueue(TExecutorPtr executor, const char* name) {
return CreateMessageQueue(TBusQueueConfig(), executor, new TBusLocator, name);
}
TBusMessageQueuePtr NBus::CreateMessageQueue(const char* name) {
- TBusQueueConfig config;
+ TBusQueueConfig config;
return CreateMessageQueue(config, name);
-}
-
+}
+
namespace {
TBusQueueConfig QueueConfigFillDefaults(const TBusQueueConfig& orig, const TString& name) {
TBusQueueConfig patched = orig;
@@ -148,8 +148,8 @@ TBusServerSessionPtr TBusMessageQueue::CreateDestination(TBusProtocol* proto, IB
} catch (...) {
Y_FAIL("create destination failure: %s", CurrentExceptionMessage().c_str());
}
-}
-
+}
+
TBusServerSessionPtr TBusMessageQueue::CreateDestination(TBusProtocol* proto, IBusServerHandler* handler, const TBusServerSessionConfig& config, const TVector<TBindResult>& bindTo, const TString& name) {
TRemoteServerSessionPtr session(new TRemoteServerSession(this, proto, handler, config, name));
try {
@@ -179,15 +179,15 @@ void TBusMessageQueue::Destroy(TBusSession* session) {
void TBusMessageQueue::DestroyAllSessions() {
TList<TIntrusivePtr<TBusSessionImpl>> sessions;
- {
- TGuard<TMutex> scope(Lock);
+ {
+ TGuard<TMutex> scope(Lock);
sessions = Sessions;
- }
-
+ }
+
for (auto& session : sessions) {
Y_VERIFY(session->IsDown(), "Session must be shut down prior to queue shutdown");
}
-}
+}
void TBusMessageQueue::Schedule(IScheduleItemAutoPtr i) {
Scheduler.Schedule(i);
diff --git a/library/cpp/messagebus/network.cpp b/library/cpp/messagebus/network.cpp
index 304bedae5a..214fbb5f1f 100644
--- a/library/cpp/messagebus/network.cpp
+++ b/library/cpp/messagebus/network.cpp
@@ -1,8 +1,8 @@
-#include "network.h"
-
+#include "network.h"
+
#include <util/generic/maybe.h>
#include <util/generic/ptr.h>
-#include <util/network/init.h>
+#include <util/network/init.h>
#include <util/network/socket.h>
#include <util/system/platform.h>
@@ -19,7 +19,7 @@ namespace {
}
int one = 1;
- int r1 = SetSockOpt(fd, SOL_SOCKET, SO_REUSEADDR, one);
+ int r1 = SetSockOpt(fd, SOL_SOCKET, SO_REUSEADDR, one);
if (r1 < 0) {
ythrow TSystemError() << "failed to setsockopt SO_REUSEADDR";
}
diff --git a/library/cpp/messagebus/oldmodule/module.cpp b/library/cpp/messagebus/oldmodule/module.cpp
index 24bd778799..3dc9c80a94 100644
--- a/library/cpp/messagebus/oldmodule/module.cpp
+++ b/library/cpp/messagebus/oldmodule/module.cpp
@@ -60,7 +60,7 @@ namespace {
}
-namespace NBus {
+namespace NBus {
namespace NPrivate {
class TJobStorage {
};
@@ -327,11 +327,11 @@ namespace NBus {
{
Handler = TJobHandler(&TBusModule::Start);
}
-
+
TBusJob::~TBusJob() {
Y_ASSERT(Pending.size() == 0);
//Y_ASSERT(SleepUntil == 0);
-
+
ClearAllMessageStates();
}
@@ -618,7 +618,7 @@ namespace NBus {
}
//////////////////////////////////////////////////////////////////////
-
+
void TBusModuleImpl::CancelJob(TBusJob* job, EMessageStatus status) {
TWhatThreadDoesAcquireGuard<TMutex> G(Lock, "modules: acquiring lock for CancelJob");
if (job) {
@@ -636,8 +636,8 @@ namespace NBus {
strReturn += "TODO\n";
}
return strReturn;
- }
-
+ }
+
TBusModuleConfig::TBusModuleConfig()
: StarterMaxInFlight(1000)
{
@@ -652,10 +652,10 @@ namespace NBus {
: Impl(new TBusModuleImpl(this, name))
{
}
-
+
TBusModule::~TBusModule() {
}
-
+
const char* TBusModule::GetName() const {
return Impl->Name;
}
@@ -680,7 +680,7 @@ namespace NBus {
bool TBusModule::Shutdown() {
Impl->Shutdown();
-
+
return true;
}
@@ -688,16 +688,16 @@ namespace NBus {
TBusJob* job = new TBusJob(this, message);
return job;
}
-
+
/**
-Example for external session creation:
-
-TBusSession* TMyModule::CreateExtSession(TBusMessageQueue& queue) {
- TBusSession* session = CreateDefaultDestination(queue, &ExternalProto, ExternalConfig);
- session->RegisterService(hostname, begin, end);
- return session;
-*/
-
+Example for external session creation:
+
+TBusSession* TMyModule::CreateExtSession(TBusMessageQueue& queue) {
+ TBusSession* session = CreateDefaultDestination(queue, &ExternalProto, ExternalConfig);
+ session->RegisterService(hostname, begin, end);
+ return session;
+*/
+
bool TBusModule::CreatePrivateSessions(TBusMessageQueue* queue) {
Impl->Queue = queue;
return true;
@@ -782,11 +782,11 @@ void TBusModuleImpl::DestroyJob(TJobRunner* job) {
ShutdownCondVar.BroadCast();
}
}
- }
+ }
job->JobStorageIterator = TList<TJobRunner*>::iterator();
}
-
+
void TBusModuleImpl::OnMessageReceived(TAutoPtr<TBusMessage> msg0, TOnMessageContext& context) {
TBusMessage* msg = !!msg0 ? msg0.Get() : context.GetMessage();
Y_VERIFY(!!msg);
@@ -797,7 +797,7 @@ void TBusModuleImpl::OnMessageReceived(TAutoPtr<TBusMessage> msg0, TOnMessageCon
SetJob(jobRunner->Job->Message, jobRunner.Get());
AtomicIncrement(JobCount);
-
+
AddJob(jobRunner.Get());
jobRunner.Release()->Schedule();
@@ -858,14 +858,14 @@ void TModuleClientHandler::OnReply(TAutoPtr<TBusMessage> req, TAutoPtr<TBusMessa
job->EnqueueAndSchedule(TJobResponseMessage(req.Release(), resp.Release(), MESSAGE_OK));
job->UnRef();
}
-
+
void TModuleClientHandler::OnMessageSentOneWay(TAutoPtr<TBusMessage> req) {
TJobRunner* job = GetJob(req.Get());
Y_ASSERT(job);
Y_ASSERT(job->Job->Message != req.Get());
job->EnqueueAndSchedule(TJobResponseMessage(req.Release(), nullptr, MESSAGE_OK));
job->UnRef();
-}
+}
void TModuleClientHandler::OnError(TAutoPtr<TBusMessage> msg, EMessageStatus status) {
TJobRunner* job = GetJob(msg.Get());
diff --git a/library/cpp/messagebus/oldmodule/module.h b/library/cpp/messagebus/oldmodule/module.h
index 8d1c4a5d52..dc3b6377f0 100644
--- a/library/cpp/messagebus/oldmodule/module.h
+++ b/library/cpp/messagebus/oldmodule/module.h
@@ -9,7 +9,7 @@
/// NBus::TBusSession.
/// To implement the module some virtual functions needs to be overridden:
-
+
/// NBus::TBusModule::CreateExtSession() creates and registers an
/// external session that receives incoming messages as input for module
/// processing.
@@ -18,13 +18,13 @@
/// NBus::TBusJob is somewhat similar to a thread, it maintains all the state
/// during processing of one incoming message. Default implementation of
/// NBus::TBusJob will maintain all send and received messages during
-/// lifetime of this job. Each message, status and reply can be found
+/// lifetime of this job. Each message, status and reply can be found
/// within NBus::TJobState using NBus::TBusJob::GetState(). If your module
/// needs to maintain an additional information during lifetime of the job
/// you can derive your own class from NBus::TBusJob and override job
-/// factory method NBus::IJobFactory::CreateJobInstance() to create your instances.
+/// factory method NBus::IJobFactory::CreateJobInstance() to create your instances.
-/// Processing of a given message starts with a call to NBus::TBusModule::Start()
+/// Processing of a given message starts with a call to NBus::TBusModule::Start()
/// handler that should be overridden in the module implementation. Within
/// the callback handler module can perform any computation and access any
/// datastore tables that it needs. The handler can also access any module
@@ -33,7 +33,7 @@
/// Handler should use NBus::TBusJob::Send() to send messages to other client
/// sessions and it can use NBus::TBusJob::Reply() to send reply to the main
-/// job message. When handler is done, it returns the pointer to the next handler to call
+/// job message. When handler is done, it returns the pointer to the next handler to call
/// when all pending messages have cleared. If handler
/// returns pointer to itself the module will reschedule execution of this handler
/// for a later time. This should be done in case NBus::TBusJob::Send() returns
diff --git a/library/cpp/messagebus/oldmodule/startsession.cpp b/library/cpp/messagebus/oldmodule/startsession.cpp
index 7c38801d62..0827972d88 100644
--- a/library/cpp/messagebus/oldmodule/startsession.cpp
+++ b/library/cpp/messagebus/oldmodule/startsession.cpp
@@ -18,7 +18,7 @@
#include <library/cpp/messagebus/ybus.h>
-namespace NBus {
+namespace NBus {
void* TBusStarter::_starter(void* data) {
TBusStarter* pThis = static_cast<TBusStarter*>(data);
pThis->Starter();
@@ -61,5 +61,5 @@ namespace NBus {
}
}
}
-
-}
+
+}
diff --git a/library/cpp/messagebus/protobuf/ybusbuf.h b/library/cpp/messagebus/protobuf/ybusbuf.h
index 57b4267ea5..1fed492d5c 100644
--- a/library/cpp/messagebus/protobuf/ybusbuf.h
+++ b/library/cpp/messagebus/protobuf/ybusbuf.h
@@ -226,8 +226,8 @@ namespace NBus {
/// serialized protocol specific data into TBusData
void Serialize(const TBusMessage* mess, TBuffer& data) override;
-
+
TAutoPtr<TBusMessage> Deserialize(ui16 messageType, TArrayRef<const char> payload) override;
};
-
+
}
diff --git a/library/cpp/messagebus/scheduler/scheduler.cpp b/library/cpp/messagebus/scheduler/scheduler.cpp
index 5a5fe52894..dd9767c25a 100644
--- a/library/cpp/messagebus/scheduler/scheduler.cpp
+++ b/library/cpp/messagebus/scheduler/scheduler.cpp
@@ -4,7 +4,7 @@
#include <util/generic/algorithm.h>
#include <util/generic/yexception.h>
-//#include "dummy_debugger.h"
+//#include "dummy_debugger.h"
using namespace NBus;
using namespace NBus::NPrivate;
diff --git a/library/cpp/messagebus/session.cpp b/library/cpp/messagebus/session.cpp
index 46a7ece6a8..69b6825bb8 100644
--- a/library/cpp/messagebus/session.cpp
+++ b/library/cpp/messagebus/session.cpp
@@ -4,7 +4,7 @@
using namespace NBus;
-namespace NBus {
+namespace NBus {
TBusSession::TBusSession() {
}
diff --git a/library/cpp/messagebus/synchandler.cpp b/library/cpp/messagebus/synchandler.cpp
index 8e891d66b3..30c2cc3806 100644
--- a/library/cpp/messagebus/synchandler.cpp
+++ b/library/cpp/messagebus/synchandler.cpp
@@ -142,7 +142,7 @@ namespace NBus {
// deletion of message and reply is a job of application.
pMessage->Data = nullptr;
-
+
return reply;
}
};
diff --git a/library/cpp/messagebus/test/perftest/perftest.cpp b/library/cpp/messagebus/test/perftest/perftest.cpp
index 8489319278..f7f5e88086 100644
--- a/library/cpp/messagebus/test/perftest/perftest.cpp
+++ b/library/cpp/messagebus/test/perftest/perftest.cpp
@@ -593,12 +593,12 @@ int main(int argc, char* argv[]) {
/* unix foo */
setvbuf(stdout, nullptr, _IONBF, 0);
setvbuf(stderr, nullptr, _IONBF, 0);
- Umask(0);
+ Umask(0);
SetAsyncSignalHandler(SIGINT, stopsignal);
SetAsyncSignalHandler(SIGTERM, stopsignal);
-#ifndef _win_
+#ifndef _win_
SetAsyncSignalHandler(SIGUSR1, stopsignal);
-#endif
+#endif
signal(SIGPIPE, SIG_IGN);
NLastGetopt::TOpts opts = NLastGetopt::TOpts::Default();
@@ -641,7 +641,7 @@ int main(int argc, char* argv[]) {
TIntrusivePtr<TBusWww> www(new TBusWww);
ServerAddresses = ParseNodes(TheConfig->Nodes);
-
+
if (TheConfig->ServerPort) {
if (TheConfig->ServerUseModules) {
ServerUsingModule = new TPerftestUsingModule();
diff --git a/library/cpp/messagebus/test/ut/one_way_ut.cpp b/library/cpp/messagebus/test/ut/one_way_ut.cpp
index 9c21227e2b..16065289ad 100644
--- a/library/cpp/messagebus/test/ut/one_way_ut.cpp
+++ b/library/cpp/messagebus/test/ut/one_way_ut.cpp
@@ -55,7 +55,7 @@ struct NullClient : TBusClientHandlerError {
UNIT_ASSERT(serverAddr.GetPort() > 0);
/// create or get instance of message queue, need one per application
- Queue = CreateMessageQueue();
+ Queue = CreateMessageQueue();
/// register source/client session
Session = TBusClientSession::Create(&Proto, this, sessionConfig, Queue);
@@ -99,7 +99,7 @@ public:
NumMessages = 0;
/// create or get instance of single message queue, need one for application
- Queue = CreateMessageQueue();
+ Queue = CreateMessageQueue();
/// register destination session
TBusServerSessionConfig sessionConfig;
diff --git a/library/cpp/messagebus/ya.make b/library/cpp/messagebus/ya.make
index e13cf06dea..e8b6701eed 100644
--- a/library/cpp/messagebus/ya.make
+++ b/library/cpp/messagebus/ya.make
@@ -1,4 +1,4 @@
-LIBRARY()
+LIBRARY()
OWNER(g:messagebus)
diff --git a/library/cpp/messagebus/ybus.h b/library/cpp/messagebus/ybus.h
index de21ad8521..2393b840ac 100644
--- a/library/cpp/messagebus/ybus.h
+++ b/library/cpp/messagebus/ybus.h
@@ -74,10 +74,10 @@ namespace NBus {
int GetPort() const {
return ServicePort;
}
-
+
virtual ~TBusProtocol() {
}
-
+
/// \brief serialized protocol specific data into TBusData
/// \note buffer passed to the function (data) is not empty, use append functions
virtual void Serialize(const TBusMessage* mess, TBuffer& data) = 0;
@@ -175,7 +175,7 @@ namespace NBus {
TBusLocator* GetLocator() const {
return Locator.Get();
}
-
+
TBusClientSessionPtr CreateSource(TBusProtocol* proto, IBusClientHandler* handler, const TBusClientSessionConfig& config, const TString& name = "");
TBusSyncClientSessionPtr CreateSyncSource(TBusProtocol* proto, const TBusClientSessionConfig& config, bool needReply = true, const TString& name = "");
TBusServerSessionPtr CreateDestination(TBusProtocol* proto, IBusServerHandler* hander, const TBusServerSessionConfig& config, const TString& name = "");
diff --git a/library/cpp/mime/types/mime.cpp b/library/cpp/mime/types/mime.cpp
index 706d776b24..2dfa73ef2b 100644
--- a/library/cpp/mime/types/mime.cpp
+++ b/library/cpp/mime/types/mime.cpp
@@ -5,7 +5,7 @@
#include <util/generic/strbuf.h>
#include <util/generic/singleton.h>
#include <util/generic/yexception.h>
-
+
#include <cctype>
/*
@@ -175,7 +175,7 @@ const char* mimetypeByExt(const char* fname, const char* check_ext) {
size_t i;
ext_p++;
for (i = 0; i < TMimeTypes::MAX_EXT_LEN && ext_p[i]; i++)
- ext[i] = (char)tolower(ext_p[i]);
+ ext[i] = (char)tolower(ext_p[i]);
ext[i] = 0;
if (check_ext != nullptr) {
diff --git a/library/cpp/mime/types/mime.h b/library/cpp/mime/types/mime.h
index 05da389ea9..ff30d24e43 100644
--- a/library/cpp/mime/types/mime.h
+++ b/library/cpp/mime/types/mime.h
@@ -3,9 +3,9 @@
#include <util/system/defaults.h>
#include <util/generic/strbuf.h>
-#include <cstring>
+#include <cstring>
-enum MimeTypes {
+enum MimeTypes {
MIME_UNKNOWN = 0,
MIME_TEXT = 1,
MIME_HTML = 2,
@@ -58,9 +58,9 @@ enum MimeTypes {
MIME_WOFF2 = 44,
MIME_TTF = 45,
MIME_WEBMANIFEST = 46,
- MIME_MAX
-};
-
+ MIME_MAX
+};
+
extern const char* MimeNames[MIME_MAX];
const char* mimetypeByExt(const char* fname, const char* check_ext = nullptr);
diff --git a/library/cpp/monlib/service/service.h b/library/cpp/monlib/service/service.h
index 2f66dddaf8..d8318a5249 100644
--- a/library/cpp/monlib/service/service.h
+++ b/library/cpp/monlib/service/service.h
@@ -11,7 +11,7 @@
#include <functional>
-struct TMonitor;
+struct TMonitor;
namespace NMonitoring {
struct IHttpRequest {
diff --git a/library/cpp/on_disk/chunks/chunked_helpers.h b/library/cpp/on_disk/chunks/chunked_helpers.h
index 5fa96afdca..5395f8c9b4 100644
--- a/library/cpp/on_disk/chunks/chunked_helpers.h
+++ b/library/cpp/on_disk/chunks/chunked_helpers.h
@@ -269,7 +269,7 @@ public:
bits = 0;
}
WriteBin<ui16>(&out, bits);
- WriteBin<ui32>(&out, (ui32)Data.size());
+ WriteBin<ui32>(&out, (ui32)Data.size());
const ui32 nBuckets = ui32(1) << bits;
TData2 data2(nBuckets);
@@ -281,8 +281,8 @@ public:
ui32 offset = 0;
for (ui32 i = 0; i < nBuckets; ++i) {
intervals[i].Offset = offset;
- intervals[i].Length = (ui32)data2[i].size();
- offset += (ui32)data2[i].size();
+ intervals[i].Length = (ui32)data2[i].size();
+ offset += (ui32)data2[i].size();
}
#ifndef NDEBUG
for (ui32 i = 0; i < nBuckets; ++i) {
diff --git a/library/cpp/on_disk/chunks/chunks_ut.cpp b/library/cpp/on_disk/chunks/chunks_ut.cpp
index f727647f7f..bcd6801cb3 100644
--- a/library/cpp/on_disk/chunks/chunks_ut.cpp
+++ b/library/cpp/on_disk/chunks/chunks_ut.cpp
@@ -90,8 +90,8 @@ public:
writer.Save(stream);
}
{
- TBlob temp = TBlob::FromStreamSingleThreaded(stream);
- TGeneralVector<ui32> reader(temp);
+ TBlob temp = TBlob::FromStreamSingleThreaded(stream);
+ TGeneralVector<ui32> reader(temp);
UNIT_ASSERT_EQUAL(reader.GetSize(), N);
for (size_t i = 0; i < N; ++i) {
ui32 value;
@@ -112,7 +112,7 @@ public:
writer.Save(stream);
}
{
- TBlob temp = TBlob::FromStreamSingleThreaded(stream);
+ TBlob temp = TBlob::FromStreamSingleThreaded(stream);
TGeneralVector<TString> reader(temp);
UNIT_ASSERT_EQUAL(reader.GetSize(), N);
for (size_t i = 0; i < N; ++i) {
@@ -135,8 +135,8 @@ public:
writer.Save(stream);
}
{
- TBlob temp = TBlob::FromStreamSingleThreaded(stream);
- TGeneralVector<TItem> reader(temp);
+ TBlob temp = TBlob::FromStreamSingleThreaded(stream);
+ TGeneralVector<TItem> reader(temp);
UNIT_ASSERT_EQUAL(reader.GetSize(), N);
TItem value;
@@ -163,8 +163,8 @@ public:
writer.Save(stream);
}
{
- TBlob temp = TBlob::FromStreamSingleThreaded(stream);
- TGeneralVector<int*> reader(temp);
+ TBlob temp = TBlob::FromStreamSingleThreaded(stream);
+ TGeneralVector<int*> reader(temp);
UNIT_ASSERT_EQUAL(reader.GetSize(), N);
for (size_t i = 0; i < N; ++i) {
int* value;
@@ -186,8 +186,8 @@ public:
writer.Save(stream);
}
{
- TBlob temp = TBlob::FromStreamSingleThreaded(stream);
- TGeneralVector<TItem> reader(temp);
+ TBlob temp = TBlob::FromStreamSingleThreaded(stream);
+ TGeneralVector<TItem> reader(temp);
UNIT_ASSERT_EQUAL(reader.GetSize(), N);
for (size_t i = 0; i < N; ++i) {
TItem value;
@@ -214,7 +214,7 @@ public:
}
{
- TBlob fIn = TBlob::FromFileSingleThreaded(FILENAME);
+ TBlob fIn = TBlob::FromFileSingleThreaded(FILENAME);
TStringsVector vct(GetBlock(fIn, 0));
UNIT_ASSERT_EQUAL(vct.Get(0), "");
UNIT_ASSERT_EQUAL(vct.Get(1), "test");
@@ -250,7 +250,7 @@ public:
}
{
- TBlob mf = TBlob::FromFileSingleThreaded(filename);
+ TBlob mf = TBlob::FromFileSingleThreaded(filename);
TNamedChunkedDataReader reader(mf);
UNIT_ASSERT(reader.GetBlocksCount() == 3);
@@ -297,7 +297,7 @@ private:
writer.WriteFooter();
}
{
- TBlob blob = TBlob::FromBufferSingleThreaded(buffer);
+ TBlob blob = TBlob::FromBufferSingleThreaded(buffer);
TChunkedDataReader data(blob);
// printf("%d\n", (int)data.GetBlockLen(3));
UNIT_ASSERT_EQUAL(4, data.GetBlockLen(0));
@@ -317,7 +317,7 @@ private:
writer.WriteFooter();
}
{
- TBlob blob = TBlob::FromBufferSingleThreaded(buffer);
+ TBlob blob = TBlob::FromBufferSingleThreaded(buffer);
TChunkedDataReader data(blob);
// printf("%d\n", (int)data.GetBlockLen(1));
UNIT_ASSERT_EQUAL(0, data.GetBlockLen(0));
diff --git a/library/cpp/packers/packers.h b/library/cpp/packers/packers.h
index 1bde1b59aa..20248defae 100644
--- a/library/cpp/packers/packers.h
+++ b/library/cpp/packers/packers.h
@@ -64,27 +64,27 @@ namespace NPackers {
}
}
- namespace NImpl {
- template <class T, bool isSigned>
- struct TConvertImpl {
- static inline ui64 Convert(const T& data);
- };
-
- template <class T>
- struct TConvertImpl<T, true> {
- static inline ui64 Convert(const T& data) {
- return ConvertIntegral<i64>(static_cast<i64>(data));
- }
- };
-
- template <class T>
- struct TConvertImpl<T, false> {
- static inline ui64 Convert(const T& data) {
- return data;
- }
- };
- }
-
+ namespace NImpl {
+ template <class T, bool isSigned>
+ struct TConvertImpl {
+ static inline ui64 Convert(const T& data);
+ };
+
+ template <class T>
+ struct TConvertImpl<T, true> {
+ static inline ui64 Convert(const T& data) {
+ return ConvertIntegral<i64>(static_cast<i64>(data));
+ }
+ };
+
+ template <class T>
+ struct TConvertImpl<T, false> {
+ static inline ui64 Convert(const T& data) {
+ return data;
+ }
+ };
+ }
+
template <class T>
inline ui64 ConvertIntegral(const T& data) {
static_assert(std::is_integral<T>::value, "T must be integral type");
@@ -149,33 +149,33 @@ namespace NPackers {
return SkipTable[(ui8)*p];
}
- namespace NImpl {
- template <class T, bool isSigned>
- struct TUnpackLeafImpl {
+ namespace NImpl {
+ template <class T, bool isSigned>
+ struct TUnpackLeafImpl {
inline void UnpackLeaf(const char* p, T& t) const;
- };
- template <class T>
- struct TUnpackLeafImpl<T, true> {
+ };
+ template <class T>
+ struct TUnpackLeafImpl<T, true> {
inline void UnpackLeaf(const char* p, T& t) const {
ui64 val;
TIntegralPacker<ui64>().UnpackLeaf(p, val);
- if (val & 1) {
+ if (val & 1) {
t = -1 * static_cast<i64>(val >> 1);
- } else {
+ } else {
t = static_cast<T>(val >> 1);
- }
- }
- };
- template <class T>
- struct TUnpackLeafImpl<T, false> {
+ }
+ }
+ };
+ template <class T>
+ struct TUnpackLeafImpl<T, false> {
inline void UnpackLeaf(const char* p, T& t) const {
ui64 tmp;
TIntegralPacker<ui64>().UnpackLeaf(p, tmp);
t = static_cast<T>(tmp);
- }
- };
- }
-
+ }
+ };
+ }
+
template <class T>
inline void TIntegralPacker<T>::UnpackLeaf(const char* p, T& t) const {
NImpl::TUnpackLeafImpl<T, std::is_signed<T>::value>().UnpackLeaf(p, t);
diff --git a/library/cpp/regex/pcre/regexp.cpp b/library/cpp/regex/pcre/regexp.cpp
index 575c09cee4..e7c2dfa047 100644
--- a/library/cpp/regex/pcre/regexp.cpp
+++ b/library/cpp/regex/pcre/regexp.cpp
@@ -4,7 +4,7 @@
#include <util/string/ascii.h>
#include <util/system/defaults.h>
-#include <cstdlib>
+#include <cstdlib>
#include <util/generic/noncopyable.h>
class TGlobalImpl : TNonCopyable {
@@ -24,7 +24,7 @@ private:
};
private:
- void CopyResults(int count) {
+ void CopyResults(int count) {
for (int i = 0; i < count; i++) {
Pmatch[MatchPos].rm_so = MatchBuf[2 * i];
Pmatch[MatchPos].rm_eo = MatchBuf[2 * i + 1];
@@ -35,7 +35,7 @@ private:
}
}
- int DoPcreExec(int opts) {
+ int DoPcreExec(int opts) {
int rc = pcre_exec(
PregComp, /* the compiled pattern */
nullptr, /* no extra data - we didn't study the pattern */
@@ -89,7 +89,7 @@ public:
StrLen = strlen(Str);
}
- int ExecGlobal() {
+ int ExecGlobal() {
StartOffset = 0;
int rc = DoPcreExec(Options);
diff --git a/library/cpp/regex/pire/regexp.h b/library/cpp/regex/pire/regexp.h
index 94bba4064b..215263f8f3 100644
--- a/library/cpp/regex/pire/regexp.h
+++ b/library/cpp/regex/pire/regexp.h
@@ -11,7 +11,7 @@
#include <util/generic/yexception.h>
namespace NRegExp {
- struct TMatcher;
+ struct TMatcher;
struct TFsmBase {
struct TOptions {
diff --git a/library/cpp/streams/bzip2/bzip2_ut.cpp b/library/cpp/streams/bzip2/bzip2_ut.cpp
index 69a98f296c..5ea06ac019 100644
--- a/library/cpp/streams/bzip2/bzip2_ut.cpp
+++ b/library/cpp/streams/bzip2/bzip2_ut.cpp
@@ -2,7 +2,7 @@
#include <library/cpp/testing/unittest/registar.h>
-#include <util/stream/file.h>
+#include <util/stream/file.h>
#include <util/system/tempfile.h>
#define ZDATA "./zdata"
diff --git a/library/cpp/streams/lz/lz_ut.cpp b/library/cpp/streams/lz/lz_ut.cpp
index 6876f070fc..c046103b55 100644
--- a/library/cpp/streams/lz/lz_ut.cpp
+++ b/library/cpp/streams/lz/lz_ut.cpp
@@ -3,7 +3,7 @@
#include <library/cpp/testing/unittest/registar.h>
#include <library/cpp/resource/resource.h>
-#include <util/stream/file.h>
+#include <util/stream/file.h>
#include <util/generic/vector.h>
#include <util/system/tempfile.h>
#include <util/generic/singleton.h>
diff --git a/library/cpp/string_utils/base64/base64.cpp b/library/cpp/string_utils/base64/base64.cpp
index 05c201f0de..ab1078e889 100644
--- a/library/cpp/string_utils/base64/base64.cpp
+++ b/library/cpp/string_utils/base64/base64.cpp
@@ -89,7 +89,7 @@ static const char base64_bkw[] = {
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'};
-
+
static_assert(Y_ARRAY_SIZE(base64_bkw) == 256, "wrong size");
// Base64 for url encoding, RFC3548
@@ -133,13 +133,13 @@ static inline char* Base64EncodeImpl(char* outstr, const unsigned char* instr, s
} else {
*outstr++ = base64_etab[GetBase64EncodedIndex1(instr[idx], '\0')];
*outstr++ = pad;
- }
+ }
*outstr++ = pad;
- }
+ }
*outstr = 0;
- return outstr;
-}
+ return outstr;
+}
static char* Base64EncodePlain(char* outstr, const unsigned char* instr, size_t len) {
return Base64EncodeImpl<false>(outstr, instr, len);
diff --git a/library/cpp/string_utils/quote/quote.cpp b/library/cpp/string_utils/quote/quote.cpp
index e523350b80..1288c8c4ec 100644
--- a/library/cpp/string_utils/quote/quote.cpp
+++ b/library/cpp/string_utils/quote/quote.cpp
@@ -112,12 +112,12 @@ static inline It1 Escape(It1 to, It2 from, It3 end, const bool* escape_map = cha
*to++ = d2x((unsigned char)*from & 0xF);
} else {
*to++ = (*from == ' ' ? '+' : *from);
- }
+ }
++from;
- }
+ }
- *to = 0;
+ *to = 0;
return to;
}
@@ -220,7 +220,7 @@ char* CGIUnescape(char* to, const char* from) {
char* CGIUnescape(char* to, const char* from, size_t len) {
return Unescape(to, from, from + len, TFromHexLenLimited(from + len));
-}
+}
void CGIUnescape(TString& url) {
if (url.empty()) {
@@ -234,7 +234,7 @@ void CGIUnescape(TString& url) {
url = CGIUnescapeRet(url);
}
}
-
+
TString CGIUnescapeRet(const TStringBuf from) {
TString to;
to.ReserveAndResize(CgiUnescapeBufLen(from.size()));
@@ -249,13 +249,13 @@ char* UrlUnescape(char* to, TStringBuf from) {
if ('%' == ch && 2 <= from.length())
ch = TFromHexZeroTerm::x2c(from);
*to++ = ch;
- }
+ }
- *to = 0;
+ *to = 0;
return to;
-}
-
+}
+
void UrlUnescape(TString& url) {
if (url.empty()) {
return;
@@ -267,8 +267,8 @@ void UrlUnescape(TString& url) {
} else {
url = UrlUnescapeRet(url);
}
-}
-
+}
+
TString UrlUnescapeRet(const TStringBuf from) {
TString to;
to.ReserveAndResize(CgiUnescapeBufLen(from.size()));
@@ -288,20 +288,20 @@ char* UrlEscape(char* to, const char* from, bool forceEscape) {
*to++ = d2x((unsigned char)*from >> 4);
*to++ = d2x((unsigned char)*from & 0xF);
} else
- *to++ = *from;
+ *to++ = *from;
++from;
- }
+ }
- *to = 0;
+ *to = 0;
return to;
-}
-
+}
+
void UrlEscape(TString& url, bool forceEscape) {
TTempBuf tempBuf(CgiEscapeBufLen(url.size()));
char* to = tempBuf.Data();
url.AssignNoAlias(to, UrlEscape(to, url.data(), forceEscape));
-}
+}
TString UrlEscapeRet(const TStringBuf from, bool forceEscape) {
TString to;
diff --git a/library/cpp/string_utils/url/url.cpp b/library/cpp/string_utils/url/url.cpp
index 85f4ac5d69..32179ead5b 100644
--- a/library/cpp/string_utils/url/url.cpp
+++ b/library/cpp/string_utils/url/url.cpp
@@ -53,15 +53,15 @@ namespace {
return 0;
}
- template <typename T>
+ template <typename T>
inline T CutHttpPrefixImpl(const T& url, bool ignorehttps) {
size_t prefixSize = GetHttpPrefixSizeImpl<typename T::char_type>(url.data(), TKnownSize(url.size()), ignorehttps);
if (prefixSize)
return url.substr(prefixSize);
- return url;
- }
-}
-
+ return url;
+ }
+}
+
namespace NUrl {
TSplitUrlToHostAndPathResult SplitUrlToHostAndPath(const TStringBuf url) {
@@ -75,8 +75,8 @@ namespace NUrl {
size_t GetHttpPrefixSize(const char* url, bool ignorehttps) noexcept {
return GetHttpPrefixSizeImpl<char>(url, TUncheckedSize(), ignorehttps);
-}
-
+}
+
size_t GetHttpPrefixSize(const wchar16* url, bool ignorehttps) noexcept {
return GetHttpPrefixSizeImpl<wchar16>(url, TUncheckedSize(), ignorehttps);
}
@@ -95,8 +95,8 @@ TStringBuf CutHttpPrefix(const TStringBuf url, bool ignorehttps) noexcept {
TWtringBuf CutHttpPrefix(const TWtringBuf url, bool ignorehttps) noexcept {
return CutHttpPrefixImpl(url, ignorehttps);
-}
-
+}
+
size_t GetSchemePrefixSize(const TStringBuf url) noexcept {
struct TDelim: public str_spn {
inline TDelim()
@@ -144,8 +144,8 @@ static inline TStringBuf GetHostAndPortImpl(const TStringBuf url) {
}
return urlNoScheme;
-}
-
+}
+
TStringBuf GetHost(const TStringBuf url) noexcept {
return GetHostAndPortImpl<false>(url);
}
@@ -279,10 +279,10 @@ TStringBuf GetZone(const TStringBuf host) noexcept {
TStringBuf CutWWWPrefix(const TStringBuf url) noexcept {
if (url.size() >= 4 && url[3] == '.' && !strnicmp(url.data(), "www", 3))
- return url.substr(4);
- return url;
-}
-
+ return url.substr(4);
+ return url;
+}
+
TStringBuf CutWWWNumberedPrefix(const TStringBuf url) noexcept {
auto it = url.begin();
@@ -334,44 +334,44 @@ TString AddSchemePrefix(const TString& url, TStringBuf scheme) {
return TString::Join(scheme, TStringBuf("://"), url);
}
-#define X(c) (c >= 'A' ? ((c & 0xdf) - 'A') + 10 : (c - '0'))
-
-static inline int x2c(unsigned char* x) {
+#define X(c) (c >= 'A' ? ((c & 0xdf) - 'A') + 10 : (c - '0'))
+
+static inline int x2c(unsigned char* x) {
if (!IsAsciiHex(x[0]) || !IsAsciiHex(x[1]))
- return -1;
- return X(x[0]) * 16 + X(x[1]);
-}
-
+ return -1;
+ return X(x[0]) * 16 + X(x[1]);
+}
+
#undef X
static inline int Unescape(char* str) {
char *to, *from;
- int dlen = 0;
+ int dlen = 0;
if ((str = strchr(str, '%')) == nullptr)
- return dlen;
- for (to = str, from = str; *from; from++, to++) {
- if ((*to = *from) == '%') {
+ return dlen;
+ for (to = str, from = str; *from; from++, to++) {
+ if ((*to = *from) == '%') {
int c = x2c((unsigned char*)from + 1);
- *to = char((c > 0) ? c : '0');
- from += 2;
- dlen += 2;
- }
- }
+ *to = char((c > 0) ? c : '0');
+ from += 2;
+ dlen += 2;
+ }
+ }
*to = 0; /* terminate it at the new length */
- return dlen;
-}
-
+ return dlen;
+}
+
size_t NormalizeUrlName(char* dest, const TStringBuf source, size_t dest_size) {
if (source.empty() || source[0] == '?')
- return strlcpy(dest, "/", dest_size);
+ return strlcpy(dest, "/", dest_size);
size_t len = Min(dest_size - 1, source.length());
memcpy(dest, source.data(), len);
dest[len] = 0;
- len -= Unescape(dest);
- strlwr(dest);
- return len;
-}
-
+ len -= Unescape(dest);
+ strlwr(dest);
+ return len;
+}
+
size_t NormalizeHostName(char* dest, const TStringBuf source, size_t dest_size, ui16 defport) {
size_t len = Min(dest_size - 1, source.length());
memcpy(dest, source.data(), len);
@@ -382,11 +382,11 @@ size_t NormalizeHostName(char* dest, const TStringBuf source, size_t dest_size,
char* ptr = strstr(dest, buf);
if (ptr && ptr[buflen] == 0) {
len -= buflen;
- *ptr = 0;
- }
- strlwr(dest);
- return len;
-}
+ *ptr = 0;
+ }
+ strlwr(dest);
+ return len;
+}
TStringBuf RemoveFinalSlash(TStringBuf str) noexcept {
if (str.EndsWith('/')) {
diff --git a/library/cpp/string_utils/url/url.h b/library/cpp/string_utils/url/url.h
index 84137ccc57..be90c4ff8a 100644
--- a/library/cpp/string_utils/url/url.h
+++ b/library/cpp/string_utils/url/url.h
@@ -42,17 +42,17 @@ size_t GetSchemePrefixSize(const TStringBuf url) noexcept;
Y_PURE_FUNCTION
TStringBuf GetSchemePrefix(const TStringBuf url) noexcept;
-//! removes protocol prefixes 'http://' and 'https://' from given URL
-//! @note if URL has no prefix or some other prefix the function does nothing
+//! removes protocol prefixes 'http://' and 'https://' from given URL
+//! @note if URL has no prefix or some other prefix the function does nothing
//! @param url URL from which the prefix should be removed
//! @param ignorehttps if true, leaves https://
-//! @return a new URL without protocol prefix
+//! @return a new URL without protocol prefix
Y_PURE_FUNCTION
TStringBuf CutHttpPrefix(const TStringBuf url, bool ignorehttps = false) noexcept;
Y_PURE_FUNCTION
TWtringBuf CutHttpPrefix(const TWtringBuf url, bool ignorehttps = false) noexcept;
-
+
Y_PURE_FUNCTION
TStringBuf CutSchemePrefix(const TStringBuf url) noexcept;
@@ -132,7 +132,7 @@ TStringBuf GetPathAndQuery(const TStringBuf url, bool trimFragment = true) noexc
*/
Y_PURE_FUNCTION
TStringBuf GetOnlyHost(const TStringBuf url) noexcept;
-
+
Y_PURE_FUNCTION
TStringBuf GetParentDomain(const TStringBuf host, size_t level) noexcept; // ("www.ya.ru", 2) -> "ya.ru"
diff --git a/library/cpp/uri/common.cpp b/library/cpp/uri/common.cpp
index 05af1e57d1..d3623f8208 100644
--- a/library/cpp/uri/common.cpp
+++ b/library/cpp/uri/common.cpp
@@ -103,8 +103,8 @@ namespace NUri {
default:
return "Field[Unknown]";
}
- }
-
+ }
+
const char* SchemeKindToString(const TScheme::EKind& t) {
const TSchemeInfo& info = TSchemeInfo::Get(t);
if (!info.Str.empty())
diff --git a/library/cpp/uri/uri-ru_ut.cpp b/library/cpp/uri/uri-ru_ut.cpp
index ec35a164d2..0cbc7a9472 100644
--- a/library/cpp/uri/uri-ru_ut.cpp
+++ b/library/cpp/uri/uri-ru_ut.cpp
@@ -2,7 +2,7 @@
#include <library/cpp/charset/recyr.hh>
#include <library/cpp/html/entity/htmlentity.h>
#include <util/system/maxlen.h>
-
+
namespace NUri {
namespace {
TString AsWin1251(const TString& s) {
@@ -70,7 +70,7 @@ namespace NUri {
"images\nil.jpg", "images%0Ail.jpg",
"http://caedebaturque.termez.su\r\n/?article=218", "http://caedebaturque.termez.su%0D%0A/?article=218",
-
+
AsKoi8("javascript:window.external.AddFavorite(\'http://www.humor.look.ru/\',\'Злобные Деды Морозы!!!\')"), "javascript:window.external.AddFavorite(\'http://www.humor.look.ru/\',\'%FA%CC%CF%C2%CE%D9%C5%20%E4%C5%C4%D9%20%ED%CF%D2%CF%DA%D9!!!\')",
"search.php?search_author=%CB%FE%E4%EC%E8%EB%E0+%C3%F3%F1%E5%E2%E0&amp;showresults=posts&amp;sid=8", "search.php?search_author=%CB%FE%E4%EC%E8%EB%E0+%C3%F3%F1%E5%E2%E0&showresults=posts&sid=8",
AsWin1251("/Search/author/?q=Штрибель Х.В."), "/Search/author/?q=%D8%F2%F0%E8%E1%E5%EB%FC%20%D5.%C2.",
@@ -108,7 +108,7 @@ namespace NUri {
"/a-mp3/stype-1/?search=Э", "/a-mp3/stype-1/?search=%D0%AD",
"/a-mp3/stype-1/?search=Ю", "/a-mp3/stype-1/?search=%D0%AE",
"/a-mp3/stype-1/?search=Я", "/a-mp3/stype-1/?search=%D0%AF",
-
+
"javascript:emoticon(\":&#39;(\")", "javascript:emoticon(\":\'(\")",
"javascript:emoticon(\'&gt;:o\')", "javascript:emoticon(\'>:o\')",
"javascript:emoticon(\']:-&gt;\')", "javascript:emoticon(\']:->\')",
@@ -119,7 +119,7 @@ namespace NUri {
"&quot;http://www.fubix.ru&quot;", "\"http://www.fubix.ru\"",
AsWin1251("mailto:&#107;&#97;&#109;&#112;&#97;&#64;&#117;&#107;&#114;&#46;&#110;&#101;&#116;?subject=Арабский язык"), "mailto:kampa@ukr.net?subject=%C0%F0%E0%E1%F1%EA%E8%E9%20%FF%E7%FB%EA",
{}};
-
+
Y_UNIT_TEST(testHtLinkDecode) {
char decodedlink[URL_MAXLEN + 10];
for (int i = 0; links[i]; i += 2) {
@@ -127,7 +127,7 @@ namespace NUri {
UNIT_ASSERT_VALUES_EQUAL(decodedlink, links[i + 1]);
}
}
-
+
Y_UNIT_TEST(testRuIDNA) {
{
#define DEC "\xD7\xE5\xF0\xE5\xEf\xEE\xE2\xE5\xF6.\xF0\xF4" /* "Череповец.рф" in Windows-1251 */
@@ -160,4 +160,4 @@ namespace NUri {
}
}
-}
+}
diff --git a/library/cpp/uri/uri.cpp b/library/cpp/uri/uri.cpp
index 56a9a4e5ef..2bb3ceac24 100644
--- a/library/cpp/uri/uri.cpp
+++ b/library/cpp/uri/uri.cpp
@@ -616,6 +616,6 @@ namespace NUri {
}
Y_ASSERT(0);
return "";
- }
-
+ }
+
}
diff --git a/library/cpp/uri/uri.h b/library/cpp/uri/uri.h
index 3b6c19fe4a..f6dc8426a2 100644
--- a/library/cpp/uri/uri.h
+++ b/library/cpp/uri/uri.h
@@ -534,7 +534,7 @@ namespace NUri {
Y_ASSERT(IsValidAbs() && other.IsValidAbs());
return Equal(other, FlagScheme | FlagHostPort);
}
-
+
TLinkType Locality(const TUri& other) const {
if (IsSameDocument(other))
return LinkIsFragment;
@@ -542,11 +542,11 @@ namespace NUri {
return LinkIsLocal;
return LinkIsGlobal;
}
-
+
static IOutputStream& ReEncodeField(IOutputStream& out, const TStringBuf& val, EField fld, long flags = FeaturesEncodeDecode) {
return NEncode::TEncoder::ReEncode(out, val, NEncode::TEncodeMapper(flags, fld));
}
-
+
static IOutputStream& ReEncodeToField(IOutputStream& out, const TStringBuf& val, EField srcfld, long srcflags, EField dstfld, long dstflags) {
return NEncode::TEncoder::ReEncodeTo(out, val, NEncode::TEncodeMapper(srcflags, srcfld), NEncode::TEncodeToMapper(dstflags, dstfld));
}
diff --git a/library/cpp/uri/uri_ut.cpp b/library/cpp/uri/uri_ut.cpp
index 2ebd83fc93..1939d3730d 100644
--- a/library/cpp/uri/uri_ut.cpp
+++ b/library/cpp/uri/uri_ut.cpp
@@ -4,7 +4,7 @@
#include <library/cpp/html/entity/htmlentity.h>
#include <util/system/maxlen.h>
-
+
namespace NUri {
Y_UNIT_TEST_SUITE(URLTest) {
static const char* urls[] = {
@@ -66,7 +66,7 @@ namespace NUri {
UNIT_ASSERT_VALUES_EQUAL(er, TState::ParsedOK);
UNIT_ASSERT(base.IsValidAbs());
UNIT_ASSERT_VALUES_EQUAL(base.PrintS(), urls[0]);
-
+
TString errbuf;
TStringOutput out(errbuf);
const long mflag = TFeature::FeaturesAll;
@@ -75,12 +75,12 @@ namespace NUri {
UNIT_ASSERT_VALUES_EQUAL_C(er, TState::ParsedOK, urls[i]);
rel.Merge(base);
UNIT_ASSERT_VALUES_EQUAL_C(rel.PrintS(), urls[i + 1], urls[i]);
-
+
// try the same thing differently
er = rel.Parse(urls[i], mflag, urls[0]);
UNIT_ASSERT_VALUES_EQUAL_C(er, TState::ParsedOK, urls[i]);
UNIT_ASSERT_VALUES_EQUAL_C(rel.PrintS(), urls[i + 1], urls[i]);
-
+
// lastly...
er = abs.Parse(urls[i + 1], mflag);
UNIT_ASSERT_VALUES_EQUAL(er, TState::ParsedOK);
@@ -120,7 +120,7 @@ namespace NUri {
const char* const result;
TUri::TLinkType ltype;
};
-
+
static const Link4Norm link4Norm[] = {
{"http://www.alltest.ru/all.php?a=aberporth", "http://www.alltest.ru/all.php?a=domestic jobs", "", TUri::LinkIsBad},
{"http://www.alltest.ru/all.php?a=aberporth", "http://www.alltest.ru/all.php?a=domestic%20jobs", "http://www.alltest.ru/all.php?a=domestic%20jobs", TUri::LinkIsLocal},
@@ -130,7 +130,7 @@ namespace NUri {
Y_UNIT_TEST(test_httpURLNormalize) {
TUri normalizedLink;
-
+
for (int i = 0; link4Norm[i].link; i++) {
TUri base;
TState::EParsed er = base.Parse(link4Norm[i].base);
@@ -141,14 +141,14 @@ namespace NUri {
UNIT_ASSERT_VALUES_EQUAL_C(s, link4Norm[i].result, link4Norm[i].link);
}
}
-
+
static const char* urlsWithMultipleSlash[] = {
"http://a/http://b", "http://a/http://b",
"http://a/https://b", "http://a/https://b",
"http://a/b://c", "http://a/b:/c",
"http://a/b//c", "http://a/b/c",
nullptr, nullptr};
-
+
Y_UNIT_TEST(test_httpURLPathOperation) {
char copyUrl[URL_MAXLEN];
for (int i = 0; urlsWithMultipleSlash[i]; i += 2) {
@@ -164,7 +164,7 @@ namespace NUri {
UNIT_ASSERT_VALUES_EQUAL_C(uri.PrintS(), normurl, url);
}
}
-
+
static const char* hostsForCheckHost[] = {
"simplehost.ru",
"third_level.host.ru",
diff --git a/tools/archiver/ya.make b/tools/archiver/ya.make
index 757378c1b3..982551aed8 100644
--- a/tools/archiver/ya.make
+++ b/tools/archiver/ya.make
@@ -15,6 +15,6 @@ SRCS(
main.cpp
)
-SET(IDE_FOLDER "_Builders")
+SET(IDE_FOLDER "_Builders")
END()
diff --git a/util/datetime/cputimer.cpp b/util/datetime/cputimer.cpp
index 516d372c37..24e40ff8bb 100644
--- a/util/datetime/cputimer.cpp
+++ b/util/datetime/cputimer.cpp
@@ -5,7 +5,7 @@
#include <util/string/printf.h>
#include <util/stream/output.h>
#include <util/generic/singleton.h>
-
+
#if defined(_unix_)
#include <unistd.h>
#include <sched.h>
@@ -14,7 +14,7 @@
#include <sys/param.h>
#elif defined(_win_)
#include <util/system/winint.h>
-#endif
+#endif
TTimer::TTimer(const TStringBuf message) {
static const int SMALL_DURATION_CHAR_LENGTH = 9; // strlen("0.123456s")
@@ -90,7 +90,7 @@ TFormattedPrecisionTimer::~TFormattedPrecisionTimer() {
*Out << Message << ": " << diff << " ticks " << FormatCycles(diff) << Endl;
}
-
+
TFuncTimer::TFuncTimer(const char* func)
: Start_(TInstant::Now())
, Func_(func)
@@ -103,26 +103,26 @@ TFuncTimer::~TFuncTimer() {
}
TTimeLogger::TTimeLogger(const TString& message, bool verbose)
- : Message(message)
+ : Message(message)
, Verbose(verbose)
- , OK(false)
+ , OK(false)
, Begin(time(nullptr))
, BeginCycles(GetCycleCount())
-{
+{
if (Verbose) {
fprintf(stderr, "=========================================================\n");
fprintf(stderr, "%s started: %.24s (%lu) (%d)\n", Message.data(), ctime(&Begin), (unsigned long)Begin, (int)getpid());
}
-}
-
+}
+
double TTimeLogger::ElapsedTime() const {
return time(nullptr) - Begin;
}
void TTimeLogger::SetOK() {
- OK = true;
-}
-
+ OK = true;
+}
+
TTimeLogger::~TTimeLogger() {
time_t tim = time(nullptr);
ui64 endCycles = GetCycleCount();
@@ -133,4 +133,4 @@ TTimeLogger::~TTimeLogger() {
(unsigned long)tim - (unsigned long)Begin, FormatCycles(endCycles - BeginCycles).data());
fprintf(stderr, "%s=========================================================\n", prefix);
}
-}
+}
diff --git a/util/datetime/cputimer.h b/util/datetime/cputimer.h
index 7d38d5bdb3..b7849cf735 100644
--- a/util/datetime/cputimer.h
+++ b/util/datetime/cputimer.h
@@ -7,7 +7,7 @@
#include <util/stream/str.h>
class TTimer {
-private:
+private:
TInstant Start_;
TStringStream Message_;
@@ -108,17 +108,17 @@ public:
#endif
class TTimeLogger {
-private:
+private:
TString Message;
bool Verbose;
- bool OK;
+ bool OK;
time_t Begin;
ui64 BeginCycles;
-
+
public:
TTimeLogger(const TString& message, bool verbose = true);
- ~TTimeLogger();
+ ~TTimeLogger();
- void SetOK();
+ void SetOK();
double ElapsedTime() const;
-};
+};
diff --git a/util/datetime/parser.rl6 b/util/datetime/parser.rl6
index 931f09eae1..8e47b66179 100644
--- a/util/datetime/parser.rl6
+++ b/util/datetime/parser.rl6
@@ -7,7 +7,7 @@
#include <util/datetime/parser.h>
#include <util/generic/ymath.h>
-
+
%%{
@@ -119,18 +119,18 @@ action set_mil_offset {
if (c <= 'M') {
// ['A'..'M'] \ 'J'
if (c < 'J')
- DateTimeFields.ZoneOffsetMinutes = (i32)TDuration::Hours(c - 'A' + 1).Minutes();
+ DateTimeFields.ZoneOffsetMinutes = (i32)TDuration::Hours(c - 'A' + 1).Minutes();
else
- DateTimeFields.ZoneOffsetMinutes = (i32)TDuration::Hours(c - 'A').Minutes();
+ DateTimeFields.ZoneOffsetMinutes = (i32)TDuration::Hours(c - 'A').Minutes();
} else {
// ['N'..'Y']
- DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(c - 'N' + 1).Minutes();
+ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(c - 'N' + 1).Minutes();
}
}
}
action set_digit_offset {
- DateTimeFields.ZoneOffsetMinutes = Sign * (i32)(TDuration::Hours(I / 100) + TDuration::Minutes(I % 100)).Minutes();
+ DateTimeFields.ZoneOffsetMinutes = Sign * (i32)(TDuration::Hours(I / 100) + TDuration::Minutes(I % 100)).Minutes();
}
mil_zone = /[A-IK-Za-ik-z]/ $set_mil_offset;
@@ -142,14 +142,14 @@ mil_zone = /[A-IK-Za-ik-z]/ $set_mil_offset;
zone = 'UT' @{ DateTimeFields.ZoneOffsetMinutes = 0; }
| 'GMT' @{ DateTimeFields.ZoneOffsetMinutes = 0; }
- | 'EST' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(5).Minutes();}
- | 'EDT' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(4).Minutes(); }
- | 'CST' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(6).Minutes();}
- | 'CDT' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(5).Minutes(); }
- | 'MST' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(7).Minutes();}
- | 'MDT' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(6).Minutes(); }
- | 'PST' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(8).Minutes();}
- | 'PDT' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(7).Minutes(); };
+ | 'EST' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(5).Minutes();}
+ | 'EDT' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(4).Minutes(); }
+ | 'CST' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(6).Minutes();}
+ | 'CDT' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(5).Minutes(); }
+ | 'MST' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(7).Minutes();}
+ | 'MDT' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(6).Minutes(); }
+ | 'PST' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(8).Minutes();}
+ | 'PDT' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(7).Minutes(); };
digit_offset = ('+' | '-') > { Sign = fc == '+' ? 1 : -1; } . int4 @set_digit_offset;
diff --git a/util/datetime/strptime.cpp b/util/datetime/strptime.cpp
index f0d4ec333e..fb6b038bf0 100644
--- a/util/datetime/strptime.cpp
+++ b/util/datetime/strptime.cpp
@@ -54,14 +54,14 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <util/system/compat.h>
-#include "systime.h"
+#include <util/system/compat.h>
+#include "systime.h"
#ifdef _win32_
#ifndef lint
#ifndef NOID
static char copyright[] =
"@(#) Copyright (c) 1994 Powerdog Industries. All rights reserved.";
-static char sccsid[] = "@(#)strptime.c 0.1 (Powerdog) 94/03/27";
+static char sccsid[] = "@(#)strptime.c 0.1 (Powerdog) 94/03/27";
#endif /* !defined NOID */
#endif /* not lint */
//__FBSDID("$FreeBSD: src/lib/libc/stdtime/strptime.c,v 1.35 2003/11/17 04:19:15 nectar Exp $");
@@ -176,31 +176,31 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
char c;
const char* ptr;
int i;
- size_t len = 0;
- int Ealternative, Oalternative;
+ size_t len = 0;
+ int Ealternative, Oalternative;
struct lc_time_T* tptr = __get_current_time_locale();
- ptr = fmt;
- while (*ptr != 0) {
- if (*buf == 0)
- break;
+ ptr = fmt;
+ while (*ptr != 0) {
+ if (*buf == 0)
+ break;
- c = *ptr++;
+ c = *ptr++;
- if (c != '%') {
- if (isspace((unsigned char)c))
- while (*buf != 0 && isspace((unsigned char)*buf))
+ if (c != '%') {
+ if (isspace((unsigned char)c))
+ while (*buf != 0 && isspace((unsigned char)*buf))
++buf;
- else if (c != *buf++)
- return 0;
- continue;
- }
+ else if (c != *buf++)
+ return 0;
+ continue;
+ }
- Ealternative = 0;
- Oalternative = 0;
+ Ealternative = 0;
+ Oalternative = 0;
label:
- c = *ptr++;
- switch (c) {
+ c = *ptr++;
+ switch (c) {
case 0:
case '%':
if (*buf++ != '%')
@@ -234,13 +234,13 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
buf = _strptime(buf, tptr->c_fmt, tm, GMTp);
if (buf == 0)
return 0;
- break;
+ break;
case 'D':
buf = _strptime(buf, "%m/%d/%y", tm, GMTp);
if (buf == 0)
return 0;
- break;
+ break;
case 'E':
if (Ealternative || Oalternative)
@@ -304,7 +304,7 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
return 0;
tm->tm_yday = i - 1;
- break;
+ break;
case 'M':
case 'S':
@@ -312,7 +312,7 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
break;
if (!isdigit((unsigned char)*buf))
- return 0;
+ return 0;
len = 2;
for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
@@ -341,13 +341,13 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
case 'k':
case 'l':
/*
- * Of these, %l is the only specifier explicitly
- * documented as not being zero-padded. However,
- * there is no harm in allowing zero-padding.
- *
- * XXX The %l specifier may gobble one too many
- * digits if used incorrectly.
- */
+ * Of these, %l is the only specifier explicitly
+ * documented as not being zero-padded. However,
+ * there is no harm in allowing zero-padding.
+ *
+ * XXX The %l specifier may gobble one too many
+ * digits if used incorrectly.
+ */
if (!isdigit((unsigned char)*buf))
return 0;
@@ -361,7 +361,7 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
if (i > 23)
return 0;
} else if (i > 12)
- return 0;
+ return 0;
tm->tm_hour = i;
@@ -372,9 +372,9 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
case 'p':
/*
- * XXX This is bogus if parsed before hour-related
- * specifiers.
- */
+ * XXX This is bogus if parsed before hour-related
+ * specifiers.
+ */
len = strlen(tptr->am);
if (strnicmp(buf, tptr->am, len) == 0) {
if (tm->tm_hour > 12)
@@ -410,20 +410,20 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
break;
}
if (i == asizeof(tptr->weekday))
- return 0;
+ return 0;
tm->tm_wday = i;
- buf += len;
- break;
+ buf += len;
+ break;
case 'U':
case 'W':
/*
- * XXX This is bogus, as we can not assume any valid
- * information present in the tm structure at this
- * point to calculate a real value, so just check the
- * range for now.
- */
+ * XXX This is bogus, as we can not assume any valid
+ * information present in the tm structure at this
+ * point to calculate a real value, so just check the
+ * range for now.
+ */
if (!isdigit((unsigned char)*buf))
return 0;
@@ -459,13 +459,13 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
case 'd':
case 'e':
/*
- * The %e specifier is explicitly documented as not
- * being zero-padded but there is no harm in allowing
- * such padding.
- *
- * XXX The %e specifier may gobble one too many
- * digits if used incorrectly.
- */
+ * The %e specifier is explicitly documented as not
+ * being zero-padded but there is no harm in allowing
+ * such padding.
+ *
+ * XXX The %e specifier may gobble one too many
+ * digits if used incorrectly.
+ */
if (!isdigit((unsigned char)*buf))
return 0;
@@ -501,13 +501,13 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
len = strlen(tptr->month[i]);
if (strnicmp(buf, tptr->month[i],
len) == 0)
- break;
+ break;
len = strlen(tptr->mon[i]);
if (strnicmp(buf, tptr->mon[i],
len) == 0)
break;
- }
- }
+ }
+ }
if (i == asizeof(tptr->month))
return 0;
@@ -548,7 +548,7 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
errno = sverrno;
return 0;
}
- errno = sverrno;
+ errno = sverrno;
buf = cp;
GmTimeR(&t, tm);
*GMTp = 1;
@@ -587,7 +587,7 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
char* zonestr;
for (cp = buf; *cp && isupper((unsigned char)*cp); ++cp) { /*empty*/
- }
+ }
if (cp - buf) {
zonestr = (char*)alloca(cp - buf + 1);
strncpy(zonestr, buf, cp - buf);
@@ -605,23 +605,23 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
buf += cp - buf;
}
} break;
- }
- }
+ }
+ }
return (char*)buf;
}
char* strptime(const char* buf, const char* fmt, struct tm* tm)
{
char* ret;
- int gmt;
+ int gmt;
- gmt = 0;
- ret = _strptime(buf, fmt, tm, &gmt);
- if (ret && gmt) {
- time_t t = timegm(tm);
- localtime_r(&t, tm);
- }
+ gmt = 0;
+ ret = _strptime(buf, fmt, tm, &gmt);
+ if (ret && gmt) {
+ time_t t = timegm(tm);
+ localtime_r(&t, tm);
+ }
- return (ret);
+ return (ret);
}
#endif //_win32_
diff --git a/util/datetime/systime.cpp b/util/datetime/systime.cpp
index 6ee7e8fc6e..b4e9c48eed 100644
--- a/util/datetime/systime.cpp
+++ b/util/datetime/systime.cpp
@@ -1,4 +1,4 @@
-#include "systime.h"
+#include "systime.h"
#include <util/system/yassert.h>
#include <util/system/defaults.h>
@@ -11,32 +11,32 @@ void FileTimeToTimeval(const FILETIME* ft, timeval* tv) {
ui64 ft_scalar;
FILETIME ft_struct;
} nt_time;
- nt_time.ft_struct = *ft;
- tv->tv_sec = (long)((nt_time.ft_scalar - NANOINTERVAL) / LL(10000000));
- tv->tv_usec = (i32)((nt_time.ft_scalar / LL(10)) % LL(1000000));
-}
-
+ nt_time.ft_struct = *ft;
+ tv->tv_sec = (long)((nt_time.ft_scalar - NANOINTERVAL) / LL(10000000));
+ tv->tv_usec = (i32)((nt_time.ft_scalar / LL(10)) % LL(1000000));
+}
+
int gettimeofday(timeval* tp, void*) {
- FILETIME ft;
- GetSystemTimeAsFileTime(&ft);
- FileTimeToTimeval(&ft, tp);
- return 0;
-}
-
+ FILETIME ft;
+ GetSystemTimeAsFileTime(&ft);
+ FileTimeToTimeval(&ft, tp);
+ return 0;
+}
+
tm* localtime_r(const time_t* clock, tm* result) {
- tzset();
- tm* res = localtime(clock);
- if (res) {
- memcpy(result, res, sizeof(tm));
- return result;
- }
- return 0;
-}
-
+ tzset();
+ tm* res = localtime(clock);
+ if (res) {
+ memcpy(result, res, sizeof(tm));
+ return result;
+ }
+ return 0;
+}
+
tm* gmtime_r(const time_t* clock, tm* result) {
return gmtime_s(result, clock) == 0 ? result : 0;
-}
-
+}
+
char* ctime_r(const time_t* clock, char* buf) {
char* res = ctime(clock);
if (res) {
@@ -54,7 +54,7 @@ char* ctime_r(const time_t* clock, char* buf) {
#define LEAPYEAR(year) (!((year) % 4) && (((year) % 100) || !((year) % 400)))
#define YEARSIZE(year) (LEAPYEAR(year) ? 366 : 365)
#define FOURCENTURIES (400 * 365 + 100 - 3)
-
+
//! Inverse of gmtime: converts struct tm to time_t, assuming the data
//! in tm is UTC rather than local timezone. This implementation
//! returns the number of seconds since 1970-01-01, converted to time_t.
@@ -83,7 +83,7 @@ time_t TimeGM(const struct tm* t) {
unsigned long secs = days * 86400ul + t->tm_hour * 3600 + t->tm_min * 60 + t->tm_sec;
return (time_t)secs;
-}
+}
struct tm* GmTimeR(const time_t* timer, struct tm* tmbuf) {
static const int _ytab[2][12] = {
diff --git a/util/datetime/systime.h b/util/datetime/systime.h
index 491d36e802..167c1dab86 100644
--- a/util/datetime/systime.h
+++ b/util/datetime/systime.h
@@ -3,7 +3,7 @@
#include <util/system/platform.h>
#include <util/generic/string.h>
-#include <ctime>
+#include <ctime>
// timegm and gmtime_r versions that don't need access to filesystem or a big stack
time_t TimeGM(const struct tm* t);
@@ -14,12 +14,12 @@ TString CTimeR(const time_t* timer);
#ifdef _win_
#include <util/system/winint.h>
#include <winsock2.h>
-
+
void FileTimeToTimeval(const FILETIME* ft, struct timeval* tv);
-
+
// obtains the current time, expressed as seconds and microseconds since 00:00 UTC, January 1, 1970
int gettimeofday(struct timeval* tp, void*);
-
+
// thou should not mix these with non-_r functions
tm* localtime_r(const time_t* clock, tm* result);
tm* gmtime_r(const time_t* clock, tm* result);
@@ -30,11 +30,11 @@ inline time_t timegm(struct tm* t) {
}
char* strptime(const char* buf, const char* fmt, struct tm* tm); // strptime.cpp
-#else
+#else
#include <sys/time.h>
-#endif
+#endif
-#ifndef timersub
+#ifndef timersub
#define timersub(tvp, uvp, vvp) \
do { \
(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
@@ -44,4 +44,4 @@ char* strptime(const char* buf, const char* fmt, struct tm* tm); // strptime.cpp
(vvp)->tv_usec += 1000000; \
} \
} while (0)
-#endif
+#endif
diff --git a/util/draft/ya.make b/util/draft/ya.make
index e00674b682..f7129447e1 100644
--- a/util/draft/ya.make
+++ b/util/draft/ya.make
@@ -2,14 +2,14 @@ LIBRARY()
OWNER(g:util)
SUBSCRIBER(g:util-subscribers)
-
+
NO_UTIL()
-
+
IF (TSTRING_IS_STD_STRING)
CFLAGS(GLOBAL -DTSTRING_IS_STD_STRING)
ENDIF()
-SRCS(
+SRCS(
date.cpp
datetime.cpp
enum.cpp
@@ -17,9 +17,9 @@ SRCS(
ip.cpp
matrix.cpp
memory.cpp
-)
-
-END()
+)
+
+END()
RECURSE_FOR_TESTS(
ut
diff --git a/util/folder/dirut.cpp b/util/folder/dirut.cpp
index ffc9b09f96..9a38a89ea0 100644
--- a/util/folder/dirut.cpp
+++ b/util/folder/dirut.cpp
@@ -12,118 +12,118 @@
#include <util/system/yassert.h>
void SlashFolderLocal(TString& folder) {
- if (!folder)
- return;
-#ifdef _win32_
- size_t pos;
+ if (!folder)
+ return;
+#ifdef _win32_
+ size_t pos;
while ((pos = folder.find('/')) != TString::npos)
folder.replace(pos, 1, LOCSLASH_S);
-#endif
+#endif
if (folder[folder.size() - 1] != LOCSLASH_C)
- folder.append(LOCSLASH_S);
-}
-
-#ifndef _win32_
-
+ folder.append(LOCSLASH_S);
+}
+
+#ifndef _win32_
+
bool correctpath(TString& folder) {
- return resolvepath(folder, "/");
-}
-
+ return resolvepath(folder, "/");
+}
+
bool resolvepath(TString& folder, const TString& home) {
Y_ASSERT(home && home.at(0) == '/');
- if (!folder) {
- return false;
- }
- // may be from windows
+ if (!folder) {
+ return false;
+ }
+ // may be from windows
char* ptr = folder.begin();
while ((ptr = strchr(ptr, '\\')) != nullptr)
- *ptr = '/';
-
- if (folder.at(0) == '~') {
- if (folder.length() == 1 || folder.at(1) == '/') {
+ *ptr = '/';
+
+ if (folder.at(0) == '~') {
+ if (folder.length() == 1 || folder.at(1) == '/') {
folder = GetHomeDir() + (folder.data() + 1);
- } else {
+ } else {
char* buf = (char*)alloca(folder.length() + 1);
strcpy(buf, folder.data() + 1);
- char* p = strchr(buf, '/');
- if (p)
- *p++ = 0;
- passwd* pw = getpwnam(buf);
- if (pw) {
- folder = pw->pw_dir;
- folder += "/";
- if (p)
- folder += p;
- } else {
- return false; // unknown user
- }
- }
- }
- int len = folder.length() + home.length() + 1;
- char* path = (char*)alloca(len);
- if (folder.at(0) != '/') {
+ char* p = strchr(buf, '/');
+ if (p)
+ *p++ = 0;
+ passwd* pw = getpwnam(buf);
+ if (pw) {
+ folder = pw->pw_dir;
+ folder += "/";
+ if (p)
+ folder += p;
+ } else {
+ return false; // unknown user
+ }
+ }
+ }
+ int len = folder.length() + home.length() + 1;
+ char* path = (char*)alloca(len);
+ if (folder.at(0) != '/') {
strcpy(path, home.data());
strcpy(strrchr(path, '/') + 1, folder.data()); // the last char must be '/' if it's a dir
- } else {
+ } else {
strcpy(path, folder.data());
- }
+ }
len = strlen(path) + 1;
- // grabbed from url.cpp
+ // grabbed from url.cpp
char* newpath = (char*)alloca(len + 2);
const char** pp = (const char**)alloca(len * sizeof(char*));
- int i = 0;
- for (char* s = path; s;) {
- pp[i++] = s;
- s = strchr(s, '/');
- if (s)
- *s++ = 0;
- }
-
- for (int j = 1; j < i;) {
+ int i = 0;
+ for (char* s = path; s;) {
+ pp[i++] = s;
+ s = strchr(s, '/');
+ if (s)
+ *s++ = 0;
+ }
+
+ for (int j = 1; j < i;) {
const char*& p = pp[j];
if (strcmp(p, ".") == 0 || strcmp(p, "") == 0) {
if (j == i - 1) {
- p = "";
- break;
- } else {
+ p = "";
+ break;
+ } else {
memmove(pp + j, pp + j + 1, (i - j - 1) * sizeof(p));
--i;
- }
- } else if (strcmp(p, "..") == 0) {
+ }
+ } else if (strcmp(p, "..") == 0) {
if (j == i - 1) {
- if (j == 1) {
- p = "";
- } else {
+ if (j == 1) {
+ p = "";
+ } else {
--i;
pp[j - 1] = "";
- }
- break;
- } else {
- if (j == 1) {
+ }
+ break;
+ } else {
+ if (j == 1) {
memmove(pp + j, pp + j + 1, (i - j - 1) * sizeof(p));
--i;
- } else {
+ } else {
memmove(pp + j - 1, pp + j + 1, (i - j - 1) * sizeof(p));
i -= 2;
--j;
- }
- }
- } else
+ }
+ }
+ } else
++j;
- }
-
- char* s = newpath;
- for (int k = 0; k < i; k++) {
- s = strchr(strcpy(s, pp[k]), 0);
- *s++ = '/';
- }
- *(--s) = 0;
- folder = newpath;
- return true;
-}
-
-#else
-
+ }
+
+ char* s = newpath;
+ for (int k = 0; k < i; k++) {
+ s = strchr(strcpy(s, pp[k]), 0);
+ *s++ = '/';
+ }
+ *(--s) = 0;
+ folder = newpath;
+ return true;
+}
+
+#else
+
using dir_type = enum {
dt_empty,
dt_error,
@@ -131,17 +131,17 @@ using dir_type = enum {
dt_dir
};
-// precondition: *ptr != '\\' || *ptr == 0 (cause dt_error)
-// postcondition: *ptr != '\\'
+// precondition: *ptr != '\\' || *ptr == 0 (cause dt_error)
+// postcondition: *ptr != '\\'
template <typename T>
static int next_dir(T*& ptr) {
- int has_blank = 0;
- int has_dot = 0;
- int has_letter = 0;
- int has_ctrl = 0;
-
+ int has_blank = 0;
+ int has_dot = 0;
+ int has_letter = 0;
+ int has_ctrl = 0;
+
while (*ptr && *ptr != '\\') {
- int c = (unsigned char)*ptr++;
+ int c = (unsigned char)*ptr++;
switch (c) {
case ' ':
++has_blank;
@@ -164,23 +164,23 @@ static int next_dir(T*& ptr) {
++has_ctrl;
else
++has_letter;
- }
- }
- if (*ptr)
+ }
+ }
+ if (*ptr)
++ptr;
- if (has_ctrl)
- return dt_error;
- if (has_letter)
- return dt_dir;
- if (has_dot && has_blank)
- return dt_error;
- if (has_dot == 1)
- return dt_empty;
- if (has_dot == 2)
- return dt_up;
- return dt_error;
-}
-
+ if (has_ctrl)
+ return dt_error;
+ if (has_letter)
+ return dt_dir;
+ if (has_dot && has_blank)
+ return dt_error;
+ if (has_dot == 1)
+ return dt_empty;
+ if (has_dot == 2)
+ return dt_up;
+ return dt_error;
+}
+
using disk_type = enum {
dk_noflags = 0,
dk_unc = 1,
@@ -192,34 +192,34 @@ using disk_type = enum {
// root slash (if any) - part of disk
template <typename T>
static int skip_disk(T*& ptr) {
- int result = dk_noflags;
- if (!*ptr)
- return result;
- if (ptr[0] == '\\' && ptr[1] == '\\') {
+ int result = dk_noflags;
+ if (!*ptr)
+ return result;
+ if (ptr[0] == '\\' && ptr[1] == '\\') {
result |= dk_unc | dk_fromroot;
- ptr += 2;
- if (next_dir(ptr) != dt_dir)
+ ptr += 2;
+ if (next_dir(ptr) != dt_dir)
return dk_error; // has no host name
- if (next_dir(ptr) != dt_dir)
+ if (next_dir(ptr) != dt_dir)
return dk_error; // has no share name
- } else {
+ } else {
if (*ptr && *(ptr + 1) == ':') {
- result |= dk_hasdrive;
- ptr += 2;
- }
- if (*ptr == '\\' || *ptr == '/') {
+ result |= dk_hasdrive;
+ ptr += 2;
+ }
+ if (*ptr == '\\' || *ptr == '/') {
++ptr;
- result |= dk_fromroot;
- }
- }
- return result;
-}
-
+ result |= dk_fromroot;
+ }
+ }
+ return result;
+}
+
int correctpath(char* cpath, const char* path) {
if (!path || !*path) {
- *cpath = 0;
- return 1;
- }
+ *cpath = 0;
+ return 1;
+ }
char* ptr = (char*)path;
char* cptr = cpath;
int counter = 0;
@@ -238,14 +238,14 @@ int correctpath(char* cpath, const char* path) {
++ptr;
}
*cptr = 0;
- // replace '/' by '\'
- int dk = skip_disk(cpath);
-
- if (dk == dk_error)
- return 0;
+ // replace '/' by '\'
+ int dk = skip_disk(cpath);
+ if (dk == dk_error)
+ return 0;
+
char* ptr1 = ptr = cpath;
- int level = 0;
+ int level = 0;
while (*ptr) {
switch (next_dir(ptr)) {
case dt_dir:
@@ -253,8 +253,8 @@ int correctpath(char* cpath, const char* path) {
break;
case dt_empty:
memmove(ptr1, ptr, strlen(ptr) + 1);
- ptr = ptr1;
- break;
+ ptr = ptr1;
+ break;
case dt_up:
--level;
if (level >= 0) {
@@ -272,100 +272,100 @@ int correctpath(char* cpath, const char* path) {
memmove(cpath - 3, ptr, strlen(ptr) + 1);
return 1;
}
- }
+ }
if (dk & dk_fromroot)
return 0;
break;
case dt_error:
default:
- return 0;
- }
- ptr1 = ptr;
- }
-
+ return 0;
+ }
+ ptr1 = ptr;
+ }
+
if ((ptr > cpath || ptr == cpath && dk & dk_unc) && *(ptr - 1) == '\\')
*(ptr - 1) = 0;
- return 1;
-}
-
+ return 1;
+}
+
static inline int normchar(unsigned char c) {
return (c < 'a' || c > 'z') ? c : c - 32;
-}
-
+}
+
static inline char* strslashcat(char* a, const char* b) {
- size_t len = strlen(a);
+ size_t len = strlen(a);
if (len && a[len - 1] != '\\')
- a[len++] = '\\';
+ a[len++] = '\\';
strcpy(a + len, b);
- return a;
-}
-
+ return a;
+}
+
int resolvepath(char* apath, const char* rpath, const char* cpath) {
const char* redisk = rpath;
- if (!rpath || !*rpath)
- return 0;
- int rdt = skip_disk(redisk);
- if (rdt == dk_error)
- return 0;
+ if (!rpath || !*rpath)
+ return 0;
+ int rdt = skip_disk(redisk);
+ if (rdt == dk_error)
+ return 0;
if (rdt & dk_unc || rdt & dk_hasdrive && rdt & dk_fromroot) {
- return correctpath(apath, rpath);
- }
-
+ return correctpath(apath, rpath);
+ }
+
const char* cedisk = cpath;
- if (!cpath || !*cpath)
- return 0;
- int cdt = skip_disk(cedisk);
- if (cdt == dk_error)
- return 0;
-
+ if (!cpath || !*cpath)
+ return 0;
+ int cdt = skip_disk(cedisk);
+ if (cdt == dk_error)
+ return 0;
+
char* tpath = (char*)alloca(strlen(rpath) + strlen(cpath) + 3);
-
- // rdt&dk_hasdrive && !rdt&dk_fromroot
+
+ // rdt&dk_hasdrive && !rdt&dk_fromroot
if (rdt & dk_hasdrive) {
if (!(cdt & dk_fromroot))
- return 0;
+ return 0;
if (cdt & dk_hasdrive && normchar(*rpath) != normchar(*cpath))
- return 0;
- memcpy(tpath, rpath, 2);
- memcpy(tpath + 2, cedisk, strlen(cedisk) + 1);
- strslashcat(tpath, redisk);
-
+ return 0;
+ memcpy(tpath, rpath, 2);
+ memcpy(tpath + 2, cedisk, strlen(cedisk) + 1);
+ strslashcat(tpath, redisk);
+
// !rdt&dk_hasdrive && rdt&dk_fromroot
} else if (rdt & dk_fromroot) {
if (!(cdt & dk_hasdrive) && !(cdt & dk_unc))
- return 0;
+ return 0;
memcpy(tpath, cpath, cedisk - cpath);
tpath[cedisk - cpath] = 0;
- strslashcat(tpath, redisk);
-
+ strslashcat(tpath, redisk);
+
// !rdt&dk_hasdrive && !rdt&dk_fromroot
- } else {
+ } else {
if (!(cdt & dk_fromroot) || !(cdt & dk_hasdrive) && !(cdt & dk_unc))
- return 0;
- strslashcat(strcpy(tpath, cpath), redisk);
- }
-
- return correctpath(apath, tpath);
-}
-
+ return 0;
+ strslashcat(strcpy(tpath, cpath), redisk);
+ }
+
+ return correctpath(apath, tpath);
+}
+
bool correctpath(TString& filename) {
char* ptr = (char*)alloca(filename.size() + 2);
if (correctpath(ptr, filename.data())) {
- filename = ptr;
- return true;
- }
- return false;
-}
-
+ filename = ptr;
+ return true;
+ }
+ return false;
+}
+
bool resolvepath(TString& folder, const TString& home) {
char* ptr = (char*)alloca(folder.size() + 3 + home.size());
if (resolvepath(ptr, folder.data(), home.data())) {
- folder = ptr;
- return true;
- }
- return false;
-}
-
+ folder = ptr;
+ return true;
+ }
+ return false;
+}
+
#endif // !defined _win32_
char GetDirectorySeparator() {
diff --git a/util/folder/dirut.h b/util/folder/dirut.h
index 2537027b12..95e265dcd1 100644
--- a/util/folder/dirut.h
+++ b/util/folder/dirut.h
@@ -1,17 +1,17 @@
#pragma once
#include <util/system/defaults.h>
-#include <util/system/sysstat.h>
+#include <util/system/sysstat.h>
#include <util/system/fs.h>
#include <util/generic/string.h>
#include <util/generic/yexception.h>
-#include <sys/types.h>
-
+#include <sys/types.h>
+
#include <cerrno>
#include <cstdlib>
-#ifdef _win32_
+#ifdef _win32_
#include <util/system/winint.h>
#include <direct.h>
#include <malloc.h>
@@ -35,14 +35,14 @@ char* mkdtemp(char* path);
#ifndef DT_DIR
#include <sys/stat.h>
#endif
-#endif
+#endif
bool IsDir(const TString& path);
int mkpath(char* path, int mode = 0777);
TString GetHomeDir();
-
+
void MakeDirIfNotExist(const char* path, int mode = 0777);
inline void MakeDirIfNotExist(const TString& path, int mode = 0777) {
diff --git a/util/folder/dirut_ut.cpp b/util/folder/dirut_ut.cpp
index 45ebfc842c..fd1cafcb7a 100644
--- a/util/folder/dirut_ut.cpp
+++ b/util/folder/dirut_ut.cpp
@@ -62,19 +62,19 @@ Y_UNIT_TEST_SUITE(TDirutTest) {
UNIT_ASSERT(resolvepath(path, base));
UNIT_ASSERT(path == canon);
}
-
+
Y_UNIT_TEST(TestResolvePath) {
-#ifdef _win_
+#ifdef _win_
DoTest("bar", "c:\\foo\\baz", "c:\\foo\\baz\\bar");
DoTest("c:\\foo\\bar", "c:\\bar\\baz", "c:\\foo\\bar");
-#else
+#else
DoTest("bar", "/foo/baz", "/foo/bar");
DoTest("/foo/bar", "/bar/baz", "/foo/bar");
#ifdef NDEBUG
DoTest("bar", "./baz", "./bar");
#if 0 // should we support, for consistency, single-label dirs
- DoTest("bar", "baz", "bar");
+ DoTest("bar", "baz", "bar");
#endif
#endif
#endif
diff --git a/util/folder/filelist.cpp b/util/folder/filelist.cpp
index b21fcdbf20..848b7af96f 100644
--- a/util/folder/filelist.cpp
+++ b/util/folder/filelist.cpp
@@ -36,5 +36,5 @@ void TFileEntitiesList::Fill(const TString& dirname, TStringBuf prefix, TStringB
}
}
- Restart();
+ Restart();
}
diff --git a/util/folder/filelist.h b/util/folder/filelist.h
index 3f615fa4c2..3dea0bb913 100644
--- a/util/folder/filelist.h
+++ b/util/folder/filelist.h
@@ -18,7 +18,7 @@ public:
EM_FILES_DIRS_SLINKS = EM_FILES | EM_DIRS | EM_SLINKS
};
Y_DECLARE_FLAGS(EMask, EMaskFlag)
-
+
TFileEntitiesList(EMask mask)
: Mask(mask)
{
@@ -50,11 +50,11 @@ public:
void Fill(const TString& dirname, TStringBuf prefix, TStringBuf suffix, int depth, bool sort = false);
- void Restart() {
+ void Restart() {
Cur = FileNames.Data();
- CurName = 0;
- }
-
+ CurName = 0;
+ }
+
protected:
TBuffer FileNames;
size_t FileNamesSize, CurName;
diff --git a/util/folder/fts.cpp b/util/folder/fts.cpp
index 0e6a6f86eb..809a589032 100644
--- a/util/folder/fts.cpp
+++ b/util/folder/fts.cpp
@@ -1,6 +1,6 @@
/*-
* Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -12,8 +12,8 @@
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
@@ -232,20 +232,20 @@ yreallocf(void* ptr, size_t size)
{
void* nptr;
- nptr = realloc(ptr, size);
+ nptr = realloc(ptr, size);
if (!nptr && ptr) {
- free(ptr);
+ free(ptr);
}
- return (nptr);
+ return (nptr);
}
FTS* yfts_open(char* const* argv, int options, int (*compar)(const FTSENT**, const FTSENT**))
{
FTS* sp;
- FTSENT *p, *root;
- int nitems;
- FTSENT *parent, *tmp;
- int len;
+ FTSENT *p, *root;
+ int nitems;
+ FTSENT *parent, *tmp;
+ int len;
errno = 0;
@@ -255,122 +255,122 @@ FTS* yfts_open(char* const* argv, int options, int (*compar)(const FTSENT**, con
return nullptr;
}
- /* Options check. */
- if (options & ~FTS_OPTIONMASK) {
- errno = EINVAL;
+ /* Options check. */
+ if (options & ~FTS_OPTIONMASK) {
+ errno = EINVAL;
return nullptr;
- }
+ }
- /* Allocate/initialize the stream */
+ /* Allocate/initialize the stream */
if ((sp = (FTS*)malloc(sizeof(FTS))) == nullptr) {
return nullptr;
}
- memset(sp, 0, sizeof(FTS));
- sp->fts_compar = compar;
- sp->fts_options = options;
+ memset(sp, 0, sizeof(FTS));
+ sp->fts_compar = compar;
+ sp->fts_options = options;
- /* Shush, GCC. */
+ /* Shush, GCC. */
tmp = nullptr;
- /* Logical walks turn on NOCHDIR; symbolic links are too hard. */
+ /* Logical walks turn on NOCHDIR; symbolic links are too hard. */
if (ISSET(FTS_LOGICAL)) {
- SET(FTS_NOCHDIR);
+ SET(FTS_NOCHDIR);
}
- /*
- * Start out with 1K of path space, and enough, in any case,
- * to hold the user's paths.
- */
+ /*
+ * Start out with 1K of path space, and enough, in any case,
+ * to hold the user's paths.
+ */
if (fts_palloc(sp, MAX(fts_maxarglen(argv), MAXPATHLEN))) {
- goto mem1;
+ goto mem1;
}
- /* Allocate/initialize root's parent. */
+ /* Allocate/initialize root's parent. */
if ((parent = fts_alloc(sp, "", 0)) == nullptr) {
- goto mem2;
+ goto mem2;
}
- parent->fts_level = FTS_ROOTPARENTLEVEL;
+ parent->fts_level = FTS_ROOTPARENTLEVEL;
- /* Allocate/initialize root(s). */
+ /* Allocate/initialize root(s). */
for (root = nullptr, nitems = 0; *argv; ++argv, ++nitems) {
- /* Don't allow zero-length paths. */
+ /* Don't allow zero-length paths. */
len = strlen(*argv);
//Any subsequent windows call will expect no trailing slashes so we will remove them here
#ifdef _win_
while (len && ((*argv)[len - 1] == '\\' || (*argv)[len - 1] == '/')) {
- --len;
- }
+ --len;
+ }
#endif
- if (len == 0) {
- errno = ENOENT;
- goto mem3;
- }
+ if (len == 0) {
+ errno = ENOENT;
+ goto mem3;
+ }
- p = fts_alloc(sp, *argv, len);
- p->fts_level = FTS_ROOTLEVEL;
- p->fts_parent = parent;
- p->fts_accpath = p->fts_name;
- p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW));
+ p = fts_alloc(sp, *argv, len);
+ p->fts_level = FTS_ROOTLEVEL;
+ p->fts_parent = parent;
+ p->fts_accpath = p->fts_name;
+ p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW));
p->fts_type = yfts_type_from_info(p->fts_info);
- /* Command-line "." and ".." are real directories. */
+ /* Command-line "." and ".." are real directories. */
if (p->fts_info == FTS_DOT) {
- p->fts_info = FTS_D;
+ p->fts_info = FTS_D;
}
- /*
- * If comparison routine supplied, traverse in sorted
- * order; otherwise traverse in the order specified.
- */
- if (compar) {
- p->fts_link = root;
- root = p;
- } else {
+ /*
+ * If comparison routine supplied, traverse in sorted
+ * order; otherwise traverse in the order specified.
+ */
+ if (compar) {
+ p->fts_link = root;
+ root = p;
+ } else {
p->fts_link = nullptr;
if (root == nullptr) {
- tmp = root = p;
+ tmp = root = p;
} else {
- tmp->fts_link = p;
- tmp = p;
- }
- }
- }
+ tmp->fts_link = p;
+ tmp = p;
+ }
+ }
+ }
if (compar && nitems > 1) {
- root = fts_sort(sp, root, nitems);
+ root = fts_sort(sp, root, nitems);
}
- /*
- * Allocate a dummy pointer and make yfts_read think that we've just
- * finished the node before the root(s); set p->fts_info to FTS_INIT
- * so that everything about the "current" node is ignored.
- */
+ /*
+ * Allocate a dummy pointer and make yfts_read think that we've just
+ * finished the node before the root(s); set p->fts_info to FTS_INIT
+ * so that everything about the "current" node is ignored.
+ */
if ((sp->fts_cur = fts_alloc(sp, "", 0)) == nullptr) {
- goto mem3;
+ goto mem3;
}
sp->fts_cur->fts_level = FTS_ROOTLEVEL;
- sp->fts_cur->fts_link = root;
- sp->fts_cur->fts_info = FTS_INIT;
+ sp->fts_cur->fts_link = root;
+ sp->fts_cur->fts_info = FTS_INIT;
- /*
- * If using chdir(2), grab a file descriptor pointing to dot to ensure
- * that we can get back here; this could be avoided for some paths,
- * but almost certainly not worth the effort. Slashes, symbolic links,
- * and ".." are all fairly nasty problems. Note, if we can't get the
- * descriptor we run anyway, just more slowly.
- */
+ /*
+ * If using chdir(2), grab a file descriptor pointing to dot to ensure
+ * that we can get back here; this could be avoided for some paths,
+ * but almost certainly not worth the effort. Slashes, symbolic links,
+ * and ".." are all fairly nasty problems. Note, if we can't get the
+ * descriptor we run anyway, just more slowly.
+ */
if (!ISSET(FTS_NOCHDIR) && valid_dird(sp->fts_rfd = get_cwdd())) {
- SET(FTS_NOCHDIR);
+ SET(FTS_NOCHDIR);
}
- return (sp);
+ return (sp);
mem3:
fts_lfree(root);
- free(parent);
+ free(parent);
mem2:
free(sp->fts_path);
mem1:
@@ -381,72 +381,72 @@ mem1:
static void
fts_load(FTS* sp, FTSENT* p)
{
- size_t len;
+ size_t len;
char* cp;
- /*
- * Load the stream structure for the next traversal. Since we don't
- * actually enter the directory until after the preorder visit, set
- * the fts_accpath field specially so the chdir gets done to the right
- * place and the user can access the first node. From yfts_open it's
- * known that the path will fit.
- */
- len = p->fts_pathlen = p->fts_namelen;
- memmove((void*)sp->fts_path, (void*)p->fts_name, len + 1);
+ /*
+ * Load the stream structure for the next traversal. Since we don't
+ * actually enter the directory until after the preorder visit, set
+ * the fts_accpath field specially so the chdir gets done to the right
+ * place and the user can access the first node. From yfts_open it's
+ * known that the path will fit.
+ */
+ len = p->fts_pathlen = p->fts_namelen;
+ memmove((void*)sp->fts_path, (void*)p->fts_name, len + 1);
if ((cp = strrchr(p->fts_name, LOCSLASH_C)) != nullptr && (cp != p->fts_name || cp[1])) {
- len = strlen(++cp);
- memmove((void*)p->fts_name, (void*)cp, len + 1);
- p->fts_namelen = (u_short)len;
- }
- p->fts_accpath = p->fts_path = sp->fts_path;
- sp->fts_dev = p->fts_dev;
+ len = strlen(++cp);
+ memmove((void*)p->fts_name, (void*)cp, len + 1);
+ p->fts_namelen = (u_short)len;
+ }
+ p->fts_accpath = p->fts_path = sp->fts_path;
+ sp->fts_dev = p->fts_dev;
}
int yfts_close(FTS* sp)
{
- FTSENT *freep, *p;
- int saved_errno;
-
- /*
- * This still works if we haven't read anything -- the dummy structure
- * points to the root list, so we step through to the end of the root
- * list which has a valid parent pointer.
- */
- if (sp->fts_cur) {
- for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) {
- freep = p;
- p = p->fts_link ? p->fts_link : p->fts_parent;
- free(freep);
- }
- free(p);
- }
-
- /* Free up child linked list, sort array, path buffer. */
+ FTSENT *freep, *p;
+ int saved_errno;
+
+ /*
+ * This still works if we haven't read anything -- the dummy structure
+ * points to the root list, so we step through to the end of the root
+ * list which has a valid parent pointer.
+ */
+ if (sp->fts_cur) {
+ for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) {
+ freep = p;
+ p = p->fts_link ? p->fts_link : p->fts_parent;
+ free(freep);
+ }
+ free(p);
+ }
+
+ /* Free up child linked list, sort array, path buffer. */
if (sp->fts_child) {
- fts_lfree(sp->fts_child);
+ fts_lfree(sp->fts_child);
}
if (sp->fts_array) {
- free(sp->fts_array);
+ free(sp->fts_array);
}
- free(sp->fts_path);
+ free(sp->fts_path);
- /* Return to original directory, save errno if necessary. */
- if (!ISSET(FTS_NOCHDIR)) {
+ /* Return to original directory, save errno if necessary. */
+ if (!ISSET(FTS_NOCHDIR)) {
saved_errno = chdir_dird(sp->fts_rfd) ? errno : 0;
close_dird(sp->fts_rfd);
- /* Set errno and return. */
- if (saved_errno != 0) {
- /* Free up the stream pointer. */
- free(sp);
- errno = saved_errno;
- return (-1);
- }
- }
-
- /* Free up the stream pointer. */
- free(sp);
- return (0);
+ /* Set errno and return. */
+ if (saved_errno != 0) {
+ /* Free up the stream pointer. */
+ free(sp);
+ errno = saved_errno;
+ return (-1);
+ }
+ }
+
+ /* Free up the stream pointer. */
+ free(sp);
+ return (0);
}
/*
@@ -460,200 +460,200 @@ int yfts_close(FTS* sp)
FTSENT*
yfts_read(FTS* sp) {
- FTSENT *p, *tmp;
- int instr;
+ FTSENT *p, *tmp;
+ int instr;
char* t;
- int saved_errno;
+ int saved_errno;
ClearLastSystemError();
- /* If finished or unrecoverable error, return NULL. */
+ /* If finished or unrecoverable error, return NULL. */
if (sp->fts_cur == nullptr || ISSET(FTS_STOP)) {
return nullptr;
}
- /* Set current node pointer. */
- p = sp->fts_cur;
+ /* Set current node pointer. */
+ p = sp->fts_cur;
- /* Save and zero out user instructions. */
- instr = p->fts_instr;
- p->fts_instr = FTS_NOINSTR;
+ /* Save and zero out user instructions. */
+ instr = p->fts_instr;
+ p->fts_instr = FTS_NOINSTR;
- /* Any type of file may be re-visited; re-stat and re-turn. */
- if (instr == FTS_AGAIN) {
- p->fts_info = fts_stat(sp, p, 0);
+ /* Any type of file may be re-visited; re-stat and re-turn. */
+ if (instr == FTS_AGAIN) {
+ p->fts_info = fts_stat(sp, p, 0);
p->fts_type = yfts_type_from_info(p->fts_info);
- return (p);
- }
-
- /*
- * Following a symlink -- SLNONE test allows application to see
- * SLNONE and recover. If indirecting through a symlink, have
- * keep a pointer to current location. If unable to get that
- * pointer, follow fails.
- */
- if (instr == FTS_FOLLOW &&
- (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) {
- p->fts_info = fts_stat(sp, p, 1);
+ return (p);
+ }
+
+ /*
+ * Following a symlink -- SLNONE test allows application to see
+ * SLNONE and recover. If indirecting through a symlink, have
+ * keep a pointer to current location. If unable to get that
+ * pointer, follow fails.
+ */
+ if (instr == FTS_FOLLOW &&
+ (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) {
+ p->fts_info = fts_stat(sp, p, 1);
p->fts_type = yfts_type_from_info(p->fts_info);
- if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
- if (valid_dird(p->fts_symfd = get_cwdd())) {
- p->fts_errno = errno;
- p->fts_info = FTS_ERR;
+ if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
+ if (valid_dird(p->fts_symfd = get_cwdd())) {
+ p->fts_errno = errno;
+ p->fts_info = FTS_ERR;
} else {
- p->fts_flags |= FTS_SYMFOLLOW;
+ p->fts_flags |= FTS_SYMFOLLOW;
}
- }
- return (p);
- }
-
- /* Directory in pre-order. */
- if (p->fts_info == FTS_D) {
- /* If skipped or crossed mount point, do post-order visit. */
- if (instr == FTS_SKIP ||
- (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) {
+ }
+ return (p);
+ }
+
+ /* Directory in pre-order. */
+ if (p->fts_info == FTS_D) {
+ /* If skipped or crossed mount point, do post-order visit. */
+ if (instr == FTS_SKIP ||
+ (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) {
if (p->fts_flags & FTS_SYMFOLLOW) {
- close_dird(p->fts_symfd);
+ close_dird(p->fts_symfd);
}
- if (sp->fts_child) {
- fts_lfree(sp->fts_child);
+ if (sp->fts_child) {
+ fts_lfree(sp->fts_child);
sp->fts_child = nullptr;
- }
- p->fts_info = FTS_DP;
- return (p);
- }
-
- /* Rebuild if only read the names and now traversing. */
- if (sp->fts_child && ISSET(FTS_NAMEONLY)) {
- CLR(FTS_NAMEONLY);
- fts_lfree(sp->fts_child);
+ }
+ p->fts_info = FTS_DP;
+ return (p);
+ }
+
+ /* Rebuild if only read the names and now traversing. */
+ if (sp->fts_child && ISSET(FTS_NAMEONLY)) {
+ CLR(FTS_NAMEONLY);
+ fts_lfree(sp->fts_child);
sp->fts_child = nullptr;
- }
-
- /*
- * Cd to the subdirectory.
- *
- * If have already read and now fail to chdir, whack the list
- * to make the names come out right, and set the parent errno
- * so the application will eventually get an error condition.
- * Set the FTS_DONTCHDIR flag so that when we logically change
- * directories back to the parent we don't do a chdir.
- *
- * If haven't read do so. If the read fails, fts_build sets
- * FTS_STOP or the fts_info field of the node.
- */
- if (sp->fts_child) {
- if (fts_safe_changedir(sp, p, -1, p->fts_accpath)) {
- p->fts_errno = errno;
- p->fts_flags |= FTS_DONTCHDIR;
+ }
+
+ /*
+ * Cd to the subdirectory.
+ *
+ * If have already read and now fail to chdir, whack the list
+ * to make the names come out right, and set the parent errno
+ * so the application will eventually get an error condition.
+ * Set the FTS_DONTCHDIR flag so that when we logically change
+ * directories back to the parent we don't do a chdir.
+ *
+ * If haven't read do so. If the read fails, fts_build sets
+ * FTS_STOP or the fts_info field of the node.
+ */
+ if (sp->fts_child) {
+ if (fts_safe_changedir(sp, p, -1, p->fts_accpath)) {
+ p->fts_errno = errno;
+ p->fts_flags |= FTS_DONTCHDIR;
for (p = sp->fts_child; p; p = p->fts_link) {
- p->fts_accpath =
- p->fts_parent->fts_accpath;
+ p->fts_accpath =
+ p->fts_parent->fts_accpath;
}
- }
+ }
} else if ((sp->fts_child = fts_build(sp, BREAD)) == nullptr) {
if (ISSET(FTS_STOP)) {
return nullptr;
}
- return (p);
- }
- p = sp->fts_child;
+ return (p);
+ }
+ p = sp->fts_child;
sp->fts_child = nullptr;
- goto name;
- }
+ goto name;
+ }
- /* Move to the next node on this level. */
+ /* Move to the next node on this level. */
next:
tmp = p;
if ((p = p->fts_link) != nullptr) {
- free(tmp);
-
- /*
- * If reached the top, return to the original directory (or
- * the root of the tree), and load the paths for the next root.
- */
- if (p->fts_level == FTS_ROOTLEVEL) {
- if (FCHDIR(sp, sp->fts_rfd)) {
- SET(FTS_STOP);
+ free(tmp);
+
+ /*
+ * If reached the top, return to the original directory (or
+ * the root of the tree), and load the paths for the next root.
+ */
+ if (p->fts_level == FTS_ROOTLEVEL) {
+ if (FCHDIR(sp, sp->fts_rfd)) {
+ SET(FTS_STOP);
return nullptr;
- }
- fts_load(sp, p);
- return (sp->fts_cur = p);
- }
-
- /*
- * User may have called yfts_set on the node. If skipped,
- * ignore. If followed, get a file descriptor so we can
- * get back if necessary.
- */
+ }
+ fts_load(sp, p);
+ return (sp->fts_cur = p);
+ }
+
+ /*
+ * User may have called yfts_set on the node. If skipped,
+ * ignore. If followed, get a file descriptor so we can
+ * get back if necessary.
+ */
if (p->fts_instr == FTS_SKIP) {
- goto next;
+ goto next;
}
- if (p->fts_instr == FTS_FOLLOW) {
- p->fts_info = fts_stat(sp, p, 1);
+ if (p->fts_instr == FTS_FOLLOW) {
+ p->fts_info = fts_stat(sp, p, 1);
p->fts_type = yfts_type_from_info(p->fts_info);
- if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
- if (valid_dird(p->fts_symfd =
+ if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
+ if (valid_dird(p->fts_symfd =
get_cwdd())) {
- p->fts_errno = errno;
- p->fts_info = FTS_ERR;
+ p->fts_errno = errno;
+ p->fts_info = FTS_ERR;
} else {
- p->fts_flags |= FTS_SYMFOLLOW;
+ p->fts_flags |= FTS_SYMFOLLOW;
}
- }
- p->fts_instr = FTS_NOINSTR;
- }
+ }
+ p->fts_instr = FTS_NOINSTR;
+ }
name:
t = sp->fts_path + NAPPEND(p->fts_parent);
- *t++ = LOCSLASH_C;
- memmove(t, p->fts_name, (size_t)p->fts_namelen + 1);
- return (sp->fts_cur = p);
- }
-
- /* Move up to the parent node. */
- p = tmp->fts_parent;
- free(tmp);
-
- if (p->fts_level == FTS_ROOTPARENTLEVEL) {
- /*
- * Done; free everything up and set errno to 0 so the user
- * can distinguish between error and EOF.
- */
- free(p);
- errno = 0;
+ *t++ = LOCSLASH_C;
+ memmove(t, p->fts_name, (size_t)p->fts_namelen + 1);
+ return (sp->fts_cur = p);
+ }
+
+ /* Move up to the parent node. */
+ p = tmp->fts_parent;
+ free(tmp);
+
+ if (p->fts_level == FTS_ROOTPARENTLEVEL) {
+ /*
+ * Done; free everything up and set errno to 0 so the user
+ * can distinguish between error and EOF.
+ */
+ free(p);
+ errno = 0;
return (sp->fts_cur = nullptr);
- }
-
- /* NUL terminate the pathname. */
- sp->fts_path[p->fts_pathlen] = '\0';
-
- /*
- * Return to the parent directory. If at a root node or came through
- * a symlink, go back through the file descriptor. Otherwise, cd up
- * one directory.
- */
- if (p->fts_level == FTS_ROOTLEVEL) {
- if (FCHDIR(sp, sp->fts_rfd)) {
- SET(FTS_STOP);
+ }
+
+ /* NUL terminate the pathname. */
+ sp->fts_path[p->fts_pathlen] = '\0';
+
+ /*
+ * Return to the parent directory. If at a root node or came through
+ * a symlink, go back through the file descriptor. Otherwise, cd up
+ * one directory.
+ */
+ if (p->fts_level == FTS_ROOTLEVEL) {
+ if (FCHDIR(sp, sp->fts_rfd)) {
+ SET(FTS_STOP);
return nullptr;
- }
- } else if (p->fts_flags & FTS_SYMFOLLOW) {
- if (FCHDIR(sp, p->fts_symfd)) {
- saved_errno = errno;
- close_dird(p->fts_symfd);
- errno = saved_errno;
- SET(FTS_STOP);
+ }
+ } else if (p->fts_flags & FTS_SYMFOLLOW) {
+ if (FCHDIR(sp, p->fts_symfd)) {
+ saved_errno = errno;
+ close_dird(p->fts_symfd);
+ errno = saved_errno;
+ SET(FTS_STOP);
return nullptr;
- }
- close_dird(p->fts_symfd);
- } else if (!(p->fts_flags & FTS_DONTCHDIR) &&
+ }
+ close_dird(p->fts_symfd);
+ } else if (!(p->fts_flags & FTS_DONTCHDIR) &&
fts_safe_changedir(sp, p->fts_parent, -1, "..")) {
SET(FTS_STOP);
return nullptr;
- }
- p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP;
- return (sp->fts_cur = p);
+ }
+ p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP;
+ return (sp->fts_cur = p);
}
/*
@@ -666,87 +666,87 @@ next:
int yfts_set(FTS* sp, FTSENT* p, int instr)
{
(void)sp; //Unused
- if (instr && instr != FTS_AGAIN && instr != FTS_FOLLOW &&
- instr != FTS_NOINSTR && instr != FTS_SKIP) {
- errno = EINVAL;
- return (1);
- }
- p->fts_instr = (u_short)instr;
- return (0);
+ if (instr && instr != FTS_AGAIN && instr != FTS_FOLLOW &&
+ instr != FTS_NOINSTR && instr != FTS_SKIP) {
+ errno = EINVAL;
+ return (1);
+ }
+ p->fts_instr = (u_short)instr;
+ return (0);
}
FTSENT*
yfts_children(FTS* sp, int instr)
{
FTSENT* p;
- dird fd;
- if (instr && instr != FTS_NAMEONLY) {
- errno = EINVAL;
+ dird fd;
+ if (instr && instr != FTS_NAMEONLY) {
+ errno = EINVAL;
return nullptr;
- }
+ }
- /* Set current node pointer. */
- p = sp->fts_cur;
+ /* Set current node pointer. */
+ p = sp->fts_cur;
- /*
- * Errno set to 0 so user can distinguish empty directory from
- * an error.
- */
- errno = 0;
+ /*
+ * Errno set to 0 so user can distinguish empty directory from
+ * an error.
+ */
+ errno = 0;
- /* Fatal errors stop here. */
+ /* Fatal errors stop here. */
if (ISSET(FTS_STOP)) {
return nullptr;
}
- /* Return logical hierarchy of user's arguments. */
+ /* Return logical hierarchy of user's arguments. */
if (p->fts_info == FTS_INIT) {
- return (p->fts_link);
+ return (p->fts_link);
}
- /*
- * If not a directory being visited in pre-order, stop here. Could
- * allow FTS_DNR, assuming the user has fixed the problem, but the
- * same effect is available with FTS_AGAIN.
- */
+ /*
+ * If not a directory being visited in pre-order, stop here. Could
+ * allow FTS_DNR, assuming the user has fixed the problem, but the
+ * same effect is available with FTS_AGAIN.
+ */
if (p->fts_info != FTS_D /* && p->fts_info != FTS_DNR */) {
return nullptr;
}
- /* Free up any previous child list. */
+ /* Free up any previous child list. */
if (sp->fts_child) {
- fts_lfree(sp->fts_child);
+ fts_lfree(sp->fts_child);
}
- if (instr == FTS_NAMEONLY) {
- SET(FTS_NAMEONLY);
- instr = BNAMES;
+ if (instr == FTS_NAMEONLY) {
+ SET(FTS_NAMEONLY);
+ instr = BNAMES;
} else {
- instr = BCHILD;
+ instr = BCHILD;
}
- /*
- * If using chdir on a relative path and called BEFORE yfts_read does
- * its chdir to the root of a traversal, we can lose -- we need to
- * chdir into the subdirectory, and we don't know where the current
- * directory is, so we can't get back so that the upcoming chdir by
- * yfts_read will work.
- */
- if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == LOCSLASH_C ||
+ /*
+ * If using chdir on a relative path and called BEFORE yfts_read does
+ * its chdir to the root of a traversal, we can lose -- we need to
+ * chdir into the subdirectory, and we don't know where the current
+ * directory is, so we can't get back so that the upcoming chdir by
+ * yfts_read will work.
+ */
+ if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == LOCSLASH_C ||
ISSET(FTS_NOCHDIR)) {
- return (sp->fts_child = fts_build(sp, instr));
+ return (sp->fts_child = fts_build(sp, instr));
}
if (valid_dird(fd = get_cwdd())) {
return nullptr;
}
- sp->fts_child = fts_build(sp, instr);
- if (chdir_dird(fd)) {
+ sp->fts_child = fts_build(sp, instr);
+ if (chdir_dird(fd)) {
close_dird(fd);
return nullptr;
}
- close_dird(fd);
- return (sp->fts_child);
+ close_dird(fd);
+ return (sp->fts_child);
}
static inline struct dirent* yreaddir(DIR* dir, struct dirent* de) {
@@ -780,9 +780,9 @@ static FTSENT*
fts_build(FTS* sp, int type)
{
struct dirent* dp;
- FTSENT *p, *head;
- int nitems;
- FTSENT *cur, *tail;
+ FTSENT *p, *head;
+ int nitems;
+ FTSENT *cur, *tail;
#ifdef _win_
dird dirpd;
@@ -792,71 +792,71 @@ fts_build(FTS* sp, int type)
#endif
void* oldaddr;
- int cderrno, descend, len, level, maxlen, nlinks, saved_errno,
- nostat, doadjust;
+ int cderrno, descend, len, level, maxlen, nlinks, saved_errno,
+ nostat, doadjust;
char* cp;
- /* Set current node pointer. */
- cur = sp->fts_cur;
+ /* Set current node pointer. */
+ cur = sp->fts_cur;
- /*
- * Open the directory for reading. If this fails, we're done.
- * If being called from yfts_read, set the fts_info field.
- */
+ /*
+ * Open the directory for reading. If this fails, we're done.
+ * If being called from yfts_read, set the fts_info field.
+ */
#ifdef FTS_WHITEOUT
- if (ISSET(FTS_WHITEOUT))
+ if (ISSET(FTS_WHITEOUT))
oflag = DTF_NODUP | DTF_REWIND;
- else
+ else
oflag = DTF_HIDEW | DTF_NODUP | DTF_REWIND;
#else
#define __opendir2(path, flag) opendir(path)
#endif
if ((dirp = __opendir2(cur->fts_accpath, oflag)) == nullptr) {
- if (type == BREAD) {
- cur->fts_info = FTS_DNR;
- cur->fts_errno = errno;
- }
+ if (type == BREAD) {
+ cur->fts_info = FTS_DNR;
+ cur->fts_errno = errno;
+ }
return nullptr;
- }
+ }
#ifdef _win_
dirpd = get_dird(cur->fts_accpath);
#endif
- /*
- * Nlinks is the number of possible entries of type directory in the
- * directory if we're cheating on stat calls, 0 if we're not doing
- * any stat calls at all, -1 if we're doing stats on everything.
- */
- if (type == BNAMES) {
- nlinks = 0;
- /* Be quiet about nostat, GCC. */
- nostat = 0;
- } else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) {
- nlinks = cur->fts_nlink - (ISSET(FTS_SEEDOT) ? 0 : 2);
- nostat = 1;
- } else {
- nlinks = -1;
- nostat = 0;
- }
-
- /*
- * If we're going to need to stat anything or we want to descend
- * and stay in the directory, chdir. If this fails we keep going,
- * but set a flag so we don't chdir after the post-order visit.
- * We won't be able to stat anything, but we can still return the
- * names themselves. Note, that since yfts_read won't be able to
- * chdir into the directory, it will have to return different path
- * names than before, i.e. "a/b" instead of "b". Since the node
- * has already been visited in pre-order, have to wait until the
- * post-order visit to return the error. There is a special case
- * here, if there was nothing to stat then it's not an error to
- * not be able to stat. This is all fairly nasty. If a program
- * needed sorted entries or stat information, they had better be
- * checking FTS_NS on the returned nodes.
- */
- cderrno = 0;
- if (nlinks || type == BREAD) {
+ /*
+ * Nlinks is the number of possible entries of type directory in the
+ * directory if we're cheating on stat calls, 0 if we're not doing
+ * any stat calls at all, -1 if we're doing stats on everything.
+ */
+ if (type == BNAMES) {
+ nlinks = 0;
+ /* Be quiet about nostat, GCC. */
+ nostat = 0;
+ } else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) {
+ nlinks = cur->fts_nlink - (ISSET(FTS_SEEDOT) ? 0 : 2);
+ nostat = 1;
+ } else {
+ nlinks = -1;
+ nostat = 0;
+ }
+
+ /*
+ * If we're going to need to stat anything or we want to descend
+ * and stay in the directory, chdir. If this fails we keep going,
+ * but set a flag so we don't chdir after the post-order visit.
+ * We won't be able to stat anything, but we can still return the
+ * names themselves. Note, that since yfts_read won't be able to
+ * chdir into the directory, it will have to return different path
+ * names than before, i.e. "a/b" instead of "b". Since the node
+ * has already been visited in pre-order, have to wait until the
+ * post-order visit to return the error. There is a special case
+ * here, if there was nothing to stat then it's not an error to
+ * not be able to stat. This is all fairly nasty. If a program
+ * needed sorted entries or stat information, they had better be
+ * checking FTS_NS on the returned nodes.
+ */
+ cderrno = 0;
+ if (nlinks || type == BREAD) {
#ifndef _win_
if (fts_safe_changedir(sp, cur, dirfd(dirp), nullptr)) {
#else
@@ -864,12 +864,12 @@ fts_build(FTS* sp, int type)
#endif
if (nlinks && type == BREAD) {
- cur->fts_errno = errno;
+ cur->fts_errno = errno;
}
- cur->fts_flags |= FTS_DONTCHDIR;
- descend = 0;
- cderrno = errno;
- (void)closedir(dirp);
+ cur->fts_flags |= FTS_DONTCHDIR;
+ descend = 0;
+ cderrno = errno;
+ (void)closedir(dirp);
dirp = nullptr;
#ifdef _win_
close_dird(dirpd);
@@ -878,107 +878,107 @@ fts_build(FTS* sp, int type)
Y_UNUSED(invalidDirD);
#endif
} else {
- descend = 1;
+ descend = 1;
}
} else {
- descend = 0;
- }
-
- /*
- * Figure out the max file name length that can be stored in the
- * current path -- the inner loop allocates more path as necessary.
- * We really wouldn't have to do the maxlen calculations here, we
- * could do them in yfts_read before returning the path, but it's a
- * lot easier here since the length is part of the dirent structure.
- *
- * If not changing directories set a pointer so that can just append
- * each new name into the path.
- */
- len = NAPPEND(cur);
- if (ISSET(FTS_NOCHDIR)) {
- cp = sp->fts_path + len;
- *cp++ = LOCSLASH_C;
- } else {
- /* GCC, you're too verbose. */
+ descend = 0;
+ }
+
+ /*
+ * Figure out the max file name length that can be stored in the
+ * current path -- the inner loop allocates more path as necessary.
+ * We really wouldn't have to do the maxlen calculations here, we
+ * could do them in yfts_read before returning the path, but it's a
+ * lot easier here since the length is part of the dirent structure.
+ *
+ * If not changing directories set a pointer so that can just append
+ * each new name into the path.
+ */
+ len = NAPPEND(cur);
+ if (ISSET(FTS_NOCHDIR)) {
+ cp = sp->fts_path + len;
+ *cp++ = LOCSLASH_C;
+ } else {
+ /* GCC, you're too verbose. */
cp = nullptr;
- }
+ }
++len;
- maxlen = sp->fts_pathlen - len;
+ maxlen = sp->fts_pathlen - len;
- level = cur->fts_level + 1;
+ level = cur->fts_level + 1;
- /* Read the directory, attaching each entry to the `link' pointer. */
- doadjust = 0;
+ /* Read the directory, attaching each entry to the `link' pointer. */
+ doadjust = 0;
//to ensure enough buffer
TTempBuf dpe;
for (head = tail = nullptr, nitems = 0; dirp && (dp = yreaddir(dirp, (struct dirent*)dpe.Data())) != nullptr;) {
if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name)) {
- continue;
+ continue;
}
if ((p = fts_alloc(sp, dp->d_name, (int)strlen(dp->d_name))) == nullptr) {
- goto mem1;
+ goto mem1;
}
if (strlen(dp->d_name) >= (size_t)maxlen) { /* include space for NUL */
- oldaddr = sp->fts_path;
+ oldaddr = sp->fts_path;
if (fts_palloc(sp, strlen(dp->d_name) + len + 1)) {
- /*
- * No more memory for path or structures. Save
- * errno, free up the current structure and the
- * structures already allocated.
- */
+ /*
+ * No more memory for path or structures. Save
+ * errno, free up the current structure and the
+ * structures already allocated.
+ */
mem1:
saved_errno = errno;
if (p) {
- free(p);
+ free(p);
}
- fts_lfree(head);
- (void)closedir(dirp);
+ fts_lfree(head);
+ (void)closedir(dirp);
#ifdef _win_
close_dird(dirpd);
#endif
- cur->fts_info = FTS_ERR;
- SET(FTS_STOP);
- errno = saved_errno;
+ cur->fts_info = FTS_ERR;
+ SET(FTS_STOP);
+ errno = saved_errno;
return nullptr;
- }
- /* Did realloc() change the pointer? */
- if (oldaddr != sp->fts_path) {
- doadjust = 1;
+ }
+ /* Did realloc() change the pointer? */
+ if (oldaddr != sp->fts_path) {
+ doadjust = 1;
if (ISSET(FTS_NOCHDIR)) {
- cp = sp->fts_path + len;
+ cp = sp->fts_path + len;
}
- }
- maxlen = sp->fts_pathlen - len;
- }
-
- if (len + strlen(dp->d_name) >= USHRT_MAX) {
- /*
- * In an FTSENT, fts_pathlen is a u_short so it is
- * possible to wraparound here. If we do, free up
- * the current structure and the structures already
- * allocated, then error out with ENAMETOOLONG.
- */
- free(p);
- fts_lfree(head);
- (void)closedir(dirp);
+ }
+ maxlen = sp->fts_pathlen - len;
+ }
+
+ if (len + strlen(dp->d_name) >= USHRT_MAX) {
+ /*
+ * In an FTSENT, fts_pathlen is a u_short so it is
+ * possible to wraparound here. If we do, free up
+ * the current structure and the structures already
+ * allocated, then error out with ENAMETOOLONG.
+ */
+ free(p);
+ fts_lfree(head);
+ (void)closedir(dirp);
#ifdef _win_
close_dird(dirpd);
#endif
- cur->fts_info = FTS_ERR;
- SET(FTS_STOP);
- errno = ENAMETOOLONG;
+ cur->fts_info = FTS_ERR;
+ SET(FTS_STOP);
+ errno = ENAMETOOLONG;
return nullptr;
- }
- p->fts_level = (short)level;
- p->fts_parent = sp->fts_cur;
- p->fts_pathlen = u_short(len + strlen(dp->d_name));
+ }
+ p->fts_level = (short)level;
+ p->fts_parent = sp->fts_cur;
+ p->fts_pathlen = u_short(len + strlen(dp->d_name));
#ifdef FTS_WHITEOUT
- if (dp->d_type == DT_WHT)
- p->fts_flags |= FTS_ISW;
+ if (dp->d_type == DT_WHT)
+ p->fts_flags |= FTS_ISW;
#endif
#ifdef _DIRENT_HAVE_D_TYPE
@@ -992,252 +992,252 @@ fts_build(FTS* sp, int type)
#endif
// coverity[dead_error_line]: false positive
- if (cderrno) {
- if (nlinks) {
- p->fts_info = FTS_NS;
- p->fts_errno = cderrno;
+ if (cderrno) {
+ if (nlinks) {
+ p->fts_info = FTS_NS;
+ p->fts_errno = cderrno;
} else {
- p->fts_info = FTS_NSOK;
+ p->fts_info = FTS_NSOK;
}
- p->fts_accpath = cur->fts_accpath;
- } else if (nlinks == 0
+ p->fts_accpath = cur->fts_accpath;
+ } else if (nlinks == 0
#ifdef DT_DIR
|| (nostat &&
dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN)
#endif
) {
- p->fts_accpath =
- ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name;
- p->fts_info = FTS_NSOK;
- } else {
- /* Build a file name for fts_stat to stat. */
- if (ISSET(FTS_NOCHDIR)) {
- p->fts_accpath = p->fts_path;
- memmove((void*)cp, (void*)p->fts_name, (size_t)p->fts_namelen + 1);
+ p->fts_accpath =
+ ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name;
+ p->fts_info = FTS_NSOK;
+ } else {
+ /* Build a file name for fts_stat to stat. */
+ if (ISSET(FTS_NOCHDIR)) {
+ p->fts_accpath = p->fts_path;
+ memmove((void*)cp, (void*)p->fts_name, (size_t)p->fts_namelen + 1);
} else {
- p->fts_accpath = p->fts_name;
+ p->fts_accpath = p->fts_name;
}
- /* Stat it. */
- p->fts_info = fts_stat(sp, p, 0);
+ /* Stat it. */
+ p->fts_info = fts_stat(sp, p, 0);
p->fts_type = yfts_type_from_info(p->fts_info);
- /* Decrement link count if applicable. */
- if (nlinks > 0 && (p->fts_info == FTS_D ||
+ /* Decrement link count if applicable. */
+ if (nlinks > 0 && (p->fts_info == FTS_D ||
p->fts_info == FTS_DC || p->fts_info == FTS_DOT)) {
- --nlinks;
+ --nlinks;
}
- }
+ }
- /* We walk in directory order so "ls -f" doesn't get upset. */
+ /* We walk in directory order so "ls -f" doesn't get upset. */
p->fts_link = nullptr;
if (head == nullptr) {
- head = tail = p;
+ head = tail = p;
} else {
- tail->fts_link = p;
- tail = p;
- }
- ++nitems;
- }
+ tail->fts_link = p;
+ tail = p;
+ }
+ ++nitems;
+ }
if (dirp) {
- (void)closedir(dirp);
+ (void)closedir(dirp);
#ifdef _win_
close_dird(dirpd);
#endif
}
- /*
- * If realloc() changed the address of the path, adjust the
- * addresses for the rest of the tree and the dir list.
- */
+ /*
+ * If realloc() changed the address of the path, adjust the
+ * addresses for the rest of the tree and the dir list.
+ */
if (doadjust) {
- fts_padjust(sp);
+ fts_padjust(sp);
}
- /*
- * If not changing directories, reset the path back to original
- * state.
- */
- if (ISSET(FTS_NOCHDIR)) {
+ /*
+ * If not changing directories, reset the path back to original
+ * state.
+ */
+ if (ISSET(FTS_NOCHDIR)) {
if (len == sp->fts_pathlen || nitems == 0) {
- --cp;
+ --cp;
}
- *cp = '\0';
- }
-
- /*
- * If descended after called from yfts_children or after called from
- * yfts_read and nothing found, get back. At the root level we use
- * the saved fd; if one of yfts_open()'s arguments is a relative path
- * to an empty directory, we wind up here with no other way back. If
- * can't get back, we're done.
- */
- if (descend && (type == BCHILD || !nitems) &&
+ *cp = '\0';
+ }
+
+ /*
+ * If descended after called from yfts_children or after called from
+ * yfts_read and nothing found, get back. At the root level we use
+ * the saved fd; if one of yfts_open()'s arguments is a relative path
+ * to an empty directory, we wind up here with no other way back. If
+ * can't get back, we're done.
+ */
+ if (descend && (type == BCHILD || !nitems) &&
(cur->fts_level == FTS_ROOTLEVEL ? FCHDIR(sp, sp->fts_rfd) : fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) {
- cur->fts_info = FTS_ERR;
- SET(FTS_STOP);
+ cur->fts_info = FTS_ERR;
+ SET(FTS_STOP);
fts_lfree(head);
return nullptr;
- }
+ }
- /* If didn't find anything, return NULL. */
- if (!nitems) {
+ /* If didn't find anything, return NULL. */
+ if (!nitems) {
if (type == BREAD) {
- cur->fts_info = FTS_DP;
+ cur->fts_info = FTS_DP;
}
fts_lfree(head);
return nullptr;
- }
+ }
- /* Sort the entries. */
+ /* Sort the entries. */
if (sp->fts_compar && nitems > 1) {
- head = fts_sort(sp, head, nitems);
+ head = fts_sort(sp, head, nitems);
}
- return (head);
+ return (head);
}
static u_short
fts_stat(FTS* sp, FTSENT* p, int follow)
{
- dev_t dev;
- ino_t ino;
+ dev_t dev;
+ ino_t ino;
stat_struct *sbp, sb;
- int saved_errno;
- /* If user needs stat info, stat buffer already allocated. */
- sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp;
+ int saved_errno;
+ /* If user needs stat info, stat buffer already allocated. */
+ sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp;
#ifdef FTS_WHITEOUT
- /* check for whiteout */
- if (p->fts_flags & FTS_ISW) {
- if (sbp != &sb) {
+ /* check for whiteout */
+ if (p->fts_flags & FTS_ISW) {
+ if (sbp != &sb) {
memset(sbp, '\0', sizeof(*sbp));
- sbp->st_mode = S_IFWHT;
- }
- return (FTS_W);
- }
+ sbp->st_mode = S_IFWHT;
+ }
+ return (FTS_W);
+ }
#endif
- /*
- * If doing a logical walk, or application requested FTS_FOLLOW, do
- * a stat(2). If that fails, check for a non-existent symlink. If
- * fail, set the errno from the stat call.
- */
- if (ISSET(FTS_LOGICAL) || follow) {
+ /*
+ * If doing a logical walk, or application requested FTS_FOLLOW, do
+ * a stat(2). If that fails, check for a non-existent symlink. If
+ * fail, set the errno from the stat call.
+ */
+ if (ISSET(FTS_LOGICAL) || follow) {
if (STAT_FUNC(p->fts_accpath, sbp)) {
- saved_errno = errno;
- if (!lstat(p->fts_accpath, sbp)) {
- errno = 0;
- return (FTS_SLNONE);
- }
- p->fts_errno = saved_errno;
+ saved_errno = errno;
+ if (!lstat(p->fts_accpath, sbp)) {
+ errno = 0;
+ return (FTS_SLNONE);
+ }
+ p->fts_errno = saved_errno;
memset(sbp, 0, sizeof(stat_struct));
return (FTS_NS);
- }
+ }
} else if (lstat(p->fts_accpath, sbp)) {
- p->fts_errno = errno;
+ p->fts_errno = errno;
memset(sbp, 0, sizeof(stat_struct));
- return (FTS_NS);
- }
+ return (FTS_NS);
+ }
if (S_ISDIR(sbp->st_mode)) {
- /*
- * Set the device/inode. Used to find cycles and check for
- * crossing mount points. Also remember the link count, used
- * in fts_build to limit the number of stat calls. It is
- * understood that these fields are only referenced if fts_info
- * is set to FTS_D.
- */
- dev = p->fts_dev = sbp->st_dev;
- ino = p->fts_ino = sbp->st_ino;
- p->fts_nlink = sbp->st_nlink;
+ /*
+ * Set the device/inode. Used to find cycles and check for
+ * crossing mount points. Also remember the link count, used
+ * in fts_build to limit the number of stat calls. It is
+ * understood that these fields are only referenced if fts_info
+ * is set to FTS_D.
+ */
+ dev = p->fts_dev = sbp->st_dev;
+ ino = p->fts_ino = sbp->st_ino;
+ p->fts_nlink = sbp->st_nlink;
const char* fts_name_x = p->fts_name;
if (ISDOT(fts_name_x)) {
- return (FTS_DOT);
+ return (FTS_DOT);
}
/*
- * Cycle detection is done by brute force when the directory
- * is first encountered. If the tree gets deep enough or the
- * number of symbolic links to directories is high enough,
- * something faster might be worthwhile.
- */
+ * Cycle detection is done by brute force when the directory
+ * is first encountered. If the tree gets deep enough or the
+ * number of symbolic links to directories is high enough,
+ * something faster might be worthwhile.
+ */
//There is no way to detect symlink or mount cycles on win32
#ifndef _win_
FTSENT* t;
- for (t = p->fts_parent;
+ for (t = p->fts_parent;
t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent) {
- if (ino == t->fts_ino && dev == t->fts_dev) {
- p->fts_cycle = t;
- return (FTS_DC);
- }
+ if (ino == t->fts_ino && dev == t->fts_dev) {
+ p->fts_cycle = t;
+ return (FTS_DC);
+ }
}
#endif /*_win_*/
- return (FTS_D);
- }
+ return (FTS_D);
+ }
if (S_ISLNK(sbp->st_mode)) {
- return (FTS_SL);
+ return (FTS_SL);
}
if (S_ISREG(sbp->st_mode)) {
- return (FTS_F);
+ return (FTS_F);
}
- return (FTS_DEFAULT);
+ return (FTS_DEFAULT);
}
static FTSENT*
fts_sort(FTS* sp, FTSENT* head, int nitems)
{
- FTSENT **ap, *p;
-
- /*
- * Construct an array of pointers to the structures and call qsort(3).
- * Reassemble the array in the order returned by qsort. If unable to
- * sort for memory reasons, return the directory entries in their
- * current order. Allocate enough space for the current needs plus
- * 40 so don't realloc one entry at a time.
- */
- if (nitems > sp->fts_nitems) {
+ FTSENT **ap, *p;
+
+ /*
+ * Construct an array of pointers to the structures and call qsort(3).
+ * Reassemble the array in the order returned by qsort. If unable to
+ * sort for memory reasons, return the directory entries in their
+ * current order. Allocate enough space for the current needs plus
+ * 40 so don't realloc one entry at a time.
+ */
+ if (nitems > sp->fts_nitems) {
struct _ftsent** a;
- sp->fts_nitems = nitems + 40;
+ sp->fts_nitems = nitems + 40;
if ((a = (struct _ftsent**)realloc(sp->fts_array,
sp->fts_nitems * sizeof(FTSENT*))) == nullptr) {
if (sp->fts_array) {
- free(sp->fts_array);
+ free(sp->fts_array);
}
sp->fts_array = nullptr;
- sp->fts_nitems = 0;
- return (head);
- }
- sp->fts_array = a;
- }
+ sp->fts_nitems = 0;
+ return (head);
+ }
+ sp->fts_array = a;
+ }
for (ap = sp->fts_array, p = head; p; p = p->fts_link) {
- *ap++ = p;
+ *ap++ = p;
}
qsort((void*)sp->fts_array, (size_t)nitems, sizeof(FTSENT*), (int (*)(const void*, const void*))sp->fts_compar);
for (head = *(ap = sp->fts_array); --nitems; ++ap) {
- ap[0]->fts_link = ap[1];
+ ap[0]->fts_link = ap[1];
}
ap[0]->fts_link = nullptr;
- return (head);
+ return (head);
}
static FTSENT*
fts_alloc(FTS* sp, const char* name, int namelen)
{
FTSENT* p;
- size_t len;
-
- /*
- * The file name is a variable length array and no stat structure is
- * necessary if the user has set the nostat bit. Allocate the FTSENT
- * structure, the file name and the stat structure in one chunk, but
- * be careful that the stat structure is reasonably aligned. Since the
- * fts_name field is declared to be of size 1, the fts_name pointer is
- * namelen + 2 before the first possible address of the stat structure.
- */
- len = sizeof(FTSENT) + namelen;
+ size_t len;
+
+ /*
+ * The file name is a variable length array and no stat structure is
+ * necessary if the user has set the nostat bit. Allocate the FTSENT
+ * structure, the file name and the stat structure in one chunk, but
+ * be careful that the stat structure is reasonably aligned. Since the
+ * fts_name field is declared to be of size 1, the fts_name pointer is
+ * namelen + 2 before the first possible address of the stat structure.
+ */
+ len = sizeof(FTSENT) + namelen;
if (!ISSET(FTS_NOSTAT)) {
len += sizeof(stat_struct) + ALIGNBYTES;
}
@@ -1245,22 +1245,22 @@ fts_alloc(FTS* sp, const char* name, int namelen)
return nullptr;
}
- /* Copy the name and guarantee NUL termination. */
- memmove((void*)p->fts_name, (void*)name, (size_t)namelen);
- p->fts_name[namelen] = '\0';
+ /* Copy the name and guarantee NUL termination. */
+ memmove((void*)p->fts_name, (void*)name, (size_t)namelen);
+ p->fts_name[namelen] = '\0';
if (!ISSET(FTS_NOSTAT)) {
p->fts_statp = (stat_struct*)ALIGN(p->fts_name + namelen + 2);
}
- p->fts_namelen = (u_short)namelen;
- p->fts_path = sp->fts_path;
- p->fts_errno = 0;
- p->fts_flags = 0;
- p->fts_instr = FTS_NOINSTR;
- p->fts_number = 0;
+ p->fts_namelen = (u_short)namelen;
+ p->fts_path = sp->fts_path;
+ p->fts_errno = 0;
+ p->fts_flags = 0;
+ p->fts_instr = FTS_NOINSTR;
+ p->fts_number = 0;
p->fts_pointer = nullptr;
p->fts_type = FTS_NSOK;
- return (p);
+ return (p);
}
static void
@@ -1268,11 +1268,11 @@ fts_lfree(FTSENT* head)
{
FTSENT* p;
- /* Free a linked list of structures. */
+ /* Free a linked list of structures. */
while ((p = head) != nullptr) {
- head = head->fts_link;
- free(p);
- }
+ head = head->fts_link;
+ free(p);
+ }
}
/*
@@ -1284,7 +1284,7 @@ fts_lfree(FTSENT* head)
static int
fts_palloc(FTS* sp, size_t more)
{
- sp->fts_pathlen += more + 256;
+ sp->fts_pathlen += more + 256;
sp->fts_path = (char*)yreallocf(sp->fts_path, (size_t)sp->fts_pathlen);
return (sp->fts_path == nullptr);
}
@@ -1292,19 +1292,19 @@ fts_palloc(FTS* sp, size_t more)
static void
ADJUST(FTSENT* p, void* addr)
{
- if ((p)->fts_accpath >= (p)->fts_path &&
- (p)->fts_accpath < (p)->fts_path + (p)->fts_pathlen) {
+ if ((p)->fts_accpath >= (p)->fts_path &&
+ (p)->fts_accpath < (p)->fts_path + (p)->fts_pathlen) {
if (p->fts_accpath != p->fts_path) {
- errx(1, "fts ADJUST: accpath %p path %p",
+ errx(1, "fts ADJUST: accpath %p path %p",
p->fts_accpath, p->fts_path);
}
if (p->fts_level != 0) {
- errx(1, "fts ADJUST: level %d not 0", p->fts_level);
+ errx(1, "fts ADJUST: level %d not 0", p->fts_level);
}
- (p)->fts_accpath =
+ (p)->fts_accpath =
(char*)addr + ((p)->fts_accpath - (p)->fts_path);
- }
- (p)->fts_path = (char*)addr;
+ }
+ (p)->fts_path = (char*)addr;
}
/*
@@ -1323,29 +1323,29 @@ fts_padjust(FTS* sp)
(p)->fts_accpath = (addr); \
(p)->fts_path = addr; \
}
- /* Adjust the current set of children. */
+ /* Adjust the current set of children. */
for (p = sp->fts_child; p; p = p->fts_link) {
- ADJUST(p, addr);
+ ADJUST(p, addr);
}
- /* Adjust the rest of the tree. */
- for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) {
- ADJUST(p, addr);
- p = p->fts_link ? p->fts_link : p->fts_parent;
- }
+ /* Adjust the rest of the tree. */
+ for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) {
+ ADJUST(p, addr);
+ p = p->fts_link ? p->fts_link : p->fts_parent;
+ }
}
static size_t
fts_maxarglen(char* const* argv)
{
- size_t len, max;
+ size_t len, max;
for (max = 0; *argv; ++argv) {
if ((len = strlen(*argv)) > max) {
- max = len;
+ max = len;
}
}
- return (max + 1);
+ return (max + 1);
}
/*
@@ -1358,33 +1358,33 @@ fts_maxarglen(char* const* argv)
static int
fts_safe_changedir(FTS* sp, FTSENT* p, int fd, const char* path)
{
- int ret, oerrno, newfd;
+ int ret, oerrno, newfd;
stat_struct sb;
- newfd = fd;
+ newfd = fd;
if (ISSET(FTS_NOCHDIR)) {
- return (0);
+ return (0);
}
if (fd < 0 && (newfd = open(path, O_RDONLY, 0)) < 0) {
- return (-1);
- }
- if (fstat(newfd, &sb)) {
- ret = -1;
- goto bail;
+ return (-1);
}
- if (p->fts_dev != sb.st_dev || p->fts_ino != sb.st_ino) {
+ if (fstat(newfd, &sb)) {
+ ret = -1;
+ goto bail;
+ }
+ if (p->fts_dev != sb.st_dev || p->fts_ino != sb.st_ino) {
errno = ENOENT; /* disinformation */
- ret = -1;
- goto bail;
- }
- ret = fchdir(newfd);
+ ret = -1;
+ goto bail;
+ }
+ ret = fchdir(newfd);
bail:
- oerrno = errno;
+ oerrno = errno;
if (fd < 0) {
- (void)close(newfd);
+ (void)close(newfd);
}
- errno = oerrno;
- return (ret);
+ errno = oerrno;
+ return (ret);
}
#else
static int
diff --git a/util/generic/buffer.cpp b/util/generic/buffer.cpp
index b92697e1d0..cc39f809f3 100644
--- a/util/generic/buffer.cpp
+++ b/util/generic/buffer.cpp
@@ -1,7 +1,7 @@
#include "buffer.h"
#include "mem_copy.h"
#include "string.h"
-#include "ymath.h"
+#include "ymath.h"
#include <util/system/sys_alloc.h>
#include <util/system/sanitizers.h>
diff --git a/util/generic/buffer.h b/util/generic/buffer.h
index 9576467404..e7811a2fc9 100644
--- a/util/generic/buffer.h
+++ b/util/generic/buffer.h
@@ -6,7 +6,7 @@
#include <util/system/align.h>
#include <util/system/yassert.h>
-#include <cstring>
+#include <cstring>
class TBuffer {
public:
diff --git a/util/generic/hash.h b/util/generic/hash.h
index e46db21fa9..8d5e01bcaf 100644
--- a/util/generic/hash.h
+++ b/util/generic/hash.h
@@ -958,12 +958,12 @@ template <class V>
__yhashtable_iterator<V>& __yhashtable_iterator<V>::operator++() {
Y_ASSERT(cur);
cur = cur->next;
- if ((uintptr_t)cur & 1) {
+ if ((uintptr_t)cur & 1) {
node** bucket = (node**)((uintptr_t)cur & ~1);
while (*bucket == nullptr)
++bucket;
Y_ASSERT(*bucket != nullptr);
- cur = (node*)((uintptr_t)*bucket & ~1);
+ cur = (node*)((uintptr_t)*bucket & ~1);
}
return *this;
}
@@ -979,12 +979,12 @@ template <class V>
__yhashtable_const_iterator<V>& __yhashtable_const_iterator<V>::operator++() {
Y_ASSERT(cur);
cur = cur->next;
- if ((uintptr_t)cur & 1) {
+ if ((uintptr_t)cur & 1) {
node** bucket = (node**)((uintptr_t)cur & ~1);
while (*bucket == nullptr)
++bucket;
Y_ASSERT(*bucket != nullptr);
- cur = (node*)((uintptr_t)*bucket & ~1);
+ cur = (node*)((uintptr_t)*bucket & ~1);
}
return *this;
}
diff --git a/util/generic/intrlist_ut.cpp b/util/generic/intrlist_ut.cpp
index eff7cdf2ee..2d4a1a44df 100644
--- a/util/generic/intrlist_ut.cpp
+++ b/util/generic/intrlist_ut.cpp
@@ -236,12 +236,12 @@ static void CheckIterationAfterCut(const TMyList& l, const TMyList& l2, size_t N
UNIT_ASSERT_EQUAL(c, 0);
}
-static void TestCutFront(int N, int M) {
+static void TestCutFront(int N, int M) {
TMyList l(N);
TMyList l2(0);
TMyList::TIterator it = l.Begin();
- for (int i = 0; i < M; ++i) {
+ for (int i = 0; i < M; ++i) {
++it;
}
@@ -249,12 +249,12 @@ static void TestCutFront(int N, int M) {
CheckIterationAfterCut(l2, l, N, M);
}
-static void TestCutBack(int N, int M) {
+static void TestCutBack(int N, int M) {
TMyList l(N);
TMyList l2(0);
TMyList::TIterator it = l.Begin();
- for (int i = 0; i < M; ++i) {
+ for (int i = 0; i < M; ++i) {
++it;
}
@@ -291,7 +291,7 @@ static void CheckIterationAfterAppend(const TMyList& l, size_t N, size_t M) {
UNIT_ASSERT_EQUAL(it, l.End());
}
-static void TestAppend(int N, int M) {
+static void TestAppend(int N, int M) {
TMyList l(N);
TMyList l2(M);
l.Append(l2);
diff --git a/util/generic/ptr.h b/util/generic/ptr.h
index 19db0e3ec5..355ea932f8 100644
--- a/util/generic/ptr.h
+++ b/util/generic/ptr.h
@@ -398,15 +398,15 @@ public:
Y_ASSERT(resultCount >= 0);
(void)resultCount;
}
-
+
TRefCounted(const TRefCounted&)
: Counter_(0)
{
}
-
+
void operator=(const TRefCounted&) {
}
-
+
private:
C Counter_;
};
@@ -459,10 +459,10 @@ public:
t->UnRef();
}
-
+
static inline void DecRef(T* t) noexcept {
Y_ASSERT(t);
-
+
t->DecRef();
}
@@ -571,10 +571,10 @@ public:
if (T_) {
Ops::DecRef(T_);
T_ = nullptr;
- }
+ }
return res;
}
-
+
inline long RefCount() const noexcept {
return T_ ? Ops::RefCount(T_) : 0;
}
diff --git a/util/generic/ptr_ut.cpp b/util/generic/ptr_ut.cpp
index c2dcff23f6..0fdfb0d67e 100644
--- a/util/generic/ptr_ut.cpp
+++ b/util/generic/ptr_ut.cpp
@@ -293,76 +293,76 @@ void TPointerTest::TestCopyPtr() {
UNIT_ASSERT_VALUES_EQUAL(cnt, 0);
}
-
+
class TOp: public TSimpleRefCount<TOp>, public TNonCopyable {
-public:
- static int Cnt;
+public:
+ static int Cnt;
-public:
- TOp() {
- ++Cnt;
- }
+public:
+ TOp() {
+ ++Cnt;
+ }
virtual ~TOp() {
- --Cnt;
- }
-};
-
-int TOp::Cnt = 0;
-
+ --Cnt;
+ }
+};
+
+int TOp::Cnt = 0;
+
class TOp2: public TOp {
-public:
- TIntrusivePtr<TOp> Op;
-
-public:
- TOp2(const TIntrusivePtr<TOp>& op)
- : Op(op)
- {
- ++Cnt;
- }
+public:
+ TIntrusivePtr<TOp> Op;
+
+public:
+ TOp2(const TIntrusivePtr<TOp>& op)
+ : Op(op)
+ {
+ ++Cnt;
+ }
~TOp2() override {
- --Cnt;
- }
-};
-
-class TOp3 {
-public:
- TIntrusivePtr<TOp2> Op2;
-};
-
-void Attach(TOp3* op3, TIntrusivePtr<TOp>* op) {
- TIntrusivePtr<TOp2> op2 = new TOp2(*op);
- op3->Op2 = op2.Get();
- *op = op2.Get();
-}
-
+ --Cnt;
+ }
+};
+
+class TOp3 {
+public:
+ TIntrusivePtr<TOp2> Op2;
+};
+
+void Attach(TOp3* op3, TIntrusivePtr<TOp>* op) {
+ TIntrusivePtr<TOp2> op2 = new TOp2(*op);
+ op3->Op2 = op2.Get();
+ *op = op2.Get();
+}
+
void TPointerTest::TestIntrPtr() {
- {
- TIntrusivePtr<TOp> p, p2;
- TOp3 op3;
- {
+ {
+ TIntrusivePtr<TOp> p, p2;
+ TOp3 op3;
+ {
TVector<TIntrusivePtr<TOp>> f1;
- {
+ {
TVector<TIntrusivePtr<TOp>> f2;
- f2.push_back(new TOp);
- p = new TOp;
- f2.push_back(p);
- Attach(&op3, &f2[1]);
- f1 = f2;
+ f2.push_back(new TOp);
+ p = new TOp;
+ f2.push_back(p);
+ Attach(&op3, &f2[1]);
+ f1 = f2;
UNIT_ASSERT_VALUES_EQUAL(f1[0]->RefCount(), 2);
UNIT_ASSERT_VALUES_EQUAL(f1[1]->RefCount(), 3);
- UNIT_ASSERT_EQUAL(f1[1].Get(), op3.Op2.Get());
+ UNIT_ASSERT_EQUAL(f1[1].Get(), op3.Op2.Get());
UNIT_ASSERT_VALUES_EQUAL(op3.Op2->RefCount(), 3);
UNIT_ASSERT_VALUES_EQUAL(op3.Op2->Op->RefCount(), 2);
UNIT_ASSERT_VALUES_EQUAL(TOp::Cnt, 4);
- }
- p2 = p;
- }
+ }
+ p2 = p;
+ }
UNIT_ASSERT_VALUES_EQUAL(op3.Op2->RefCount(), 1);
UNIT_ASSERT_VALUES_EQUAL(op3.Op2->Op->RefCount(), 3);
UNIT_ASSERT_VALUES_EQUAL(TOp::Cnt, 3);
- }
+ }
UNIT_ASSERT_VALUES_EQUAL(TOp::Cnt, 0);
-}
+}
namespace NTestIntrusiveConvertion {
struct TA: public TSimpleRefCount<TA> {
diff --git a/util/generic/refcount.h b/util/generic/refcount.h
index 966e853b77..538f295e58 100644
--- a/util/generic/refcount.h
+++ b/util/generic/refcount.h
@@ -2,7 +2,7 @@
#include <util/system/guard.h>
#include <util/system/atomic.h>
-#include <util/system/defaults.h>
+#include <util/system/defaults.h>
#include <util/system/yassert.h>
template <class TCounterCheckPolicy>
diff --git a/util/generic/strbase.h b/util/generic/strbase.h
index ab39fc7537..dc8ce69dbc 100644
--- a/util/generic/strbase.h
+++ b/util/generic/strbase.h
@@ -9,7 +9,7 @@
#include <util/charset/unidata.h>
#include <util/system/platform.h>
-#include <util/system/yassert.h>
+#include <util/system/yassert.h>
#include <contrib/libs/libc_compat/string.h>
diff --git a/util/generic/string.cpp b/util/generic/string.cpp
index 3c655f1f66..279fc4f865 100644
--- a/util/generic/string.cpp
+++ b/util/generic/string.cpp
@@ -69,17 +69,17 @@ TBasicString<wchar16, std::char_traits<wchar16>>::AppendUtf8(const ::TStringBuf&
template <>
bool TBasicString<wchar16, std::char_traits<wchar16>>::to_lower(size_t pos, size_t n) {
return ToLower(*this, pos, n);
-}
-
+}
+
template <>
bool TBasicString<wchar16, std::char_traits<wchar16>>::to_upper(size_t pos, size_t n) {
return ToUpper(*this, pos, n);
-}
-
+}
+
template <>
bool TBasicString<wchar16, std::char_traits<wchar16>>::to_title(size_t pos, size_t n) {
return ToTitle(*this, pos, n);
-}
+}
template <>
TUtf32String&
diff --git a/util/generic/string.h b/util/generic/string.h
index 8cd8aa6917..7bff6fc224 100644
--- a/util/generic/string.h
+++ b/util/generic/string.h
@@ -6,12 +6,12 @@
#include <stdexcept>
#include <string>
#include <string_view>
-
-#include <util/system/yassert.h>
+
+#include <util/system/yassert.h>
#include <util/system/atomic.h>
#include "ptr.h"
-#include "utility.h"
+#include "utility.h"
#include "bitops.h"
#include "explicit_type.h"
#include "reserve.h"
diff --git a/util/generic/string_ut.h b/util/generic/string_ut.h
index 44bb10bdeb..0701a6d6d8 100644
--- a/util/generic/string_ut.h
+++ b/util/generic/string_ut.h
@@ -578,23 +578,23 @@ public:
// append family
s.append(Data.x());
UNIT_ASSERT(s == Data._0123456x());
-
+
#ifdef TSTRING_IS_STD_STRING
s.append(Data.xyz() + 1, 1);
#else
s.append(Data.xyz(), 1, 1);
#endif
UNIT_ASSERT(s == Data._0123456xy());
-
+
s.append(TStringType(Data.z()));
UNIT_ASSERT(s == Data._0123456xyz());
-
+
s.append(TStringType(Data.XYZ()), 2, 1);
UNIT_ASSERT(s == Data._0123456xyzZ());
-
+
s.append(*Data._0());
UNIT_ASSERT(s == Data._0123456xyzZ0());
-
+
// prepend family
s = Data._0123456xyz();
s.prepend(TStringType(Data.abc()));
@@ -649,7 +649,7 @@ public:
UNIT_ASSERT(s.at(s.size()) == 0);
UNIT_ASSERT(s[s.size()] == 0);
}
-
+
#ifndef TSTRING_IS_STD_STRING
void TestRefCount() {
using TStr = TStringType;
@@ -682,12 +682,12 @@ public:
UNIT_ASSERT(s.find(Data._345()) == 3);
UNIT_ASSERT(s.find(Data._345(), 5) == 10);
-
+
UNIT_ASSERT(s.find(Data._345(), 20) == TStringType::npos);
UNIT_ASSERT(s.find(*Data._3()) == 3);
UNIT_ASSERT(s.find(TStringType(Data._345())) == 3);
UNIT_ASSERT(s.find(TStringType(Data._345()), 2) == 3);
-
+
UNIT_ASSERT(s.find_first_of(TStringType(Data._389())) == 3);
UNIT_ASSERT(s.find_first_of(Data._389()) == 3);
UNIT_ASSERT(s.find_first_of(Data._389(), s.size()) == TStringType::npos);
@@ -696,7 +696,7 @@ public:
UNIT_ASSERT(s.find_first_of('1', 2) == 8);
UNIT_ASSERT(s.find_first_not_of('0') == 1);
UNIT_ASSERT(s.find_first_not_of('1', 1) == 2);
-
+
const TStringType rs = Data._0123401234();
UNIT_ASSERT(rs.rfind(*Data._3()) == 8);
@@ -720,8 +720,8 @@ public:
UNIT_ASSERT(s.rfind(TStringType(Data._345()), 6) == 3);
UNIT_ASSERT(s.rfind(TStringType(Data._345()), 3) == 3);
UNIT_ASSERT(s.rfind(TStringType(Data._345()), 2) == TStringType::npos);
- }
-
+ }
+
void TestContains() {
const TStringType s(Data._0123456_12345());
const TStringType s2(Data._0123());
@@ -743,7 +743,7 @@ public:
void TestOperators() {
TStringType s(Data._0123456());
-
+
// operator +=
s += TStringType(Data.x());
UNIT_ASSERT(s == Data._0123456x());
diff --git a/util/generic/vector.h b/util/generic/vector.h
index a5b258955a..92ec4488e9 100644
--- a/util/generic/vector.h
+++ b/util/generic/vector.h
@@ -1,5 +1,5 @@
#pragma once
-
+
#include "fwd.h"
#include "reserve.h"
@@ -129,4 +129,4 @@ public:
this->erase(this->begin() + size, this->end());
}
}
-};
+};
diff --git a/util/generic/yexception_ut.cpp b/util/generic/yexception_ut.cpp
index cb3e29fed8..a0a4e1c06c 100644
--- a/util/generic/yexception_ut.cpp
+++ b/util/generic/yexception_ut.cpp
@@ -21,8 +21,8 @@ static inline void Throw2DontMove() {
#if defined(_MSC_VER)
#pragma warning(disable : 4702) /*unreachable code*/
-#endif
-
+#endif
+
static void CallbackFun(int i) {
throw i;
}
diff --git a/util/generic/ymath.cpp b/util/generic/ymath.cpp
index 31270728f4..d713267537 100644
--- a/util/generic/ymath.cpp
+++ b/util/generic/ymath.cpp
@@ -8,7 +8,7 @@ float Exp2f(float x) {
return powf(2.0f, x);
}
-#ifdef _MSC_VER
+#ifdef _MSC_VER
double Erf(double x) {
static constexpr double _M_2_SQRTPI = 1.12837916709551257390;
diff --git a/util/generic/ymath.h b/util/generic/ymath.h
index 9ff9ae2abe..9ed3110211 100644
--- a/util/generic/ymath.h
+++ b/util/generic/ymath.h
@@ -68,7 +68,7 @@ static inline bool IsFinite(double f) {
#if defined(isfinite)
return isfinite(f);
#elif defined(_win_)
- return _finite(f) != 0;
+ return _finite(f) != 0;
#elif defined(_darwin_)
return isfinite(f);
#elif defined(__GNUC__)
@@ -82,7 +82,7 @@ static inline bool IsFinite(double f) {
static inline bool IsNan(double f) {
#if defined(_win_)
- return _isnan(f) != 0;
+ return _isnan(f) != 0;
#else
return std::isnan(f);
#endif
@@ -92,7 +92,7 @@ inline bool IsValidFloat(double f) {
return IsFinite(f) && !IsNan(f);
}
-#ifdef _MSC_VER
+#ifdef _MSC_VER
double Erf(double x);
#else
inline double Erf(double x) {
diff --git a/util/memory/blob.cpp b/util/memory/blob.cpp
index 91da5cadca..ab5bb88fc1 100644
--- a/util/memory/blob.cpp
+++ b/util/memory/blob.cpp
@@ -166,7 +166,7 @@ TBlob TBlob::SubBlob(size_t begin, size_t end) const {
}
TBlob TBlob::DeepCopy() const {
- return TBlob::Copy(Data(), Length());
+ return TBlob::Copy(Data(), Length());
}
template <class TCounter>
@@ -184,11 +184,11 @@ static inline TBlob CopyConstruct(const void* data, size_t len) {
return ret;
}
-TBlob TBlob::CopySingleThreaded(const void* data, size_t length) {
+TBlob TBlob::CopySingleThreaded(const void* data, size_t length) {
return CopyConstruct<TSimpleCounter>(data, length);
}
-TBlob TBlob::Copy(const void* data, size_t length) {
+TBlob TBlob::Copy(const void* data, size_t length) {
return CopyConstruct<TAtomicCounter>(data, length);
}
@@ -292,11 +292,11 @@ TBlob TBlob::LockedFromMemoryMap(const TMemoryMap& map, ui64 offset, size_t leng
return ConstructFromMap<TAtomicCounter>(map, offset, length, EMappingMode::Locked);
}
-TBlob TBlob::FromMemoryMapSingleThreaded(const TMemoryMap& map, ui64 offset, size_t length) {
+TBlob TBlob::FromMemoryMapSingleThreaded(const TMemoryMap& map, ui64 offset, size_t length) {
return ConstructFromMap<TSimpleCounter>(map, offset, length, EMappingMode::Standard);
}
-TBlob TBlob::FromMemoryMap(const TMemoryMap& map, ui64 offset, size_t length) {
+TBlob TBlob::FromMemoryMap(const TMemoryMap& map, ui64 offset, size_t length) {
return ConstructFromMap<TAtomicCounter>(map, offset, length, EMappingMode::Standard);
}
@@ -334,34 +334,34 @@ TBlob TBlob::FromFileContent(const TString& path) {
return ConstructFromFileContent<TAtomicCounter>(file, 0, file.GetLength());
}
-TBlob TBlob::FromFileContentSingleThreaded(const TFile& file) {
+TBlob TBlob::FromFileContentSingleThreaded(const TFile& file) {
return ConstructFromFileContent<TSimpleCounter>(file, 0, file.GetLength());
}
-TBlob TBlob::FromFileContent(const TFile& file) {
+TBlob TBlob::FromFileContent(const TFile& file) {
return ConstructFromFileContent<TAtomicCounter>(file, 0, file.GetLength());
}
-TBlob TBlob::FromFileContentSingleThreaded(const TFile& file, ui64 offset, size_t length) {
+TBlob TBlob::FromFileContentSingleThreaded(const TFile& file, ui64 offset, size_t length) {
return ConstructFromFileContent<TSimpleCounter>(file, offset, length);
}
-TBlob TBlob::FromFileContent(const TFile& file, ui64 offset, size_t length) {
+TBlob TBlob::FromFileContent(const TFile& file, ui64 offset, size_t length) {
return ConstructFromFileContent<TAtomicCounter>(file, offset, length);
}
template <class TCounter>
-static inline TBlob ConstructFromBuffer(TBuffer& in) {
+static inline TBlob ConstructFromBuffer(TBuffer& in) {
using TBase = TBufferBlobBase<TCounter>;
- THolder<TBase> base(new TBase(in));
-
- TBlob ret(base->Buffer().Data(), base->Buffer().Size(), base.Get());
+ THolder<TBase> base(new TBase(in));
+
+ TBlob ret(base->Buffer().Data(), base->Buffer().Size(), base.Get());
Y_UNUSED(base.Release());
-
- return ret;
-}
-
-template <class TCounter>
+
+ return ret;
+}
+
+template <class TCounter>
static inline TBlob ConstructFromStream(IInputStream& in) {
TBuffer buf;
@@ -371,7 +371,7 @@ static inline TBlob ConstructFromStream(IInputStream& in) {
TransferData(&in, &out);
}
- return ConstructFromBuffer<TCounter>(buf);
+ return ConstructFromBuffer<TCounter>(buf);
}
TBlob TBlob::FromStreamSingleThreaded(IInputStream& in) {
@@ -381,14 +381,14 @@ TBlob TBlob::FromStreamSingleThreaded(IInputStream& in) {
TBlob TBlob::FromStream(IInputStream& in) {
return ConstructFromStream<TAtomicCounter>(in);
}
-
-TBlob TBlob::FromBufferSingleThreaded(TBuffer& in) {
- return ConstructFromBuffer<TSimpleCounter>(in);
-}
-
-TBlob TBlob::FromBuffer(TBuffer& in) {
- return ConstructFromBuffer<TAtomicCounter>(in);
-}
+
+TBlob TBlob::FromBufferSingleThreaded(TBuffer& in) {
+ return ConstructFromBuffer<TSimpleCounter>(in);
+}
+
+TBlob TBlob::FromBuffer(TBuffer& in) {
+ return ConstructFromBuffer<TAtomicCounter>(in);
+}
template <class TCounter, class S>
TBlob ConstructFromString(S&& s) {
diff --git a/util/memory/blob.h b/util/memory/blob.h
index 20c02a68df..84d4ebaa4d 100644
--- a/util/memory/blob.h
+++ b/util/memory/blob.h
@@ -7,8 +7,8 @@
class TMemoryMap;
class IInputStream;
-class TFile;
-class TBuffer;
+class TFile;
+class TBuffer;
enum class EMappingMode {
/// Just mmap a file allowing lazy page loading at access
@@ -289,11 +289,11 @@ public:
/// Creates a blob with a single-threaded (non atomic) refcounter. No memory allocation, no content copy.
/// @details The input object becomes empty.
static TBlob FromBufferSingleThreaded(TBuffer& in);
-
+
/// Creates a blob with a multi-threaded (atomic) refcounter. No memory allocation, no content copy.
/// @details The input object becomes empty.
static TBlob FromBuffer(TBuffer& in);
-
+
/// Creates a blob from TString with a single-threaded (non atomic) refcounter.
static TBlob FromStringSingleThreaded(const TString& s);
diff --git a/util/memory/blob_ut.cpp b/util/memory/blob_ut.cpp
index 023f9a0487..405717c275 100644
--- a/util/memory/blob_ut.cpp
+++ b/util/memory/blob_ut.cpp
@@ -1,7 +1,7 @@
#include "blob.h"
#include <library/cpp/testing/unittest/registar.h>
-
+
#include <util/system/tempfile.h>
#include <util/folder/path.h>
#include <util/stream/output.h>
@@ -13,7 +13,7 @@ Y_UNIT_TEST_SUITE(TBlobTest) {
Y_UNIT_TEST(TestSubBlob) {
TBlob child;
const char* p = nullptr;
-
+
{
TBlob parent = TBlob::CopySingleThreaded("0123456789", 10);
UNIT_ASSERT_EQUAL(parent.Length(), 10);
@@ -21,12 +21,12 @@ Y_UNIT_TEST_SUITE(TBlobTest) {
UNIT_ASSERT_EQUAL(memcmp(p, "0123456789", 10), 0);
child = parent.SubBlob(2, 5);
} // Don't worry about parent
-
+
UNIT_ASSERT_EQUAL(child.Length(), 3);
UNIT_ASSERT_EQUAL(memcmp(child.AsCharPtr(), "234", 3), 0);
UNIT_ASSERT_EQUAL(p + 2, child.AsCharPtr());
}
-
+
Y_UNIT_TEST(TestFromStream) {
TString s("sjklfgsdyutfuyas54fa78s5f89a6df790asdf7");
TMemoryInput mi(s.data(), s.size());
diff --git a/util/memory/segmented_string_pool.h b/util/memory/segmented_string_pool.h
index a40aa408f5..bb8818e7b6 100644
--- a/util/memory/segmented_string_pool.h
+++ b/util/memory/segmented_string_pool.h
@@ -11,17 +11,17 @@
#include <cstdio>
#include <cstdlib>
-/*
- * Non-reallocated storage for the objects of POD type
- */
+/*
+ * Non-reallocated storage for the objects of POD type
+ */
template <class T, class Alloc = std::allocator<T>>
class segmented_pool: TNonCopyable {
-protected:
+protected:
Alloc seg_allocator;
struct seg_inf {
T* data; // allocated chunk
- size_t _size; // size of allocated chunk in sizeof(T)-units
- size_t freepos; // offset to free chunk's memory in bytes
+ size_t _size; // size of allocated chunk in sizeof(T)-units
+ size_t freepos; // offset to free chunk's memory in bytes
seg_inf()
: data(nullptr)
, _size(0)
@@ -38,63 +38,63 @@ protected:
using seg_container = TVector<seg_inf>;
using seg_iterator = typename seg_container::iterator;
using seg_const_iterator = typename seg_container::const_iterator;
- const size_t segment_size; // default size of a memory chunk in sizeof(T)-units
- size_t last_free; // size of free memory in chunk in sizeof(T)-units
- size_t last_ins_size; // size of memory used in chunk by the last append() in bytes
- seg_container segs; // array of memory chunks
- seg_iterator curseg; // a segment for the current insertion
- const char* Name; // for debug memory usage
-protected:
- void check_capacity(size_t len) {
+ const size_t segment_size; // default size of a memory chunk in sizeof(T)-units
+ size_t last_free; // size of free memory in chunk in sizeof(T)-units
+ size_t last_ins_size; // size of memory used in chunk by the last append() in bytes
+ seg_container segs; // array of memory chunks
+ seg_iterator curseg; // a segment for the current insertion
+ const char* Name; // for debug memory usage
+protected:
+ void check_capacity(size_t len) {
if (Y_UNLIKELY(!last_free || len > last_free)) {
- if (curseg != segs.end() && curseg->freepos > 0)
- ++curseg;
- last_free = (len > segment_size ? len : segment_size);
- if (curseg == segs.end() || curseg->_size < last_free) {
- segs.push_back(seg_inf(seg_allocator.allocate(last_free), last_free));
+ if (curseg != segs.end() && curseg->freepos > 0)
+ ++curseg;
+ last_free = (len > segment_size ? len : segment_size);
+ if (curseg == segs.end() || curseg->_size < last_free) {
+ segs.push_back(seg_inf(seg_allocator.allocate(last_free), last_free));
if (Y_UNLIKELY(Name))
printf("Pool \"%s\" was increased by %" PRISZT " bytes to %" PRISZT " Mb.\n", Name, last_free * sizeof(T), capacity() / 0x100000);
- curseg = segs.end() - 1;
- }
+ curseg = segs.end() - 1;
+ }
Y_ASSERT(curseg->freepos == 0);
Y_ASSERT(curseg->_size >= last_free);
- }
- }
+ }
+ }
-public:
+public:
explicit segmented_pool(size_t segsz, const char* name = nullptr)
: segment_size(segsz)
, last_free(0)
, last_ins_size(0)
, Name(name)
- {
- curseg = segs.begin();
- }
- ~segmented_pool() {
- clear();
+ {
+ curseg = segs.begin();
+ }
+ ~segmented_pool() {
+ clear();
}
- /* src - array of objects, len - count of elements in array */
+ /* src - array of objects, len - count of elements in array */
T* append(const T* src, size_t len) {
- check_capacity(len);
+ check_capacity(len);
ui8* rv = (ui8*)curseg->data + curseg->freepos;
- last_ins_size = sizeof(T) * len;
- if (src)
- memcpy(rv, src, last_ins_size);
- curseg->freepos += last_ins_size, last_free -= len;
- return (T*)rv;
+ last_ins_size = sizeof(T) * len;
+ if (src)
+ memcpy(rv, src, last_ins_size);
+ curseg->freepos += last_ins_size, last_free -= len;
+ return (T*)rv;
}
T* append() {
- T* obj = get_raw();
+ T* obj = get_raw();
new (obj) T();
- return obj;
+ return obj;
}
T* get_raw() { // append(0, 1)
- check_capacity(1);
+ check_capacity(1);
ui8* rv = (ui8*)curseg->data + curseg->freepos;
- last_ins_size = sizeof(T);
- curseg->freepos += last_ins_size, last_free -= 1;
- return (T*)rv;
- }
+ last_ins_size = sizeof(T);
+ curseg->freepos += last_ins_size, last_free -= 1;
+ return (T*)rv;
+ }
size_t get_segment_size() const {
return segment_size;
}
@@ -104,27 +104,27 @@ public:
return true;
return false;
}
- size_t size() const {
- size_t r = 0;
- for (seg_const_iterator i = segs.begin(); i != segs.end(); ++i)
- r += i->freepos;
- return r;
- }
- size_t capacity() const {
- return segs.size() * segment_size * sizeof(T);
- }
- void restart() {
+ size_t size() const {
+ size_t r = 0;
+ for (seg_const_iterator i = segs.begin(); i != segs.end(); ++i)
+ r += i->freepos;
+ return r;
+ }
+ size_t capacity() const {
+ return segs.size() * segment_size * sizeof(T);
+ }
+ void restart() {
if (curseg != segs.end())
++curseg;
for (seg_iterator i = segs.begin(); i != curseg; ++i)
- i->freepos = 0;
- curseg = segs.begin();
- last_free = 0;
- last_ins_size = 0;
- }
+ i->freepos = 0;
+ curseg = segs.begin();
+ last_free = 0;
+ last_ins_size = 0;
+ }
void clear() {
- for (seg_iterator i = segs.begin(); i != segs.end(); ++i)
- seg_allocator.deallocate(i->data, i->_size);
+ for (seg_iterator i = segs.begin(); i != segs.end(); ++i)
+ seg_allocator.deallocate(i->data, i->_size);
segs.clear();
curseg = segs.begin();
last_free = 0;
@@ -132,25 +132,25 @@ public:
}
void undo_last_append() {
Y_ASSERT(curseg != segs.end()); // do not use before append()
- if (last_ins_size) {
+ if (last_ins_size) {
Y_ASSERT(last_ins_size <= curseg->freepos);
- curseg->freepos -= last_ins_size;
- last_free += last_ins_size / sizeof(T);
+ curseg->freepos -= last_ins_size;
+ last_free += last_ins_size / sizeof(T);
last_ins_size = 0;
}
}
- void alloc_first_seg() {
+ void alloc_first_seg() {
Y_ASSERT(capacity() == 0);
- check_capacity(segment_size);
+ check_capacity(segment_size);
Y_ASSERT(capacity() == segment_size * sizeof(T));
- }
+ }
};
class segmented_string_pool: public segmented_pool<char> {
-private:
+private:
using _Base = segmented_pool<char>;
-public:
+public:
segmented_string_pool()
: segmented_string_pool(1024 * 1024)
{
@@ -162,8 +162,8 @@ public:
}
char* append(const char* src) {
Y_ASSERT(src);
- return _Base::append(src, strlen(src) + 1);
- }
+ return _Base::append(src, strlen(src) + 1);
+ }
char* append(const char* src, size_t len) {
char* rv = _Base::append(nullptr, len + 1);
if (src)
@@ -174,16 +174,16 @@ public:
char* Append(const TStringBuf s) {
return append(s.data(), s.size());
}
- void align_4() {
- size_t t = (curseg->freepos + 3) & ~3;
- last_free -= t - curseg->freepos;
- curseg->freepos = t;
- }
+ void align_4() {
+ size_t t = (curseg->freepos + 3) & ~3;
+ last_free -= t - curseg->freepos;
+ curseg->freepos = t;
+ }
char* Allocate(size_t len) {
return append(nullptr, len);
}
-};
-
+};
+
template <typename T, typename C>
inline T* pool_push(segmented_pool<C>& pool, const T* v) {
static_assert(sizeof(C) == 1, "only char type supported");
diff --git a/util/memory/segpool_alloc.h b/util/memory/segpool_alloc.h
index 1a83b7a543..78a7bad222 100644
--- a/util/memory/segpool_alloc.h
+++ b/util/memory/segpool_alloc.h
@@ -1,6 +1,6 @@
#pragma once
-#include "segmented_string_pool.h"
+#include "segmented_string_pool.h"
/**
This is a partially implemented allocator class that uses segmented_pool
diff --git a/util/network/address.h b/util/network/address.h
index 448fcac0c9..f6ea9bf117 100644
--- a/util/network/address.h
+++ b/util/network/address.h
@@ -87,7 +87,7 @@ namespace NAddr {
}
socklen_t Len() const override {
- return (socklen_t)AI_->ai_addrlen;
+ return (socklen_t)AI_->ai_addrlen;
}
private:
diff --git a/util/network/init.h b/util/network/init.h
index 08a79c0fca..16c27770f6 100644
--- a/util/network/init.h
+++ b/util/network/init.h
@@ -33,16 +33,16 @@ using SOCKET = int;
using nfds_t = ULONG;
#undef Yield
-
+
struct sockaddr_un {
short sun_family;
char sun_path[108];
};
-
+
#define PF_LOCAL AF_UNIX
#define NETDB_INTERNAL -1
#define NETDB_SUCCESS 0
-
+
#endif
#if defined(_win_) || defined(_darwin_)
diff --git a/util/network/ip.h b/util/network/ip.h
index dc7c2d24a0..ad53edad85 100644
--- a/util/network/ip.h
+++ b/util/network/ip.h
@@ -29,7 +29,7 @@ static inline TIpHost IpFromString(const char* ipStr) {
}
static inline char* IpToString(TIpHost ip, char* buf, size_t len) {
- if (!inet_ntop(AF_INET, (void*)&ip, buf, (socklen_t)len)) {
+ if (!inet_ntop(AF_INET, (void*)&ip, buf, (socklen_t)len)) {
ythrow TSystemError() << "Failed to get ip address string";
}
diff --git a/util/network/pollerimpl.h b/util/network/pollerimpl.h
index e8c7e40fba..a9e8dffe9d 100644
--- a/util/network/pollerimpl.h
+++ b/util/network/pollerimpl.h
@@ -360,7 +360,7 @@ struct TSelectPollerNoTemplate {
(*this)[fd].Set(data, filter);
}
- inline void Remove(SOCKET fd) {
+ inline void Remove(SOCKET fd) {
erase(fd);
}
@@ -424,7 +424,7 @@ public:
closesocket(Signal_[1]);
}
- inline void SetImpl(void* data, SOCKET fd, int what) {
+ inline void SetImpl(void* data, SOCKET fd, int what) {
with_lock (CommandLock_) {
Commands_.push_back(TCommand(fd, what, data));
}
@@ -512,7 +512,7 @@ public:
tout.tv_sec = timeout / 1000000;
tout.tv_usec = timeout % 1000000;
- int ret = ContSelect(int(maxFdNum + 1), in, out, errFds, &tout);
+ int ret = ContSelect(int(maxFdNum + 1), in, out, errFds, &tout);
if (ret > 0 && FD_ISSET(WaitSock(), in)) {
--ret;
@@ -524,7 +524,7 @@ public:
TEvent* eventsStart = events;
for (typename TFds::iterator it = Fds_.begin(); it != Fds_.end(); ++it) {
- const SOCKET fd = it->first;
+ const SOCKET fd = it->first;
THandle& handle = it->second;
if (FD_ISSET(fd, errFds)) {
@@ -659,7 +659,7 @@ public:
using TEvent = typename TBase::TEvent;
- inline void Set(void* data, SOCKET fd, int what) {
+ inline void Set(void* data, SOCKET fd, int what) {
if (what) {
this->SetImpl(data, fd, what);
} else {
diff --git a/util/network/sock.h b/util/network/sock.h
index b10be2f715..53ddd4b61b 100644
--- a/util/network/sock.h
+++ b/util/network/sock.h
@@ -4,7 +4,7 @@
#include <util/system/defaults.h>
#include <util/string/cast.h>
#include <util/stream/output.h>
-#include <util/system/sysstat.h>
+#include <util/system/sysstat.h>
#if defined(_win_) || defined(_cygwin_)
#include <util/system/file.h>
@@ -193,7 +193,7 @@ struct TSockAddrLocal: public sockaddr_un, public ISockAddr {
if (ret < 0)
return -errno;
- ret = Chmod(sun_path, mode);
+ ret = Chmod(sun_path, mode);
if (ret < 0)
return -errno;
return 0;
@@ -365,7 +365,7 @@ public:
static ssize_t Check(ssize_t ret, const char* op = "") {
if (ret < 0)
- ythrow TSystemError(-(int)ret) << "socket operation " << op;
+ ythrow TSystemError(-(int)ret) << "socket operation " << op;
return ret;
}
};
@@ -461,7 +461,7 @@ public:
s = accept((SOCKET) * this, nullptr, nullptr);
}
- if (s == INVALID_SOCKET)
+ if (s == INVALID_SOCKET)
return -errno;
TSocketHolder sock(s);
@@ -569,7 +569,7 @@ protected:
return (size_t)ret;
}
- ythrow TSystemError(-(int)ret) << "can not read from socket input stream";
+ ythrow TSystemError(-(int)ret) << "can not read from socket input stream";
}
};
@@ -597,7 +597,7 @@ protected:
const ssize_t ret = Socket->Send(ptr, len);
if (ret < 0) {
- ythrow TSystemError(-(int)ret) << "can not write to socket output stream";
+ ythrow TSystemError(-(int)ret) << "can not write to socket output stream";
}
Y_ASSERT((size_t)ret <= len);
diff --git a/util/network/socket.cpp b/util/network/socket.cpp
index 4f6e804346..597740e285 100644
--- a/util/network/socket.cpp
+++ b/util/network/socket.cpp
@@ -6,7 +6,7 @@
#include <util/system/defaults.h>
#include <util/system/byteorder.h>
-
+
#if defined(_unix_)
#include <netdb.h>
#include <sys/types.h>
@@ -51,16 +51,16 @@ using namespace NAddr;
#if defined(_win_)
int inet_aton(const char* cp, struct in_addr* inp) {
- sockaddr_in addr;
- addr.sin_family = AF_INET;
- int psz = sizeof(addr);
+ sockaddr_in addr;
+ addr.sin_family = AF_INET;
+ int psz = sizeof(addr);
if (0 == WSAStringToAddress((char*)cp, AF_INET, nullptr, (LPSOCKADDR)&addr, &psz)) {
- memcpy(inp, &addr.sin_addr, sizeof(in_addr));
- return 1;
- }
- return 0;
-}
-
+ memcpy(inp, &addr.sin_addr, sizeof(in_addr));
+ return 1;
+ }
+ return 0;
+}
+
#if (_WIN32_WINNT < 0x0600)
const char* inet_ntop(int af, const void* src, char* dst, socklen_t size) {
if (af != AF_INET) {
@@ -238,8 +238,8 @@ int poll(struct pollfd fds[], nfds_t nfds, int timeout) noexcept {
}
#endif
-#endif
-
+#endif
+
bool GetRemoteAddr(SOCKET Socket, char* str, socklen_t size) {
if (!size) {
return false;
@@ -267,7 +267,7 @@ bool GetRemoteAddr(SOCKET Socket, char* str, socklen_t size) {
void SetSocketTimeout(SOCKET s, long timeout) {
SetSocketTimeout(s, timeout, 0);
-}
+}
void SetSocketTimeout(SOCKET s, long sec, long msec) {
#ifdef SO_SNDTIMEO
@@ -282,15 +282,15 @@ void SetSocketTimeout(SOCKET s, long sec, long msec) {
CheckedSetSockOpt(s, SOL_SOCKET, SO_SNDTIMEO, timeout, "send timeout");
#endif
}
-
+
void SetLinger(SOCKET s, bool on, unsigned len) {
-#ifdef SO_LINGER
- struct linger l = {on, (u_short)len};
+#ifdef SO_LINGER
+ struct linger l = {on, (u_short)len};
CheckedSetSockOpt(s, SOL_SOCKET, SO_LINGER, l, "linger");
-#endif
-}
-
+#endif
+}
+
void SetZeroLinger(SOCKET s) {
SetLinger(s, 1, 0);
}
@@ -659,7 +659,7 @@ static inline SOCKET DoConnectImpl(const struct addrinfo* res, const TInstant& d
SetNonBlock(s, true);
- if (connect(s, res->ai_addr, (int)res->ai_addrlen)) {
+ if (connect(s, res->ai_addr, (int)res->ai_addrlen)) {
int err = LastSystemError();
if (err == EINPROGRESS || err == EAGAIN || err == EWOULDBLOCK) {
@@ -671,13 +671,13 @@ static inline SOCKET DoConnectImpl(const struct addrinfo* res, const TInstant& d
POLLOUT,
0};
- const ssize_t n = PollD(&p, 1, deadLine);
+ const ssize_t n = PollD(&p, 1, deadLine);
/*
* timeout occured
*/
if (n < 0) {
- ythrow TSystemError(-(int)n) << "can not connect";
+ ythrow TSystemError(-(int)n) << "can not connect";
}
CheckedGetSockOpt(s, SOL_SOCKET, SO_ERROR, err, "socket error");
@@ -902,7 +902,7 @@ size_t TSocketInput::DoRead(void* buf, size_t len) {
return (size_t)ret;
}
- ythrow TSystemError(-(int)ret) << "can not read from socket input stream";
+ ythrow TSystemError(-(int)ret) << "can not read from socket input stream";
}
TSocketOutput::TSocketOutput(const TSocket& s) noexcept
@@ -936,7 +936,7 @@ void TSocketOutput::DoWriteV(const TPart* parts, size_t count) {
const ssize_t ret = S_.SendV(parts, count);
if (ret < 0) {
- ythrow TSystemError(-(int)ret) << "can not writev to socket output stream";
+ ythrow TSystemError(-(int)ret) << "can not writev to socket output stream";
}
/*
@@ -1157,7 +1157,7 @@ static inline bool FlagsAreEnabled(int fd, int flags) {
#endif
#if defined(_win_)
-static inline void SetNonBlockSocket(SOCKET fd, int value) {
+static inline void SetNonBlockSocket(SOCKET fd, int value) {
unsigned long inbuf = value;
unsigned long outbuf = 0;
DWORD written = 0;
@@ -1171,7 +1171,7 @@ static inline void SetNonBlockSocket(SOCKET fd, int value) {
}
}
-static inline bool IsNonBlockSocket(SOCKET fd) {
+static inline bool IsNonBlockSocket(SOCKET fd) {
unsigned long buf = 0;
if (WSAIoctl(fd, FIONBIO, 0, 0, &buf, sizeof(buf), 0, 0, 0) == SOCKET_ERROR) {
@@ -1182,7 +1182,7 @@ static inline bool IsNonBlockSocket(SOCKET fd) {
}
#endif
-void SetNonBlock(SOCKET fd, bool value) {
+void SetNonBlock(SOCKET fd, bool value) {
#if defined(_unix_)
#if defined(FIONBIO)
Y_UNUSED(SetFlag); // shut up clang about unused function
@@ -1201,7 +1201,7 @@ void SetNonBlock(SOCKET fd, bool value) {
#endif
}
-bool IsNonBlock(SOCKET fd) {
+bool IsNonBlock(SOCKET fd) {
#if defined(_unix_)
return FlagsAreEnabled(fd, O_NONBLOCK);
#elif defined(_win_)
diff --git a/util/network/socket.h b/util/network/socket.h
index 40c8648b40..ea9c01f6bb 100644
--- a/util/network/socket.h
+++ b/util/network/socket.h
@@ -1,17 +1,17 @@
#pragma once
-
+
#include "init.h"
#include <util/system/yassert.h>
#include <util/system/defaults.h>
-#include <util/system/error.h>
+#include <util/system/error.h>
#include <util/stream/output.h>
#include <util/stream/input.h>
#include <util/generic/ptr.h>
#include <util/generic/yexception.h>
#include <util/generic/noncopyable.h>
#include <util/datetime/base.h>
-
+
#include <cerrno>
#ifndef INET_ADDRSTRLEN
@@ -50,14 +50,14 @@ int poll(struct pollfd fds[], nfds_t nfds, int timeout) noexcept;
int inet_aton(const char* cp, struct in_addr* inp);
#define get_host_error() WSAGetLastError()
-
+
#define SHUT_RD SD_RECEIVE
#define SHUT_WR SD_SEND
#define SHUT_RDWR SD_BOTH
#define INFTIM (-1)
-#endif
-
+#endif
+
template <class T>
static inline int SetSockOpt(SOCKET s, int level, int optname, T opt) noexcept {
return setsockopt(s, level, optname, (const char*)&opt, sizeof(opt));
@@ -141,8 +141,8 @@ bool HasLocalAddress(SOCKET socket);
**/
extern "C" bool IsReusePortAvailable();
-bool IsNonBlock(SOCKET fd);
-void SetNonBlock(SOCKET fd, bool nonBlock = true);
+bool IsNonBlock(SOCKET fd);
+void SetNonBlock(SOCKET fd, bool nonBlock = true);
struct addrinfo;
diff --git a/util/network/socket_ut.cpp b/util/network/socket_ut.cpp
index 6b20e11f70..ff7a9e6279 100644
--- a/util/network/socket_ut.cpp
+++ b/util/network/socket_ut.cpp
@@ -312,29 +312,29 @@ void TPollTest::TestPollInOut() {
}
}
- int expectedCount = 0;
+ int expectedCount = 0;
for (size_t i = 0; i < connectedSockets.size(); ++i) {
pollfd fd = {(i % 5 == 4) ? INVALID_SOCKET : static_cast<SOCKET>(*connectedSockets[i]), POLLIN | POLLOUT, 0};
fds.push_back(fd);
- if (i % 5 != 4)
- ++expectedCount;
+ if (i % 5 != 4)
+ ++expectedCount;
}
int polledCount = poll(&fds[0], fds.size(), INFTIM);
- UNIT_ASSERT_EQUAL(expectedCount, polledCount);
+ UNIT_ASSERT_EQUAL(expectedCount, polledCount);
for (size_t i = 0; i < connectedSockets.size(); ++i) {
- short revents = fds[i].revents;
+ short revents = fds[i].revents;
if (i % 5 == 0) {
- UNIT_ASSERT_EQUAL(static_cast<short>(POLLRDNORM | POLLWRNORM), revents);
+ UNIT_ASSERT_EQUAL(static_cast<short>(POLLRDNORM | POLLWRNORM), revents);
} else if (i % 5 == 1) {
- UNIT_ASSERT_EQUAL(static_cast<short>(POLLOUT | POLLWRNORM), revents);
+ UNIT_ASSERT_EQUAL(static_cast<short>(POLLOUT | POLLWRNORM), revents);
} else if (i % 5 == 2) {
- UNIT_ASSERT_EQUAL(static_cast<short>(POLLHUP | POLLRDNORM | POLLWRNORM), revents);
+ UNIT_ASSERT_EQUAL(static_cast<short>(POLLHUP | POLLRDNORM | POLLWRNORM), revents);
} else if (i % 5 == 3) {
- UNIT_ASSERT_EQUAL(static_cast<short>(POLLHUP | POLLWRNORM), revents);
+ UNIT_ASSERT_EQUAL(static_cast<short>(POLLHUP | POLLWRNORM), revents);
} else if (i % 5 == 4) {
- UNIT_ASSERT_EQUAL(static_cast<short>(POLLNVAL), revents);
+ UNIT_ASSERT_EQUAL(static_cast<short>(POLLNVAL), revents);
}
}
#endif
diff --git a/util/str_stl.h b/util/str_stl.h
index f1e137181d..3e7f61e551 100644
--- a/util/str_stl.h
+++ b/util/str_stl.h
@@ -59,8 +59,8 @@ namespace NHashPrivate {
template <class T>
struct hash: public NHashPrivate::THashHelper<T, std::is_scalar<T>::value && !std::is_integral<T>::value> {
-};
-
+};
+
template <typename T>
struct hash<const T*> {
inline size_t operator()(const T* t) const noexcept {
@@ -76,11 +76,11 @@ template <>
struct hash<const char*>: ::NHashPrivate::TStringHash<char> {
};
-template <>
+template <>
struct THash<TStringBuf>: ::NHashPrivate::TStringHash<char> {
};
-template <>
+template <>
struct hash<TString>: ::NHashPrivate::TStringHash<char> {
};
@@ -236,7 +236,7 @@ struct TCIEqualTo<TString> {
template <class T>
struct TLess: public std::less<T> {
};
-
+
template <>
struct TLess<TString>: public TLess<TStringBuf> {
using is_transparent = void;
diff --git a/util/stream/file.cpp b/util/stream/file.cpp
index dc5d2f6311..00b1827429 100644
--- a/util/stream/file.cpp
+++ b/util/stream/file.cpp
@@ -5,12 +5,12 @@
TUnbufferedFileInput::TUnbufferedFileInput(const TString& path)
: File_(path, OpenExisting | RdOnly | Seq)
-{
+{
if (!File_.IsOpen()) {
ythrow TIoException() << "file " << path << " not open";
- }
-}
-
+ }
+}
+
TUnbufferedFileInput::TUnbufferedFileInput(const TFile& file)
: File_(file)
{
@@ -80,7 +80,7 @@ public:
inline ~TImpl() = default;
};
-TMappedFileInput::TMappedFileInput(const TFile& file)
+TMappedFileInput::TMappedFileInput(const TFile& file)
: TMemoryInput(nullptr, 0)
, Impl_(new TImpl(file))
{
@@ -90,8 +90,8 @@ TMappedFileInput::TMappedFileInput(const TFile& file)
TMappedFileInput::TMappedFileInput(const TString& path)
: TMemoryInput(nullptr, 0)
, Impl_(new TImpl(TFile(path, OpenExisting | RdOnly)))
-{
+{
Reset(Impl_->Data(), Impl_->Size());
-}
-
+}
+
TMappedFileInput::~TMappedFileInput() = default;
diff --git a/util/stream/file.h b/util/stream/file.h
index c1cf4f591d..a0010a909c 100644
--- a/util/stream/file.h
+++ b/util/stream/file.h
@@ -6,7 +6,7 @@
#include "buffered.h"
#include "mem.h"
-#include <util/system/file.h>
+#include <util/system/file.h>
#include <utility>
/**
diff --git a/util/stream/pipe.cpp b/util/stream/pipe.cpp
index 51be1934a7..4f44b5ea60 100644
--- a/util/stream/pipe.cpp
+++ b/util/stream/pipe.cpp
@@ -39,7 +39,7 @@ TPipeBase::TPipeBase(const TString& command, const char* mode)
TPipeBase::~TPipeBase() = default;
TPipeInput::TPipeInput(const TString& command)
- : TPipeBase(command, "r")
+ : TPipeBase(command, "r")
{
}
@@ -62,7 +62,7 @@ size_t TPipeInput::DoRead(void* buf, size_t len) {
}
TPipeOutput::TPipeOutput(const TString& command)
- : TPipeBase(command, "w")
+ : TPipeBase(command, "w")
{
}
diff --git a/util/stream/zlib_ut.cpp b/util/stream/zlib_ut.cpp
index 2290b4a9de..b6b89e4a82 100644
--- a/util/stream/zlib_ut.cpp
+++ b/util/stream/zlib_ut.cpp
@@ -73,7 +73,7 @@ Y_UNIT_TEST_SUITE(TZLibTest) {
UNIT_ASSERT_EQUAL(d.ReadAll(), DATA);
}
- }
+ }
Y_UNIT_TEST(Dictionary) {
static constexpr TStringBuf data = "<html><body></body></html>";
diff --git a/util/string/cstriter.h b/util/string/cstriter.h
index ca57728c39..2fa5576788 100644
--- a/util/string/cstriter.h
+++ b/util/string/cstriter.h
@@ -10,5 +10,5 @@ static inline bool operator==(It b, TCStringEndIterator) {
template <class It>
static inline bool operator!=(It b, TCStringEndIterator) {
- return !!*b;
+ return !!*b;
}
diff --git a/util/string/strip_ut.cpp b/util/string/strip_ut.cpp
index d1029d1498..7db5d4615a 100644
--- a/util/string/strip_ut.cpp
+++ b/util/string/strip_ut.cpp
@@ -134,5 +134,5 @@ Y_UNIT_TEST_SUITE(TStripStringTest) {
UNIT_ASSERT_EQUAL(abs1 == "Very long description string written in unknown language.", true);
UNIT_ASSERT_EQUAL(abs2 == "Very long description string written in unknown ...", true);
UNIT_ASSERT_EQUAL(abs3 == "Very long description string written in ...", true);
- }
+ }
}
diff --git a/util/string/util.cpp b/util/string/util.cpp
index b14f20bf75..3579dde04d 100644
--- a/util/string/util.cpp
+++ b/util/string/util.cpp
@@ -2,10 +2,10 @@
#include <util/generic/utility.h>
-#include <cstdio>
-#include <cstdarg>
+#include <cstdio>
+#include <cstdarg>
#include <cstdlib>
-
+
int a2i(const TString& s) {
return atoi(s.c_str());
}
diff --git a/util/string/util.h b/util/string/util.h
index 0d77a5042b..d423c328e6 100644
--- a/util/string/util.h
+++ b/util/string/util.h
@@ -2,10 +2,10 @@
//THIS FILE A COMPAT STUB HEADER
-#include <cstring>
+#include <cstring>
#include <cstdarg>
#include <algorithm>
-
+
#include <util/system/defaults.h>
#include <util/generic/string.h>
#include <util/generic/strbuf.h>
@@ -20,16 +20,16 @@ inline void RemoveIfLast(T& s, int c) {
const size_t length = s.length();
if (length && s[length - 1] == c)
s.remove(length - 1);
-}
-
+}
+
/// Adds lastCh symbol to the the of the string if it is not already there.
inline void addIfNotLast(TString& s, int lastCh) {
size_t len = s.length();
if (!len || s[len - 1] != lastCh) {
s.append(char(lastCh));
}
-}
-
+}
+
/// @details Finishes the string with lastCh1 if lastCh2 is not present in the string and lastCh1 is not already at the end of the string.
/// Else, if lastCh2 is not equal to the symbol before the last, it finishes the string with lastCh2.
/// @todo ?? Define, when to apply the function. Is in use several times for URLs parsing.
@@ -41,8 +41,8 @@ inline void addIfAbsent(TString& s, char lastCh1, char lastCh2) {
} else if (pos < s.length() - 1) {
addIfNotLast(s, lastCh2);
}
-}
-
+}
+
/// @}
/*
diff --git a/util/string/vector.h b/util/string/vector.h
index e36c348bbe..6769446810 100644
--- a/util/string/vector.h
+++ b/util/string/vector.h
@@ -1,5 +1,5 @@
#pragma once
-
+
#include "cast.h"
#include "split.h"
diff --git a/util/system/atomic_gcc.h b/util/system/atomic_gcc.h
index ed8dc2bdc5..5adc1b7906 100644
--- a/util/system/atomic_gcc.h
+++ b/util/system/atomic_gcc.h
@@ -73,18 +73,18 @@ static inline intptr_t AtomicGetAndCas(TAtomic* a, intptr_t exchange, intptr_t c
return compare;
}
-static inline intptr_t AtomicOr(TAtomic& a, intptr_t b) {
+static inline intptr_t AtomicOr(TAtomic& a, intptr_t b) {
return __atomic_or_fetch(&a, b, __ATOMIC_SEQ_CST);
-}
-
+}
+
static inline intptr_t AtomicXor(TAtomic& a, intptr_t b) {
return __atomic_xor_fetch(&a, b, __ATOMIC_SEQ_CST);
}
-static inline intptr_t AtomicAnd(TAtomic& a, intptr_t b) {
+static inline intptr_t AtomicAnd(TAtomic& a, intptr_t b) {
return __atomic_and_fetch(&a, b, __ATOMIC_SEQ_CST);
-}
-
+}
+
static inline void AtomicBarrier() {
__sync_synchronize();
}
diff --git a/util/system/atomic_ut.cpp b/util/system/atomic_ut.cpp
index 07211ffba7..8205bdcfd1 100644
--- a/util/system/atomic_ut.cpp
+++ b/util/system/atomic_ut.cpp
@@ -188,9 +188,9 @@ private:
}
};
-UNIT_TEST_SUITE_REGISTRATION(TAtomicTest<TAtomic>);
-
-#ifndef _MSC_VER
+UNIT_TEST_SUITE_REGISTRATION(TAtomicTest<TAtomic>);
+
+#ifndef _MSC_VER
// chooses type *other than* T1
template <typename T1, typename T2, typename T3>
struct TChooser {
@@ -216,7 +216,7 @@ public:
TString Name() const noexcept override {
return "TAtomicTest<TAltAtomic>";
}
-
+
static TString StaticName() noexcept {
return "TAtomicTest<TAltAtomic>";
}
@@ -224,4 +224,4 @@ public:
UNIT_TEST_SUITE_REGISTRATION(TTTest);
-#endif
+#endif
diff --git a/util/system/atomic_win.h b/util/system/atomic_win.h
index 65c290e6cc..509fa1dc69 100644
--- a/util/system/atomic_win.h
+++ b/util/system/atomic_win.h
@@ -4,7 +4,7 @@
#define USE_GENERIC_SETGET
-#if defined(_i386_)
+#if defined(_i386_)
#pragma intrinsic(_InterlockedIncrement)
#pragma intrinsic(_InterlockedDecrement)
@@ -92,14 +92,14 @@ static inline intptr_t AtomicGetAndCas(TAtomic* a, intptr_t exchange, intptr_t c
return _InterlockedCompareExchange64((volatile __int64*)a, exchange, compare);
}
-static inline intptr_t AtomicOr(TAtomic& a, intptr_t b) {
- return _InterlockedOr64(&a, b) | b;
-}
-
-static inline intptr_t AtomicAnd(TAtomic& a, intptr_t b) {
- return _InterlockedAnd64(&a, b) & b;
-}
-
+static inline intptr_t AtomicOr(TAtomic& a, intptr_t b) {
+ return _InterlockedOr64(&a, b) | b;
+}
+
+static inline intptr_t AtomicAnd(TAtomic& a, intptr_t b) {
+ return _InterlockedAnd64(&a, b) & b;
+}
+
static inline intptr_t AtomicXor(TAtomic& a, intptr_t b) {
return _InterlockedXor64(&a, b) ^ b;
}
diff --git a/util/system/backtrace_ut.cpp b/util/system/backtrace_ut.cpp
index 9b5ead71bc..dc83df033f 100644
--- a/util/system/backtrace_ut.cpp
+++ b/util/system/backtrace_ut.cpp
@@ -8,12 +8,12 @@
using PFunc = int (*)(void**, size_t);
int Dbg1(void** buf, size_t len) {
- volatile int ret = (int)BackTrace(buf, len);
+ volatile int ret = (int)BackTrace(buf, len);
return ret;
}
int Dbg2(void** buf, size_t len) {
- volatile int ret = (int)BackTrace(buf, len);
+ volatile int ret = (int)BackTrace(buf, len);
return ret;
}
diff --git a/util/system/byteorder.h b/util/system/byteorder.h
index 94b9fea515..1f32cf8473 100644
--- a/util/system/byteorder.h
+++ b/util/system/byteorder.h
@@ -1,6 +1,6 @@
#pragma once
-#include "defaults.h"
+#include "defaults.h"
//#define USE_GENERIC_ENDIAN_CVT
diff --git a/util/system/compat.cpp b/util/system/compat.cpp
index 18fbfa296a..a00d03dbe9 100644
--- a/util/system/compat.cpp
+++ b/util/system/compat.cpp
@@ -2,12 +2,12 @@
#include "defaults.h"
#include "progname.h"
-#include <cctype>
-#include <cerrno>
-#include <cstdio>
+#include <cctype>
+#include <cerrno>
+#include <cstdio>
#include <cstring>
-#include <cstdarg>
-#include <cstdlib>
+#include <cstdarg>
+#include <cstdlib>
#include <util/generic/string.h>
@@ -34,12 +34,12 @@ void usleep(i64 len) {
#include <fcntl.h>
int ftruncate(int fd, i64 length) {
- return _chsize_s(fd, length);
+ return _chsize_s(fd, length);
}
int truncate(const char* name, i64 length) {
- int fd = ::_open(name, _O_WRONLY);
- int ret = ftruncate(fd, length);
- ::close(fd);
- return ret;
-}
+ int fd = ::_open(name, _O_WRONLY);
+ int ret = ftruncate(fd, length);
+ ::close(fd);
+ return ret;
+}
#endif
diff --git a/util/system/compat.h b/util/system/compat.h
index c53dbcca17..dc53e32ffe 100644
--- a/util/system/compat.h
+++ b/util/system/compat.h
@@ -49,18 +49,18 @@ extern "C" {
#endif
}
-#ifdef _MSC_VER
+#ifdef _MSC_VER
#define popen _popen
#define pclose _pclose
-#endif
-
+#endif
+
#ifdef _win_
#define NAME_MAX FILENAME_MAX
-#endif
-#ifdef _sun_
+#endif
+#ifdef _sun_
#define NAME_MAX PATH_MAX
-#endif
-
+#endif
+
#ifdef _win_
#ifdef sleep // may be defined by perl
@@ -71,10 +71,10 @@ void sleep(i64 len);
void usleep(i64 len);
#endif
-
+
#ifdef _win_
-int ftruncate(int fd, i64 length);
-int truncate(const char* name, i64 length);
+int ftruncate(int fd, i64 length);
+int truncate(const char* name, i64 length);
#endif
#if defined(GNUC)
diff --git a/util/system/condvar.cpp b/util/system/condvar.cpp
index 62f3d22356..d1ba5cf8b9 100644
--- a/util/system/condvar.cpp
+++ b/util/system/condvar.cpp
@@ -121,7 +121,7 @@ public:
int ret = pthread_cond_broadcast(&Cond_);
Y_VERIFY(ret == 0, "pthread_cond_broadcast failed: %s", LastSystemErrorText(ret));
}
-
+
private:
pthread_cond_t Cond_;
};
diff --git a/util/system/context.h b/util/system/context.h
index d2a349bfc5..361c5ae0a1 100644
--- a/util/system/context.h
+++ b/util/system/context.h
@@ -8,7 +8,7 @@
#include <util/generic/array_ref.h>
#include <util/generic/utility.h>
#include <util/generic/yexception.h>
-
+
#define STACK_ALIGN (8 * PLATFORM_DATA_ALIGN)
#if defined(_x86_64_) || defined(_i386_) || defined(_arm_) || defined(_ppc64_)
diff --git a/util/system/datetime.h b/util/system/datetime.h
index aa009974e0..6482847403 100644
--- a/util/system/datetime.h
+++ b/util/system/datetime.h
@@ -94,5 +94,5 @@ Y_FORCE_INLINE ui64 GetCycleCount() noexcept {
return x;
#else
#error "unsupported arch"
-#endif
+#endif
}
diff --git a/util/system/defaults.h b/util/system/defaults.h
index dcd7abea38..c99e483a7f 100644
--- a/util/system/defaults.h
+++ b/util/system/defaults.h
@@ -1,6 +1,6 @@
#pragma once
-#include "platform.h"
+#include "platform.h"
#if defined _unix_
#define LOCSLASH_C '/'
@@ -15,7 +15,7 @@
#endif
// low and high parts of integers
-#if !defined(_win_)
+#if !defined(_win_)
#include <sys/param.h>
#endif
@@ -79,7 +79,7 @@
#include <malloc.h>
#elif defined(_sun_)
#include <alloca.h>
-#endif
+#endif
#ifdef NDEBUG
#define Y_IF_DEBUG(X)
diff --git a/util/system/dynlib.h b/util/system/dynlib.h
index 66eaf4a5c1..ef4ab29823 100644
--- a/util/system/dynlib.h
+++ b/util/system/dynlib.h
@@ -1,5 +1,5 @@
#pragma once
-
+
#include "defaults.h"
#include <util/generic/ptr.h>
@@ -7,7 +7,7 @@
#define Y_GET_FUNC(dll, name) FUNC_##name((dll).Sym(#name))
#define Y_GET_FUNC_OPTIONAL(dll, name) FUNC_##name((dll).SymOptional(#name))
-
+
#ifdef _win32_
#define DEFAULT_DLLOPEN_FLAGS 0
#else
@@ -25,95 +25,95 @@ public:
TDynamicLibrary() noexcept;
TDynamicLibrary(const TString& path, int flags = DEFAULT_DLLOPEN_FLAGS);
~TDynamicLibrary();
-
+
void Open(const char* path, int flags = DEFAULT_DLLOPEN_FLAGS);
void Close() noexcept;
void* SymOptional(const char* name) noexcept;
void* Sym(const char* name);
bool IsLoaded() const noexcept;
void SetUnloadable(bool unloadable); // Set to false to avoid unloading on destructor
-
+
private:
class TImpl;
THolder<TImpl> Impl_;
-};
-
-// a wrapper for a symbol
-template <class TLib>
+};
+
+// a wrapper for a symbol
+template <class TLib>
class TExternalSymbol {
-private:
+private:
TLib* PLib;
TDynamicLibrary* DLib;
TString lname;
TString vname;
-public:
+public:
TExternalSymbol() noexcept {
PLib = nullptr;
DLib = nullptr;
- }
+ }
TExternalSymbol(const TExternalSymbol& es) {
PLib = nullptr;
DLib = nullptr;
- if (es.IsDynamic())
+ if (es.IsDynamic())
Open(es.LibName().data(), es.VtblName().data());
- else if (es.IsStatic())
- SetSym(es.Symbol());
- }
+ else if (es.IsStatic())
+ SetSym(es.Symbol());
+ }
TExternalSymbol& operator=(const TExternalSymbol& es) {
- if (this != &es) {
- Close();
- if (es.IsDynamic())
+ if (this != &es) {
+ Close();
+ if (es.IsDynamic())
Open(es.LibName().data(), es.VtblName().data());
- else if (es.IsStatic())
- SetSym(es.Symbol());
- }
- return *this;
- }
+ else if (es.IsStatic())
+ SetSym(es.Symbol());
+ }
+ return *this;
+ }
~TExternalSymbol() {
- delete DLib;
- }
- // set the symbol from dynamic source
+ delete DLib;
+ }
+ // set the symbol from dynamic source
void Open(const char* lib_name, const char* vtbl_name) {
if (DLib != nullptr || PLib != nullptr)
- return;
- try {
- DLib = new TDynamicLibrary();
- DLib->Open(lib_name);
+ return;
+ try {
+ DLib = new TDynamicLibrary();
+ DLib->Open(lib_name);
PLib = (TLib*)DLib->Sym(vtbl_name);
} catch (...) {
- delete DLib;
+ delete DLib;
DLib = nullptr;
- throw;
- }
- lname = lib_name;
- vname = vtbl_name;
- }
- // set the symbol from static source
+ throw;
+ }
+ lname = lib_name;
+ vname = vtbl_name;
+ }
+ // set the symbol from static source
void SetSym(TLib* pl) noexcept {
if (DLib == nullptr && PLib == nullptr)
- PLib = pl;
- }
+ PLib = pl;
+ }
void Close() noexcept {
- delete DLib;
- DLib = 0;
- PLib = 0;
- lname.remove();
- vname.remove();
- }
+ delete DLib;
+ DLib = 0;
+ PLib = 0;
+ lname.remove();
+ vname.remove();
+ }
TLib* Symbol() const noexcept {
- return PLib;
- }
+ return PLib;
+ }
const TString& LibName() const noexcept {
- return lname;
- }
+ return lname;
+ }
const TString& VtblName() const noexcept {
- return vname;
- }
+ return vname;
+ }
bool IsStatic() const noexcept {
return DLib == nullptr && PLib != nullptr;
- }
+ }
bool IsDynamic() const noexcept {
return DLib && DLib->IsLoaded() && PLib != nullptr;
- }
-};
+ }
+};
diff --git a/util/system/err.cpp b/util/system/err.cpp
index 5573ea1ee9..48bddb783d 100644
--- a/util/system/err.cpp
+++ b/util/system/err.cpp
@@ -1,4 +1,4 @@
-#include "defaults.h"
+#include "defaults.h"
#include "progname.h"
#include "compat.h"
#include "error.h"
@@ -21,7 +21,7 @@ void vwarnx(const char* fmt, va_list args) {
void vwarn(const char* fmt, va_list args) {
int curErrNo = errno;
auto curErrText = LastSystemErrorText();
-
+
Y_DEFER {
errno = curErrNo;
};
diff --git a/util/system/error.h b/util/system/error.h
index 5f2d4cc547..e70c881fde 100644
--- a/util/system/error.h
+++ b/util/system/error.h
@@ -1,6 +1,6 @@
#pragma once
-#include "defaults.h"
+#include "defaults.h"
#if defined(_win_)
#include <winerror.h>
@@ -38,7 +38,7 @@
#undef EWOULDBLOCK
#undef ENAMETOOLONG
#undef ENOTEMPTY
-
+
#define EWOULDBLOCK WSAEWOULDBLOCK
#define EINPROGRESS WSAEINPROGRESS
#define EALREADY WSAEALREADY
diff --git a/util/system/error_ut.cpp b/util/system/error_ut.cpp
index 763b0dddb7..ad6857da82 100644
--- a/util/system/error_ut.cpp
+++ b/util/system/error_ut.cpp
@@ -4,12 +4,12 @@
#include <util/generic/ylimits.h>
-#ifdef _win_
+#ifdef _win_
#include "winint.h"
#else
#include <fcntl.h>
-#endif
-
+#endif
+
class TSysErrorTest: public TTestBase {
UNIT_TEST_SUITE(TSysErrorTest);
UNIT_TEST(TestErrorCode)
@@ -30,11 +30,11 @@ private:
}
inline void GenFailure() {
-#ifdef _win_
+#ifdef _win_
SetLastError(3);
-#else
+#else
UNIT_ASSERT(open("/non-existent", O_RDONLY) < 0);
-#endif
+#endif
}
};
diff --git a/util/system/event.cpp b/util/system/event.cpp
index 79b3cdb291..1eb0380eac 100644
--- a/util/system/event.cpp
+++ b/util/system/event.cpp
@@ -1,5 +1,5 @@
-#include "datetime.h"
-#include "defaults.h"
+#include "datetime.h"
+#include "defaults.h"
#include <cstdio>
@@ -7,7 +7,7 @@
#include "event.h"
#include "mutex.h"
#include "condvar.h"
-
+
#ifdef _win_
#include "winint.h"
#endif
@@ -66,7 +66,7 @@ public:
Cond.Signal();
}
}
-
+
inline void Reset() noexcept {
AtomicSet(Signaled, 0);
}
@@ -109,9 +109,9 @@ private:
TSystemEvent::TSystemEvent(ResetMode rmode)
: EvImpl_(new TEvImpl(rmode))
-{
-}
-
+{
+}
+
TSystemEvent::TSystemEvent(const TSystemEvent& other) noexcept
: EvImpl_(other.EvImpl_)
{
@@ -123,11 +123,11 @@ TSystemEvent& TSystemEvent::operator=(const TSystemEvent& other) noexcept {
}
TSystemEvent::~TSystemEvent() = default;
-
+
void TSystemEvent::Reset() noexcept {
EvImpl_->Reset();
-}
-
+}
+
void TSystemEvent::Signal() noexcept {
EvImpl_->Signal();
}
diff --git a/util/system/event.h b/util/system/event.h
index cab2fc478a..f2c999273a 100644
--- a/util/system/event.h
+++ b/util/system/event.h
@@ -1,15 +1,15 @@
#pragma once
-
+
#include <util/generic/ptr.h>
#include <util/datetime/base.h>
-
+
struct TEventResetType {
enum ResetMode {
rAuto, // the state will be nonsignaled after Wait() returns
rManual, // we need call Reset() to set the state to nonsignaled.
};
};
-
+
/**
* DEPRECATED!
*
@@ -23,7 +23,7 @@ public:
TSystemEvent& operator=(const TSystemEvent& other) noexcept;
~TSystemEvent();
-
+
void Reset() noexcept;
void Signal() noexcept;
diff --git a/util/system/execpath.cpp b/util/system/execpath.cpp
index 33198af58b..4433510773 100644
--- a/util/system/execpath.cpp
+++ b/util/system/execpath.cpp
@@ -29,7 +29,7 @@
#include "filemap.h"
#include "execpath.h"
-#include "fs.h"
+#include "fs.h"
#if defined(_freebsd_)
static inline bool GoodPath(const TString& path) {
diff --git a/util/system/execpath_ut.cpp b/util/system/execpath_ut.cpp
index 16b01466f5..14fe4ad345 100644
--- a/util/system/execpath_ut.cpp
+++ b/util/system/execpath_ut.cpp
@@ -1,4 +1,4 @@
-#include "execpath.h"
+#include "execpath.h"
#include <library/cpp/testing/unittest/registar.h>
diff --git a/util/system/fhandle.h b/util/system/fhandle.h
index f8033e3c14..2e012cca43 100644
--- a/util/system/fhandle.h
+++ b/util/system/fhandle.h
@@ -1,22 +1,22 @@
-#pragma once
-
-#include "defaults.h"
-
+#pragma once
+
+#include "defaults.h"
+
using WIN_HANDLE = void*;
#define INVALID_WIN_HANDLE ((WIN_HANDLE)(long)-1)
using UNIX_HANDLE = int;
#define INVALID_UNIX_HANDLE -1
-#if defined(_win_)
+#if defined(_win_)
using FHANDLE = WIN_HANDLE;
#define INVALID_FHANDLE INVALID_WIN_HANDLE
-#elif defined(_unix_)
+#elif defined(_unix_)
using FHANDLE = UNIX_HANDLE;
#define INVALID_FHANDLE INVALID_UNIX_HANDLE
-#else
+#else
#error
-#endif
+#endif
#if defined(_cygwin_)
using OS_HANDLE = WIN_HANDLE;
diff --git a/util/system/file.cpp b/util/system/file.cpp
index 4a261d020c..2698ee3d2f 100644
--- a/util/system/file.cpp
+++ b/util/system/file.cpp
@@ -25,7 +25,7 @@
#include <errno.h>
-#if defined(_unix_)
+#if defined(_unix_)
#include <fcntl.h>
#if defined(_linux_) && (!defined(_android_) || __ANDROID_API__ >= 21) && !defined(FALLOC_FL_KEEP_SIZE)
@@ -35,12 +35,12 @@
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
-#elif defined(_win_)
+#elif defined(_win_)
#include "winint.h"
#include "fs_win.h"
#include <io.h>
-#endif
-
+#endif
+
#if defined(_bionic_)
#include <sys/sendfile.h>
#define HAVE_POSIX_FADVISE 0
@@ -64,46 +64,46 @@ static bool IsStupidFlagCombination(EOpenMode oMode) {
}
TFileHandle::TFileHandle(const TString& fName, EOpenMode oMode) noexcept {
- ui32 fcMode = 0;
+ ui32 fcMode = 0;
EOpenMode createMode = oMode & MaskCreation;
Y_VERIFY(!IsStupidFlagCombination(oMode), "oMode %d makes no sense", static_cast<int>(oMode));
if (!(oMode & MaskRW)) {
- oMode |= RdWr;
+ oMode |= RdWr;
}
if (!(oMode & AMask)) {
- oMode |= ARW;
- }
-
-#ifdef _win_
-
- switch (createMode) {
- case OpenExisting:
- fcMode = OPEN_EXISTING;
- break;
- case TruncExisting:
- fcMode = TRUNCATE_EXISTING;
- break;
- case OpenAlways:
- fcMode = OPEN_ALWAYS;
- break;
+ oMode |= ARW;
+ }
+
+#ifdef _win_
+
+ switch (createMode) {
+ case OpenExisting:
+ fcMode = OPEN_EXISTING;
+ break;
+ case TruncExisting:
+ fcMode = TRUNCATE_EXISTING;
+ break;
+ case OpenAlways:
+ fcMode = OPEN_ALWAYS;
+ break;
case CreateNew:
- fcMode = CREATE_NEW;
- break;
+ fcMode = CREATE_NEW;
+ break;
case CreateAlways:
- fcMode = CREATE_ALWAYS;
- break;
- default:
- abort();
- break;
- }
-
- ui32 faMode = 0;
+ fcMode = CREATE_ALWAYS;
+ break;
+ default:
+ abort();
+ break;
+ }
+
+ ui32 faMode = 0;
if (oMode & RdOnly) {
- faMode |= GENERIC_READ;
+ faMode |= GENERIC_READ;
}
if (oMode & WrOnly) {
// WrOnly or RdWr
- faMode |= GENERIC_WRITE;
+ faMode |= GENERIC_WRITE;
}
if (oMode & ::ForAppend) {
faMode |= GENERIC_WRITE;
@@ -113,14 +113,14 @@ TFileHandle::TFileHandle(const TString& fName, EOpenMode oMode) noexcept {
bool inheritHandle = !(oMode & CloseOnExec);
- ui32 shMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
-
- ui32 attrMode = FILE_ATTRIBUTE_NORMAL;
+ ui32 shMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
+
+ ui32 attrMode = FILE_ATTRIBUTE_NORMAL;
if ((createMode == OpenExisting || createMode == OpenAlways) && ((oMode & AMask) == (oMode & AR))) {
- attrMode |= FILE_ATTRIBUTE_READONLY;
+ attrMode |= FILE_ATTRIBUTE_READONLY;
}
if (oMode & Seq) {
- attrMode |= FILE_FLAG_SEQUENTIAL_SCAN;
+ attrMode |= FILE_FLAG_SEQUENTIAL_SCAN;
}
if (oMode & Temp) {
// we use TTempFile instead of FILE_FLAG_DELETE_ON_CLOSE
@@ -131,46 +131,46 @@ TFileHandle::TFileHandle(const TString& fName, EOpenMode oMode) noexcept {
}
if ((oMode & (Direct | DirectAligned)) && (oMode & WrOnly)) {
// WrOnly or RdWr
- attrMode |= /*FILE_FLAG_NO_BUFFERING |*/ FILE_FLAG_WRITE_THROUGH;
+ attrMode |= /*FILE_FLAG_NO_BUFFERING |*/ FILE_FLAG_WRITE_THROUGH;
}
-
+
Fd_ = NFsPrivate::CreateFileWithUtf8Name(fName, faMode, shMode, fcMode, attrMode, inheritHandle);
-
+
if ((oMode & ::ForAppend) && (Fd_ != INVALID_FHANDLE)) {
::SetFilePointer(Fd_, 0, 0, FILE_END);
}
#elif defined(_unix_)
-
- switch (createMode) {
- case OpenExisting:
- fcMode = 0;
- break;
- case TruncExisting:
- fcMode = O_TRUNC;
- break;
- case OpenAlways:
- fcMode = O_CREAT;
- break;
+
+ switch (createMode) {
+ case OpenExisting:
+ fcMode = 0;
+ break;
+ case TruncExisting:
+ fcMode = O_TRUNC;
+ break;
+ case OpenAlways:
+ fcMode = O_CREAT;
+ break;
case CreateNew:
- fcMode = O_CREAT | O_EXCL;
- break;
+ fcMode = O_CREAT | O_EXCL;
+ break;
case CreateAlways:
- fcMode = O_CREAT | O_TRUNC;
- break;
- default:
- abort();
- break;
- }
-
+ fcMode = O_CREAT | O_TRUNC;
+ break;
+ default:
+ abort();
+ break;
+ }
+
if ((oMode & RdOnly) && (oMode & WrOnly)) {
- fcMode |= O_RDWR;
+ fcMode |= O_RDWR;
} else if (oMode & RdOnly) {
- fcMode |= O_RDONLY;
+ fcMode |= O_RDONLY;
} else if (oMode & WrOnly) {
- fcMode |= O_WRONLY;
+ fcMode |= O_WRONLY;
}
-
+
if (oMode & ::ForAppend) {
fcMode |= O_APPEND;
}
@@ -180,9 +180,9 @@ TFileHandle::TFileHandle(const TString& fName, EOpenMode oMode) noexcept {
}
/* I don't now about this for unix...
- if (oMode & Temp) {
- }
- */
+ if (oMode & Temp) {
+ }
+ */
#if defined(_freebsd_)
if (oMode & (Direct | DirectAligned)) {
fcMode |= O_DIRECT;
@@ -193,51 +193,51 @@ TFileHandle::TFileHandle(const TString& fName, EOpenMode oMode) noexcept {
}
#elif defined(_linux_)
if (oMode & DirectAligned) {
- /*
+ /*
* O_DIRECT in Linux requires aligning request size and buffer address
* to size of hardware sector (see hw_sector_size or ioctl BLKSSZGET).
* Usually 512 bytes, but modern hardware works better with 4096 bytes.
- */
- fcMode |= O_DIRECT;
+ */
+ fcMode |= O_DIRECT;
}
if (oMode & Sync) {
fcMode |= O_SYNC;
}
#endif
-
+
#if defined(_linux_)
fcMode |= O_LARGEFILE;
#endif
- ui32 permMode = 0;
+ ui32 permMode = 0;
if (oMode & AXOther) {
- permMode |= S_IXOTH;
+ permMode |= S_IXOTH;
}
if (oMode & AWOther) {
- permMode |= S_IWOTH;
+ permMode |= S_IWOTH;
}
if (oMode & AROther) {
- permMode |= S_IROTH;
+ permMode |= S_IROTH;
}
if (oMode & AXGroup) {
- permMode |= S_IXGRP;
+ permMode |= S_IXGRP;
}
if (oMode & AWGroup) {
- permMode |= S_IWGRP;
+ permMode |= S_IWGRP;
}
if (oMode & ARGroup) {
- permMode |= S_IRGRP;
+ permMode |= S_IRGRP;
}
if (oMode & AXUser) {
- permMode |= S_IXUSR;
+ permMode |= S_IXUSR;
}
if (oMode & AWUser) {
- permMode |= S_IWUSR;
+ permMode |= S_IWUSR;
}
if (oMode & ARUser) {
- permMode |= S_IRUSR;
+ permMode |= S_IRUSR;
}
-
+
do {
Fd_ = ::open(fName.data(), fcMode, permMode);
} while (Fd_ == -1 && errno == EINTR);
@@ -264,12 +264,12 @@ TFileHandle::TFileHandle(const TString& fName, EOpenMode oMode) noexcept {
}
#else
#error unsupported platform
-#endif
-}
-
+#endif
+}
+
bool TFileHandle::Close() noexcept {
- bool isOk = true;
-#ifdef _win_
+ bool isOk = true;
+#ifdef _win_
if (Fd_ != INVALID_FHANDLE) {
isOk = (::CloseHandle(Fd_) != 0);
}
@@ -287,28 +287,28 @@ bool TFileHandle::Close() noexcept {
// that is disasterous
Y_VERIFY(errno != EBADF, "must not quietly close bad descriptor: fd=%d", int(Fd_));
}
-#else
+#else
#error unsupported platform
-#endif
+#endif
Fd_ = INVALID_FHANDLE;
- return isOk;
-}
-
+ return isOk;
+}
+
static inline i64 DoSeek(FHANDLE h, i64 offset, SeekDir origin) noexcept {
if (h == INVALID_FHANDLE) {
- return -1L;
+ return -1L;
}
#if defined(_win_)
- static ui32 dir[] = {FILE_BEGIN, FILE_CURRENT, FILE_END};
- LARGE_INTEGER pos;
- pos.QuadPart = offset;
- pos.LowPart = ::SetFilePointer(h, pos.LowPart, &pos.HighPart, dir[origin]);
+ static ui32 dir[] = {FILE_BEGIN, FILE_CURRENT, FILE_END};
+ LARGE_INTEGER pos;
+ pos.QuadPart = offset;
+ pos.LowPart = ::SetFilePointer(h, pos.LowPart, &pos.HighPart, dir[origin]);
if (pos.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) {
- pos.QuadPart = -1;
+ pos.QuadPart = -1;
}
- return pos.QuadPart;
+ return pos.QuadPart;
#elif defined(_unix_)
- static int dir[] = {SEEK_SET, SEEK_CUR, SEEK_END};
+ static int dir[] = {SEEK_SET, SEEK_CUR, SEEK_END};
#if defined(_sun_)
return ::llseek(h, (offset_t)offset, dir[origin]);
#else
@@ -317,27 +317,27 @@ static inline i64 DoSeek(FHANDLE h, i64 offset, SeekDir origin) noexcept {
#else
#error unsupported platform
#endif
-}
-
+}
+
i64 TFileHandle::GetPosition() const noexcept {
return DoSeek(Fd_, 0, sCur);
-}
-
+}
+
i64 TFileHandle::Seek(i64 offset, SeekDir origin) noexcept {
return DoSeek(Fd_, offset, origin);
-}
-
+}
+
i64 TFileHandle::GetLength() const noexcept {
// XXX: returns error code, but does not set errno
if (!IsOpen()) {
return -1L;
}
- return GetFileLength(Fd_);
-}
-
+ return GetFileLength(Fd_);
+}
+
bool TFileHandle::Resize(i64 length) noexcept {
if (!IsOpen()) {
- return false;
+ return false;
}
i64 currentLength = GetLength();
if (length == currentLength) {
@@ -346,23 +346,23 @@ bool TFileHandle::Resize(i64 length) noexcept {
#if defined(_win_)
i64 currentPosition = GetPosition();
if (currentPosition == -1L) {
- return false;
+ return false;
}
Seek(length, sSet);
if (!::SetEndOfFile(Fd_)) {
- return false;
+ return false;
}
if (currentPosition < length) {
Seek(currentPosition, sSet);
}
- return true;
+ return true;
#elif defined(_unix_)
return (0 == ftruncate(Fd_, (off_t)length));
-#else
+#else
#error unsupported platform
-#endif
-}
-
+#endif
+}
+
bool TFileHandle::Reserve(i64 length) noexcept {
// FIXME this should reserve disk space with fallocate
if (!IsOpen()) {
@@ -414,9 +414,9 @@ bool TFileHandle::ShrinkToFit() noexcept {
bool TFileHandle::Flush() noexcept {
if (!IsOpen()) {
- return false;
+ return false;
}
-#if defined(_win_)
+#if defined(_win_)
bool ok = ::FlushFileBuffers(Fd_) != 0;
/*
* FlushFileBuffers fails if hFile is a handle to the console output.
@@ -438,11 +438,11 @@ bool TFileHandle::Flush() noexcept {
|| errno == ENOTSUP
#endif
;
-#else
+#else
#error unsupported platform
-#endif
+#endif
}
-
+
bool TFileHandle::FlushData() noexcept {
#if defined(_linux_)
if (!IsOpen()) {
@@ -461,14 +461,14 @@ bool TFileHandle::FlushData() noexcept {
i32 TFileHandle::Read(void* buffer, ui32 byteCount) noexcept {
// FIXME size and return must be 64-bit
if (!IsOpen()) {
- return -1;
+ return -1;
}
-#if defined(_win_)
- DWORD bytesRead = 0;
+#if defined(_win_)
+ DWORD bytesRead = 0;
if (::ReadFile(Fd_, buffer, byteCount, &bytesRead, nullptr)) {
- return bytesRead;
+ return bytesRead;
}
- return -1;
+ return -1;
#elif defined(_unix_)
i32 ret;
do {
@@ -477,19 +477,19 @@ i32 TFileHandle::Read(void* buffer, ui32 byteCount) noexcept {
return ret;
#else
#error unsupported platform
-#endif
-}
-
+#endif
+}
+
i32 TFileHandle::Write(const void* buffer, ui32 byteCount) noexcept {
if (!IsOpen()) {
- return -1;
+ return -1;
}
-#if defined(_win_)
- DWORD bytesWritten = 0;
+#if defined(_win_)
+ DWORD bytesWritten = 0;
if (::WriteFile(Fd_, buffer, byteCount, &bytesWritten, nullptr)) {
- return bytesWritten;
+ return bytesWritten;
}
- return -1;
+ return -1;
#elif defined(_unix_)
i32 ret;
do {
@@ -498,23 +498,23 @@ i32 TFileHandle::Write(const void* buffer, ui32 byteCount) noexcept {
return ret;
#else
#error unsupported platform
-#endif
-}
-
+#endif
+}
+
i32 TFileHandle::Pread(void* buffer, ui32 byteCount, i64 offset) const noexcept {
-#if defined(_win_)
+#if defined(_win_)
OVERLAPPED io;
Zero(io);
- DWORD bytesRead = 0;
- io.Offset = (ui32)offset;
- io.OffsetHigh = (ui32)(offset >> 32);
+ DWORD bytesRead = 0;
+ io.Offset = (ui32)offset;
+ io.OffsetHigh = (ui32)(offset >> 32);
if (::ReadFile(Fd_, buffer, byteCount, &bytesRead, &io)) {
- return bytesRead;
+ return bytesRead;
}
if (::GetLastError() == ERROR_HANDLE_EOF) {
return 0;
}
- return -1;
+ return -1;
#elif defined(_unix_)
i32 ret;
do {
@@ -523,20 +523,20 @@ i32 TFileHandle::Pread(void* buffer, ui32 byteCount, i64 offset) const noexcept
return ret;
#else
#error unsupported platform
-#endif
-}
-
+#endif
+}
+
i32 TFileHandle::Pwrite(const void* buffer, ui32 byteCount, i64 offset) const noexcept {
-#if defined(_win_)
+#if defined(_win_)
OVERLAPPED io;
Zero(io);
- DWORD bytesWritten = 0;
- io.Offset = (ui32)offset;
- io.OffsetHigh = (ui32)(offset >> 32);
+ DWORD bytesWritten = 0;
+ io.Offset = (ui32)offset;
+ io.OffsetHigh = (ui32)(offset >> 32);
if (::WriteFile(Fd_, buffer, byteCount, &bytesWritten, &io)) {
- return bytesWritten;
+ return bytesWritten;
}
- return -1;
+ return -1;
#elif defined(_unix_)
i32 ret;
do {
@@ -545,26 +545,26 @@ i32 TFileHandle::Pwrite(const void* buffer, ui32 byteCount, i64 offset) const no
return ret;
#else
#error unsupported platform
-#endif
-}
-
+#endif
+}
+
FHANDLE TFileHandle::Duplicate() const noexcept {
if (!IsOpen()) {
- return INVALID_FHANDLE;
+ return INVALID_FHANDLE;
}
-#if defined(_win_)
- FHANDLE dupHandle;
+#if defined(_win_)
+ FHANDLE dupHandle;
if (!::DuplicateHandle(GetCurrentProcess(), Fd_, GetCurrentProcess(), &dupHandle, 0, TRUE, DUPLICATE_SAME_ACCESS)) {
- return INVALID_FHANDLE;
+ return INVALID_FHANDLE;
}
- return dupHandle;
+ return dupHandle;
#elif defined(_unix_)
return ::dup(Fd_);
#else
#error unsupported platform
-#endif
-}
-
+#endif
+}
+
int TFileHandle::Duplicate2Posix(int dstHandle) const noexcept {
if (!IsOpen()) {
return -1;
@@ -623,8 +623,8 @@ bool TFileHandle::LinkTo(const TFileHandle& fh) const noexcept {
int TFileHandle::Flock(int op) noexcept {
return ::Flock(Fd_, op);
-}
-
+}
+
bool TFileHandle::SetDirect() {
#ifdef _linux_
const long flags = fcntl(Fd_, F_GETFL);
@@ -848,36 +848,36 @@ public:
, FileName_(fname)
{
}
-
+
inline TImpl(const TString& fName, EOpenMode oMode)
: Handle_(fName, oMode)
, FileName_(fName)
{
if (!Handle_.IsOpen()) {
ythrow TFileError() << "can't open " << fName.Quote() << " with mode " << DecodeOpenMode(oMode) << " (" << Hex(oMode.ToBaseType()) << ")";
- }
+ }
}
-
+
inline ~TImpl() = default;
-
+
inline void Close() {
if (!Handle_.Close()) {
ythrow TFileError() << "can't close " << FileName_.Quote();
}
}
-
+
const TString& GetName() const noexcept {
return FileName_;
}
-
+
void SetName(const TString& newName) {
FileName_ = newName;
}
-
+
const TFileHandle& GetHandle() const noexcept {
return Handle_;
}
-
+
i64 Seek(i64 offset, SeekDir origin) {
i64 pos = Handle_.Seek(offset, origin);
if (pos == -1L) {
@@ -885,13 +885,13 @@ public:
}
return pos;
}
-
+
void Resize(i64 length) {
if (!Handle_.Resize(length)) {
ythrow TFileError() << "can't resize " << FileName_.Quote() << " to size " << length;
}
}
-
+
void Reserve(i64 length) {
if (!Handle_.Reserve(length)) {
ythrow TFileError() << "can't reserve " << length << " for file " << FileName_.Quote();
@@ -915,7 +915,7 @@ public:
ythrow TFileError() << "can't flush " << FileName_.Quote();
}
}
-
+
void FlushData() {
if (!Handle_.FlushData()) {
ythrow TFileError() << "can't flush data " << FileName_.Quote();
@@ -931,7 +931,7 @@ public:
dupH.Release();
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.
@@ -954,28 +954,28 @@ public:
size_t Read(void* bufferIn, size_t numBytes) {
ui8* buf = (ui8*)bufferIn;
-
+
while (numBytes) {
const size_t reallyRead = ReadOrFail(buf, numBytes);
-
+
if (reallyRead == 0) {
// file exhausted
break;
}
-
+
buf += reallyRead;
numBytes -= reallyRead;
- }
-
+ }
+
return buf - (ui8*)bufferIn;
}
-
+
void Load(void* buf, size_t len) {
if (Read(buf, len) != len) {
ythrow TFileError() << "can't read " << len << " bytes from " << FileName_.Quote();
}
}
-
+
// 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.
@@ -983,44 +983,44 @@ public:
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 reallyWritten = Handle_.Write(buf, toWrite);
-
+
if (reallyWritten < 0) {
ythrow TFileError() << "can't write " << toWrite << " bytes to " << FileName_.Quote();
}
buf += reallyWritten;
numBytes -= reallyWritten;
- }
+ }
}
-
+
size_t Pread(void* bufferIn, size_t numBytes, i64 offset) const {
ui8* buf = (ui8*)bufferIn;
-
+
while (numBytes) {
const i32 toRead = (i32)Min(MaxReadPortion, numBytes);
const i32 reallyRead = RawPread(buf, toRead, offset);
-
+
if (reallyRead < 0) {
ythrow TFileError() << "can not read data from " << FileName_.Quote();
}
-
+
if (reallyRead == 0) {
// file exausted
break;
}
-
+
buf += reallyRead;
offset += reallyRead;
numBytes -= reallyRead;
- }
-
+ }
+
return buf - (ui8*)bufferIn;
}
-
+
i32 RawPread(void* buf, ui32 len, i64 offset) const {
return Handle_.Pread(buf, len, offset);
}
@@ -1030,24 +1030,24 @@ public:
ythrow TFileError() << "can't read " << len << " bytes at offset " << offset << " from " << FileName_.Quote();
}
}
-
+
void Pwrite(const void* buffer, size_t numBytes, i64 offset) const {
const ui8* buf = (const ui8*)buffer;
-
+
while (numBytes) {
const i32 toWrite = (i32)Min(MaxWritePortion, numBytes);
const i32 reallyWritten = Handle_.Pwrite(buf, toWrite, offset);
-
+
if (reallyWritten < 0) {
ythrow TFileError() << "can't write " << toWrite << " bytes to " << FileName_.Quote();
}
-
+
buf += reallyWritten;
offset += reallyWritten;
numBytes -= reallyWritten;
- }
+ }
}
-
+
void Flock(int op) {
if (0 != Handle_.Flock(op)) {
ythrow TFileError() << "can't flock " << FileName_.Quote();
@@ -1085,18 +1085,18 @@ public:
private:
TFileHandle Handle_;
TString FileName_;
-};
-
-TFile::TFile()
+};
+
+TFile::TFile()
: Impl_(new TImpl(INVALID_FHANDLE))
-{
-}
-
-TFile::TFile(FHANDLE fd)
+{
+}
+
+TFile::TFile(FHANDLE fd)
: Impl_(new TImpl(fd))
-{
-}
-
+{
+}
+
TFile::TFile(FHANDLE fd, const TString& name)
: Impl_(new TImpl(fd, name))
{
@@ -1104,43 +1104,43 @@ TFile::TFile(FHANDLE fd, const TString& name)
TFile::TFile(const TString& fName, EOpenMode oMode)
: Impl_(new TImpl(fName, oMode))
-{
-}
-
+{
+}
+
TFile::~TFile() = default;
-
-void TFile::Close() {
+
+void TFile::Close() {
Impl_->Close();
-}
-
+}
+
const TString& TFile::GetName() const noexcept {
return Impl_->GetName();
-}
-
+}
+
i64 TFile::GetPosition() const noexcept {
return Impl_->GetHandle().GetPosition();
-}
-
+}
+
i64 TFile::GetLength() const noexcept {
return Impl_->GetHandle().GetLength();
-}
-
+}
+
bool TFile::IsOpen() const noexcept {
return Impl_->GetHandle().IsOpen();
-}
-
+}
+
FHANDLE TFile::GetHandle() const noexcept {
return Impl_->GetHandle();
-}
-
-i64 TFile::Seek(i64 offset, SeekDir origin) {
+}
+
+i64 TFile::Seek(i64 offset, SeekDir origin) {
return Impl_->Seek(offset, origin);
-}
-
+}
+
void TFile::Resize(i64 length) {
Impl_->Resize(length);
-}
-
+}
+
void TFile::Reserve(i64 length) {
Impl_->Reserve(length);
}
@@ -1153,10 +1153,10 @@ void TFile::ShrinkToFit() {
Impl_->ShrinkToFit();
}
-void TFile::Flush() {
+void TFile::Flush() {
Impl_->Flush();
-}
-
+}
+
void TFile::FlushData() {
Impl_->FlushData();
}
@@ -1164,13 +1164,13 @@ void TFile::FlushData() {
TFile TFile::Duplicate() const {
TFile res = Impl_->Duplicate();
res.Impl_->SetName(Impl_->GetName());
- return res;
-}
-
-size_t TFile::Read(void* buf, size_t len) {
+ return res;
+}
+
+size_t TFile::Read(void* buf, size_t len) {
return Impl_->Read(buf, len);
-}
-
+}
+
i32 TFile::RawRead(void* buf, size_t len) {
return Impl_->RawRead(buf, len);
}
@@ -1179,34 +1179,34 @@ size_t TFile::ReadOrFail(void* buf, size_t len) {
return Impl_->ReadOrFail(buf, len);
}
-void TFile::Load(void* buf, size_t len) {
+void TFile::Load(void* buf, size_t len) {
Impl_->Load(buf, len);
-}
-
-void TFile::Write(const void* buf, size_t len) {
+}
+
+void TFile::Write(const void* buf, size_t len) {
Impl_->Write(buf, len);
-}
-
-size_t TFile::Pread(void* buf, size_t len, i64 offset) const {
+}
+
+size_t TFile::Pread(void* buf, size_t len, i64 offset) const {
return Impl_->Pread(buf, len, offset);
-}
-
+}
+
i32 TFile::RawPread(void* buf, ui32 len, i64 offset) const {
return Impl_->RawPread(buf, len, offset);
}
-void TFile::Pload(void* buf, size_t len, i64 offset) const {
+void TFile::Pload(void* buf, size_t len, i64 offset) const {
Impl_->Pload(buf, len, offset);
-}
-
-void TFile::Pwrite(const void* buf, size_t len, i64 offset) const {
+}
+
+void TFile::Pwrite(const void* buf, size_t len, i64 offset) const {
Impl_->Pwrite(buf, len, offset);
-}
-
-void TFile::Flock(int op) {
+}
+
+void TFile::Flock(int op) {
Impl_->Flock(op);
-}
-
+}
+
void TFile::SetDirect() {
Impl_->SetDirect();
}
@@ -1246,11 +1246,11 @@ TFile TFile::ForAppend(const TString& path) {
return TFile(path, OpenAlways | WrOnly | Seq | ::ForAppend);
}
-TFile Duplicate(FILE* f) {
- return Duplicate(fileno(f));
-}
-
-TFile Duplicate(int fd) {
+TFile Duplicate(FILE* f) {
+ return Duplicate(fileno(f));
+}
+
+TFile Duplicate(int fd) {
#if defined(_win_)
/* There are two options of how to duplicate a file descriptor on Windows:
*
@@ -1278,10 +1278,10 @@ TFile Duplicate(int fd) {
return TFile(dupHandle);
#elif defined(_unix_)
return TFile(::dup(fd));
-#else
+#else
#error unsupported platform
-#endif
-}
+#endif
+}
bool PosixDisableReadAhead(FHANDLE fileHandle, void* addr) noexcept {
int ret = -1;
diff --git a/util/system/file.h b/util/system/file.h
index 9502e159b6..7d2cb11d4e 100644
--- a/util/system/file.h
+++ b/util/system/file.h
@@ -1,27 +1,27 @@
#pragma once
-
-#include "fhandle.h"
+
+#include "fhandle.h"
#include "flock.h"
#include <util/generic/flags.h>
#include <util/generic/ptr.h>
#include <util/generic/noncopyable.h>
-
+
#include <cstdio>
enum EOpenModeFlag {
OpenExisting = 0, // Opens a file. It fails if the file does not exist.
- TruncExisting = 1, // Opens a file and truncates it to zero size. It fails if the file does not exist.
+ TruncExisting = 1, // Opens a file and truncates it to zero size. It fails if the file does not exist.
OpenAlways = 2, // Opens a file, always. If a file does not exist, it creates a file.
CreateNew = 3, // Creates a new file. It fails if a specified file exists.
CreateAlways = 4, // Creates a new file, always. If a file exists, it overwrites the file.
MaskCreation = 7,
-
- RdOnly = 8, // open for reading only
- WrOnly = 16, // open for writing only
+
+ RdOnly = 8, // open for reading only
+ WrOnly = 16, // open for writing only
RdWr = 24, // open for reading and writing
- MaskRW = 24,
-
+ MaskRW = 24,
+
Seq = 0x20, // file access is primarily sequential (POSIX_FADV_SEQUENTIAL)
Direct = 0x40, // file is being opened with no system caching (Does not work as intended! See implementation)
Temp = 0x80, // avoid writing data back to disk if sufficient cache memory is available (no op for linux)
@@ -32,44 +32,44 @@ enum EOpenModeFlag {
DirectAligned = 0x1000, // file is actually being opened with no system caching (may require buffer alignment) (O_DIRECT)
Sync = 0x2000, // no write call will return before the data is transferred to the disk (O_SYNC)
NoReadAhead = 0x4000, // no sequential access expected, opposite for Seq (POSIX_FADV_RANDOM)
-
- AXOther = 0x00010000,
- AWOther = 0x00020000,
- AROther = 0x00040000,
- AXGroup = 0x00100000,
- AWGroup = 0x00200000,
- ARGroup = 0x00400000,
+
+ AXOther = 0x00010000,
+ AWOther = 0x00020000,
+ AROther = 0x00040000,
+ AXGroup = 0x00100000,
+ AWGroup = 0x00200000,
+ ARGroup = 0x00400000,
AXUser = 0x01000000,
AWUser = 0x02000000,
ARUser = 0x04000000,
AX = AXUser | AXGroup | AXOther,
AW = AWUser | AWGroup,
AR = ARUser | ARGroup | AROther,
- ARW = AR | AW,
- AMask = 0x0FFF0000,
-};
-
+ ARW = AR | AW,
+ AMask = 0x0FFF0000,
+};
+
Y_DECLARE_FLAGS(EOpenMode, EOpenModeFlag)
Y_DECLARE_OPERATORS_FOR_FLAGS(EOpenMode)
TString DecodeOpenMode(ui32 openMode);
-enum SeekDir {
- sSet = 0,
- sCur = 1,
- sEnd = 2,
-};
-
+enum SeekDir {
+ sSet = 0,
+ sCur = 1,
+ sEnd = 2,
+};
+
class TFileHandle: public TNonCopyable {
-public:
+public:
constexpr TFileHandle() = default;
/// Warning: takes ownership of fd, so closes it in destructor.
inline TFileHandle(FHANDLE fd) noexcept
: Fd_(fd)
- {
- }
-
+ {
+ }
+
inline TFileHandle(TFileHandle&& other) noexcept
: Fd_(other.Fd_)
{
@@ -77,34 +77,34 @@ public:
}
TFileHandle(const TString& fName, EOpenMode oMode) noexcept;
-
+
inline ~TFileHandle() {
- Close();
- }
-
+ Close();
+ }
+
bool Close() noexcept;
-
+
inline FHANDLE Release() noexcept {
FHANDLE ret = Fd_;
Fd_ = INVALID_FHANDLE;
- return ret;
- }
-
+ return ret;
+ }
+
inline void Swap(TFileHandle& r) noexcept {
DoSwap(Fd_, r.Fd_);
- }
-
+ }
+
inline operator FHANDLE() const noexcept {
return Fd_;
- }
-
+ }
+
inline bool IsOpen() const noexcept {
return Fd_ != INVALID_FHANDLE;
- }
-
+ }
+
i64 GetPosition() const noexcept;
i64 GetLength() const noexcept;
-
+
i64 Seek(i64 offset, SeekDir origin) noexcept;
bool Resize(i64 length) noexcept;
bool Reserve(i64 length) noexcept;
@@ -118,17 +118,17 @@ public:
i32 Pread(void* buffer, ui32 byteCount, i64 offset) const noexcept;
i32 Pwrite(const void* buffer, ui32 byteCount, i64 offset) const noexcept;
int Flock(int op) noexcept;
-
+
FHANDLE Duplicate() const noexcept;
int Duplicate2Posix(int dstHandle) const noexcept;
-
+
//dup2 - like semantics, return true on success
bool LinkTo(const TFileHandle& fh) const noexcept;
//very low-level methods
bool SetDirect();
void ResetDirect();
-
+
/* Manual file cache management, length = 0 means "as much as possible" */
//measure amount of cached data in bytes, returns -1 if failed
@@ -140,66 +140,66 @@ public:
//flush unwritten data in this range and optionally wait for completion
bool FlushCache(i64 offset = 0, i64 length = 0, bool wait = true) noexcept;
-private:
+private:
FHANDLE Fd_ = INVALID_FHANDLE;
-};
-
-class TFile {
-public:
- TFile();
+};
+
+class TFile {
+public:
+ TFile();
/// Takes ownership of handle, so closes it when the last holder of descriptor dies.
- explicit TFile(FHANDLE fd);
+ explicit TFile(FHANDLE fd);
TFile(FHANDLE fd, const TString& fname);
TFile(const TString& fName, EOpenMode oMode);
~TFile();
-
- void Close();
-
+
+ void Close();
+
const TString& GetName() const noexcept;
i64 GetPosition() const noexcept;
i64 GetLength() const noexcept;
bool IsOpen() const noexcept;
FHANDLE GetHandle() const noexcept;
-
- i64 Seek(i64 offset, SeekDir origin);
+
+ i64 Seek(i64 offset, SeekDir origin);
void Resize(i64 length);
void Reserve(i64 length);
void FallocateNoResize(i64 length);
void ShrinkToFit();
- void Flush();
+ void Flush();
void FlushData();
-
+
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
- size_t Read(void* buf, size_t len);
+ size_t Read(void* buf, size_t len);
// Reads exactly len bytes, throws on premature EOF or error
- void Load(void* buf, size_t len);
+ void Load(void* buf, size_t len);
// Retries incomplete writes, will either write len bytes or throw
- void Write(const void* buf, size_t len);
+ void Write(const void* buf, size_t len);
// Retries incomplete reads until EOF, throws on error
- size_t Pread(void* buf, size_t len, i64 offset) const;
+ 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
- void Pload(void* buf, size_t len, i64 offset) const;
+ void Pload(void* buf, size_t len, i64 offset) const;
// Retries incomplete writes, will either write len bytes or throw
- void Pwrite(const void* buf, size_t len, i64 offset) const;
+ void Pwrite(const void* buf, size_t len, i64 offset) const;
- void Flock(int op);
+ void Flock(int op);
//do not use, their meaning very platform-dependant
void SetDirect();
void ResetDirect();
-
+
/* Manual file cache management, length = 0 means "as much as possible" */
//measure amount of cached data in bytes, returns -1 if failed
@@ -214,12 +214,12 @@ public:
static TFile Temporary(const TString& prefix);
static TFile ForAppend(const TString& path);
-private:
- class TImpl;
+private:
+ class TImpl;
TSimpleIntrusivePtr<TImpl> Impl_;
-};
-
-TFile Duplicate(FILE*);
-TFile Duplicate(int);
+};
+
+TFile Duplicate(FILE*);
+TFile Duplicate(int);
bool PosixDisableReadAhead(FHANDLE fileHandle, void* addr) noexcept;
diff --git a/util/system/file_ut.cpp b/util/system/file_ut.cpp
index 941e6a50f3..322f36622c 100644
--- a/util/system/file_ut.cpp
+++ b/util/system/file_ut.cpp
@@ -1,13 +1,13 @@
#include "file.h"
-#include "fs.h"
+#include "fs.h"
#include "tempfile.h"
#include <library/cpp/testing/unittest/registar.h>
#include <util/stream/file.h>
#include <util/generic/yexception.h>
-
-class TFileTest: public TTestBase {
+
+class TFileTest: public TTestBase {
UNIT_TEST_SUITE(TFileTest);
UNIT_TEST(TestOpen);
UNIT_TEST(TestOpenSync);
@@ -115,45 +115,45 @@ public:
UNIT_ASSERT_EQUAL(data.length(), 12);
UNIT_ASSERT(data.StartsWith("12345"));
}
-};
-
-UNIT_TEST_SUITE_REGISTRATION(TFileTest);
-
-void TFileTest::TestOpen() {
+};
+
+UNIT_TEST_SUITE_REGISTRATION(TFileTest);
+
+void TFileTest::TestOpen() {
TString res;
- TFile f1;
-
- try {
- TFile f2("f1.txt", OpenExisting);
- } catch (const yexception& e) {
- res = e.what();
- }
- UNIT_ASSERT(!res.empty());
- res.remove();
-
- try {
- TFile f2("f1.txt", OpenAlways);
- f1 = f2;
- } catch (const yexception& e) {
- res = e.what();
- }
- UNIT_ASSERT(res.empty());
- UNIT_ASSERT(f1.IsOpen());
- UNIT_ASSERT_VALUES_EQUAL(f1.GetName(), "f1.txt");
- UNIT_ASSERT_VALUES_EQUAL(f1.GetLength(), 0);
-
- try {
+ TFile f1;
+
+ try {
+ TFile f2("f1.txt", OpenExisting);
+ } catch (const yexception& e) {
+ res = e.what();
+ }
+ UNIT_ASSERT(!res.empty());
+ res.remove();
+
+ try {
+ TFile f2("f1.txt", OpenAlways);
+ f1 = f2;
+ } catch (const yexception& e) {
+ res = e.what();
+ }
+ UNIT_ASSERT(res.empty());
+ UNIT_ASSERT(f1.IsOpen());
+ UNIT_ASSERT_VALUES_EQUAL(f1.GetName(), "f1.txt");
+ UNIT_ASSERT_VALUES_EQUAL(f1.GetLength(), 0);
+
+ try {
TFile f2("f1.txt", CreateNew);
- } catch (const yexception& e) {
- res = e.what();
- }
- UNIT_ASSERT(!res.empty());
- res.remove();
-
- f1.Close();
- UNIT_ASSERT(unlink("f1.txt") == 0);
-}
-
+ } catch (const yexception& e) {
+ res = e.what();
+ }
+ UNIT_ASSERT(!res.empty());
+ res.remove();
+
+ f1.Close();
+ UNIT_ASSERT(unlink("f1.txt") == 0);
+}
+
void TFileTest::TestOpenSync() {
TFile f1("f1.txt", CreateNew | Sync);
UNIT_ASSERT(f1.IsOpen());
@@ -162,60 +162,60 @@ void TFileTest::TestOpenSync() {
UNIT_ASSERT(unlink("f1.txt") == 0);
}
-void TFileTest::TestRW() {
+void TFileTest::TestRW() {
TFile f1("f1.txt", CreateNew);
- UNIT_ASSERT(f1.IsOpen());
- UNIT_ASSERT_VALUES_EQUAL(f1.GetName(), "f1.txt");
- UNIT_ASSERT_VALUES_EQUAL(f1.GetLength(), 0);
- ui32 d[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
+ UNIT_ASSERT(f1.IsOpen());
+ UNIT_ASSERT_VALUES_EQUAL(f1.GetName(), "f1.txt");
+ UNIT_ASSERT_VALUES_EQUAL(f1.GetLength(), 0);
+ ui32 d[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
f1.Write(&d, sizeof(ui32) * 10);
- UNIT_ASSERT_VALUES_EQUAL(f1.GetLength(), 40);
- UNIT_ASSERT_VALUES_EQUAL(f1.GetPosition(), 40);
- UNIT_ASSERT_VALUES_EQUAL(f1.Seek(12, sSet), 12);
- f1.Flush();
- ui32 v;
- f1.Load(&v, sizeof(v));
+ UNIT_ASSERT_VALUES_EQUAL(f1.GetLength(), 40);
+ UNIT_ASSERT_VALUES_EQUAL(f1.GetPosition(), 40);
+ UNIT_ASSERT_VALUES_EQUAL(f1.Seek(12, sSet), 12);
+ f1.Flush();
+ ui32 v;
+ f1.Load(&v, sizeof(v));
UNIT_ASSERT_VALUES_EQUAL(v, 3u);
- UNIT_ASSERT_VALUES_EQUAL(f1.GetPosition(), 16);
-
- TFile f2 = f1;
- UNIT_ASSERT(f2.IsOpen());
- UNIT_ASSERT_VALUES_EQUAL(f2.GetName(), "f1.txt");
- UNIT_ASSERT_VALUES_EQUAL(f2.GetPosition(), 16);
- UNIT_ASSERT_VALUES_EQUAL(f2.GetLength(), 40);
- f2.Write(&v, sizeof(v));
-
- UNIT_ASSERT_VALUES_EQUAL(f1.GetPosition(), 20);
- UNIT_ASSERT_VALUES_EQUAL(f1.Seek(-4, sCur), 16);
- v = 0;
- f1.Load(&v, sizeof(v));
+ UNIT_ASSERT_VALUES_EQUAL(f1.GetPosition(), 16);
+
+ TFile f2 = f1;
+ UNIT_ASSERT(f2.IsOpen());
+ UNIT_ASSERT_VALUES_EQUAL(f2.GetName(), "f1.txt");
+ UNIT_ASSERT_VALUES_EQUAL(f2.GetPosition(), 16);
+ UNIT_ASSERT_VALUES_EQUAL(f2.GetLength(), 40);
+ f2.Write(&v, sizeof(v));
+
+ UNIT_ASSERT_VALUES_EQUAL(f1.GetPosition(), 20);
+ UNIT_ASSERT_VALUES_EQUAL(f1.Seek(-4, sCur), 16);
+ v = 0;
+ f1.Load(&v, sizeof(v));
UNIT_ASSERT_VALUES_EQUAL(v, 3u);
- f1.Close();
- UNIT_ASSERT(!f1.IsOpen());
- UNIT_ASSERT(!f2.IsOpen());
- UNIT_ASSERT(unlink("f1.txt") == 0);
+ f1.Close();
+ UNIT_ASSERT(!f1.IsOpen());
+ UNIT_ASSERT(!f2.IsOpen());
+ UNIT_ASSERT(unlink("f1.txt") == 0);
}
-#ifdef _unix_
+#ifdef _unix_
#include <locale.h>
-#endif
-
-void TFileTest::TestLocale() {
-#ifdef _unix_
+#endif
+
+void TFileTest::TestLocale() {
+#ifdef _unix_
const char* loc = setlocale(LC_CTYPE, nullptr);
- setlocale(LC_CTYPE, "ru_RU.UTF-8");
-#endif
- TFile f("Имя.txt", CreateNew);
- UNIT_ASSERT(f.IsOpen());
- UNIT_ASSERT_VALUES_EQUAL(f.GetName(), "Имя.txt");
- UNIT_ASSERT_VALUES_EQUAL(f.GetLength(), 0);
- f.Close();
+ setlocale(LC_CTYPE, "ru_RU.UTF-8");
+#endif
+ TFile f("Имя.txt", CreateNew);
+ UNIT_ASSERT(f.IsOpen());
+ UNIT_ASSERT_VALUES_EQUAL(f.GetName(), "Имя.txt");
+ UNIT_ASSERT_VALUES_EQUAL(f.GetLength(), 0);
+ f.Close();
UNIT_ASSERT(NFs::Remove("Имя.txt"));
-#ifdef _unix_
- setlocale(LC_CTYPE, loc);
-#endif
-}
-
+#ifdef _unix_
+ setlocale(LC_CTYPE, loc);
+#endif
+}
+
void TFileTest::TestFlush() {
TTempFile tmp("tmp");
diff --git a/util/system/filemap.cpp b/util/system/filemap.cpp
index 7454a4cb94..aa05a4be33 100644
--- a/util/system/filemap.cpp
+++ b/util/system/filemap.cpp
@@ -1,10 +1,10 @@
#include "info.h"
#include "madvise.h"
-#include "defaults.h"
+#include "defaults.h"
#include "hi_lo.h"
#include <util/generic/buffer.h>
-#include <util/generic/yexception.h>
+#include <util/generic/yexception.h>
#include <util/generic/singleton.h>
#if defined(_win_)
@@ -149,7 +149,7 @@ public:
} else {
PtrStart_ = nullptr;
}
-#endif
+#endif
}
void CheckFile() const {
@@ -210,7 +210,7 @@ public:
return File_.IsOpen()
#if defined(_win_)
&& Mapping_ != nullptr
-#endif
+#endif
;
}
@@ -437,8 +437,8 @@ TMemoryMap::EOpenMode TMemoryMap::GetMode() const noexcept {
TFile TMemoryMap::GetFile() const noexcept {
return Impl_->GetFile();
-}
-
+}
+
TFileMap::TFileMap(const TMemoryMap& map) noexcept
: Map_(map)
{
@@ -523,8 +523,8 @@ TFileMap::~TFileMap() {
} catch (...) {
// ¯\_(ツ)_/¯
}
-}
-
+}
+
void TFileMap::Precharge(size_t pos, size_t size) const {
NPrivate::Precharge(Ptr(), MappedSize(), pos, size);
}
@@ -535,51 +535,51 @@ TMappedAllocation::TMappedAllocation(size_t size, bool shared, void* addr)
, Shared_(shared)
#if defined(_win_)
, Mapping_(nullptr)
-#endif
-{
+#endif
+{
if (size != 0) {
Alloc(size, addr);
}
-}
-
+}
+
void* TMappedAllocation::Alloc(size_t size, void* addr) {
assert(Ptr_ == nullptr);
#if defined(_win_)
(void)addr;
Mapping_ = CreateFileMapping((HANDLE)-1, nullptr, PAGE_READWRITE, 0, size ? size : 1, nullptr);
Ptr_ = MapViewOfFile(Mapping_, FILE_MAP_WRITE, 0, 0, size ? size : 1);
-#else
+#else
Ptr_ = mmap(addr, size, PROT_READ | PROT_WRITE, (Shared_ ? MAP_SHARED : MAP_PRIVATE) | MAP_ANON, -1, 0);
if (Ptr_ == (void*)MAP_FAILED) {
Ptr_ = nullptr;
- }
-#endif
+ }
+#endif
if (Ptr_ != nullptr) {
Size_ = size;
}
return Ptr_;
-}
-
+}
+
void TMappedAllocation::Dealloc() {
if (Ptr_ == nullptr) {
- return;
+ return;
}
#if defined(_win_)
UnmapViewOfFile(Ptr_);
CloseHandle(Mapping_);
Mapping_ = nullptr;
-#else
+#else
munmap((caddr_t)Ptr_, Size_);
-#endif
+#endif
Ptr_ = nullptr;
Size_ = 0;
-}
-
+}
+
void TMappedAllocation::swap(TMappedAllocation& with) {
DoSwap(Ptr_, with.Ptr_);
DoSwap(Size_, with.Size_);
#if defined(_win_)
DoSwap(Mapping_, with.Mapping_);
-#endif
-}
+#endif
+}
diff --git a/util/system/filemap.h b/util/system/filemap.h
index 11be64bff4..2edc313aaa 100644
--- a/util/system/filemap.h
+++ b/util/system/filemap.h
@@ -7,7 +7,7 @@
#include <util/generic/noncopyable.h>
#include <util/generic/ptr.h>
#include <util/generic/utility.h>
-#include <util/generic/yexception.h>
+#include <util/generic/yexception.h>
#include <util/generic/flags.h>
#include <util/generic/string.h>
@@ -117,7 +117,7 @@ public:
TFileMap(const TFileMap& fm) noexcept;
~TFileMap();
-
+
TMapResult Map(i64 offset, size_t size);
TMapResult ResizeAndRemap(i64 offset, size_t size);
void Unmap();
@@ -125,7 +125,7 @@ public:
void Flush(void* ptr, size_t size) {
Flush(ptr, size, true);
}
-
+
void Flush() {
Flush(Ptr(), MappedSize());
}
@@ -288,11 +288,11 @@ private:
};
class TMappedAllocation: TMoveOnly {
-public:
+public:
TMappedAllocation(size_t size = 0, bool shared = false, void* addr = nullptr);
~TMappedAllocation() {
- Dealloc();
- }
+ Dealloc();
+ }
TMappedAllocation(TMappedAllocation&& other) {
this->swap(other);
}
@@ -301,13 +301,13 @@ public:
return *this;
}
void* Alloc(size_t size, void* addr = nullptr);
- void Dealloc();
- void* Ptr() const {
+ void Dealloc();
+ void* Ptr() const {
return Ptr_;
- }
- char* Data(ui32 pos = 0) const {
+ }
+ char* Data(ui32 pos = 0) const {
return (char*)(Ptr_ ? ((char*)Ptr_ + pos) : nullptr);
- }
+ }
char* Begin() const noexcept {
return (char*)Ptr();
}
@@ -316,66 +316,66 @@ public:
}
size_t MappedSize() const {
return Size_;
- }
+ }
void swap(TMappedAllocation& with);
-private:
+private:
void* Ptr_ = nullptr;
size_t Size_ = 0;
bool Shared_ = false;
#ifdef _win_
void* Mapping_ = nullptr;
#endif
-};
-
+};
+
template <class T>
class TMappedArray: private TMappedAllocation {
-public:
+public:
TMappedArray(size_t siz = 0)
: TMappedAllocation(0)
{
- if (siz)
- Create(siz);
- }
+ if (siz)
+ Create(siz);
+ }
~TMappedArray() {
- Destroy();
- }
+ Destroy();
+ }
T* Create(size_t siz) {
Y_ASSERT(MappedSize() == 0 && Ptr() == nullptr);
T* arr = (T*)Alloc((sizeof(T) * siz));
if (!arr)
return nullptr;
Y_ASSERT(MappedSize() == sizeof(T) * siz);
- for (size_t n = 0; n < siz; n++)
+ for (size_t n = 0; n < siz; n++)
new (&arr[n]) T();
return arr;
- }
- void Destroy() {
- T* arr = (T*)Ptr();
- if (arr) {
- for (size_t n = 0; n < size(); n++)
- arr[n].~T();
- Dealloc();
- }
- }
+ }
+ void Destroy() {
+ T* arr = (T*)Ptr();
+ if (arr) {
+ for (size_t n = 0; n < size(); n++)
+ arr[n].~T();
+ Dealloc();
+ }
+ }
T& operator[](size_t pos) {
Y_ASSERT(pos < size());
- return ((T*)Ptr())[pos];
- }
+ return ((T*)Ptr())[pos];
+ }
const T& operator[](size_t pos) const {
Y_ASSERT(pos < size());
- return ((T*)Ptr())[pos];
- }
+ return ((T*)Ptr())[pos];
+ }
T* begin() {
return (T*)Ptr();
}
T* end() {
return (T*)((char*)Ptr() + MappedSize());
}
- size_t size() const {
+ size_t size() const {
return MappedSize() / sizeof(T);
- }
+ }
void swap(TMappedArray<T>& with) {
TMappedAllocation::swap(with);
- }
-};
+ }
+};
diff --git a/util/system/filemap_ut.cpp b/util/system/filemap_ut.cpp
index 73f109dc88..c53b874586 100644
--- a/util/system/filemap_ut.cpp
+++ b/util/system/filemap_ut.cpp
@@ -18,7 +18,7 @@ Y_UNIT_TEST_SUITE(TFileMapTest) {
char data[] = "abcdefgh";
TFile file(FileName_, CreateAlways | WrOnly);
- file.Write(static_cast<void*>(data), sizeof(data));
+ file.Write(static_cast<void*>(data), sizeof(data));
file.Close();
{
@@ -218,7 +218,7 @@ Y_UNIT_TEST_SUITE(TFileMapTest) {
size_t sz = sizeof(data) / sizeof(data[0]);
TFile file(FileName_, CreateAlways | WrOnly);
- file.Write(static_cast<void*>(data), sizeof(data));
+ file.Write(static_cast<void*>(data), sizeof(data));
file.Close();
mappedArray.Init(FileName_);
@@ -253,8 +253,8 @@ Y_UNIT_TEST_SUITE(TFileMapTest) {
// actual test end
file = TFile(FileName_, WrOnly);
- file.Seek(0, sEnd);
- file.Write("x", 1);
+ file.Seek(0, sEnd);
+ file.Write("x", 1);
file.Close();
bool caught = false;
@@ -279,7 +279,7 @@ Y_UNIT_TEST_SUITE(TFileMapTest) {
UNIT_ASSERT(mappedArray.begin() + sz == mappedArray.end());
for (size_t i = 0; i < sz; ++i) {
- mappedArray[i] = (ui32)i;
+ mappedArray[i] = (ui32)i;
}
for (size_t i = 0; i < sz; ++i) {
UNIT_ASSERT(mappedArray[i] == i);
@@ -287,7 +287,7 @@ Y_UNIT_TEST_SUITE(TFileMapTest) {
TMappedArray<ui32> mappedArray2(1000);
mappedArray.swap(mappedArray2);
- UNIT_ASSERT(mappedArray.size() == 1000 && mappedArray2.size() == sz);
+ UNIT_ASSERT(mappedArray.size() == 1000 && mappedArray2.size() == sz);
}
Y_UNIT_TEST(TestMemoryMap) {
diff --git a/util/system/flock.cpp b/util/system/flock.cpp
index fe88fecaff..f00b7fd5d1 100644
--- a/util/system/flock.cpp
+++ b/util/system/flock.cpp
@@ -1,36 +1,36 @@
#include "flock.h"
-
-#ifndef _unix_
-
+
+#ifndef _unix_
+
#include <util/generic/utility.h>
#include "winint.h"
#include <io.h>
#include <errno.h>
-
+
#ifdef __cplusplus
-extern "C" {
+extern "C" {
#endif
-
+
int flock(int fd, int op) {
return Flock((HANDLE)_get_osfhandle(fd), op);
}
-
+
int Flock(void* hdl, int op) {
errno = 0;
-
+
if (hdl == INVALID_HANDLE_VALUE) {
errno = EBADF;
return -1;
}
-
+
DWORD low = 1, high = 0;
OVERLAPPED io;
-
+
Zero(io);
UnlockFileEx(hdl, 0, low, high, &io);
-
+
switch (op & ~LOCK_NB) {
case LOCK_EX:
case LOCK_SH: {
@@ -47,9 +47,9 @@ extern "C" {
if (LockFileEx(hdl, mode, 0, low, high, &io)) {
return 0;
}
- }
+ }
break;
- }
+ }
case LOCK_UN:
return 0;
break;
@@ -58,14 +58,14 @@ extern "C" {
}
errno = EINVAL;
return -1;
- }
-
+ }
+
int fsync(int fd) {
return _commit(fd);
}
-
+
#ifdef __cplusplus
-}
+}
#endif
-
-#endif
+
+#endif
diff --git a/util/system/flock.h b/util/system/flock.h
index 797b1970a1..41eb6a1e5b 100644
--- a/util/system/flock.h
+++ b/util/system/flock.h
@@ -1,14 +1,14 @@
#pragma once
-
+
#include "error.h"
-#include "defaults.h"
+#include "defaults.h"
#include "file.h"
-
-#if defined(_unix_)
-
+
+#if defined(_unix_)
+
#include <sys/file.h>
#include <fcntl.h>
-
+
static inline int Flock(int fd, int op) {
return flock(fd, op);
}
@@ -16,20 +16,20 @@ static inline int Flock(int fd, int op) {
#else // not _unix_
#ifdef __cplusplus
-extern "C" {
+extern "C" {
#endif
-
+
#define LOCK_SH 1 /* shared lock */
#define LOCK_EX 2 /* exclusive lock */
#define LOCK_NB 4 /* don't block when locking */
#define LOCK_UN 8 /* unlock */
-
+
int Flock(void* hndl, int operation);
int flock(int fd, int operation);
int fsync(int fd);
-
+
#ifdef __cplusplus
-}
+}
#endif
-
+
#endif // not _unix_
diff --git a/util/system/fs.cpp b/util/system/fs.cpp
index d2611a8ccc..5ca9a77c9f 100644
--- a/util/system/fs.cpp
+++ b/util/system/fs.cpp
@@ -1,9 +1,9 @@
-#include "fs.h"
-#include "defaults.h"
+#include "fs.h"
+#include "defaults.h"
#if defined(_win_)
#include "fs_win.h"
-#else
+#else
#include <unistd.h>
#include <errno.h>
#endif
@@ -11,17 +11,17 @@
#include <util/generic/yexception.h>
#include <util/memory/tempbuf.h>
#include <util/stream/file.h>
-#include <util/charset/wide.h>
+#include <util/charset/wide.h>
#include <util/folder/iterator.h>
#include <util/system/fstat.h>
#include <util/folder/path.h>
bool NFs::Remove(const TString& path) {
-#if defined(_win_)
+#if defined(_win_)
return NFsPrivate::WinRemove(path);
-#else
+#else
return ::remove(path.data()) == 0;
-#endif
+#endif
}
void NFs::RemoveRecursive(const TString& path) {
@@ -107,19 +107,19 @@ bool NFs::HardLink(const TString& existingPath, const TString& newPath) {
}
bool NFs::SymLink(const TString& targetPath, const TString& linkPath) {
-#if defined(_win_)
+#if defined(_win_)
return NFsPrivate::WinSymLink(targetPath, linkPath);
-#elif defined(_unix_)
+#elif defined(_unix_)
return 0 == symlink(targetPath.data(), linkPath.data());
-#endif
-}
-
+#endif
+}
+
TString NFs::ReadLink(const TString& path) {
-#if defined(_win_)
+#if defined(_win_)
return NFsPrivate::WinReadLink(path);
-#elif defined(_unix_)
- TTempBuf buf;
- while (true) {
+#elif defined(_unix_)
+ TTempBuf buf;
+ while (true) {
ssize_t r = readlink(path.data(), buf.Data(), buf.Size());
if (r < 0) {
ythrow yexception() << "can't read link " << path << ", errno = " << errno;
@@ -127,11 +127,11 @@ TString NFs::ReadLink(const TString& path) {
if (r < (ssize_t)buf.Size()) {
return TString(buf.Data(), r);
}
- buf = TTempBuf(buf.Size() * 2);
- }
-#endif
-}
-
+ buf = TTempBuf(buf.Size() * 2);
+ }
+#endif
+}
+
void NFs::Cat(const TString& dstPath, const TString& srcPath) {
TUnbufferedFileInput src(srcPath);
TUnbufferedFileOutput dst(TFile(dstPath, ForAppend | WrOnly | Seq));
diff --git a/util/system/fs.h b/util/system/fs.h
index 237daf2d2d..1b51613cd5 100644
--- a/util/system/fs.h
+++ b/util/system/fs.h
@@ -29,7 +29,7 @@ namespace NFs {
/// @returns true on success or false otherwise
/// LastSystemError() is set in case of failure
bool Remove(const TString& path);
-
+
/// Remove a file or directory with contents
///
/// @param[in] path Path to file or directory
diff --git a/util/system/fs_ut.cpp b/util/system/fs_ut.cpp
index de071ebf55..7c9636ce3c 100644
--- a/util/system/fs_ut.cpp
+++ b/util/system/fs_ut.cpp
@@ -1,24 +1,24 @@
-#include "fs.h"
-
+#include "fs.h"
+
#include <library/cpp/testing/unittest/registar.h>
-
+
#include "file.h"
#include "sysstat.h"
#include "fstat.h"
-#include <util/folder/dirut.h>
+#include <util/folder/dirut.h>
#include <util/folder/path.h>
-
+
//WARNING: on windows the test must be run with administative rules
-class TFsTest: public TTestBase {
- UNIT_TEST_SUITE(TFsTest);
+class TFsTest: public TTestBase {
+ UNIT_TEST_SUITE(TFsTest);
UNIT_TEST(TestCreateRemove);
UNIT_TEST(TestRename);
UNIT_TEST(TestSymlink);
UNIT_TEST(TestHardlink);
UNIT_TEST(TestCwdOpts);
UNIT_TEST(TestEnsureExists);
- UNIT_TEST_SUITE_END();
+ UNIT_TEST_SUITE_END();
public:
void TestCreateRemove();
@@ -27,10 +27,10 @@ public:
void TestHardlink();
void TestCwdOpts();
void TestEnsureExists();
-};
-
-UNIT_TEST_SUITE_REGISTRATION(TFsTest);
-
+};
+
+UNIT_TEST_SUITE_REGISTRATION(TFsTest);
+
static void Touch(const TFsPath& path) {
TFile file(path, CreateAlways | WrOnly);
file.Write("123", 3);
@@ -192,10 +192,10 @@ void TFsTest::TestHardlink() {
}
static void RunSymLinkTest(TString fileLocalName, TString symLinkName) {
- // if previous running was failed
+ // if previous running was failed
TFsPath subDir = "tempsubdir";
TFsPath srcFile = subDir / fileLocalName;
-
+
TFsPath subsubDir1 = subDir / "dir1";
TFsPath subsubDir2 = subDir / "dir2";
@@ -215,51 +215,51 @@ static void RunSymLinkTest(TString fileLocalName, TString symLinkName) {
NFs::MakeDirectory(subDir);
NFs::MakeDirectory(subsubDir1, NFs::FP_NONSECRET_FILE);
NFs::MakeDirectory(subsubDir2, NFs::FP_SECRET_FILE);
- {
+ {
TFile file(srcFile, CreateNew | WrOnly);
- file.Write("1234567", 7);
- }
+ file.Write("1234567", 7);
+ }
UNIT_ASSERT(NFs::SymLink(subDir, linkD1));
UNIT_ASSERT(NFs::SymLink("../dir2", linkD2));
UNIT_ASSERT(NFs::SymLink("../dir3", dangling));
UNIT_ASSERT_STRINGS_EQUAL(NFs::ReadLink(linkD2), TString("..") + LOCSLASH_S "dir2");
UNIT_ASSERT_STRINGS_EQUAL(NFs::ReadLink(dangling), TString("..") + LOCSLASH_S "dir3");
- {
+ {
TFile file(linkD1 / fileLocalName, OpenExisting | RdOnly);
- UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 7);
- }
+ UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 7);
+ }
UNIT_ASSERT(NFs::SymLink(srcFile, symLinkName));
- {
+ {
TFile file(symLinkName, OpenExisting | RdOnly);
- UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 7);
- }
- {
+ UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 7);
+ }
+ {
TFileStat fs(linkD1);
- UNIT_ASSERT(!fs.IsFile());
- UNIT_ASSERT(fs.IsDir());
- UNIT_ASSERT(!fs.IsSymlink());
- }
- {
+ UNIT_ASSERT(!fs.IsFile());
+ UNIT_ASSERT(fs.IsDir());
+ UNIT_ASSERT(!fs.IsSymlink());
+ }
+ {
TFileStat fs(linkD1, true);
- UNIT_ASSERT(!fs.IsFile());
- //UNIT_ASSERT(fs.IsDir()); // failed on unix
- UNIT_ASSERT(fs.IsSymlink());
- }
- {
+ UNIT_ASSERT(!fs.IsFile());
+ //UNIT_ASSERT(fs.IsDir()); // failed on unix
+ UNIT_ASSERT(fs.IsSymlink());
+ }
+ {
TFileStat fs(symLinkName);
- UNIT_ASSERT(fs.IsFile());
- UNIT_ASSERT(!fs.IsDir());
- UNIT_ASSERT(!fs.IsSymlink());
+ UNIT_ASSERT(fs.IsFile());
+ UNIT_ASSERT(!fs.IsDir());
+ UNIT_ASSERT(!fs.IsSymlink());
UNIT_ASSERT_VALUES_EQUAL(fs.Size, 7u);
- }
+ }
- {
+ {
TFileStat fs(symLinkName, true);
//UNIT_ASSERT(fs.IsFile()); // no evidence that symlink has to be a file as well
- UNIT_ASSERT(!fs.IsDir());
- UNIT_ASSERT(fs.IsSymlink());
- }
-
+ UNIT_ASSERT(!fs.IsDir());
+ UNIT_ASSERT(fs.IsSymlink());
+ }
+
UNIT_ASSERT(NFs::Remove(symLinkName));
UNIT_ASSERT(NFs::Exists(srcFile));
@@ -274,7 +274,7 @@ static void RunSymLinkTest(TString fileLocalName, TString symLinkName) {
UNIT_ASSERT(NFs::Remove(subsubDir1));
UNIT_ASSERT(NFs::Remove(subsubDir2));
UNIT_ASSERT(NFs::Remove(subDir));
-}
+}
void TFsTest::TestSymlink() {
// if previous running was failed
diff --git a/util/system/fs_win.cpp b/util/system/fs_win.cpp
index a410ccac06..c03dcea108 100644
--- a/util/system/fs_win.cpp
+++ b/util/system/fs_win.cpp
@@ -1,13 +1,13 @@
-#include "fs_win.h"
-#include "defaults.h"
-#include "maxlen.h"
-
-#include <util/folder/dirut.h>
-#include <util/charset/wide.h>
+#include "fs_win.h"
+#include "defaults.h"
+#include "maxlen.h"
+
+#include <util/folder/dirut.h>
+#include <util/charset/wide.h>
#include "file.h"
-
+
#include <winioctl.h>
-
+
namespace NFsPrivate {
static LPCWSTR UTF8ToWCHAR(const TStringBuf str, TUtf16String& wstr) {
wstr.resize(str.size());
@@ -17,8 +17,8 @@ namespace NFsPrivate {
wstr.erase(written);
static_assert(sizeof(WCHAR) == sizeof(wchar16), "expect sizeof(WCHAR) == sizeof(wchar16)");
return (const WCHAR*)wstr.data();
- }
-
+ }
+
static TString WCHARToUTF8(const LPWSTR wstr, size_t len) {
static_assert(sizeof(WCHAR) == sizeof(wchar16), "expect sizeof(WCHAR) == sizeof(wchar16)");
@@ -49,7 +49,7 @@ namespace NFsPrivate {
}
return MoveFileExW(opPtr, npPtr, MOVEFILE_REPLACE_EXISTING) != 0;
- }
+ }
bool WinRemove(const TString& path) {
TUtf16String wstr;
@@ -64,9 +64,9 @@ namespace NFsPrivate {
return ::RemoveDirectoryW(wname) != 0;
return ::DeleteFileW(wname) != 0;
}
-
+
return false;
- }
+ }
bool WinSymLink(const TString& targetName, const TString& linkName) {
TString tName(targetName);
@@ -96,11 +96,11 @@ namespace NFsPrivate {
LPCWSTR ptrFullTarget = UTF8ToWCHAR(fullTarget, fullTargetW);
attr = ::GetFileAttributesW(ptrFullTarget);
}
- }
- }
+ }
+ }
return 0 != CreateSymbolicLinkW(lname, wname, attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY) ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0);
- }
-
+ }
+
bool WinHardLink(const TString& existingPath, const TString& newPath) {
TUtf16String ep, np;
LPCWSTR epPtr = UTF8ToWCHAR(existingPath, ep);
@@ -144,29 +144,29 @@ namespace NFsPrivate {
return CreateDirectoryW(ptr, (LPSECURITY_ATTRIBUTES) nullptr);
}
// edited part of <Ntifs.h> from Windows DDK
-
-#define SYMLINK_FLAG_RELATIVE 1
-
+
+#define SYMLINK_FLAG_RELATIVE 1
+
struct TReparseBufferHeader {
USHORT SubstituteNameOffset;
USHORT SubstituteNameLength;
USHORT PrintNameOffset;
USHORT PrintNameLength;
};
-
+
struct TSymbolicLinkReparseBuffer: public TReparseBufferHeader {
ULONG Flags; // 0 or SYMLINK_FLAG_RELATIVE
wchar16 PathBuffer[1];
};
-
+
struct TMountPointReparseBuffer: public TReparseBufferHeader {
wchar16 PathBuffer[1];
};
-
+
struct TGenericReparseBuffer {
wchar16 DataBuffer[1];
};
-
+
struct REPARSE_DATA_BUFFER {
ULONG ReparseTag;
USHORT ReparseDataLength;
@@ -176,10 +176,10 @@ namespace NFsPrivate {
TMountPointReparseBuffer MountPointReparseBuffer;
TGenericReparseBuffer GenericReparseBuffer;
};
- };
-
+ };
+
// the end of edited part of <Ntifs.h>
-
+
TString WinReadLink(const TString& name) {
TFileHandle h = CreateFileWithUtf8Name(name, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING,
FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, true);
@@ -200,34 +200,34 @@ namespace NFsPrivate {
}
//this reparse point is unsupported in arcadia
return TString();
- } else {
+ } else {
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
buf = TTempBuf(buf.Size() * 2);
} else {
ythrow yexception() << "can't read link " << name;
}
- }
- }
- }
-
+ }
+ }
+ }
+
// we can't use this function to get an analog of unix inode due to a lot of NTFS folders do not have this GUID
//(it will be 'create' case really)
/*
-bool GetObjectId(const char* path, GUID* id) {
- TFileHandle h = CreateFileWithUtf8Name(path, 0, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+bool GetObjectId(const char* path, GUID* id) {
+ TFileHandle h = CreateFileWithUtf8Name(path, 0, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT|FILE_FLAG_BACKUP_SEMANTICS, true);
- if (h.IsOpen()) {
- FILE_OBJECTID_BUFFER fob;
- DWORD resSize = 0;
+ if (h.IsOpen()) {
+ FILE_OBJECTID_BUFFER fob;
+ DWORD resSize = 0;
if (DeviceIoControl(h, FSCTL_CREATE_OR_GET_OBJECT_ID, nullptr, 0, &fob, sizeof(fob), &resSize, nullptr)) {
Y_ASSERT(resSize == sizeof(fob));
- memcpy(id, &fob.ObjectId, sizeof(GUID));
- return true;
- }
- }
- memset(id, 0, sizeof(GUID));
- return false;
-}
-*/
+ memcpy(id, &fob.ObjectId, sizeof(GUID));
+ return true;
+ }
+ }
+ memset(id, 0, sizeof(GUID));
+ return false;
+}
+*/
}
diff --git a/util/system/fs_win.h b/util/system/fs_win.h
index 8086129828..5c304d7d3c 100644
--- a/util/system/fs_win.h
+++ b/util/system/fs_win.h
@@ -1,11 +1,11 @@
-#pragma once
-
-#include "winint.h"
-#include "defaults.h"
-
+#pragma once
+
+#include "winint.h"
+#include "defaults.h"
+
#include <util/generic/strbuf.h>
#include <util/generic/string.h>
-
+
namespace NFsPrivate {
bool WinRename(const TString& oldPath, const TString& newPath);
diff --git a/util/system/fstat.cpp b/util/system/fstat.cpp
index 81e98cbc6b..7e253b9f80 100644
--- a/util/system/fstat.cpp
+++ b/util/system/fstat.cpp
@@ -1,4 +1,4 @@
-#include "fstat.h"
+#include "fstat.h"
#include "file.h"
#include <sys/stat.h>
@@ -16,20 +16,20 @@
#define _S_IFLNK 0x80000000
ui32 GetFileMode(DWORD fileAttributes) {
- ui32 mode = 0;
- if (fileAttributes == 0xFFFFFFFF)
- return mode;
+ ui32 mode = 0;
+ if (fileAttributes == 0xFFFFFFFF)
+ return mode;
if (fileAttributes & FILE_ATTRIBUTE_DEVICE)
- mode |= _S_IFCHR;
+ mode |= _S_IFCHR;
if (fileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
- mode |= _S_IFLNK; // todo: was undefined by the moment of writing this code
+ mode |= _S_IFLNK; // todo: was undefined by the moment of writing this code
if (fileAttributes & FILE_ATTRIBUTE_DIRECTORY)
- mode |= _S_IFDIR;
- if (fileAttributes & (FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE))
- mode |= _S_IFREG;
+ mode |= _S_IFDIR;
+ if (fileAttributes & (FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE))
+ mode |= _S_IFREG;
if ((fileAttributes & FILE_ATTRIBUTE_READONLY) == 0)
mode |= _S_IWRITE;
- return mode;
+ return mode;
}
#define S_ISDIR(st_mode) (st_mode & _S_IFDIR)
@@ -57,21 +57,21 @@ static void MakeStat(TFileStat& st, const TSystemFStat& fs) {
st.CTime = fs.st_ctime;
st.INode = fs.st_ino;
#else
- timeval tv;
+ timeval tv;
FileTimeToTimeval(&fs.ftCreationTime, &tv);
- st.CTime = tv.tv_sec;
+ st.CTime = tv.tv_sec;
FileTimeToTimeval(&fs.ftLastAccessTime, &tv);
- st.ATime = tv.tv_sec;
+ st.ATime = tv.tv_sec;
FileTimeToTimeval(&fs.ftLastWriteTime, &tv);
- st.MTime = tv.tv_sec;
+ st.MTime = tv.tv_sec;
st.NLinks = fs.nNumberOfLinks;
st.Mode = GetFileMode(fs.dwFileAttributes);
- st.Uid = 0;
- st.Gid = 0;
+ st.Uid = 0;
+ st.Gid = 0;
st.Size = ((ui64)fs.nFileSizeHigh << 32) | fs.nFileSizeLow;
st.AllocationSize = st.Size; // FIXME
st.INode = ((ui64)fs.nFileIndexHigh << 32) | fs.nFileIndexLow;
-#endif
+#endif
}
static bool GetStatByHandle(TSystemFStat& fs, FHANDLE f) {
@@ -147,7 +147,7 @@ bool TFileStat::IsDir() const noexcept {
bool TFileStat::IsSymlink() const noexcept {
return S_ISLNK(Mode);
}
-
+
bool operator==(const TFileStat& l, const TFileStat& r) noexcept {
return l.Mode == r.Mode &&
l.Uid == r.Uid &&
@@ -163,27 +163,27 @@ bool operator!=(const TFileStat& l, const TFileStat& r) noexcept {
return !(l == r);
}
-i64 GetFileLength(FHANDLE fd) {
+i64 GetFileLength(FHANDLE fd) {
#if defined(_win_)
- LARGE_INTEGER pos;
- if (!::GetFileSizeEx(fd, &pos))
- return -1L;
- return pos.QuadPart;
+ LARGE_INTEGER pos;
+ if (!::GetFileSizeEx(fd, &pos))
+ return -1L;
+ return pos.QuadPart;
#elif defined(_unix_)
- struct stat statbuf;
+ struct stat statbuf;
if (::fstat(fd, &statbuf) != 0) {
- return -1L;
+ 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
+ return statbuf.st_size;
+#else
#error unsupported platform
-#endif
-}
+#endif
+}
i64 GetFileLength(const char* name) {
#if defined(_win_)
diff --git a/util/system/fstat.h b/util/system/fstat.h
index 64e79e1b55..418303fd28 100644
--- a/util/system/fstat.h
+++ b/util/system/fstat.h
@@ -41,7 +41,7 @@ public:
private:
void MakeFromFileName(const char* fileName, bool nofollow);
};
-
-i64 GetFileLength(FHANDLE fd);
+
+i64 GetFileLength(FHANDLE fd);
i64 GetFileLength(const char* name);
i64 GetFileLength(const TString& name);
diff --git a/util/system/fstat_ut.cpp b/util/system/fstat_ut.cpp
index 160ecd936e..8bef783b32 100644
--- a/util/system/fstat_ut.cpp
+++ b/util/system/fstat_ut.cpp
@@ -1,11 +1,11 @@
-#include "fstat.h"
-#include "file.h"
-#include "sysstat.h"
-#include "fs.h"
-
+#include "fstat.h"
+#include "file.h"
+#include "sysstat.h"
+#include "fs.h"
+
#include <library/cpp/testing/unittest/registar.h>
#include <library/cpp/testing/unittest/tests_data.h>
-
+
#include <util/folder/path.h>
Y_UNIT_TEST_SUITE(TestFileStat) {
@@ -26,11 +26,11 @@ Y_UNIT_TEST_SUITE(TestFileStat) {
UNIT_ASSERT(fs.NLinks == 1);
oFs = fs;
}
-
+
UNIT_ASSERT(file.IsOpen());
UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 7);
file.Close();
- }
+ }
TFileStat cFs(fileName);
UNIT_ASSERT(cFs.IsFile());
UNIT_ASSERT(!cFs.IsDir());
@@ -45,7 +45,7 @@ Y_UNIT_TEST_SUITE(TestFileStat) {
UNIT_ASSERT_VALUES_EQUAL(cFs.INode, oFs.INode);
UNIT_ASSERT(unlink(fileName.data()) == 0);
}
-
+
Y_UNIT_TEST(DirTest) {
Mkdir("tmpd", MODE0777);
TFileStat fs("tmpd");
@@ -60,8 +60,8 @@ Y_UNIT_TEST_SUITE(TestFileStat) {
UNIT_ASSERT(!fs.IsSymlink());
UNIT_ASSERT(fs.Size == 0);
UNIT_ASSERT(fs.CTime == 0);
- }
-
+ }
+
Y_UNIT_TEST(SymlinkToExistingFileTest) {
const auto path = GetOutputPath() / "file_1";
const auto link = GetOutputPath() / "symlink_1";
diff --git a/util/system/hostname.cpp b/util/system/hostname.cpp
index 386f646d6b..e64f4bb185 100644
--- a/util/system/hostname.cpp
+++ b/util/system/hostname.cpp
@@ -13,8 +13,8 @@
#include <WinSock2.h>
#endif
-#include "defaults.h"
-#include "yassert.h"
+#include "defaults.h"
+#include "yassert.h"
#include "hostname.h"
namespace {
diff --git a/util/system/info.cpp b/util/system/info.cpp
index cf6681e89a..34699e5dd2 100644
--- a/util/system/info.cpp
+++ b/util/system/info.cpp
@@ -146,14 +146,14 @@ size_t NSystemInfo::NumberOfCpus() {
size_t NSystemInfo::LoadAverage(double* la, size_t len) {
#if defined(_win_) || defined(_musl_) || defined(_bionic_)
- int ret = -1;
-#else
+ int ret = -1;
+#else
for (size_t i = 0; i < len; ++i) {
la[i] = 0;
}
int ret = getloadavg(la, len);
-#endif
+#endif
if (ret < 0) {
for (size_t i = 0; i < len; ++i) {
diff --git a/util/system/info.h b/util/system/info.h
index 73ebe48a9a..906439ac40 100644
--- a/util/system/info.h
+++ b/util/system/info.h
@@ -1,6 +1,6 @@
#pragma once
-#include "defaults.h"
+#include "defaults.h"
namespace NSystemInfo {
size_t NumberOfCpus();
diff --git a/util/system/maxlen.h b/util/system/maxlen.h
index e1ff7f5008..1eac920e53 100644
--- a/util/system/maxlen.h
+++ b/util/system/maxlen.h
@@ -15,11 +15,11 @@
#define LINKTEXT_MAX 1024
-#ifdef WIN32
+#ifdef WIN32
#ifndef PATH_MAX
#define PATH_MAX _MAX_PATH
#endif
-#else
+#else
#ifndef MAX_PATH
#define MAX_PATH PATH_MAX
diff --git a/util/system/mktemp.cpp b/util/system/mktemp.cpp
index 505b7b4a4b..355d1be875 100644
--- a/util/system/mktemp.cpp
+++ b/util/system/mktemp.cpp
@@ -4,8 +4,8 @@
#include <util/generic/yexception.h>
#include <util/stream/file.h>
-#include <cerrno>
-#include <cstring>
+#include <cerrno>
+#include <cstring>
#ifdef _win32_
#include "winint.h"
diff --git a/util/system/mktemp_system.cpp b/util/system/mktemp_system.cpp
index 32bea2987c..d84e596c47 100644
--- a/util/system/mktemp_system.cpp
+++ b/util/system/mktemp_system.cpp
@@ -31,8 +31,8 @@
* SUCH DAMAGE.
*/
-#include "defaults.h"
-
+#include "defaults.h"
+
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
@@ -42,7 +42,7 @@
#include <ctype.h>
#ifdef _win32_
- #include "winint.h"
+ #include "winint.h"
#include <util/folder/dirut.h>
#else
#include <unistd.h>
diff --git a/util/system/mutex.h b/util/system/mutex.h
index 032630d134..60de2730f2 100644
--- a/util/system/mutex.h
+++ b/util/system/mutex.h
@@ -14,7 +14,7 @@ public:
inline bool TryAcquire() noexcept {
return true;
}
-
+
inline void Release() noexcept {
}
diff --git a/util/system/sem.cpp b/util/system/sem.cpp
index 4a93b903b5..3e773e08a4 100644
--- a/util/system/sem.cpp
+++ b/util/system/sem.cpp
@@ -4,11 +4,11 @@
#include <malloc.h>
#elif defined(_sun)
#include <alloca.h>
-#endif
+#endif
#include <cerrno>
#include <cstring>
-
+
#ifdef _win_
#include "winint.h"
#else
@@ -23,7 +23,7 @@
#endif
#endif
-#ifdef USE_SYSV_SEMAPHORES
+#ifdef USE_SYSV_SEMAPHORES
#include <errno.h>
#include <sys/types.h>
#include <sys/ipc.h>
@@ -38,7 +38,7 @@ union semun {
#else
union semun arg;
#endif
-#endif
+#endif
#include <util/digest/city.h>
#include <util/string/cast.h>
@@ -50,7 +50,7 @@ namespace {
private:
#ifdef _win_
using SEMHANDLE = HANDLE;
-#else
+#else
#ifdef USE_SYSV_SEMAPHORES
using SEMHANDLE = int;
#else
@@ -102,12 +102,12 @@ namespace {
}
#endif
#endif
- }
-
+ }
+
inline ~TSemaphoreImpl() {
#ifdef _win_
::CloseHandle(Handle);
-#else
+#else
#ifdef USE_SYSV_SEMAPHORES
// we DO NOT want 'semctl(Handle, 0, IPC_RMID)' for multiprocess tasks;
//struct sembuf ops[] = {{0, 0, IPC_NOWAIT}};
@@ -116,13 +116,13 @@ namespace {
#else
sem_close(Handle); // we DO NOT want sem_unlink(...)
#endif
-#endif
+#endif
}
-
+
inline void Release() noexcept {
#ifdef _win_
::ReleaseSemaphore(Handle, 1, 0);
-#else
+#else
#ifdef USE_SYSV_SEMAPHORES
struct sembuf ops[] = {{0, 1, SEM_UNDO}};
int ret = semop(Handle, ops, 1);
@@ -130,15 +130,15 @@ namespace {
int ret = sem_post(Handle);
#endif
Y_VERIFY(ret == 0, "can not release semaphore");
-#endif
+#endif
}
-
+
//The UNIX semaphore object does not support a timed "wait", and
//hence to maintain consistancy, for win32 case we use INFINITE or 0 timeout.
inline void Acquire() noexcept {
#ifdef _win_
Y_VERIFY(::WaitForSingleObject(Handle, INFINITE) == WAIT_OBJECT_0, "can not acquire semaphore");
-#else
+#else
#ifdef USE_SYSV_SEMAPHORES
struct sembuf ops[] = {{0, -1, SEM_UNDO}};
int ret = semop(Handle, ops, 1);
@@ -146,16 +146,16 @@ namespace {
int ret = sem_wait(Handle);
#endif
Y_VERIFY(ret == 0, "can not acquire semaphore");
-#endif
+#endif
}
-
+
inline bool TryAcquire() noexcept {
#ifdef _win_
// zero-second time-out interval
// WAIT_OBJECT_0: current free count > 0
// WAIT_TIMEOUT: current free count == 0
return ::WaitForSingleObject(Handle, 0) == WAIT_OBJECT_0;
-#else
+#else
#ifdef USE_SYSV_SEMAPHORES
struct sembuf ops[] = {{0, -1, SEM_UNDO | IPC_NOWAIT}};
int ret = semop(Handle, ops, 1);
@@ -163,7 +163,7 @@ namespace {
int ret = sem_trywait(Handle);
#endif
return ret == 0;
-#endif
+#endif
}
};
@@ -252,7 +252,7 @@ class TFastSemaphore::TImpl: public TString, public TSemaphoreImpl {
public:
inline TImpl(ui32 n)
: TString(ToString(RandomNumber<ui64>()))
- , TSemaphoreImpl(c_str(), n)
+ , TSemaphoreImpl(c_str(), n)
{
}
};
diff --git a/util/system/sem.h b/util/system/sem.h
index 0c964ad6b6..545dc263be 100644
--- a/util/system/sem.h
+++ b/util/system/sem.h
@@ -1,7 +1,7 @@
#pragma once
-
-#include "defaults.h"
-
+
+#include "defaults.h"
+
#include <util/generic/ptr.h>
//named sempahore
@@ -9,21 +9,21 @@ class TSemaphore {
public:
TSemaphore(const char* name, ui32 maxFreeCount);
~TSemaphore();
-
+
//Increase the semaphore counter.
void Release() noexcept;
-
+
//Keep a thread held while the semaphore counter is equal 0.
void Acquire() noexcept;
-
+
//Try to enter the semaphore gate. A non-blocking variant of Acquire.
//Returns 'true' if the semaphore counter decreased
bool TryAcquire() noexcept;
-
+
private:
class TImpl;
THolder<TImpl> Impl_;
-};
+};
//unnamed semaphore, faster, than previous
class TFastSemaphore {
diff --git a/util/system/sigset.h b/util/system/sigset.h
index 8dd02fd817..f4035425e3 100644
--- a/util/system/sigset.h
+++ b/util/system/sigset.h
@@ -2,7 +2,7 @@
// Functions for manipulating signal sets
-#include "compat.h"
+#include "compat.h"
#if defined _unix_
#include <pthread.h>
@@ -20,39 +20,39 @@ using sigset_t = ui32;
inline int SigEmptySet(sigset_t* set) {
#if defined _unix_
- return sigemptyset(set);
+ return sigemptyset(set);
#else
Y_UNUSED(set);
- return 0;
+ return 0;
#endif
}
inline int SigFillSet(sigset_t* set) {
#if defined _unix_
- return sigfillset(set);
+ return sigfillset(set);
#else
Y_UNUSED(set);
- return 0;
+ return 0;
#endif
}
inline int SigAddSet(sigset_t* set, int signo) {
#if defined _unix_
- return sigaddset(set, signo);
+ return sigaddset(set, signo);
#else
Y_UNUSED(set);
Y_UNUSED(signo);
- return 0;
+ return 0;
#endif
}
inline int SigDelSet(sigset_t* set, int signo) {
#if defined _unix_
- return sigdelset(set, signo);
+ return sigdelset(set, signo);
#else
Y_UNUSED(set);
Y_UNUSED(signo);
- return 0;
+ return 0;
#endif
}
@@ -62,7 +62,7 @@ inline int SigIsMember(const sigset_t* set, int signo) {
#else
Y_UNUSED(set);
Y_UNUSED(signo);
- return 0;
+ return 0;
#endif
}
diff --git a/util/system/sys_alloc.h b/util/system/sys_alloc.h
index 4221a28f8c..1c23ea291d 100644
--- a/util/system/sys_alloc.h
+++ b/util/system/sys_alloc.h
@@ -12,11 +12,11 @@ inline void* y_allocate(size_t n) {
throw std::bad_alloc();
}
- return r;
+ return r;
}
inline void y_deallocate(void* p) {
- free(p);
+ free(p);
}
/**
@@ -39,5 +39,5 @@ inline void* y_reallocate(void* p, size_t new_sz) {
throw std::bad_alloc();
}
- return r;
+ return r;
}
diff --git a/util/system/sysstat.cpp b/util/system/sysstat.cpp
index db3338b02e..2cc5aa7793 100644
--- a/util/system/sysstat.cpp
+++ b/util/system/sysstat.cpp
@@ -1,47 +1,47 @@
-#include "sysstat.h"
-
-#ifdef _win_
-
+#include "sysstat.h"
+
+#ifdef _win_
+
#include "winint.h"
#include <errno.h>
-
-int Chmod(const char* fname, int mode) {
- if (!fname) {
- errno = EINVAL;
- return -1;
- }
- ui32 fAttr = ::GetFileAttributesA(fname);
+
+int Chmod(const char* fname, int mode) {
+ if (!fname) {
+ errno = EINVAL;
+ return -1;
+ }
+ ui32 fAttr = ::GetFileAttributesA(fname);
if (fAttr == 0xffffffff)
- return -1;
- if (mode & _S_IWRITE) {
- fAttr &= ~FILE_ATTRIBUTE_READONLY;
- } else {
- fAttr |= FILE_ATTRIBUTE_READONLY;
- }
- if (!::SetFileAttributesA(fname, fAttr)) {
- return -1;
- }
- return 0;
-}
-
-int Mkdir(const char* path, int /*mode*/) {
- errno = 0;
- if (!path) {
- errno = EINVAL;
- return -1;
- }
+ return -1;
+ if (mode & _S_IWRITE) {
+ fAttr &= ~FILE_ATTRIBUTE_READONLY;
+ } else {
+ fAttr |= FILE_ATTRIBUTE_READONLY;
+ }
+ if (!::SetFileAttributesA(fname, fAttr)) {
+ return -1;
+ }
+ return 0;
+}
+
+int Mkdir(const char* path, int /*mode*/) {
+ errno = 0;
+ if (!path) {
+ errno = EINVAL;
+ return -1;
+ }
if (!CreateDirectoryA(path, (LPSECURITY_ATTRIBUTES) nullptr)) {
- ui32 errCode = GetLastError();
- if (errCode == ERROR_ALREADY_EXISTS) {
- errno = EEXIST;
- } else if (errCode == ERROR_PATH_NOT_FOUND) {
- errno = ENOENT;
- } else {
- errno = EINVAL;
- }
- return -1;
- }
- return 0;
-}
-
-#endif
+ ui32 errCode = GetLastError();
+ if (errCode == ERROR_ALREADY_EXISTS) {
+ errno = EEXIST;
+ } else if (errCode == ERROR_PATH_NOT_FOUND) {
+ errno = ENOENT;
+ } else {
+ errno = EINVAL;
+ }
+ return -1;
+ }
+ return 0;
+}
+
+#endif
diff --git a/util/system/sysstat.h b/util/system/sysstat.h
index b7c424c11b..1f4ac613be 100644
--- a/util/system/sysstat.h
+++ b/util/system/sysstat.h
@@ -1,52 +1,52 @@
-#pragma once
-
-#include "defaults.h"
-#include <sys/stat.h>
-
-#ifdef _win_
+#pragma once
+
+#include "defaults.h"
+#include <sys/stat.h>
+
+#ifdef _win_
#define S_IRUSR _S_IREAD
#define S_IWUSR _S_IWRITE
#define S_IXUSR _S_IEXEC
#define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
-
+
#define S_IRGRP _S_IREAD
#define S_IWGRP _S_IWRITE
#define S_IXGRP _S_IEXEC
#define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
-
+
#define S_IROTH _S_IREAD
#define S_IWOTH _S_IWRITE
#define S_IXOTH _S_IEXEC
#define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
-#endif
-
-int Chmod(const char* fname, int mode);
-int Umask(int mode);
-
+#endif
+
+int Chmod(const char* fname, int mode);
+int Umask(int mode);
+
static constexpr int MODE0777 = (S_IRWXU | S_IRWXG | S_IRWXO);
static constexpr int MODE0775 = (S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
static constexpr int MODE0755 = (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
-
-int Mkdir(const char* path, int mode);
-
-/* uff... mkfifo(...) is not used now */
-
-#ifdef _unix_
-inline int Chmod(const char* fname, int mode) {
- return ::chmod(fname, mode);
-}
-inline int Umask(int mode) {
- return ::umask(mode);
-}
-inline int Mkdir(const char* path, int mode) {
- return ::mkdir(path, mode);
-}
-#endif
-
-#ifdef _win_
-inline int Umask(int /*mode*/) {
- /* The only thing this method could make is to set FILE_ATTRIBUTE_READONLY on a handle from 'int open(...)',
- but open() is deprecated. */
- return 0;
-}
-#endif
+
+int Mkdir(const char* path, int mode);
+
+/* uff... mkfifo(...) is not used now */
+
+#ifdef _unix_
+inline int Chmod(const char* fname, int mode) {
+ return ::chmod(fname, mode);
+}
+inline int Umask(int mode) {
+ return ::umask(mode);
+}
+inline int Mkdir(const char* path, int mode) {
+ return ::mkdir(path, mode);
+}
+#endif
+
+#ifdef _win_
+inline int Umask(int /*mode*/) {
+ /* The only thing this method could make is to set FILE_ATTRIBUTE_READONLY on a handle from 'int open(...)',
+ but open() is deprecated. */
+ return 0;
+}
+#endif
diff --git a/util/system/thread.cpp b/util/system/thread.cpp
index 6236746c2d..0a50954446 100644
--- a/util/system/thread.cpp
+++ b/util/system/thread.cpp
@@ -89,7 +89,7 @@ namespace {
inline TId SystemThreadId() const noexcept {
#if _WIN32_WINNT < 0x0502
- return (TId)ThreadId;
+ return (TId)ThreadId;
#else
return (TId)GetThreadId(Handle);
#endif
@@ -106,7 +106,7 @@ namespace {
::CloseHandle(Handle);
}
- static ui32 __stdcall Proxy(void* ptr) {
+ static ui32 __stdcall Proxy(void* ptr) {
NTls::TCleaner cleaner;
(void)cleaner;
@@ -121,7 +121,7 @@ namespace {
p->Result = p->Proc(p->Data);
}
- return 0;
+ return 0;
}
inline void Start() {
@@ -148,7 +148,7 @@ namespace {
};
using TThreadBase = TWinThread;
-#else
+#else
//unix
#define PCHECK(x, y) \
@@ -273,8 +273,8 @@ private:
TThread::TThread(const TParams& p)
: Impl_(new TImpl(p))
{
-}
-
+}
+
TThread::TThread(TThreadProc threadProc, void* param)
: Impl_(new TImpl(TParams(threadProc, param)))
{
diff --git a/util/system/thread.h b/util/system/thread.h
index a6e8abdb5b..6d205ff7b4 100644
--- a/util/system/thread.h
+++ b/util/system/thread.h
@@ -7,7 +7,7 @@
#include <util/generic/ptr.h>
#include <util/generic/string.h>
-#include "defaults.h"
+#include "defaults.h"
#include "progname.h"
bool SetHighestThreadPriority();
diff --git a/util/system/tls.h b/util/system/tls.h
index 3c4f56dbeb..bcf8ebeb2a 100644
--- a/util/system/tls.h
+++ b/util/system/tls.h
@@ -4,7 +4,7 @@
#include <util/generic/ptr.h>
#include <util/generic/noncopyable.h>
-
+
#include <new>
#if defined(_darwin_)
@@ -124,7 +124,7 @@
#define Y_THREAD(T) ::NTls::TValue<T>
#define Y_STATIC_THREAD(T) static Y_THREAD(T)
-
+
// gcc and msvc support automatic tls for POD types
#if defined(Y_DISABLE_THRKEY_OPTIMIZATION)
// nothing to do
@@ -169,8 +169,8 @@ namespace NTls {
class TImpl;
THolder<TImpl> Impl_;
};
-
- struct TCleaner {
+
+ struct TCleaner {
inline ~TCleaner() {
TKey::Cleanup();
}
@@ -220,7 +220,7 @@ namespace NTls {
: Constructor_(new TDefaultConstructor())
, Key_(Dtor)
{
- }
+ }
template <class T1>
inline TValue(const T1& value)
@@ -236,7 +236,7 @@ namespace NTls {
inline operator const T&() const {
return Get();
- }
+ }
inline operator T&() {
return Get();
diff --git a/util/system/user.cpp b/util/system/user.cpp
index 83e89ea0a8..fe76d779c2 100644
--- a/util/system/user.cpp
+++ b/util/system/user.cpp
@@ -25,7 +25,7 @@ TString GetUsername() {
for (;;) {
#if defined(_win_)
DWORD len = (DWORD)Min(nameBuf.Size(), size_t(32767));
- if (!GetUserNameA(nameBuf.Data(), &len)) {
+ if (!GetUserNameA(nameBuf.Data(), &len)) {
DWORD err = GetLastError();
if ((err == ERROR_INSUFFICIENT_BUFFER) && (nameBuf.Size() <= 32767))
nameBuf = TTempBuf((size_t)len);
diff --git a/util/system/utime.h b/util/system/utime.h
index 1c52e6614d..0afc61719f 100644
--- a/util/system/utime.h
+++ b/util/system/utime.h
@@ -1,6 +1,6 @@
-#pragma once
-
-#include "defaults.h"
-
+#pragma once
+
+#include "defaults.h"
+
int TouchFile(const char* filePath);
int SetModTime(const char* filePath, time_t modtime, time_t actime);
diff --git a/util/system/winint.h b/util/system/winint.h
index ebeaefb3d2..6eed1df32e 100644
--- a/util/system/winint.h
+++ b/util/system/winint.h
@@ -1,9 +1,9 @@
-#pragma once
-
+#pragma once
+
#include "platform.h"
-
-#if defined(_win_)
-
+
+#if defined(_win_)
+
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
@@ -13,7 +13,7 @@
#endif
#include <windows.h>
-
+
#undef GetFreeSpace
#undef LoadImage
#undef GetMessage
@@ -33,11 +33,11 @@
#undef GetProp
#undef SetProp
#undef RemoveProp
-
+
#undef IGNORE
#undef ERROR
#undef TRANSPARENT
-
+
#undef CM_NONE
-#endif
+#endif
diff --git a/util/system/yassert.h b/util/system/yassert.h
index 529823440c..f256cdf5d7 100644
--- a/util/system/yassert.h
+++ b/util/system/yassert.h
@@ -56,7 +56,7 @@ inline void YaDebugBreak() {
#undef Y_ASSERT
-#if !defined(NDEBUG) && !defined(__GCCXML__)
+#if !defined(NDEBUG) && !defined(__GCCXML__)
#define Y_ASSERT(a) \
do { \
try { \
diff --git a/util/thread/pool.cpp b/util/thread/pool.cpp
index 05fad02e9b..a83b996daa 100644
--- a/util/thread/pool.cpp
+++ b/util/thread/pool.cpp
@@ -1,7 +1,7 @@
#include <atomic>
#include <util/system/defaults.h>
-
+
#if defined(_unix_)
#include <pthread.h>
#endif
@@ -21,7 +21,7 @@
#include <util/system/atomic.h>
#include <util/system/condvar.h>
#include <util/system/thread.h>
-
+
#include <util/datetime/base.h>
#include "factory.h"
@@ -122,7 +122,7 @@ public:
}
Queue.Push(obj);
- }
+ }
QueuePushCond.Signal();
@@ -357,8 +357,8 @@ bool TThreadPool::Add(IObjectInQueue* obj) {
}
return Impl_->Add(obj);
-}
-
+}
+
void TThreadPool::Start(size_t thrnum, size_t maxque) {
Impl_.Reset(new TImpl(this, thrnum, maxque, Params));
}
diff --git a/util/thread/pool.h b/util/thread/pool.h
index d1ea3a67cb..e6c5a34625 100644
--- a/util/thread/pool.h
+++ b/util/thread/pool.h
@@ -1,5 +1,5 @@
#pragma once
-
+
#include "fwd.h"
#include "factory.h"
@@ -311,8 +311,8 @@ public:
private:
class TImpl;
THolder<TImpl> Impl_;
-};
-
+};
+
/** Behave like TThreadPool or TAdaptiveThreadPool, choosen by thrnum parameter of Start() */
class TSimpleThreadPool: public TThreadPoolBase {
public:
diff --git a/util/ya.make b/util/ya.make
index 6ebe7e40cf..4574f74b8a 100644
--- a/util/ya.make
+++ b/util/ya.make
@@ -9,11 +9,11 @@ NO_UTIL()
# stream
# string
-PEERDIR(
+PEERDIR(
util/charset
contrib/libs/zlib
contrib/libs/double-conversion
-)
+)
PEERDIR(
contrib/libs/libc_compat