Skip to content

Commit 2423219

Browse files
cfriedtkartben
authored andcommitted
posix: include: dirent: rework the dirent.h header
Declare standard functions and split type definitions into sys/dirent.h . Signed-off-by: Chris Friedt <[email protected]>
1 parent c0e0fc5 commit 2423219

File tree

3 files changed

+61
-20
lines changed

3 files changed

+61
-20
lines changed

include/zephyr/posix/dirent.h

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,46 @@
11
/*
22
* Copyright (c) 2018 Intel Corporation
3+
* Copyright (c) 2024 Tenstorrent AI ULC
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*/
7+
68
#ifndef ZEPHYR_INCLUDE_POSIX_DIRENT_H_
79
#define ZEPHYR_INCLUDE_POSIX_DIRENT_H_
810

9-
#include <limits.h>
10-
11-
#include <zephyr/posix/posix_types.h>
12-
13-
#ifdef CONFIG_POSIX_FILE_SYSTEM
14-
#include <zephyr/fs/fs.h>
11+
#include <zephyr/posix/sys/dirent.h>
12+
#include <zephyr/toolchain.h>
1513

1614
#ifdef __cplusplus
1715
extern "C" {
1816
#endif
1917

20-
typedef void DIR;
21-
22-
struct dirent {
23-
unsigned int d_ino;
24-
char d_name[PATH_MAX + 1];
25-
};
26-
27-
/* Directory related operations */
28-
DIR *opendir(const char *dirname);
18+
#if (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700)
19+
int alphasort(const struct dirent **d1, const struct dirent **d2);
20+
#endif
2921
int closedir(DIR *dirp);
22+
#if (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700)
23+
int dirfd(DIR *dirp);
24+
#endif
25+
DIR *fdopendir(int fd);
26+
DIR *opendir(const char *dirname);
3027
struct dirent *readdir(DIR *dirp);
28+
#if (_POSIX_C_SOURCE >= 199506L) || (_XOPEN_SOURCE >= 500)
3129
int readdir_r(DIR *ZRESTRICT dirp, struct dirent *ZRESTRICT entry,
3230
struct dirent **ZRESTRICT result);
31+
#endif
32+
void rewinddir(DIR *dirp);
33+
#if (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700)
34+
int scandir(const char *dir, struct dirent ***namelist, int (*sel)(const struct dirent *),
35+
int (*compar)(const struct dirent **, const struct dirent **));
36+
#endif
37+
#if defined(_XOPEN_SOURCE)
38+
void seekdir(DIR *dirp, long loc);
39+
long telldir(DIR *dirp);
40+
#endif
3341

3442
#ifdef __cplusplus
3543
}
3644
#endif
3745

38-
#endif /* CONFIG_POSIX_FILE_SYSTEM */
39-
40-
#endif /* ZEPHYR_INCLUDE_POSIX_DIRENT_H_ */
46+
#endif /* ZEPHYR_INCLUDE_POSIX_DIRENT_H_ */

include/zephyr/posix/sys/dirent.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2024 Tenstorrent AI ULC
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_INCLUDE_POSIX_SYS_DIRENT_H_
8+
#define ZEPHYR_INCLUDE_POSIX_SYS_DIRENT_H_
9+
10+
#include <limits.h>
11+
12+
#include <zephyr/posix/posix_features.h>
13+
14+
#if !defined(NAME_MAX) && defined(_XOPEN_SOURCE)
15+
#define NAME_MAX _XOPEN_NAME_MAX
16+
#endif
17+
18+
#if !defined(NAME_MAX) && defined(_POSIX_C_SOURCE)
19+
#define NAME_MAX _POSIX_NAME_MAX
20+
#endif
21+
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
26+
typedef void DIR;
27+
28+
struct dirent {
29+
unsigned int d_ino;
30+
char d_name[NAME_MAX + 1];
31+
};
32+
33+
#ifdef __cplusplus
34+
}
35+
#endif
36+
37+
#endif /* ZEPHYR_INCLUDE_POSIX_SYS_DIRENT_H_ */

lib/posix/options/file_system_r.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
#include "fs_priv.h"
88

99
#include <errno.h>
10-
#include <limits.h>
1110
#include <string.h>
1211

1312
#include <zephyr/fs/fs.h>
14-
#include <zephyr/posix/posix_features.h>
1513
#include <zephyr/posix/dirent.h>
1614
#include <zephyr/sys/util.h>
1715

0 commit comments

Comments
 (0)