LLM inference in C/C++
C++ ggml
common : add common_is_tty() helper and fix deprecated warnings on Windows (#29860)
Adrien Gallouëtedd6e2bbdad5
diff --git a/common/common.cpp b/common/common.cppindex 0269bc895c..d3617fbf1c 100644--- a/common/common.cpp+++ b/common/common.cpp@@ -1078,6 +1078,14 @@ std::vector<common_file_info> fs_list(const std::string & path, bool include_dir// TTY utils//+bool common_is_tty(FILE * file) {+#if defined(_WIN32)+ return _isatty(_fileno(file));+#else+ return isatty(fileno(file));+#endif+}+bool tty_can_use_colors() {// Check NO_COLOR environment variable (https://no-color.org/)if (const char * no_color = std::getenv("NO_COLOR")) {@@ -1095,10 +1103,7 @@ bool tty_can_use_colors() {// Check if stdout and stderr are connected to a terminal// We check both because log messages can go to either- bool stdout_is_tty = isatty(fileno(stdout));- bool stderr_is_tty = isatty(fileno(stderr));-- return stdout_is_tty || stderr_is_tty;+ return common_is_tty(stdout) || common_is_tty(stderr);}//diff --git a/common/common.h b/common/common.hindex 27be5c0586..4308b07035 100644--- a/common/common.h+++ b/common/common.h@@ -19,6 +19,7 @@#include <algorithm>#include <filesystem>#include <fstream>+#include <cstdio>#if defined(_WIN32) && !defined(_WIN32_WINNT)#define _WIN32_WINNT 0x0A00@@ -946,6 +947,9 @@ void fs_write_atomic(const std::filesystem::path & path, const std::string & dat// Auto-detect if colors can be enabled based on terminal and environmentbool tty_can_use_colors();+// Check if the given file is attached to a terminal+bool common_is_tty(FILE * file);+//// Model utils//diff --git a/common/download.cpp b/common/download.cppindex 6b7123e476..ae0f7ffede 100644--- a/common/download.cpp+++ b/common/download.cpp@@ -35,13 +35,6 @@#endif#endif-// isatty-#if defined(_WIN32)-#include <io.h>-#else-#include <unistd.h>-#endif-//// downloader//@@ -97,11 +90,7 @@ class ProgressBar : public common_download_callback {}static bool is_output_a_tty() {-#if defined(_WIN32)- return _isatty(_fileno(stdout));-#else- return isatty(1);-#endif+ return common_is_tty(stdout);}public:diff --git a/common/log.cpp b/common/log.cppindex 0a9a4eb9ea..b60e8d2687 100644--- a/common/log.cpp+++ b/common/log.cpp@@ -14,19 +14,6 @@#include <vector>#include <algorithm>-#if defined(_WIN32)-# define WIN32_LEAN_AND_MEAN-# ifndef NOMINMAX-# define NOMINMAX-# endif-# include <io.h>-# include <windows.h>-# define isatty _isatty-# define fileno _fileno-#else-# include <unistd.h>-#endif // defined(_WIN32)-int common_log_verbosity_thold = LOG_DEFAULT_LLAMA;int common_log_get_verbosity_thold(void) {