Skip to content
Commit 74c4d5ae authored by Evgeniy Paltsev's avatar Evgeniy Paltsev Committed by Anas Nashif
Browse files

libc: minimal: stdout: fix fputs return value



The 'fputs' has flaw in the implementation. It almost always
returns 'EOF' even if completed successfully.
This happens because we compare 'fwrite' return value which is
"number of members successfully written" (which is 1 in current
implementation) to the total string size:

----------------------------->8-----------------------
int fputs(const char *_MLIBC_RESTRICT string,
          FILE *_MLIBC_RESTRICT stream)
{
	int len = strlen(string);
	int ret;

	ret = fwrite(string, len, 1, stream);

	return len == ret ? 0 : EOF;
}
----------------------------->8-----------------------

In result 'fputs' return 'EOF' in case of string length bigger
than 1.

There are several fixes possible, and one of the fixes is to
swap number of items (1) with size (string length) when we
are calling 'fwrite'. The only difference will be that
'fwrite' will return actual numbers of bytes written which
can be compared with the string length.

Signed-off-by: default avatarEugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
parent a086e19d
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment