Skip to content

Commit

Permalink
posix: include: dirent: rework the dirent.h header
Browse files Browse the repository at this point in the history
Declare standard functions and split type definitions into
sys/dirent.h .

Signed-off-by: Chris Friedt <[email protected]>
  • Loading branch information
cfriedt committed Dec 27, 2024
1 parent 09a1355 commit 94f1055
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 19 deletions.
43 changes: 24 additions & 19 deletions include/zephyr/posix/dirent.h
Original file line number Diff line number Diff line change
@@ -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 <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_ */
45 changes: 45 additions & 0 deletions include/zephyr/posix/sys/dirent.h
Original file line number Diff line number Diff line change
@@ -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 <limits.h>

#include <zephyr/posix/posix_features.h>

#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_ */

0 comments on commit 94f1055

Please sign in to comment.