LibCore: Implement System::isatty on Windows

Also fixes a bug introduced in 642b7b6a5e: Core::System functions
expect a handle now, so we have to use _get_osfhandle in STD*_FILENO.
This commit is contained in:
stasoid 2025-02-15 18:37:38 +05:00
commit c55ba17d66
3 changed files with 10 additions and 5 deletions

View file

@ -7,15 +7,11 @@
#include <LibCore/File.h> #include <LibCore/File.h>
#include <LibCore/System.h> #include <LibCore/System.h>
#include <fcntl.h>
#if !defined(AK_OS_WINDOWS) #if !defined(AK_OS_WINDOWS)
# include <unistd.h> # include <unistd.h>
#else #else
# include <WinSock2.h> # include <AK/Windows.h>
# define STDIN_FILENO _fileno(stdin)
# define STDOUT_FILENO _fileno(stdout)
# define STDERR_FILENO _fileno(stderr)
#endif #endif
namespace Core { namespace Core {

View file

@ -33,7 +33,11 @@
# include <utime.h> # include <utime.h>
#else #else
# include "SocketAddressWindows.h" # include "SocketAddressWindows.h"
# include <io.h>
# define O_CLOEXEC O_NOINHERIT # define O_CLOEXEC O_NOINHERIT
# define STDIN_FILENO _get_osfhandle(_fileno(stdin))
# define STDOUT_FILENO _get_osfhandle(_fileno(stdout))
# define STDERR_FILENO _get_osfhandle(_fileno(stderr))
# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
# define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
using sighandler_t = void (*)(int); using sighandler_t = void (*)(int);

View file

@ -276,4 +276,9 @@ ErrorOr<void> set_close_on_exec(int handle, bool enabled)
return {}; return {};
} }
ErrorOr<bool> isatty(int handle)
{
return GetFileType(to_handle(handle)) == FILE_TYPE_CHAR;
}
} }