diff --git a/drivers/DirHandle.h b/drivers/DirHandle.h index 521a7ff5ca..479237df61 100644 --- a/drivers/DirHandle.h +++ b/drivers/DirHandle.h @@ -17,33 +17,10 @@ #define MBED_DIRHANDLE_H #include - -#if defined(__ARMCC_VERSION) || defined(__ICCARM__) -# define NAME_MAX 255 -typedef int mode_t; - -#else -# include -#endif +#include "retarget.h" #include "FileHandle.h" -struct dirent { - char d_name[NAME_MAX+1]; - uint8_t d_type; -}; - -enum { - DT_UNKNOWN, // The file type could not be determined. - DT_FIFO, // This is a named pipe (FIFO). - DT_CHR, // This is a character device. - DT_DIR, // This is a directory. - DT_BLK, // This is a block device. - DT_REG, // This is a regular file. - DT_LNK, // This is a symbolic link. - DT_SOCK, // This is a UNIX domain socket. -}; - namespace mbed { /** \addtogroup drivers */ /** @{*/ diff --git a/drivers/FileHandle.h b/drivers/FileHandle.h index 1900630a9d..08f498569e 100644 --- a/drivers/FileHandle.h +++ b/drivers/FileHandle.h @@ -19,14 +19,7 @@ typedef int FILEHANDLE; #include - -#if defined(__ARMCC_VERSION) || defined(__ICCARM__) -typedef int ssize_t; -typedef long off_t; - -#else -# include -#endif +#include "retarget.h" namespace mbed { /** \addtogroup drivers */ diff --git a/features/filesystem/FileSystem.h b/features/filesystem/FileSystem.h index a255e57b10..1f2e622663 100644 --- a/features/filesystem/FileSystem.h +++ b/features/filesystem/FileSystem.h @@ -38,18 +38,6 @@ enum fs_error { FS_ERROR_PARAMETER = -5002, ///< invalid parameter }; -// TODO move to retarget -enum fs_type { - DT_UNKNOWN, // The file type could not be determined. - DT_FIFO, // This is a named pipe (FIFO). - DT_CHR, // This is a character device. - DT_DIR, // This is a directory. - DT_BLK, // This is a block device. - DT_REG, // This is a regular file. - DT_LNK, // This is a symbolic link. - DT_SOCK, // This is a UNIX domain socket. -}; - // Opaque pointer representing files and directories typedef void *fs_file_t; typedef void *fs_dir_t; diff --git a/platform/retarget.h b/platform/retarget.h index 1ba9a77830..bb23fe7870 100644 --- a/platform/retarget.h +++ b/platform/retarget.h @@ -19,6 +19,21 @@ #ifndef RETARGET_H #define RETARGET_H +/* We can get the following standard types from sys/types for gcc, but we + * need to define the types ourselves for the other compilers that normally + * target embedded systems */ +#if defined(__ARMCC_VERSION) || defined(__ICCARM__) +typedef int ssize_t; ///< Signed size type, usually encodes negative errors +typedef long off_t; ///< Offset in a data stream +typedef int mode_t; ///< Mode for opening files + +#define NAME_MAX 255 ///< Maximum size of a name in a file path +#else +#include +#include +#endif + + #if defined(__ARMCC_VERSION) || defined(__ICCARM__) /* The intent of this section is to unify the errno error values to match * the POSIX definitions for the GCC_ARM, ARMCC and IAR compilers. This is @@ -108,4 +123,24 @@ #endif /* defined(__ARMCC_VERSION) || defined(__ICCARM__) */ + +/* The following are dirent.h definitions are declared here to garuntee + * consistency where structure may be different with different toolchains */ +struct dirent { + char d_name[NAME_MAX+1]; + uint8_t d_type; +}; + +enum { + DT_UNKNOWN, // The file type could not be determined. + DT_FIFO, // This is a named pipe (FIFO). + DT_CHR, // This is a character device. + DT_DIR, // This is a directory. + DT_BLK, // This is a block device. + DT_REG, // This is a regular file. + DT_LNK, // This is a symbolic link. + DT_SOCK, // This is a UNIX domain socket. +}; + + #endif /* RETARGET_H */