From 94f105501519229c7eff3f73f9cb9f69a895a6b9 Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Thu, 26 Dec 2024 10:48:48 -0500 Subject: [PATCH] posix: include: dirent: rework the dirent.h header Declare standard functions and split type definitions into sys/dirent.h . Signed-off-by: Chris Friedt --- include/zephyr/posix/dirent.h | 43 ++++++++++++++++------------- include/zephyr/posix/sys/dirent.h | 45 +++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 19 deletions(-) create mode 100644 include/zephyr/posix/sys/dirent.h diff --git a/include/zephyr/posix/dirent.h b/include/zephyr/posix/dirent.h index 0ffe875606f01fb..35dfbecb5706b3e 100644 --- a/include/zephyr/posix/dirent.h +++ b/include/zephyr/posix/dirent.h @@ -1,40 +1,45 @@ /* - * Copyright (c) 2018 Intel Corporation + * Copyright (c) 2024 Tenstorrent AI ULC * * SPDX-License-Identifier: Apache-2.0 */ + #ifndef ZEPHYR_INCLUDE_POSIX_DIRENT_H_ #define ZEPHYR_INCLUDE_POSIX_DIRENT_H_ -#include - -#include - -#ifdef CONFIG_POSIX_FILE_SYSTEM -#include +#include +#include #ifdef __cplusplus extern "C" { #endif -typedef void DIR; - -struct dirent { - unsigned int d_ino; - char d_name[PATH_MAX + 1]; -}; - -/* Directory related operations */ -DIR *opendir(const char *dirname); +#if (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) +int alphasort(const struct dirent **d1, const struct dirent **d2); +#endif int closedir(DIR *dirp); +#if (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) +int dirfd(DIR *dirp); +#endif +DIR *fdopendir(int fd); +DIR *opendir(const char *dirname); struct dirent *readdir(DIR *dirp); +#if (_POSIX_C_SOURCE >= 199506L) || (_XOPEN_SOURCE >= 500) int readdir_r(DIR *ZRESTRICT dirp, struct dirent *ZRESTRICT entry, struct dirent **ZRESTRICT result); +#endif +void rewinddir(DIR *dirp); +#if (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700) +int scandir(const char *dir, struct dirent ***namelist, int (*sel)(const struct dirent *), + int (*compar)(const struct dirent **, const struct dirent **)); +#endif +#if defined(_XOPEN_SOURCE) +void seekdir(DIR *dirp, long loc); +long telldir(DIR *dirp); +#endif #ifdef __cplusplus } #endif -#endif /* CONFIG_POSIX_FILE_SYSTEM */ - -#endif /* ZEPHYR_INCLUDE_POSIX_DIRENT_H_ */ +#endif /* ZEPHYR_INCLUDE_POSIX_DIRENT_H_ */ diff --git a/include/zephyr/posix/sys/dirent.h b/include/zephyr/posix/sys/dirent.h new file mode 100644 index 000000000000000..7c787523bc49f37 --- /dev/null +++ b/include/zephyr/posix/sys/dirent.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 Tenstorrent AI ULC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_POSIX_SYS_DIRENT_H_ +#define ZEPHYR_INCLUDE_POSIX_SYS_DIRENT_H_ + +#include + +#include + +#ifndef PATH_MAX +#ifdef _XOPEN_SOURCE +#define PATH_MAX _XOPEN_PATH_MAX +#endif +#endif + +#ifndef PATH_MAX +#ifdef _POSIX_C_SOURCE +#define PATH_MAX _POSIX_PATH_MAX +#endif +#endif + +#ifndef PATH_MAX +#define PATH_MAX 31 +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void DIR; + +struct dirent { + unsigned int d_ino; + char d_name[PATH_MAX + 1]; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_POSIX_SYS_DIRENT_H_ */