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
b37b967a
Commit
b37b967a
authored
Jul 29, 2006
by
Duane Clark
Committed by
Alexandre Julliard
Jul 31, 2006
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
msvcrt: Fix _read and fgetc.
parent
1aa8db05
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
24 deletions
+38
-24
file.c
dlls/msvcrt/file.c
+29
-12
file.c
dlls/msvcrt/tests/file.c
+9
-12
No files found.
dlls/msvcrt/file.c
View file @
b37b967a
...
...
@@ -1615,9 +1615,9 @@ static unsigned int remove_cr(char *buf, unsigned int count)
}
/*********************************************************************
*
_read (MSVCRT.@)
*
(internal) read_i
*/
int
CDECL
_read
(
int
fd
,
void
*
buf
,
unsigned
int
count
)
static
int
read_i
(
int
fd
,
void
*
buf
,
unsigned
int
count
)
{
DWORD
num_read
,
all_read
=
0
;
char
*
bufstart
=
buf
;
...
...
@@ -1641,17 +1641,11 @@ int CDECL _read(int fd, void *buf, unsigned int count)
{
TRACE
(
":EOF
\n
"
);
MSVCRT_fdesc
[
fd
].
wxflag
|=
WX_ATEOF
;
if
(
MSVCRT_fdesc
[
fd
].
wxflag
&
WX_TEXT
)
num_read
-=
remove_cr
(
bufstart
+
all_read
,
num_read
);
all_read
+=
num_read
;
if
(
count
>
4
)
TRACE
(
"%s
\n
"
,
debugstr_an
(
buf
,
all_read
));
return
all_read
;
}
if
(
MSVCRT_fdesc
[
fd
].
wxflag
&
WX_TEXT
)
{
num_read
-=
remove_cr
(
bufstart
+
all_read
,
num_read
);
}
all_read
+=
num_read
;
}
else
...
...
@@ -1667,6 +1661,20 @@ int CDECL _read(int fd, void *buf, unsigned int count)
}
/*********************************************************************
* _read (MSVCRT.@)
*/
int
CDECL
_read
(
int
fd
,
void
*
buf
,
unsigned
int
count
)
{
int
num_read
;
num_read
=
read_i
(
fd
,
buf
,
count
);
if
(
num_read
>
0
&&
MSVCRT_fdesc
[
fd
].
wxflag
&
WX_TEXT
)
{
num_read
-=
remove_cr
(
buf
,
num_read
);
}
return
num_read
;
}
/*********************************************************************
* _getw (MSVCRT.@)
*/
int
CDECL
MSVCRT__getw
(
MSVCRT_FILE
*
file
)
...
...
@@ -2109,13 +2117,13 @@ int CDECL MSVCRT__filbuf(MSVCRT_FILE* file)
if
(
file
->
_flag
&
MSVCRT__IONBF
)
{
unsigned
char
c
;
int
r
;
if
((
r
=
_read
(
file
->
_file
,
&
c
,
1
))
!=
1
)
{
if
((
r
=
read_i
(
file
->
_file
,
&
c
,
1
))
!=
1
)
{
file
->
_flag
|=
(
r
==
0
)
?
MSVCRT__IOEOF
:
MSVCRT__IOERR
;
return
MSVCRT_EOF
;
}
return
c
;
}
else
{
file
->
_cnt
=
_read
(
file
->
_file
,
file
->
_base
,
file
->
_bufsiz
);
file
->
_cnt
=
read_i
(
file
->
_file
,
file
->
_base
,
file
->
_bufsiz
);
if
(
file
->
_cnt
<=
0
)
{
file
->
_flag
|=
(
file
->
_cnt
==
0
)
?
MSVCRT__IOEOF
:
MSVCRT__IOERR
;
file
->
_cnt
=
0
;
...
...
@@ -2132,12 +2140,21 @@ int CDECL MSVCRT__filbuf(MSVCRT_FILE* file)
*/
int
CDECL
MSVCRT_fgetc
(
MSVCRT_FILE
*
file
)
{
char
*
i
;
int
j
;
do
{
if
(
file
->
_cnt
>
0
)
{
file
->
_cnt
--
;
return
*
(
unsigned
char
*
)
file
->
_ptr
++
;
i
=
file
->
_ptr
++
;
j
=
*
i
;
}
else
{
return
MSVCRT__filbuf
(
file
);
j
=
MSVCRT__filbuf
(
file
);
if
(
j
==
MSVCRT_EOF
)
return
j
;
}
if
(
!
(
MSVCRT_fdesc
[
file
->
_file
].
wxflag
&
WX_TEXT
)
||
(
j
!=
'\r'
))
return
j
;
}
while
(
1
);
}
/*********************************************************************
...
...
dlls/msvcrt/tests/file.c
View file @
b37b967a
...
...
@@ -184,9 +184,6 @@ static void test_readmode( BOOL ascii_mode )
fp
++
;
ok
(
fgets
(
buffer
,
256
,
file
)
!=
0
,
"line 1 fgets failed unexpected in %s
\n
"
,
IOMODE
);
l
=
ftell
(
file
);
if
(
ao
==
-
1
)
todo_wine
ok
(
l
==
pl
+
fp
,
"line 1 ftell got %ld should be %d in %s
\n
"
,
l
,
pl
+
fp
,
IOMODE
);
else
ok
(
l
==
pl
+
fp
,
"line 1 ftell got %ld should be %d in %s
\n
"
,
l
,
pl
+
fp
,
IOMODE
);
ok
(
lstrlenA
(
buffer
)
==
fp
+
ao
,
"line 1 fgets got size %d should be %d in %s
\n
"
,
lstrlenA
(
buffer
),
fp
+
ao
,
IOMODE
);
...
...
@@ -197,18 +194,12 @@ static void test_readmode( BOOL ascii_mode )
ok
(
l
==
pl
,
"ftell after seek got %ld should be %d in %s
\n
"
,
l
,
pl
,
IOMODE
);
ok
(
fgets
(
buffer
,
256
,
file
)
!=
0
,
"second read of line 1 fgets failed unexpected in %s
\n
"
,
IOMODE
);
l
=
ftell
(
file
);
if
(
ao
==
-
1
)
todo_wine
ok
(
l
==
pl
+
fp
,
"second read of line 1 ftell got %ld should be %d in %s
\n
"
,
l
,
pl
+
fp
,
IOMODE
);
else
ok
(
l
==
pl
+
fp
,
"second read of line 1 ftell got %ld should be %d in %s
\n
"
,
l
,
pl
+
fp
,
IOMODE
);
ok
(
lstrlenA
(
buffer
)
==
fp
+
ao
,
"second read of line 1 fgets got size %d should be %d in %s
\n
"
,
lstrlenA
(
buffer
),
fp
+
ao
,
IOMODE
);
ok
(
fgets
(
buffer
,
256
,
file
)
!=
0
,
"line 2 fgets failed unexpected in %s
\n
"
,
IOMODE
);
fp
+=
2
;
l
=
ftell
(
file
);
if
(
ao
==
-
1
)
todo_wine
ok
(
l
==
pl
+
fp
,
"line 2 ftell got %ld should be %d in %s
\n
"
,
l
,
pl
+
fp
,
IOMODE
);
else
ok
(
l
==
pl
+
fp
,
"line 2 ftell got %ld should be %d in %s
\n
"
,
l
,
pl
+
fp
,
IOMODE
);
ok
(
lstrlenA
(
buffer
)
==
2
+
ao
,
"line 2 fgets got size %d should be %d in %s
\n
"
,
lstrlenA
(
buffer
),
2
+
ao
,
IOMODE
);
...
...
@@ -219,6 +210,9 @@ static void test_readmode( BOOL ascii_mode )
ok
(
fgets
(
buffer
,
MSVCRT_BUFSIZ
-
6
,
file
)
!=
0
,
"padding line fgets failed unexpected in %s
\n
"
,
IOMODE
);
j
=
strlen
(
outbuffer
);
i
=
fread
(
buffer
,
1
,
256
,
file
);
if
(
ao
==
-
1
)
todo_wine
todo_wine
ok
(
i
==
j
+
6
+
ao
*
4
,
"fread failed, expected %d got %d in %s
\n
"
,
j
+
6
+
ao
*
4
,
i
,
IOMODE
);
else
ok
(
i
==
j
+
6
+
ao
*
4
,
"fread failed, expected %d got %d in %s
\n
"
,
j
+
6
+
ao
*
4
,
i
,
IOMODE
);
l
=
ftell
(
file
);
ok
(
l
==
pl
+
j
+
1
,
"ftell after fread got %ld should be %d in %s
\n
"
,
l
,
pl
+
j
+
1
,
IOMODE
);
...
...
@@ -228,6 +222,9 @@ static void test_readmode( BOOL ascii_mode )
ok
(
fgets
(
buffer
,
MSVCRT_BUFSIZ
-
6
,
file
)
!=
0
,
"padding line fgets failed unexpected in %s
\n
"
,
IOMODE
);
j
=
fp
+
10
;
i
=
fread
(
buffer
,
1
,
j
,
file
);
if
(
ao
==
-
1
)
todo_wine
ok
(
i
==
j
,
"fread failed, expected %d got %d in %s
\n
"
,
j
,
i
,
IOMODE
);
else
ok
(
i
==
j
,
"fread failed, expected %d got %d in %s
\n
"
,
j
,
i
,
IOMODE
);
/* test some additional functions */
...
...
@@ -370,7 +367,7 @@ static void test_file_write_read( void )
"problems with _O_BINARY _write / _read
\n
"
);
_close
(
tempfd
);
tempfd
=
_open
(
tempf
,
_O_RDONLY
|
_O_TEXT
);
/* open in TEXT mode */
todo_wine
ok
(
_read
(
tempfd
,
btext
,
i
)
==
i
-
1
,
ok
(
_read
(
tempfd
,
btext
,
i
)
==
i
-
1
,
"_read _O_TEXT got bad length
\n
"
);
ok
(
memcmp
(
mytext
,
btext
,
i
-
1
)
==
0
,
"problems with _O_BINARY _write / _O_TEXT _read
\n
"
);
...
...
@@ -413,8 +410,8 @@ static void test_file_write_read( void )
ok
(
ret
==
1
&&
*
btext
==
'\n'
,
"_read expected '
\\
n' got bad length: %d
\n
"
,
ret
);
_lseek
(
tempfd
,
-
3
,
FILE_END
);
ret
=
_read
(
tempfd
,
btext
,
2
);
todo_wine
ok
(
ret
==
1
&&
*
btext
==
'e'
,
"_read expected 'e' got
\"
%.*s
\"
bad length: %d
\n
"
,
ret
,
btext
,
ret
);
todo_wine
ok
(
tell
(
tempfd
)
==
42
,
"bad position %lu expecting 42
\n
"
,
tell
(
tempfd
));
ok
(
ret
==
1
&&
*
btext
==
'e'
,
"_read expected 'e' got
\"
%.*s
\"
bad length: %d
\n
"
,
ret
,
btext
,
ret
);
ok
(
tell
(
tempfd
)
==
42
,
"bad position %lu expecting 42
\n
"
,
tell
(
tempfd
));
_close
(
tempfd
);
ret
=
unlink
(
tempf
);
...
...
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