From bc4a9ad406aa0da02d81684951f1a9d990d3fb4a Mon Sep 17 00:00:00 2001 From: Alexey Lapshin Date: Thu, 28 Aug 2025 23:52:46 +0700 Subject: [PATCH] change(newlib): remove sys/dirent.h from newlib component --- .../newlib/platform_include/sys/dirent.h | 70 ------------------- .../newlib/test_apps/newlib/main/test_misc.c | 4 -- components/vfs/include/esp_vfs.h | 4 -- components/vfs/include/esp_vfs_ops.h | 4 -- .../vfs/test_apps/main/test_vfs_paths.c | 4 -- .../release-6.x/6.0/toolchain.rst | 33 +++++++++ .../release-6.x/6.0/toolchain.rst | 33 +++++++++ tools/idf_py_actions/hints.yml | 2 +- 8 files changed, 67 insertions(+), 87 deletions(-) delete mode 100644 components/newlib/platform_include/sys/dirent.h diff --git a/components/newlib/platform_include/sys/dirent.h b/components/newlib/platform_include/sys/dirent.h deleted file mode 100644 index 2643ddc954..0000000000 --- a/components/newlib/platform_include/sys/dirent.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ -#ifdef __clang__ // TODO LLVM-330 -#pragma once - -#include -#include -#include - -/** - * This header file provides POSIX-compatible definitions of directory - * access data types. Starting with newlib 3.3, related functions are defined - * in 'dirent.h' bundled with newlib. - * See http://pubs.opengroup.org/onlinepubs/7908799/xsh/dirent.h.html - * for reference. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Opaque directory structure - */ -typedef struct { - uint16_t dd_vfs_idx; /*!< VFS index, not to be used by applications */ - uint16_t dd_rsv; /*!< field reserved for future extension */ - /* remaining fields are defined by VFS implementation */ -} DIR; - -/** - * @brief Directory entry structure - */ -struct dirent { - ino_t d_ino; /*!< file number */ - uint8_t d_type; /*!< not defined in POSIX, but present in BSD and Linux */ -#define DT_UNKNOWN 0 -#define DT_REG 1 -#define DT_DIR 2 -#if __BSD_VISIBLE -#define MAXNAMLEN 255 - char d_name[MAXNAMLEN + 1]; /*!< zero-terminated file name */ -#else - char d_name[256]; -#endif -}; - -DIR* opendir(const char* name); -struct dirent* readdir(DIR* pdir); -long telldir(DIR* pdir); -void seekdir(DIR* pdir, long loc); -void rewinddir(DIR* pdir); -int closedir(DIR* pdir); -int readdir_r(DIR* pdir, struct dirent* entry, struct dirent** out_dirent); -int scandir(const char *dirname, struct dirent ***out_dirlist, - int (*select_func)(const struct dirent *), - int (*cmp_func)(const struct dirent **, const struct dirent **)); -int alphasort(const struct dirent **d1, const struct dirent **d2); - -#ifdef __cplusplus -} -#endif - -#else // __clang__ TODO: IDF-10675 -#include_next -#include -#endif // __clang__ diff --git a/components/newlib/test_apps/newlib/main/test_misc.c b/components/newlib/test_apps/newlib/main/test_misc.c index bc7c076ebc..bc4e6656c8 100644 --- a/components/newlib/test_apps/newlib/main/test_misc.c +++ b/components/newlib/test_apps/newlib/main/test_misc.c @@ -12,11 +12,7 @@ #include #include #include -#ifdef __clang__ // TODO LLVM-330 -#include -#else #include -#endif #include "unity.h" #include "esp_heap_caps.h" #include "esp_vfs.h" diff --git a/components/vfs/include/esp_vfs.h b/components/vfs/include/esp_vfs.h index c0f20979ad..48308fa0c4 100644 --- a/components/vfs/include/esp_vfs.h +++ b/components/vfs/include/esp_vfs.h @@ -21,11 +21,7 @@ #include #include #include -#ifdef __clang__ // TODO LLVM-330 -#include -#else #include -#endif #include #include "sdkconfig.h" diff --git a/components/vfs/include/esp_vfs_ops.h b/components/vfs/include/esp_vfs_ops.h index 2875b8c3e2..d04753f082 100644 --- a/components/vfs/include/esp_vfs_ops.h +++ b/components/vfs/include/esp_vfs_ops.h @@ -19,11 +19,7 @@ #include #include #include -#ifdef __clang__ // TODO LLVM-330 -#include -#else #include -#endif #include #include "sdkconfig.h" diff --git a/components/vfs/test_apps/main/test_vfs_paths.c b/components/vfs/test_apps/main/test_vfs_paths.c index 48a41089e2..f7b9234bd8 100644 --- a/components/vfs/test_apps/main/test_vfs_paths.c +++ b/components/vfs/test_apps/main/test_vfs_paths.c @@ -10,11 +10,7 @@ #include #include #include -#ifdef __clang__ // TODO LLVM-330 -#include -#else #include -#endif #include "esp_vfs.h" #include "unity.h" #include "esp_log.h" diff --git a/docs/en/migration-guides/release-6.x/6.0/toolchain.rst b/docs/en/migration-guides/release-6.x/6.0/toolchain.rst index 65fd8f781a..9eae908210 100644 --- a/docs/en/migration-guides/release-6.x/6.0/toolchain.rst +++ b/docs/en/migration-guides/release-6.x/6.0/toolchain.rst @@ -93,6 +93,39 @@ Warn when an explicitly defaulted function is deleted by the compiler. That can C(const C&&) = default; /* Implicitly deleted. */ }; +``sys/dirent.h`` No Longer Includes Function Prototypes +------------------------------------------------------- + +Issue +^^^^^^ + +Compilation errors may occur in code that previously worked with the old toolchain. For example: + +.. code-block:: c + + #include + /* .... */ + DIR* dir = opendir("test_dir"); + /* .... */ + /** + * Compile error: + * test.c: In function 'test_opendir': + * test.c:100:16: error: implicit declaration of function 'opendir' [-Werror=implicit-function-declaration] + * 100 | DIR* dir = opendir(path); + * | ^~~~~~~ + */ + +Solution +^^^^^^^^^ + +To resolve this issue, the correct header must be included. Refactor the code like this: + +.. code-block:: c + + #include + /* .... */ + DIR* dir = opendir("test_dir"); + Picolibc -------- diff --git a/docs/zh_CN/migration-guides/release-6.x/6.0/toolchain.rst b/docs/zh_CN/migration-guides/release-6.x/6.0/toolchain.rst index 62daaf47e1..c64c8c97ec 100644 --- a/docs/zh_CN/migration-guides/release-6.x/6.0/toolchain.rst +++ b/docs/zh_CN/migration-guides/release-6.x/6.0/toolchain.rst @@ -93,6 +93,39 @@ GCC 版本更新说明 C(const C&&) = default; /* 被隐式删除 */ }; +``sys/dirent.h`` 不再包含一些函数原型 +------------------------------------------------------- + +问题 +^^^^^^ + +使用旧工具链的代码可能会出现编译错误。例如: + +.. code-block:: c + + #include + /* .... */ + DIR* dir = opendir("test_dir"); + /* .... */ + /** + * Compile error: + * test.c: In function 'test_opendir': + * test.c:100:16: error: implicit declaration of function 'opendir' [-Werror=implicit-function-declaration] + * 100 | DIR* dir = opendir(path); + * | ^~~~~~~ + */ + +解决方法 +^^^^^^^^^ + +包含正确的头文件即可解决此问题。请将代码重构如下: + +.. code-block:: c + + #include + /* .... */ + DIR* dir = opendir("test_dir"); + Picolibc -------- diff --git a/tools/idf_py_actions/hints.yml b/tools/idf_py_actions/hints.yml index f9f0e6855b..0c4889ecb4 100644 --- a/tools/idf_py_actions/hints.yml +++ b/tools/idf_py_actions/hints.yml @@ -433,7 +433,7 @@ match_to_output: True - - re: "implicit declaration of function '(opendir|readdir|telldir|seekdir|rewinddir|closedir|readdir_r|scandir|alphasort)'" + re: "implicit declaration of function '(opendir|readdir|telldir|seekdir|rewinddir|closedir|readdir_r|scandir|alphasort|dirfd|fdclosedir|fdopendir|scandirat|versionsort|posix_getdents)'" hint: "Please include (not )" -