Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-cw
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-cw
Commits
7880525f
Commit
7880525f
authored
Jan 23, 2015
by
Piotr Caban
Committed by
Alexandre Julliard
Jan 26, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
msvcrt: Handle read buffer flushing in msvcrt_flush_buffer helper.
parent
52171a8b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
32 deletions
+31
-32
file.c
dlls/msvcrt/file.c
+17
-32
file.c
dlls/msvcrt/tests/file.c
+14
-0
No files found.
dlls/msvcrt/file.c
View file @
7880525f
...
...
@@ -606,16 +606,18 @@ void msvcrt_init_io(void)
/* INTERNAL: Flush stdio file buffer */
static
int
msvcrt_flush_buffer
(
MSVCRT_FILE
*
file
)
{
if
(
file
->
_flag
&
(
MSVCRT__IOMYBUF
|
MSVCRT__USERBUF
))
{
if
((
file
->
_flag
&
(
MSVCRT__IOREAD
|
MSVCRT__IOWRT
))
==
MSVCRT__IOWRT
&&
file
->
_flag
&
(
MSVCRT__IOMYBUF
|
MSVCRT__USERBUF
))
{
int
cnt
=
file
->
_ptr
-
file
->
_base
;
if
(
cnt
>
0
&&
MSVCRT__write
(
file
->
_file
,
file
->
_base
,
cnt
)
!=
cnt
)
{
file
->
_flag
|=
MSVCRT__IOERR
;
return
MSVCRT_EOF
;
}
file
->
_ptr
=
file
->
_base
;
file
->
_cnt
=
0
;
}
return
0
;
}
file
->
_ptr
=
file
->
_base
;
file
->
_cnt
=
0
;
return
0
;
}
/*********************************************************************
...
...
@@ -964,23 +966,17 @@ int CDECL MSVCRT_fflush(MSVCRT_FILE* file)
*/
int
CDECL
MSVCRT__fflush_nolock
(
MSVCRT_FILE
*
file
)
{
int
res
;
if
(
!
file
)
{
msvcrt_flush_all_buffers
(
MSVCRT__IOWRT
);
}
else
if
(
file
->
_flag
&
MSVCRT__IOWRT
)
{
int
res
;
res
=
msvcrt_flush_buffer
(
file
);
if
(
!
res
&&
(
file
->
_flag
&
MSVCRT__IOCOMMIT
))
res
=
MSVCRT__commit
(
file
->
_file
)
?
MSVCRT_EOF
:
0
;
return
res
;
}
else
if
(
file
->
_flag
&
MSVCRT__IOREAD
)
{
file
->
_cnt
=
0
;
file
->
_ptr
=
file
->
_base
;
return
0
;
}
return
0
;
res
=
msvcrt_flush_buffer
(
file
);
if
(
!
res
&&
(
file
->
_flag
&
MSVCRT__IOCOMMIT
))
res
=
MSVCRT__commit
(
file
->
_file
)
?
MSVCRT_EOF
:
0
;
return
res
;
}
/*********************************************************************
...
...
@@ -1333,18 +1329,13 @@ int CDECL MSVCRT__fseeki64_nolock(MSVCRT_FILE* file, __int64 offset, int whence)
{
int
ret
;
/* Flush output if needed */
if
(
file
->
_flag
&
MSVCRT__IOWRT
)
msvcrt_flush_buffer
(
file
);
if
(
whence
==
SEEK_CUR
&&
file
->
_flag
&
MSVCRT__IOREAD
)
{
whence
=
SEEK_SET
;
offset
+=
MSVCRT__ftelli64_nolock
(
file
);
}
/* Discard buffered input */
file
->
_cnt
=
0
;
file
->
_ptr
=
file
->
_base
;
/* Flush output if needed */
msvcrt_flush_buffer
(
file
);
/* Reset direction of i/o */
if
(
file
->
_flag
&
MSVCRT__IORW
)
{
file
->
_flag
&=
~
(
MSVCRT__IOREAD
|
MSVCRT__IOWRT
);
...
...
@@ -4369,14 +4360,8 @@ int CDECL MSVCRT_fsetpos(MSVCRT_FILE* file, MSVCRT_fpos_t *pos)
int
ret
;
MSVCRT__lock_file
(
file
);
/* Note that all this has been lifted 'as is' from fseek */
if
(
file
->
_flag
&
MSVCRT__IOWRT
)
msvcrt_flush_buffer
(
file
);
msvcrt_flush_buffer
(
file
);
/* Discard buffered input */
file
->
_cnt
=
0
;
file
->
_ptr
=
file
->
_base
;
/* Reset direction of i/o */
if
(
file
->
_flag
&
MSVCRT__IORW
)
{
file
->
_flag
&=
~
(
MSVCRT__IOREAD
|
MSVCRT__IOWRT
);
...
...
dlls/msvcrt/tests/file.c
View file @
7880525f
...
...
@@ -2244,6 +2244,7 @@ static void test_write_flush_size(FILE *file, int bufsize)
char
*
inbuffer
;
char
*
outbuffer
;
int
size
,
fd
;
fpos_t
pos
,
pos2
;
fd
=
fileno
(
file
);
inbuffer
=
calloc
(
bufsize
+
1
,
1
);
...
...
@@ -2275,6 +2276,19 @@ static void test_write_flush_size(FILE *file, int bufsize)
fseek
(
file
,
0
,
SEEK_SET
);
ok
(
fread
(
inbuffer
,
1
,
bufsize
,
file
)
==
bufsize
,
"read failed
\n
"
);
ok
(
memcmp
(
outbuffer
,
inbuffer
,
bufsize
)
!=
0
,
"unexpected flush by %d/2 byte double write
\n
"
,
bufsize
);
ok
(
!
fseek
(
file
,
-
1
,
SEEK_END
),
"fseek failed
\n
"
);
ok
(
!
fgetpos
(
file
,
&
pos
),
"fgetpos failed
\n
"
);
ok
(
fread
(
inbuffer
,
1
,
1
,
file
)
==
1
,
"fread failed
\n
"
);
ok
(
file
->
_flag
&
_IOREAD
,
"file->_flag = %x
\n
"
,
file
->
_flag
);
ok
(
!
file
->
_cnt
,
"file->_cnt = %d
\n
"
,
file
->
_cnt
);
ok
(
file
->
_ptr
!=
file
->
_base
,
"file->_ptr == file->_base
\n
"
);
ok
(
fwrite
(
outbuffer
,
1
,
bufsize
,
file
),
"fwrite failed
\n
"
);
ok
(
file
->
_flag
&
_IOREAD
,
"file->_flag = %x
\n
"
,
file
->
_flag
);
ok
(
!
file
->
_cnt
,
"file->_cnt = %d
\n
"
,
file
->
_cnt
);
ok
(
file
->
_ptr
==
file
->
_base
,
"file->_ptr == file->_base
\n
"
);
ok
(
!
fgetpos
(
file
,
&
pos2
),
"fgetpos failed
\n
"
);
ok
(
pos
+
bufsize
+
1
==
pos2
,
"pos = %d (%d)
\n
"
,
(
int
)
pos
,
(
int
)
pos2
);
free
(
inbuffer
);
free
(
outbuffer
);
}
...
...
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