From 2423219ea12ccecf64355fd3f26e4fdf95f5100c 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 | 42 ++++++++++++++++++------------- include/zephyr/posix/sys/dirent.h | 37 +++++++++++++++++++++++++++ lib/posix/options/file_system_r.c | 2 -- 3 files changed, 61 insertions(+), 20 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 0ffe875606f..b4327ac45f9 100644 --- a/include/zephyr/posix/dirent.h +++ b/include/zephyr/posix/dirent.h @@ -1,40 +1,46 @@ /* * 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 00000000000..63d02dc511e --- /dev/null +++ b/include/zephyr/posix/sys/dirent.h @@ -0,0 +1,37 @@ +/* + * 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 + +#if !defined(NAME_MAX) && defined(_XOPEN_SOURCE) +#define NAME_MAX _XOPEN_NAME_MAX +#endif + +#if !defined(NAME_MAX) && defined(_POSIX_C_SOURCE) +#define NAME_MAX _POSIX_NAME_MAX +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void DIR; + +struct dirent { + unsigned int d_ino; + char d_name[NAME_MAX + 1]; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_POSIX_SYS_DIRENT_H_ */ diff --git a/lib/posix/options/file_system_r.c b/lib/posix/options/file_system_r.c index a23a081b75b..6cd14f9f81a 100644 --- a/lib/posix/options/file_system_r.c +++ b/lib/posix/options/file_system_r.c @@ -7,11 +7,9 @@ #include "fs_priv.h" #include -#include #include #include -#include #include #include