Skip to content

Commit 6e2d937

Browse files
committed
Filesystem: Moved toolchain-specific types into retarget.h
1 parent eee515c commit 6e2d937

File tree

4 files changed

+37
-44
lines changed

4 files changed

+37
-44
lines changed

drivers/DirHandle.h

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,10 @@
1717
#define MBED_DIRHANDLE_H
1818

1919
#include <stdint.h>
20-
21-
#if defined(__ARMCC_VERSION) || defined(__ICCARM__)
22-
# define NAME_MAX 255
23-
typedef int mode_t;
24-
25-
#else
26-
# include <sys/syslimits.h>
27-
#endif
20+
#include "retarget.h"
2821

2922
#include "FileHandle.h"
3023

31-
struct dirent {
32-
char d_name[NAME_MAX+1];
33-
uint8_t d_type;
34-
};
35-
36-
enum {
37-
DT_UNKNOWN, // The file type could not be determined.
38-
DT_FIFO, // This is a named pipe (FIFO).
39-
DT_CHR, // This is a character device.
40-
DT_DIR, // This is a directory.
41-
DT_BLK, // This is a block device.
42-
DT_REG, // This is a regular file.
43-
DT_LNK, // This is a symbolic link.
44-
DT_SOCK, // This is a UNIX domain socket.
45-
};
46-
4724
namespace mbed {
4825
/** \addtogroup drivers */
4926
/** @{*/

drivers/FileHandle.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,7 @@
1919
typedef int FILEHANDLE;
2020

2121
#include <stdio.h>
22-
23-
#if defined(__ARMCC_VERSION) || defined(__ICCARM__)
24-
typedef int ssize_t;
25-
typedef long off_t;
26-
27-
#else
28-
# include <sys/types.h>
29-
#endif
22+
#include "retarget.h"
3023

3124
namespace mbed {
3225
/** \addtogroup drivers */

features/filesystem/FileSystem.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,6 @@ enum fs_error {
3838
FS_ERROR_PARAMETER = -5002, ///< invalid parameter
3939
};
4040

41-
// TODO move to retarget
42-
enum fs_type {
43-
DT_UNKNOWN, // The file type could not be determined.
44-
DT_FIFO, // This is a named pipe (FIFO).
45-
DT_CHR, // This is a character device.
46-
DT_DIR, // This is a directory.
47-
DT_BLK, // This is a block device.
48-
DT_REG, // This is a regular file.
49-
DT_LNK, // This is a symbolic link.
50-
DT_SOCK, // This is a UNIX domain socket.
51-
};
52-
5341
// Opaque pointer representing files and directories
5442
typedef void *fs_file_t;
5543
typedef void *fs_dir_t;

platform/retarget.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@
2222
#ifndef RETARGET_H
2323
#define RETARGET_H
2424

25+
/* We can get the following standard types from sys/types for gcc, but we
26+
* need to define the types ourselves for the other compilers that normally
27+
* target embedded systems */
28+
#if defined(__ARMCC_VERSION) || defined(__ICCARM__)
29+
typedef int ssize_t; ///< Signed size type, usually encodes negative errors
30+
typedef long off_t; ///< Offset in a data stream
31+
typedef int mode_t; ///< Mode for opening files
32+
33+
#define NAME_MAX 255 ///< Maximum size of a name in a file path
34+
#else
35+
#include <sys/types.h>
36+
#include <sys/syslimits.h>
37+
#endif
38+
39+
2540
#if defined TOOLCHAIN_ARM_STD || defined TOOLCHAIN_IAR
2641
/* The following are errno.h definitions not currently present in the ARMCC
2742
* errno.h. Note, ARMCC errno.h defines some symbols values differing from
@@ -108,4 +123,24 @@
108123

109124
#endif /* TOOLCHAIN_ARM_STD || defined TOOLCHAIN_IAR */
110125

126+
127+
/* The following are dirent.h definitions are declared here to garuntee
128+
* consistency where structure may be different with different toolchains */
129+
struct dirent {
130+
char d_name[NAME_MAX+1];
131+
uint8_t d_type;
132+
};
133+
134+
enum {
135+
DT_UNKNOWN, // The file type could not be determined.
136+
DT_FIFO, // This is a named pipe (FIFO).
137+
DT_CHR, // This is a character device.
138+
DT_DIR, // This is a directory.
139+
DT_BLK, // This is a block device.
140+
DT_REG, // This is a regular file.
141+
DT_LNK, // This is a symbolic link.
142+
DT_SOCK, // This is a UNIX domain socket.
143+
};
144+
145+
111146
#endif /* RETARGET_H */

0 commit comments

Comments
 (0)