posix: include: dirent: rework the dirent.h header

Declare standard functions and split type definitions into
sys/dirent.h .

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
This commit is contained in:
Chris Friedt 2024-12-26 10:48:48 -05:00 committed by Benjamin Cabé
parent c0e0fc5d7f
commit 2423219ea1
3 changed files with 61 additions and 20 deletions

View file

@ -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 <limits.h>
#include <zephyr/posix/posix_types.h>
#ifdef CONFIG_POSIX_FILE_SYSTEM
#include <zephyr/fs/fs.h>
#include <zephyr/posix/sys/dirent.h>
#include <zephyr/toolchain.h>
#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_ */

View file

@ -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 <limits.h>
#include <zephyr/posix/posix_features.h>
#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_ */

View file

@ -7,11 +7,9 @@
#include "fs_priv.h"
#include <errno.h>
#include <limits.h>
#include <string.h>
#include <zephyr/fs/fs.h>
#include <zephyr/posix/posix_features.h>
#include <zephyr/posix/dirent.h>
#include <zephyr/sys/util.h>