diff --git a/src/pipes/terminal_pipe.h b/src/pipes/terminal_pipe.h index eaf0bd9b..386153bd 100644 --- a/src/pipes/terminal_pipe.h +++ b/src/pipes/terminal_pipe.h @@ -7,48 +7,46 @@ #include #include +#ifdef _WIN32 extern "C" { __declspec(dllexport) const int CreateTerminalPipe() { - #ifdef _WIN32 - { - HANDLE hPipe = CreateFileA(R"(\\.\pipe\MillenniumStdoutPipe)", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); - - if (hPipe == INVALID_HANDLE_VALUE) - { - std::cerr << "Failed to connect to pipe." << std::endl; - return 1; - } + HANDLE hPipe = CreateFileA(R"(\\.\pipe\MillenniumStdoutPipe)", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); - int pipeDescriptor = _open_osfhandle((intptr_t)hPipe, _O_WRONLY); - if (pipeDescriptor == -1) - { - std::cerr << "Failed to get pipe file descriptor." << std::endl; - CloseHandle(hPipe); - return 1; - } + if (hPipe == INVALID_HANDLE_VALUE) + { + std::cerr << "Failed to connect to pipe." << std::endl; + return 1; + } - FILE* pipeFile = _fdopen(pipeDescriptor, "w"); - if (!pipeFile) - { - std::cerr << "Failed to open pipe file descriptor as FILE*." << std::endl; - CloseHandle(hPipe); - return 1; - } + int pipeDescriptor = _open_osfhandle((intptr_t)hPipe, _O_WRONLY); + if (pipeDescriptor == -1) + { + std::cerr << "Failed to get pipe file descriptor." << std::endl; + CloseHandle(hPipe); + return 1; + } - // Redirect stdout to the named pipe - if (dup2(_fileno(pipeFile), _fileno(stdout)) == -1) - { - std::cerr << "Failed to redirect stdout to pipe." << std::endl; - CloseHandle(hPipe); - fclose(pipeFile); // Close the FILE* on failure - return 1; - } - setvbuf(stdout, NULL, _IONBF, 0); + FILE* pipeFile = _fdopen(pipeDescriptor, "w"); + if (!pipeFile) + { + std::cerr << "Failed to open pipe file descriptor as FILE*." << std::endl; + CloseHandle(hPipe); + return 1; + } - std::shared_ptr pipePtr = std::make_shared(pipeFile); + // Redirect stdout to the named pipe + if (dup2(_fileno(pipeFile), _fileno(stdout)) == -1) + { + std::cerr << "Failed to redirect stdout to pipe." << std::endl; + CloseHandle(hPipe); + fclose(pipeFile); // Close the FILE* on failure + return 1; } - #endif + setvbuf(stdout, NULL, _IONBF, 0); + + std::shared_ptr pipePtr = std::make_shared(pipeFile); return 0; } -} \ No newline at end of file +} +#endif \ No newline at end of file