Skip to content

Commit c152ebd

Browse files
pfalconnashif
authored andcommitted
include: posix: Split dirent.h from unistd.h
From POSIX http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/dirent.h.html """ The <dirent.h> header shall define the following type: DIR ... also define the structure dirent """ etc. Signed-off-by: Paul Sokolovsky <[email protected]>
1 parent 260fbc4 commit c152ebd

File tree

4 files changed

+39
-11
lines changed

4 files changed

+39
-11
lines changed

include/posix/dirent.h

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2018 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#ifndef ZEPHYR_INCLUDE_POSIX_DIRENT_H_
7+
#define ZEPHYR_INCLUDE_POSIX_DIRENT_H_
8+
9+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif
12+
13+
#include <limits.h>
14+
#include "sys/types.h"
15+
16+
#ifdef CONFIG_POSIX_FS
17+
#include <fs.h>
18+
19+
typedef struct fs_dir_t DIR;
20+
21+
struct dirent {
22+
unsigned int d_ino;
23+
char d_name[PATH_MAX + 1];
24+
};
25+
26+
/* Directory related operations */
27+
extern DIR *opendir(const char *dirname);
28+
extern int closedir(DIR *dirp);
29+
extern struct dirent *readdir(DIR *dirp);
30+
31+
#endif
32+
33+
#ifdef __cplusplus
34+
}
35+
#endif
36+
37+
#endif /* ZEPHYR_INCLUDE_POSIX_DIRENT_H_ */

include/posix/unistd.h

-11
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,15 @@ extern "C" {
1616
#ifdef CONFIG_POSIX_FS
1717
#include <fs.h>
1818

19-
typedef struct fs_dir_t DIR;
2019
typedef unsigned int mode_t;
2120

22-
struct dirent {
23-
unsigned int d_ino;
24-
char d_name[PATH_MAX + 1];
25-
};
26-
2721
/* File related operations */
2822
extern int open(const char *name, int flags);
2923
extern int close(int file);
3024
extern ssize_t write(int file, char *buffer, unsigned int count);
3125
extern ssize_t read(int file, char *buffer, unsigned int count);
3226
extern int lseek(int file, int offset, int whence);
3327

34-
/* Directory related operations */
35-
extern DIR *opendir(const char *dirname);
36-
extern int closedir(DIR *dirp);
37-
extern struct dirent *readdir(DIR *dirp);
38-
3928
/* File System related operations */
4029
extern int rename(const char *old, const char *newp);
4130
extern int unlink(const char *path);

lib/posix/fs.c

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <limits.h>
1010
#include <posix/pthread.h>
1111
#include <posix/unistd.h>
12+
#include <posix/dirent.h>
1213
#include <string.h>
1314

1415
BUILD_ASSERT_MSG(PATH_MAX > MAX_FILE_NAME,

tests/posix/fs/src/test_fs_dir.c

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <stdio.h>
88
#include <posix/unistd.h>
9+
#include <posix/dirent.h>
910
#include "test_fs.h"
1011

1112
extern int test_file_write(void);

0 commit comments

Comments
 (0)