-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtermos.cc
More file actions
37 lines (36 loc) · 893 Bytes
/
Copy pathtermos.cc
File metadata and controls
37 lines (36 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifdef _WIN32
#include <windows.h>
void hideInput(){
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode = 0;
GetConsoleMode(hStdin, &mode);
SetConsoleMode(hStdin, mode & (~ENABLE_ECHO_INPUT));
}
long long totalram(){
static long long mb = 0;
if (mb) return mb;
MEMORYSTATUSEX status;
status.dwLength = sizeof(status);
GlobalMemoryStatusEx(&status);
mb = status.ullTotalPhys / (1024 * 1024);
return mb;
}
#else
#include <termios.h>
#include <unistd.h>
void hideInput(){
termios oldt;
tcgetattr(STDIN_FILENO, &oldt);
termios newt = oldt;
newt.c_lflag &= ~ECHO;
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
}
long long totalram(){
static long long mb = 0;
if (mb) return mb;
long long pages = sysconf(_SC_PHYS_PAGES);
long long page_size = sysconf(_SC_PAGE_SIZE);
mb = (pages * page_size) / (1024 * 1024);
return mb;
}
#endif