mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-02 18:10:57 +02:00
change(newlib): remove sys/dirent.h from newlib component
This commit is contained in:
@@ -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 <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/**
|
||||
* 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 <sys/dirent.h>
|
||||
#include <dirent.h>
|
||||
#endif // __clang__
|
@@ -12,11 +12,7 @@
|
||||
#include <errno.h>
|
||||
#include <sys/param.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef __clang__ // TODO LLVM-330
|
||||
#include <sys/dirent.h>
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
#include "unity.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "esp_vfs.h"
|
||||
|
@@ -21,11 +21,7 @@
|
||||
#include <sys/time.h>
|
||||
#include <sys/termios.h>
|
||||
#include <sys/poll.h>
|
||||
#ifdef __clang__ // TODO LLVM-330
|
||||
#include <sys/dirent.h>
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include "sdkconfig.h"
|
||||
|
||||
|
@@ -19,11 +19,7 @@
|
||||
#include <sys/time.h>
|
||||
#include <sys/termios.h>
|
||||
#include <sys/poll.h>
|
||||
#ifdef __clang__ // TODO LLVM-330
|
||||
#include <sys/dirent.h>
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include "sdkconfig.h"
|
||||
|
||||
|
@@ -10,11 +10,7 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/fcntl.h>
|
||||
#ifdef __clang__ // TODO LLVM-330
|
||||
#include <sys/dirent.h>
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
#include "esp_vfs.h"
|
||||
#include "unity.h"
|
||||
#include "esp_log.h"
|
||||
|
@@ -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 <sys/dirent.h>
|
||||
/* .... */
|
||||
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 <dirent.h>
|
||||
/* .... */
|
||||
DIR* dir = opendir("test_dir");
|
||||
|
||||
Picolibc
|
||||
--------
|
||||
|
||||
|
@@ -93,6 +93,39 @@ GCC 版本更新说明
|
||||
C(const C&&) = default; /* 被隐式删除 */
|
||||
};
|
||||
|
||||
``sys/dirent.h`` 不再包含一些函数原型
|
||||
-------------------------------------------------------
|
||||
|
||||
问题
|
||||
^^^^^^
|
||||
|
||||
使用旧工具链的代码可能会出现编译错误。例如:
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
#include <sys/dirent.h>
|
||||
/* .... */
|
||||
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 <dirent.h>
|
||||
/* .... */
|
||||
DIR* dir = opendir("test_dir");
|
||||
|
||||
Picolibc
|
||||
--------
|
||||
|
||||
|
@@ -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 <dirent.h> (not <sys/dirent.h>)"
|
||||
|
||||
-
|
||||
|
Reference in New Issue
Block a user