Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
6e011b83
Commit
6e011b83
authored
Jan 10, 2013
by
Piotr Caban
Committed by
Alexandre Julliard
Jan 10, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
msvcrt: Fixed handling of '\r' when it's the last character in the buffer in read.
parent
5778bdbc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
22 deletions
+61
-22
file.c
dlls/msvcrt/file.c
+61
-22
No files found.
dlls/msvcrt/file.c
View file @
6e011b83
...
...
@@ -60,8 +60,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
/* values for wxflag in file descriptor */
#define WX_OPEN 0x01
#define WX_ATEOF 0x02
#define WX_READ
EOF 0x04
/* like ATEOF, but for underlying file rather than buffe
r */
#define WX_
READCR 0x08
/* underlying file is at \r */
#define WX_READ
CR 0x04
/* underlying file is at \
r */
#define WX_
PIPE 0x08
#define WX_DONTINHERIT 0x10
#define WX_APPEND 0x20
#define WX_TEXT 0x80
...
...
@@ -83,7 +83,7 @@ static char utf16_bom[2] = { 0xff, 0xfe };
typedef
struct
{
HANDLE
handle
;
unsigned
char
wxflag
;
char
unk1
;
char
lookahead
[
3
]
;
int
exflag
;
CRITICAL_SECTION
crit
;
}
ioinfo
;
...
...
@@ -319,7 +319,10 @@ static int msvcrt_alloc_fd_from(HANDLE hand, int flag, int fd)
}
fdinfo
->
handle
=
hand
;
fdinfo
->
wxflag
=
WX_OPEN
|
(
flag
&
(
WX_DONTINHERIT
|
WX_APPEND
|
WX_TEXT
));
fdinfo
->
wxflag
=
WX_OPEN
|
(
flag
&
(
WX_DONTINHERIT
|
WX_APPEND
|
WX_TEXT
|
WX_PIPE
));
fdinfo
->
lookahead
[
0
]
=
'\n'
;
fdinfo
->
lookahead
[
1
]
=
'\n'
;
fdinfo
->
lookahead
[
2
]
=
'\n'
;
fdinfo
->
exflag
=
0
;
/* locate next free slot */
...
...
@@ -494,6 +497,9 @@ void msvcrt_init_io(void)
GetCurrentProcess
(),
&
fdinfo
->
handle
,
0
,
TRUE
,
DUPLICATE_SAME_ACCESS
))
fdinfo
->
wxflag
=
WX_OPEN
|
WX_TEXT
;
fdinfo
->
lookahead
[
0
]
=
'\n'
;
fdinfo
->
lookahead
[
1
]
=
'\n'
;
fdinfo
->
lookahead
[
2
]
=
'\n'
;
fdinfo
->
exflag
=
0
;
}
...
...
@@ -505,6 +511,9 @@ void msvcrt_init_io(void)
GetCurrentProcess
(),
&
fdinfo
->
handle
,
0
,
TRUE
,
DUPLICATE_SAME_ACCESS
))
fdinfo
->
wxflag
=
WX_OPEN
|
WX_TEXT
;
fdinfo
->
lookahead
[
0
]
=
'\n'
;
fdinfo
->
lookahead
[
1
]
=
'\n'
;
fdinfo
->
lookahead
[
2
]
=
'\n'
;
fdinfo
->
exflag
=
0
;
}
...
...
@@ -516,6 +525,9 @@ void msvcrt_init_io(void)
GetCurrentProcess
(),
&
fdinfo
->
handle
,
0
,
TRUE
,
DUPLICATE_SAME_ACCESS
))
fdinfo
->
wxflag
=
WX_OPEN
|
WX_TEXT
;
fdinfo
->
lookahead
[
0
]
=
'\n'
;
fdinfo
->
lookahead
[
1
]
=
'\n'
;
fdinfo
->
lookahead
[
2
]
=
'\n'
;
fdinfo
->
exflag
=
0
;
}
...
...
@@ -1050,7 +1062,7 @@ __int64 CDECL MSVCRT__lseeki64(int fd, __int64 offset, int whence)
if
((
ofs
.
u
.
LowPart
=
SetFilePointer
(
hand
,
ofs
.
u
.
LowPart
,
&
ofs
.
u
.
HighPart
,
whence
))
!=
INVALID_SET_FILE_POINTER
||
GetLastError
()
==
ERROR_SUCCESS
)
{
msvcrt_get_ioinfo
(
fd
)
->
wxflag
&=
~
(
WX_ATEOF
|
WX_READEOF
)
;
msvcrt_get_ioinfo
(
fd
)
->
wxflag
&=
~
WX_ATEOF
;
/* FIXME: What if we seek _to_ EOF - is EOF set? */
return
ofs
.
QuadPart
;
...
...
@@ -1727,11 +1739,11 @@ int CDECL MSVCRT__pipe(int *pfds, unsigned int psize, int textmode)
int
fd
;
LOCK_FILES
();
fd
=
msvcrt_alloc_fd
(
readHandle
,
wxflags
);
fd
=
msvcrt_alloc_fd
(
readHandle
,
wxflags
|
WX_PIPE
);
if
(
fd
!=
-
1
)
{
pfds
[
0
]
=
fd
;
fd
=
msvcrt_alloc_fd
(
writeHandle
,
wxflags
);
fd
=
msvcrt_alloc_fd
(
writeHandle
,
wxflags
|
WX_PIPE
);
if
(
fd
!=
-
1
)
{
pfds
[
1
]
=
fd
;
...
...
@@ -2117,8 +2129,7 @@ static int read_i(int fd, void *buf, unsigned int count)
if
(
count
==
0
)
return
0
;
if
(
fdinfo
->
wxflag
&
WX_READEOF
)
{
fdinfo
->
wxflag
|=
WX_ATEOF
;
if
(
fdinfo
->
wxflag
&
WX_ATEOF
)
{
TRACE
(
"already at EOF, returning 0
\n
"
);
return
0
;
}
...
...
@@ -2128,14 +2139,22 @@ static int read_i(int fd, void *buf, unsigned int count)
if
(
hand
==
INVALID_HANDLE_VALUE
)
return
-
1
;
/* Reading single bytes in O_TEXT mode makes things slow
* So read big chunks
*/
if
(
ReadFile
(
hand
,
bufstart
,
count
,
&
num_read
,
NULL
))
if
(
fdinfo
->
lookahead
[
0
]
!=
'\n'
||
ReadFile
(
hand
,
bufstart
,
count
,
&
num_read
,
NULL
))
{
if
(
fdinfo
->
lookahead
[
0
]
!=
'\n'
)
{
bufstart
[
0
]
=
fdinfo
->
lookahead
[
0
];
fdinfo
->
lookahead
[
0
]
=
'\n'
;
if
(
count
>
1
&&
ReadFile
(
hand
,
bufstart
+
1
,
count
-
1
,
&
num_read
,
NULL
))
num_read
++
;
else
num_read
=
1
;
}
if
(
count
!=
0
&&
num_read
==
0
)
{
fdinfo
->
wxflag
|=
(
WX_ATEOF
|
WX_READEOF
)
;
fdinfo
->
wxflag
|=
WX_ATEOF
;
TRACE
(
":EOF %s
\n
"
,
debugstr_an
(
buf
,
num_read
));
}
else
if
(
fdinfo
->
wxflag
&
WX_TEXT
)
...
...
@@ -2161,16 +2180,36 @@ static int read_i(int fd, void *buf, unsigned int count)
/* in text mode, a ctrl-z signals EOF */
if
(
bufstart
[
i
]
==
0x1a
)
{
fdinfo
->
wxflag
|=
(
WX_ATEOF
|
WX_READEOF
)
;
fdinfo
->
wxflag
|=
WX_ATEOF
;
TRACE
(
":^Z EOF %s
\n
"
,
debugstr_an
(
buf
,
num_read
));
break
;
}
/* in text mode, strip \r if followed by \n.
* BUG: should save state across calls somehow, so CR LF that
* straddles buffer boundary gets recognized properly?
*/
if
((
bufstart
[
i
]
!=
'\r'
)
||
((
i
+
1
)
<
num_read
&&
bufstart
[
i
+
1
]
!=
'\n'
))
/* in text mode, strip \r if followed by \n */
if
(
bufstart
[
i
]
==
'\r'
&&
i
+
1
==
num_read
)
{
char
lookahead
;
DWORD
len
;
if
(
ReadFile
(
hand
,
&
lookahead
,
1
,
&
len
,
NULL
)
&&
len
)
{
if
(
lookahead
==
'\n'
&&
j
==
0
)
bufstart
[
j
++
]
=
'\n'
;
else
{
if
(
lookahead
!=
'\n'
)
bufstart
[
j
++
]
=
'\r'
;
if
(
fdinfo
->
wxflag
&
WX_PIPE
)
fdinfo
->
lookahead
[
0
]
=
lookahead
;
else
SetFilePointer
(
fdinfo
->
handle
,
-
1
,
NULL
,
FILE_CURRENT
);
}
}
else
bufstart
[
j
++
]
=
'\r'
;
}
else
if
(
bufstart
[
i
]
!=
'\r'
||
bufstart
[
i
+
1
]
!=
'\n'
)
bufstart
[
j
++
]
=
bufstart
[
i
];
}
num_read
=
j
;
...
...
@@ -2181,7 +2220,7 @@ static int read_i(int fd, void *buf, unsigned int count)
if
(
GetLastError
()
==
ERROR_BROKEN_PIPE
)
{
TRACE
(
":end-of-pipe
\n
"
);
fdinfo
->
wxflag
|=
(
WX_ATEOF
|
WX_READEOF
)
;
fdinfo
->
wxflag
|=
WX_ATEOF
;
return
0
;
}
else
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment