Skip to content

Conflict between picolibc and POSIX_DEVICE_IO #85013

@lromeraj

Description

@lromeraj

Describe the bug
There is a conflict between the picolibc implementation of fdopen() and Zephyr's implementation in zephyr/lib/posix/options/device_io.c. The fopen() function from picolibc uses its own fdopen() implementation, but instead of using picolibc's fdopen(), Zephyr’s fdopen() from device_io.c is being used. This causes issues with file stream flags and the behavior of functions like fgetc().

This issue arises from the changes introduced in PR #76352.

Steps to Reproduce:

  1. Enable the POSIX_API in Zephyr by setting the appropriate configuration.
  2. Build the project with picolibc (precompiled in toolchain or using CONFIG_PICOLIBC_USE_MODULE=y it doesn't matter).
  3. Attempt to use fgetc() or other file I/O operations.
  4. Observe that __SRD flag is not set, causing functions like fgetc() to fail.

You can add a breakpoint for fdopen and see that it is using the implementation from zephyr/lib/posix/options/device_io.c.

Expected Behavior:
The fdopen() function from picolibc should be used, ensuring proper handling of file stream flags and correct behavior of file-related functions like fgetc() and fileno().

Actual Behavior:
The fdopen() function from zephyr/lib/posix/options/device_io.c is used instead, causing stream flag issues that prevent proper file I/O behavior, affecting functions such as fgetc() and equivalent.

Affected Versions:
Zephyr 4.0.0 and later (introduced by PR #76352).

Impact
This issue prevents proper file I/O behavior when using picolib and POSIX API.

Environment:

  • OS: Windows (WSL)
  • Toolchain: Zephyr SDK 0.17
  • Version used: Zephyr >= 4.0.0

Additional context
I'm not sure exactly where this issue should be reported—whether in the main Zephyr repository or in the picolibc repository. However, it seems like it might be something that needs to be addressed on the picolibc side (or in my project configuration).

Metadata

Metadata

Assignees

Labels

area: POSIXPOSIX API LibrarybugThe issue is a bug, or the PR is fixing a bugpriority: mediumMedium impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions