Skip to content

Commit a3cf816

Browse files
Add Guard for pGetFileInformationByHandleEx + clean real estate + bug
1 parent e76c9f5 commit a3cf816

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,7 @@ sqFileStdioHandlesInto(SQFile files[])
570570
}
571571

572572
sqInt sqStdioDescriptorIsATTY(void) {
573-
//There is always an TTY to write into for Unix and Mac
574-
return 1;
573+
return isatty(fileno(stdin));
575574
}
576575

577576

platforms/win32/vm/sqWin32Main.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -879,8 +879,10 @@ sqInt isStdioDescriptorATTY(void) {
879879
//In case of Windows Shell case
880880
int stdOutFd = _fileno(stdout);
881881
int res = _isatty(stdOutFd);
882-
if (res != 0) return res > 0;
883-
if (errno == EBADF) return 0;
882+
if (res != 0)
883+
return res > 0;
884+
if (errno == EBADF)
885+
return 0;
884886
//In case of Unix emulator, we parse the name of the pipe
885887
HANDLE h;
886888
int size = sizeof(FILE_NAME_INFO) + sizeof(WCHAR) * MAX_PATH;
@@ -894,11 +896,12 @@ sqInt isStdioDescriptorATTY(void) {
894896
DWORD dwBufferSize
895897
);
896898
static pfnGetFileInformationByHandleEx pGetFileInformationByHandleEx = NULL;
897-
898-
pGetFileInformationByHandleEx = (pfnGetFileInformationByHandleEx)
899-
GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetFileInformationByHandleEx");
900-
if (pGetFileInformationByHandleEx == NULL) return -2;
901-
899+
if (!pGetFileInformationByHandleEx) {
900+
pGetFileInformationByHandleEx = (pfnGetFileInformationByHandleEx)
901+
GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetFileInformationByHandleEx");
902+
if (!pGetFileInformationByHandleEx)
903+
return 0;
904+
}
902905
h = (HANDLE)_get_osfhandle(2);
903906
if (h == INVALID_HANDLE_VALUE) {
904907
return 0;

0 commit comments

Comments
 (0)