Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2018-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <compat/stdin.h>7#include <cstdio>9#ifdef WIN3210#include <windows.h>11#include <io.h>12#else13#include <termios.h>14#include <unistd.h>15#include <poll.h>16#endif18// https://stackoverflow.com/questions/1413445/reading-a-password-from-stdcin19void SetStdinEcho(bool enable)20{21if (!StdinTerminal()) {22return;23}24#ifdef WIN3225HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);26DWORD mode;27if (!GetConsoleMode(hStdin, &mode)) {28fputs("GetConsoleMode failed\n", stderr);29return;30}31if (!enable) {32mode &= ~ENABLE_ECHO_INPUT;33} else {34mode |= ENABLE_ECHO_INPUT;35}36if (!SetConsoleMode(hStdin, mode)) {37fputs("SetConsoleMode failed\n", stderr);38}39#else40struct termios tty;41if (tcgetattr(STDIN_FILENO, &tty) != 0) {42fputs("tcgetattr failed\n", stderr);43return;44}45if (!enable) {46tty.c_lflag &= static_cast<decltype(tty.c_lflag)>(~ECHO);47} else {48tty.c_lflag |= ECHO;49}50if (tcsetattr(STDIN_FILENO, TCSANOW, &tty) != 0) {51fputs("tcsetattr failed\n", stderr);52}53#endif54}56bool StdinTerminal()57{58#ifdef WIN3259return _isatty(_fileno(stdin));60#else61return isatty(fileno(stdin));62#endif63}65bool StdinReady()66{67if (!StdinTerminal()) {68return true;69}70#ifdef WIN3271return false;72#else73struct pollfd fds;74fds.fd = STDIN_FILENO;75fds.events = POLLIN;76return poll(&fds, 1, 0) == 1;77#endif78}80NoechoInst::NoechoInst() { SetStdinEcho(false); }81NoechoInst::~NoechoInst() { SetStdinEcho(true); }
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.