Skip to content

Conversation

@keith-packard
Copy link
Contributor

Use picolibc 'bufio' interfaces to provide a non-POSIX implementation of fdopen. This depends upon CONFIG_ZVFS_FDTABLE as that provides an fd abstraction on top of regular zephyr APIs.

Use this API to provide zvfs_fdopen and zvfs_fileno.

@keith-packard
Copy link
Contributor Author

Two alternatives:

  1. Require C libraries provide fdopen/fileno in terms of existing Zephyr APIs (perhaps using POSIX APIs?). Deprecate zvfs_fdopen and zvfs_fileno.
  2. Require C libraries provide zvfs_fdopen and zvfs_fileno and have POSIX wrappers that expose fdopen and fileno.

The first is 'more effiicient' as no-one will ever need a wrapper function. The second avoids adding POSIX APIs to the standard Zephyr suite.

#
# SPDX-License-Identifier: Apache-2.0

board_runner_args(openocd --cmd-reset-halt "reset halt")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't seem related?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, thanks -- this diff was hanging around after testing with a TI board...

@aescolar aescolar requested a review from de-nordic December 23, 2025 09:56
Comment on lines +447 to +449
#ifdef CONFIG_PICOLIBC
return fileno(file);
#else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds a dependency cycle at the API level, so will not work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, this is using fileno from picolibc, not Zephyr. Note that the Zephyr versions of fdopen and fileno should both be disabled by this patch.

FUNC_ALIAS(close, _close, int);
#endif

#ifndef CONFIG_PICOLIBC
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this PR be modified to implement POSIX_DEVICE_IO? Picolibc would need to add select TC_PROVIDES_POSIX_DEVICE_IO.

Ideally, this would only be merged after #97855, so that it could be done indpendently of the Zephyr implementation.

The Zephyr implementation should remain untouched, but lib/libc/picolibc/CMakeLists.txt could pull in Zephyr's implementation if it's convenient or simpler.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All I'm trying to do in this PR is fix the current fdopen/fileno disaster. If you want to take it further, please feel free.

Copy link
Member

@cfriedt cfriedt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add select TC_PROVIDES_POSIX_DEVICE_IO under config PICOLIBC in lib/libc/Kconfig, implement (or borrow) the rest of POSIX_DEVICE_IO, and remove the layering violation in zvfs.

Use picolibc 'bufio' interfaces to provide a non-POSIX implementation
of fdopen. This depends upon CONFIG_ZVFS_FDTABLE as that provides an
fd abstraction on top of regular zephyr APIs.

Use this API to provide zvfs_fdopen and zvfs_fileno.

Signed-off-by: Keith Packard <[email protected]>
@keith-packard
Copy link
Contributor Author

Please add select TC_PROVIDES_POSIX_DEVICE_IO under config PICOLIBC in lib/libc/Kconfig, implement (or borrow) the rest of POSIX_DEVICE_IO, and remove the layering violation in zvfs.

There is no layering violation; this removes the layering violation where zvfs provides broken versions of fdopen and fileno.

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Base OS Base OS Library (lib/os) area: Boards/SoCs area: C Library C Standard Library area: POSIX POSIX API Library platform: TI SimpleLink Texas Instruments SimpleLink MCU

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants