Commit d3a48ee3 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Only check for flag presence in isatty function.

parent 3cf2fb3a
......@@ -65,7 +65,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
#define WX_PIPE 0x08
#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*/
......@@ -376,7 +376,7 @@ static int msvcrt_set_fd(HANDLE hand, int flag, int fd)
}
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';
......@@ -550,7 +550,7 @@ void msvcrt_init_io(void)
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
DWORD type = GetFileType(h);
msvcrt_set_fd(h, WX_OPEN|WX_TEXT|((type&0xf)==FILE_TYPE_CHAR ? WX_NOSEEK : 0)
msvcrt_set_fd(h, WX_OPEN|WX_TEXT|((type&0xf)==FILE_TYPE_CHAR ? WX_TTY : 0)
|((type&0xf)==FILE_TYPE_PIPE ? WX_PIPE : 0), MSVCRT_STDIN_FILENO);
}
......@@ -559,7 +559,7 @@ void msvcrt_init_io(void)
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD type = GetFileType(h);
msvcrt_set_fd(h, WX_OPEN|WX_TEXT|((type&0xf)==FILE_TYPE_CHAR ? WX_NOSEEK : 0)
msvcrt_set_fd(h, WX_OPEN|WX_TEXT|((type&0xf)==FILE_TYPE_CHAR ? WX_TTY : 0)
|((type&0xf)==FILE_TYPE_PIPE ? WX_PIPE : 0), MSVCRT_STDOUT_FILENO);
}
......@@ -568,7 +568,7 @@ void msvcrt_init_io(void)
HANDLE h = GetStdHandle(STD_ERROR_HANDLE);
DWORD type = GetFileType(h);
msvcrt_set_fd(h, WX_OPEN|WX_TEXT|((type&0xf)==FILE_TYPE_CHAR ? WX_NOSEEK : 0)
msvcrt_set_fd(h, WX_OPEN|WX_TEXT|((type&0xf)==FILE_TYPE_CHAR ? WX_TTY : 0)
|((type&0xf)==FILE_TYPE_PIPE ? WX_PIPE : 0), MSVCRT_STDERR_FILENO);
}
......@@ -607,13 +607,9 @@ static int msvcrt_flush_buffer(MSVCRT_FILE* file)
*/
int CDECL MSVCRT__isatty(int fd)
{
HANDLE hand = msvcrt_fdtoh(fd);
TRACE(":fd (%d)\n",fd);
TRACE(":fd (%d) handle (%p)\n",fd,hand);
if (hand == INVALID_HANDLE_VALUE)
return 0;
return GetFileType(hand) == FILE_TYPE_CHAR? 1 : 0;
return msvcrt_get_ioinfo(fd)->wxflag & WX_TTY;
}
/* INTERNAL: Allocate stdio file buffer */
......@@ -2006,7 +2002,7 @@ int CDECL MSVCRT__wsopen_s( int *fd, const MSVCRT_wchar_t* path, int oflags, int
{
DWORD access = 0, creation = 0, attrib;
SECURITY_ATTRIBUTES sa;
DWORD sharing;
DWORD sharing, type;
int wxflag;
HANDLE hand;
......@@ -2139,6 +2135,12 @@ int CDECL MSVCRT__wsopen_s( int *fd, const MSVCRT_wchar_t* path, int oflags, int
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 = msvcrt_alloc_fd(hand, wxflag);
if (*fd == -1)
return *MSVCRT__errno();
......@@ -2300,7 +2302,7 @@ int CDECL MSVCRT__open_osfhandle(MSVCRT_intptr_t handle, int oflags)
}
if (flags == FILE_TYPE_CHAR)
flags = WX_NOSEEK;
flags = WX_TTY;
else if (flags == FILE_TYPE_PIPE)
flags = WX_PIPE;
else
......@@ -2424,7 +2426,7 @@ static int read_utf8(int fd, MSVCRT_wchar_t *buf, unsigned int count)
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);
......@@ -2472,7 +2474,7 @@ static int read_utf8(int fd, MSVCRT_wchar_t *buf, unsigned int count)
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)
......@@ -2500,7 +2502,7 @@ static int read_utf8(int fd, MSVCRT_wchar_t *buf, unsigned int count)
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);
......@@ -2634,7 +2636,7 @@ static int read_i(int fd, void *buf, unsigned int count)
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]))
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment