mirror of
git://source.winehq.org/git/wine.git
synced 2024-09-02 22:23:39 +00:00
msvcrt: Fix write() behaviour on "no console" file descriptors.
Signed-off-by: Piotr Caban <piotr@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
9b2397d5c8
commit
7aa4b6d170
|
@ -3423,7 +3423,7 @@ int CDECL MSVCRT__write(int fd, const void* buf, unsigned int count)
|
|||
if (count > 32)
|
||||
TRACE(":fd (%d) handle (%d) buf (%p) len (%d)\n",fd,hand,buf,count);
|
||||
#endif
|
||||
if (hand == INVALID_HANDLE_VALUE)
|
||||
if (hand == INVALID_HANDLE_VALUE || fd == MSVCRT_NO_CONSOLE_FD)
|
||||
{
|
||||
*MSVCRT__errno() = MSVCRT_EBADF;
|
||||
release_ioinfo(info);
|
||||
|
@ -3451,14 +3451,14 @@ int CDECL MSVCRT__write(int fd, const void* buf, unsigned int count)
|
|||
}
|
||||
TRACE("WriteFile (fd %d, hand %p) failed-last error (%d)\n", fd,
|
||||
hand, GetLastError());
|
||||
*MSVCRT__errno() = MSVCRT_ENOSPC;
|
||||
msvcrt_set_errno(GetLastError());
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int i, j, nr_lf, size;
|
||||
char *p = NULL;
|
||||
const char *q;
|
||||
const char *s = buf, *buf_start = buf;
|
||||
const char *s = buf;
|
||||
|
||||
if (!(info->exflag & (EF_UTF8|EF_UTF16)))
|
||||
{
|
||||
|
@ -3577,8 +3577,8 @@ int CDECL MSVCRT__write(int fd, const void* buf, unsigned int count)
|
|||
{
|
||||
TRACE("WriteFile (fd %d, hand %p) failed-last error (%d), num_written %d\n",
|
||||
fd, hand, GetLastError(), num_written);
|
||||
*MSVCRT__errno() = MSVCRT_ENOSPC;
|
||||
return s - buf_start;
|
||||
msvcrt_set_errno(GetLastError());
|
||||
return -1;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
@ -3927,6 +3927,7 @@ int CDECL MSVCRT__flsbuf(int c, MSVCRT_FILE* file)
|
|||
if(!(file->_flag & MSVCRT__IOWRT)) {
|
||||
if(!(file->_flag & MSVCRT__IORW)) {
|
||||
file->_flag |= MSVCRT__IOERR;
|
||||
*MSVCRT__errno() = MSVCRT_EBADF;
|
||||
return MSVCRT_EOF;
|
||||
}
|
||||
file->_flag |= MSVCRT__IOWRT;
|
||||
|
|
|
@ -1556,6 +1556,26 @@ static void test_invalid_stdin_child( void )
|
|||
ok(ret == -1, "read(STDIN_FILENO) returned %d\n", ret);
|
||||
ok(errno == EBADF, "errno = %d\n", errno);
|
||||
|
||||
errno = 0xdeadbeef;
|
||||
ret = _flsbuf('a', stdin);
|
||||
ok(ret == EOF, "_flsbuf(stdin) returned %d\n", ret);
|
||||
ok(errno == EBADF, "errno = %d\n", errno);
|
||||
|
||||
errno = 0xdeadbeef;
|
||||
ret = fwrite(&c, 1, 1, stdin);
|
||||
ok(!ret, "fwrite(stdin) returned %d\n", ret);
|
||||
ok(errno == EBADF, "errno = %d\n", errno);
|
||||
|
||||
errno = 0xdeadbeef;
|
||||
ret = write(-2, &c, 1);
|
||||
ok(ret == -1, "write(-2) returned %d\n", ret);
|
||||
ok(errno == EBADF, "errno = %d\n", errno);
|
||||
|
||||
errno = 0xdeadbeef;
|
||||
ret = write(STDIN_FILENO, &c, 1);
|
||||
ok(ret == -1, "write(STDIN_FILENO) returned %d\n", ret);
|
||||
ok(errno == EBADF, "errno = %d\n", errno);
|
||||
|
||||
errno = 0xdeadbeef;
|
||||
ret = fclose(stdin);
|
||||
ok(ret == -1, "fclose(stdin) returned %d\n", ret);
|
||||
|
|
Loading…
Reference in a new issue