diff options
author | alexv-smirnov <[email protected]> | 2022-12-20 00:50:48 +0300 |
---|---|---|
committer | alexv-smirnov <[email protected]> | 2022-12-20 00:50:48 +0300 |
commit | 84f2cfa253cc618438ed6e9d68b33fa7c0d88cb9 (patch) | |
tree | f0cf2236e0aafb3e437199f1ac7b559e7fad554a /util/system/err.cpp | |
parent | bde6febc1ad3b826e72746de21d7250803e8e0b5 (diff) |
add windows platform to ydb github export
Diffstat (limited to 'util/system/err.cpp')
-rw-r--r-- | util/system/err.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/util/system/err.cpp b/util/system/err.cpp new file mode 100644 index 00000000000..e2e5d8c9fdb --- /dev/null +++ b/util/system/err.cpp @@ -0,0 +1,80 @@ +#include "defaults.h" +#include "progname.h" +#include "compat.h" +#include "error.h" + +#include <util/generic/scope.h> + +#include <util/system/compat.h> +#include <util/stream/printf.h> +#include <util/stream/output.h> + +void vwarnx(const char* fmt, va_list args) { + Cerr << GetProgramName() << ": "; + + if (fmt) { + Printf(Cerr, fmt, args); + } + + Cerr << '\n'; +} + +void vwarn(const char* fmt, va_list args) { + int curErrNo = errno; + auto curErrText = LastSystemErrorText(); + + Y_DEFER { + errno = curErrNo; + }; + + Cerr << GetProgramName() << ": "; + + if (fmt) { + Printf(Cerr, fmt, args); + Cerr << ": "; + } + + Cerr << curErrText << '\n'; +} + +void warn(const char* fmt, ...) { + va_list args; + + va_start(args, fmt); + vwarn(fmt, args); + va_end(args); +} + +void warnx(const char* fmt, ...) { + va_list args; + + va_start(args, fmt); + vwarnx(fmt, args); + va_end(args); +} + +[[noreturn]] void verr(int status, const char* fmt, va_list args) { + vwarn(fmt, args); + std::exit(status); +} + +[[noreturn]] void err(int status, const char* fmt, ...) { + va_list args; + + va_start(args, fmt); + verr(status, fmt, args); + va_end(args); +} + +[[noreturn]] void verrx(int status, const char* fmt, va_list args) { + vwarnx(fmt, args); + std::exit(status); +} + +[[noreturn]] void errx(int status, const char* fmt, ...) { + va_list args; + + va_start(args, fmt); + verrx(status, fmt, args); + va_end(args); +} |