Skip to content

posix: add include/posix to search path based on Kconfig #43998

@cfriedt

Description

@cfriedt

Is your enhancement proposal related to a problem? Please describe.
It is a pain point to prefix standard POSIX APIs (e.g.#include <posix/unistd.h>).

In particular, when integrating third-party code into an external module, a large majority of work is simply applying the following to dozens of files:

#ifdef CONFIG_ARCH_POSIX
#include <posix/unistd.h>
#else
#include <unistd.h>
#endif

Of course, there are ~20 different POSIX headers in the Zephyr tree (netinet/in.h, sys/socket.h, etc), so the process requires a sometimes unsustainable amount of repetition, which is (for the most part) completely unnecessary.

Describe the solution you'd like
There are a few Kconfig values that indicate when the end-user would like to use POSIX headers. For example:

  • CONFIG_POSIX_API
  • CONFIG_PTHREAD_IPC
  • CONFIG_POSIX_CLOCK
  • CONFIG_POSIX_MQUEUE
  • CONFIG_POSIX_FS
  • CONFIG_EVENTFD (not strictly POSIX, but depends on POSIX, in practice)
  • CONFIG_GETOPT
  • CONFIG_NET_SOCKETS_POSIX_NAMES

If a user chooses to use POSIX APIs, then we should mainly just need to include posix/ in the default search path. The original reason against that was to avoid inadvertantly including the native POSIX header by accident. However, CONFIG_POSIX_API and CONFIG_ARCH_POSIX are mutually exclusive options. Thus, if CONFIG_ARCH_POSIX is selected, we do not include Zephyr's version of those headers, in order to avoid conflicting, standard declarations.

Describe alternatives you've considered
The alternative is the status quo, but it is a bit of a nightmare to maintain (coincidentally, we lack a current maintainer for the POSIX subsys).

Additional context

Metadata

Metadata

Assignees

Labels

EnhancementChanges/Updates/Additions to existing featuresarea: POSIXPOSIX API Library

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions