来源:Pbrt
static int TerminalWidth() { #ifdef PBRT_IS_WINDOWS HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); if (h == INVALID_HANDLE_VALUE || !h) { fprintf(stderr, "GetStdHandle() call failed"); return 80; } CONSOLE_SCREEN_BUFFER_INFO bufferInfo = {0}; GetConsoleScreenBufferInfo(h, &bufferInfo); return bufferInfo.dwSize.X; #else struct winsize w; if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) < 0) { // ENOTTY is fine and expected, e.g. if output is being piped to a file. if (errno != ENOTTY) { static bool warned = false; if (!warned) { warned = true; fprintf(stderr, "Error in ioctl() in TerminalWidth(): %d\\n", errno); } } return 80; } return w.ws_col; #endif // PBRT_IS_WINDOWS }
换行:\n 回到行首:\r