Skip to content

libc: picolibc: fputc should return the value it has written #74629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

ycsin
Copy link
Member

@ycsin ycsin commented Jun 20, 2024

According to the documentations:

Return value

On success, returns the written character.
On failure, returns EOF and sets the error indicator (see ferror()) on stream.

Upon successful completion, fputc() shall return the value it has written. Otherwise, it shall return EOF, the error indicator for the stream shall be set, [CX] [Option Start] and errno shall be set to indicate the error.

This commit changes it to return the written value on success, and EOF if failed, which is the same as minimal libc, but the error indicator is still not set.

int z_impl_zephyr_fputc(int c, FILE *stream)
{
return ((stream == stdout) || (stream == stderr)) ? _stdout_hook(c) : EOF;
}

@zephyrbot zephyrbot added the area: C Library C Standard Library label Jun 20, 2024
@ycsin ycsin added the bug The issue is a bug, or the PR is fixing a bug label Jun 20, 2024
@keith-packard
Copy link
Collaborator

If I recall correctly, this is an internal implementation detail of the picolibc layer for Zephyr -- the actual fputc code seen by applications should come from picolibc itself and have the correct return value.

@ycsin ycsin force-pushed the pr/fix_picolibc_fputc branch from c805bf9 to 357a405 Compare June 24, 2024 04:50
@ycsin
Copy link
Member Author

ycsin commented Jun 24, 2024

If I recall correctly, this is an internal implementation detail of the picolibc layer for Zephyr -- the actual fputc code seen by applications should come from picolibc itself and have the correct return value.

I think you are right.

In that case, what's the role of zephyr_fputc() & picolibc_put() for picolibc? Just stubs?

@ycsin ycsin added this to the v3.7.0 milestone Jul 11, 2024
@nashif nashif removed this from the v3.7.0 milestone Jul 16, 2024
@nashif nashif added the backport v3.7-branch Request backport to the v3.7-branch label Jul 16, 2024
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Sep 15, 2024
@github-actions github-actions bot closed this Sep 29, 2024
According to the documentations:
- en.cppreference.com/w/c/io/fputc
- pubs.opengroup.org/onlinepubs/9699919799/functions/fputc.html

Return value
- On success, returns the written character.
- On failure, returns EOF and sets the error indicator
  (see ferror()) on stream.

This commit changes it to return the written value on success,
and EOF if failed, which is the same as minimal libc, but the
error indicator is still not set.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
@ycsin ycsin reopened this Jun 25, 2025
@ycsin ycsin marked this pull request as draft June 25, 2025 08:59
@ycsin ycsin removed backport v3.7-branch Request backport to the v3.7-branch Stale labels Jun 25, 2025
@ycsin ycsin force-pushed the pr/fix_picolibc_fputc branch from 357a405 to 9ac7df5 Compare June 25, 2025 08:59
Copy link

@ycsin ycsin marked this pull request as ready for review June 25, 2025 15:39
@keith-packard
Copy link
Collaborator

I think I already responded to this appropriately -- you are mis-understanding how these functions are used; they are implementation details specific to supporting the picolibc stdio stack on Zephyr. They are not the POSIX API used by applications.

@ycsin
Copy link
Member Author

ycsin commented Jun 26, 2025

It was required for #74350, but @cfriedt already has something WIP in #84860, so I will close this.

@ycsin ycsin closed this Jun 26, 2025
@ycsin ycsin deleted the pr/fix_picolibc_fputc branch June 26, 2025 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: C Library C Standard Library bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants