Skip to content

Commit

Permalink
fdtable: workaround posix->zephyr->posix dependency cycle
Browse files Browse the repository at this point in the history
Currently Zephyr depends on POSIX, which presents a
dependency cycle.

Newlib does not seem to like this dependency cycle so it
requires that we re-declare off_t and ssize_t.

We should really stop using off_t and ssize_t below the
POSIX API line in Zephyr.

Signed-off-by: Chris Friedt <[email protected]>
  • Loading branch information
Chris Friedt committed Aug 30, 2024
1 parent 9b942b8 commit a7935e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 3 additions & 5 deletions include/zephyr/posix/sys/select.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
#ifndef ZEPHYR_INCLUDE_POSIX_SYS_SELECT_H_
#define ZEPHYR_INCLUDE_POSIX_SYS_SELECT_H_

#include <zephyr/net/socket_types.h>
#include <zephyr/net/socket_select.h>
#include <zephyr/sys/fdtable.h>

#ifdef __cplusplus
extern "C" {
#endif

#undef fd_set
#define fd_set zsock_fd_set

#define FD_SETSIZE ZVFS_FD_SETSIZE

typedef struct zvfs_fd_set fd_set;

struct timeval;

int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
Expand Down
12 changes: 12 additions & 0 deletions include/zephyr/sys/fdtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@
extern "C" {
#endif

/* FIXME: use k_off_t and k_ssize_t to avoid the POSIX->Zephyr->POSIX dependency cycle */
#ifdef CONFIG_NEWLIB_LIBC
#ifndef _OFF_T_DECLARED
typedef __off_t off_t;
#define _OFF_T_DECLARED
#endif
#ifndef _SSIZE_T_DECLARED
typedef _ssize_t ssize_t;
#define _SSIZE_T_DECLARED
#endif

Check notice on line 51 in include/zephyr/sys/fdtable.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/sys/fdtable.h:51 -typedef __off_t off_t; -#define _OFF_T_DECLARED +typedef __off_t off_t; +#define _OFF_T_DECLARED #endif #ifndef _SSIZE_T_DECLARED typedef _ssize_t ssize_t; -#define _SSIZE_T_DECLARED +#define _SSIZE_T_DECLARED
#endif

/**
* File descriptor virtual method table.
* Currently all operations beyond read/write/close go thru ioctl method.
Expand Down

0 comments on commit a7935e1

Please sign in to comment.