This repository has been archived on 2020-05-25. You can view files and clone it, but cannot push or open issues or pull requests.
tdlib-fork/tdutils/td/utils/port/StdStreams.cpp
Arseny Smirnov bf15a5ac12 tg_cli works under posix
GitOrigin-RevId: 632e05de183a55b045f74e09ca8d41060f55ad41
2018-08-17 16:41:51 +03:00

48 lines
964 B
C++

//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "td/utils/port/StdStreams.h"
namespace td {
namespace {
template <class T>
FileFd create(T handle) {
return FileFd::from_native_fd(NativeFd(handle, true)).move_as_ok();
}
} // namespace
FileFd &Stdin() {
static FileFd res = create(
#if TD_PORT_POSIX
0
#elif TD_PORT_WINDOWS
GetStdHandle(STD_INPUT_HANDLE)
#endif
);
return res;
}
FileFd &Stdout() {
static FileFd res = create(
#if TD_PORT_POSIX
1
#elif TD_PORT_WINDOWS
GetStdHandle(STD_OUTPUT_HANDLE)
#endif
);
return res;
}
FileFd &Stderr() {
static FileFd res = create(
#if TD_PORT_POSIX
2
#elif TD_PORT_WINDOWS
GetStdHandle(STD_ERROR_HANDLE)
#endif
);
return res;
}
} // namespace td