Author: akhaldi
Date: Sat Sep 3 10:32:43 2016
New Revision: 72540
URL:
http://svn.reactos.org/svn/reactos?rev=72540&view=rev
Log:
[CRT] Apply Wine commit d3a48ee by Piotr Caban: Only check for flag presence in isatty
function. CORE-11866 CORE-11904
Modified:
trunk/reactos/sdk/lib/crt/stdio/file.c
Modified: trunk/reactos/sdk/lib/crt/stdio/file.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/sdk/lib/crt/stdio/file.c?r…
==============================================================================
--- trunk/reactos/sdk/lib/crt/stdio/file.c [iso-8859-1] (original)
+++ trunk/reactos/sdk/lib/crt/stdio/file.c [iso-8859-1] Sat Sep 3 10:32:43 2016
@@ -95,7 +95,7 @@
#define WX_READCR 0x08 /* underlying file is at \r */
#define WX_DONTINHERIT 0x10
#define WX_APPEND 0x20
-#define WX_NOSEEK 0x40
+#define WX_TTY 0x40
#define WX_TEXT 0x80
/* values for exflag - it's used differently in msvcr90.dll*/
@@ -167,6 +167,17 @@
static CRITICAL_SECTION file_cs = { &file_cs_debug, -1, 0, 0, 0, 0 };
#define LOCK_FILES() do { EnterCriticalSection(&file_cs); } while (0)
#define UNLOCK_FILES() do { LeaveCriticalSection(&file_cs); } while (0)
+
+static inline ioinfo* get_ioinfo_nolock(int fd)
+{
+ ioinfo *ret = NULL;
+ if(fd>=0 && fd<MAX_FILES)
+ ret = __pioinfo[fd/FD_BLOCK_SIZE];
+ if(!ret)
+ return &__badioinfo;
+
+ return ret + (fd%FD_BLOCK_SIZE);
+}
static inline ioinfo* get_ioinfo(int fd)
{
@@ -298,7 +309,7 @@
}
fdinfo->handle = hand;
- fdinfo->wxflag = WX_OPEN | (flag & (WX_DONTINHERIT | WX_APPEND | WX_TEXT |
WX_PIPE | WX_NOSEEK));
+ fdinfo->wxflag = WX_OPEN | (flag & (WX_DONTINHERIT | WX_APPEND | WX_TEXT |
WX_PIPE | WX_TTY));
fdinfo->lookahead[0] = '\n';
fdinfo->lookahead[1] = '\n';
fdinfo->lookahead[2] = '\n';
@@ -467,7 +478,7 @@
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
DWORD type = GetFileType(h);
- set_fd(h, WX_OPEN|WX_TEXT|((type&0xf)==FILE_TYPE_CHAR ? WX_NOSEEK : 0)
+ set_fd(h, WX_OPEN|WX_TEXT|((type&0xf)==FILE_TYPE_CHAR ? WX_TTY : 0)
|((type&0xf)==FILE_TYPE_PIPE ? WX_PIPE : 0), STDIN_FILENO);
}
@@ -476,7 +487,7 @@
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD type = GetFileType(h);
- set_fd(h, WX_OPEN|WX_TEXT|((type&0xf)==FILE_TYPE_CHAR ? WX_NOSEEK : 0)
+ set_fd(h, WX_OPEN|WX_TEXT|((type&0xf)==FILE_TYPE_CHAR ? WX_TTY : 0)
|((type&0xf)==FILE_TYPE_PIPE ? WX_PIPE : 0), STDOUT_FILENO);
}
@@ -485,7 +496,7 @@
HANDLE h = GetStdHandle(STD_ERROR_HANDLE);
DWORD type = GetFileType(h);
- set_fd(h, WX_OPEN|WX_TEXT|((type&0xf)==FILE_TYPE_CHAR ? WX_NOSEEK : 0)
+ set_fd(h, WX_OPEN|WX_TEXT|((type&0xf)==FILE_TYPE_CHAR ? WX_TTY : 0)
|((type&0xf)==FILE_TYPE_PIPE ? WX_PIPE : 0), STDERR_FILENO);
}
@@ -524,13 +535,9 @@
*/
int CDECL _isatty(int fd)
{
- HANDLE hand = fdtoh(fd);
-
- TRACE(":fd (%d) handle (%p)\n",fd,hand);
- if (hand == INVALID_HANDLE_VALUE)
- return 0;
-
- return GetFileType(hand) == FILE_TYPE_CHAR? 1 : 0;
+ TRACE(":fd (%d)\n",fd);
+
+ return get_ioinfo_nolock(fd)->wxflag & WX_TTY;
}
/* INTERNAL: Allocate stdio file buffer */
@@ -1688,7 +1695,7 @@
{
DWORD access = 0, creation = 0, attrib;
SECURITY_ATTRIBUTES sa;
- DWORD sharing;
+ DWORD sharing, type;
int wxflag;
HANDLE hand;
@@ -1820,6 +1827,11 @@
else if (access & GENERIC_READ)
oflags = check_bom(hand, oflags, TRUE);
}
+ type = GetFileType(hand);
+ if (type == FILE_TYPE_CHAR)
+ wxflag |= WX_TTY;
+ else if (type == FILE_TYPE_PIPE)
+ wxflag |= WX_PIPE;
*fd = alloc_fd(hand, wxflag);
if (*fd == -1)
@@ -1979,7 +1991,7 @@
}
if (flags == FILE_TYPE_CHAR)
- flags = WX_NOSEEK;
+ flags = WX_TTY;
else if (flags == FILE_TYPE_PIPE)
flags = WX_PIPE;
else
@@ -2103,7 +2115,7 @@
buf[0] = '\n';
else {
buf[0] = '\r';
- if(fdinfo->wxflag & (WX_PIPE | WX_NOSEEK))
+ if(fdinfo->wxflag & (WX_PIPE | WX_TTY))
fdinfo->lookahead[0] = lookahead;
else
SetFilePointer(fdinfo->handle, -1, NULL, FILE_CURRENT);
@@ -2151,7 +2163,7 @@
if(char_len+i <= pos)
i += char_len;
- if(fdinfo->wxflag & (WX_PIPE | WX_NOSEEK)) {
+ if(fdinfo->wxflag & (WX_PIPE | WX_TTY)) {
if(i < pos)
fdinfo->lookahead[0] = readbuf[i];
if(i+1 < pos)
@@ -2179,7 +2191,7 @@
if(lookahead != '\n')
readbuf[j++] = '\r';
- if(fdinfo->wxflag & (WX_PIPE | WX_NOSEEK))
+ if(fdinfo->wxflag & (WX_PIPE | WX_TTY))
fdinfo->lookahead[0] = lookahead;
else
SetFilePointer(fdinfo->handle, -1, NULL, FILE_CURRENT);
@@ -2313,7 +2325,7 @@
if(utf16) bufstart[j++] = 0;
}
- if (fdinfo->wxflag & (WX_PIPE | WX_NOSEEK))
+ if (fdinfo->wxflag & (WX_PIPE | WX_TTY))
{
if (lookahead[0]=='\n' && (!utf16 ||
!lookahead[1]))
{