Forked.

Fork of mbed-dev by mbed official

Committer:
AnnaBridge
Date:
Wed Jun 21 17:46:44 2017 +0100
Revision:
167:e84263d55307
Parent:
161:2cc1468da177
This updates the lib to the mbed lib v 145

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 160:d5399cc887bb 1 /*
<> 160:d5399cc887bb 2 * mbed Microcontroller Library
<> 160:d5399cc887bb 3 * Copyright (c) 2006-2016 ARM Limited
<> 160:d5399cc887bb 4 *
<> 160:d5399cc887bb 5 * Licensed under the Apache License, Version 2.0 (the "License");
<> 160:d5399cc887bb 6 * you may not use this file except in compliance with the License.
<> 160:d5399cc887bb 7 * You may obtain a copy of the License at
<> 160:d5399cc887bb 8 *
<> 160:d5399cc887bb 9 * http://www.apache.org/licenses/LICENSE-2.0
<> 160:d5399cc887bb 10 *
<> 160:d5399cc887bb 11 * Unless required by applicable law or agreed to in writing, software
<> 160:d5399cc887bb 12 * distributed under the License is distributed on an "AS IS" BASIS,
<> 160:d5399cc887bb 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 160:d5399cc887bb 14 * See the License for the specific language governing permissions and
<> 160:d5399cc887bb 15 * limitations under the License.
<> 160:d5399cc887bb 16 *
<> 160:d5399cc887bb 17 */
<> 160:d5399cc887bb 18
<> 160:d5399cc887bb 19 #ifndef RETARGET_H
<> 160:d5399cc887bb 20 #define RETARGET_H
<> 160:d5399cc887bb 21
AnnaBridge 167:e84263d55307 22 #if __cplusplus
AnnaBridge 167:e84263d55307 23 #include <cstdio>
AnnaBridge 167:e84263d55307 24 #endif //__cplusplus
<> 160:d5399cc887bb 25 #include <stdint.h>
<> 160:d5399cc887bb 26 #include <stddef.h>
<> 160:d5399cc887bb 27
<> 160:d5399cc887bb 28 /* We can get the following standard types from sys/types for gcc, but we
<> 160:d5399cc887bb 29 * need to define the types ourselves for the other compilers that normally
<> 160:d5399cc887bb 30 * target embedded systems */
<> 160:d5399cc887bb 31 #if defined(__ARMCC_VERSION) || defined(__ICCARM__)
<> 160:d5399cc887bb 32 typedef int ssize_t; ///< Signed size type, usually encodes negative errors
<> 160:d5399cc887bb 33 typedef long off_t; ///< Offset in a data stream
<> 160:d5399cc887bb 34 typedef int mode_t; ///< Mode for opening files
<> 160:d5399cc887bb 35
<> 160:d5399cc887bb 36 #define O_RDONLY 0
<> 160:d5399cc887bb 37 #define O_WRONLY 1
<> 160:d5399cc887bb 38 #define O_RDWR 2
<> 160:d5399cc887bb 39 #define O_CREAT 0x0200
<> 160:d5399cc887bb 40 #define O_TRUNC 0x0400
<> 160:d5399cc887bb 41 #define O_APPEND 0x0008
<> 160:d5399cc887bb 42
<> 160:d5399cc887bb 43 #define NAME_MAX 255 ///< Maximum size of a name in a file path
<> 160:d5399cc887bb 44
<> 160:d5399cc887bb 45 #else
<> 160:d5399cc887bb 46 #include <sys/fcntl.h>
<> 160:d5399cc887bb 47 #include <sys/types.h>
<> 160:d5399cc887bb 48 #include <sys/syslimits.h>
<> 160:d5399cc887bb 49 #endif
<> 160:d5399cc887bb 50
<> 160:d5399cc887bb 51
<> 160:d5399cc887bb 52 /* DIR declarations must also be here */
<> 160:d5399cc887bb 53 #if __cplusplus
AnnaBridge 167:e84263d55307 54 namespace mbed {
AnnaBridge 167:e84263d55307 55 class FileHandle;
AnnaBridge 167:e84263d55307 56 class DirHandle;
AnnaBridge 167:e84263d55307 57 std::FILE *mbed_fdopen(FileHandle *fh, const char *mode);
AnnaBridge 167:e84263d55307 58 }
AnnaBridge 167:e84263d55307 59 typedef mbed::DirHandle DIR;
<> 161:2cc1468da177 60 #else
<> 161:2cc1468da177 61 typedef struct Dir DIR;
<> 161:2cc1468da177 62 #endif
<> 160:d5399cc887bb 63
<> 161:2cc1468da177 64 #if __cplusplus
<> 160:d5399cc887bb 65 extern "C" {
<> 161:2cc1468da177 66 #endif
<> 160:d5399cc887bb 67 DIR *opendir(const char*);
<> 160:d5399cc887bb 68 struct dirent *readdir(DIR *);
<> 160:d5399cc887bb 69 int closedir(DIR*);
<> 160:d5399cc887bb 70 void rewinddir(DIR*);
<> 160:d5399cc887bb 71 long telldir(DIR*);
<> 160:d5399cc887bb 72 void seekdir(DIR*, long);
<> 160:d5399cc887bb 73 int mkdir(const char *name, mode_t n);
<> 161:2cc1468da177 74 #if __cplusplus
<> 160:d5399cc887bb 75 };
<> 160:d5399cc887bb 76 #endif
<> 160:d5399cc887bb 77
<> 160:d5399cc887bb 78
<> 160:d5399cc887bb 79 #if defined(__ARMCC_VERSION) || defined(__ICCARM__)
<> 160:d5399cc887bb 80 /* The intent of this section is to unify the errno error values to match
<> 160:d5399cc887bb 81 * the POSIX definitions for the GCC_ARM, ARMCC and IAR compilers. This is
<> 160:d5399cc887bb 82 * necessary because the ARMCC/IAR errno.h, or sys/stat.h are missing some
<> 160:d5399cc887bb 83 * symbol definitions used by the POSIX filesystem API to return errno codes.
<> 160:d5399cc887bb 84 * Note also that ARMCC errno.h defines some symbol values differently from
<> 160:d5399cc887bb 85 * the GCC_ARM/IAR/standard POSIX definitions. The definitions guard against
<> 160:d5399cc887bb 86 * this and future changes by changing the symbol definition as shown below. */
<> 160:d5399cc887bb 87 #undef ENOENT
<> 160:d5399cc887bb 88 #define ENOENT 2 /* No such file or directory. */
<> 160:d5399cc887bb 89
<> 160:d5399cc887bb 90 #undef EIO
<> 160:d5399cc887bb 91 #define EIO 5 /* I/O error */
<> 160:d5399cc887bb 92
<> 160:d5399cc887bb 93 #undef ENXIO
<> 160:d5399cc887bb 94 #define ENXIO 6 /* No such device or address */
<> 160:d5399cc887bb 95
<> 160:d5399cc887bb 96 #undef ENOEXEC
<> 160:d5399cc887bb 97 #define ENOEXEC 8 /* Exec format error */
<> 160:d5399cc887bb 98
<> 160:d5399cc887bb 99 #undef EBADF
<> 160:d5399cc887bb 100 #define EBADF 9 /* Bad file number */
<> 160:d5399cc887bb 101
AnnaBridge 167:e84263d55307 102 #undef EAGAIN
AnnaBridge 167:e84263d55307 103 #define EAGAIN 11 /* Resource unavailable, try again */
AnnaBridge 167:e84263d55307 104
AnnaBridge 167:e84263d55307 105 #undef EWOULDBLOCK
AnnaBridge 167:e84263d55307 106 #define EWOULDBLOCK EAGAIN /* Operation would block */
AnnaBridge 167:e84263d55307 107
<> 160:d5399cc887bb 108 #undef ENOMEM
<> 160:d5399cc887bb 109 #define ENOMEM 12 /* Not enough space */
<> 160:d5399cc887bb 110
<> 160:d5399cc887bb 111 #undef EACCES
<> 160:d5399cc887bb 112 #define EACCES 13 /* Permission denied */
<> 160:d5399cc887bb 113
<> 160:d5399cc887bb 114 #undef EFAULT
<> 160:d5399cc887bb 115 #define EFAULT 14 /* Bad address */
<> 160:d5399cc887bb 116
<> 160:d5399cc887bb 117 #undef EEXIST
<> 160:d5399cc887bb 118 #define EEXIST 17 /* File exists */
<> 160:d5399cc887bb 119
AnnaBridge 167:e84263d55307 120 #undef EXDEV
AnnaBridge 167:e84263d55307 121 #define EXDEV 18 /* Cross-device link */
AnnaBridge 167:e84263d55307 122
<> 160:d5399cc887bb 123 #undef EINVAL
<> 160:d5399cc887bb 124 #define EINVAL 22 /* Invalid argument */
<> 160:d5399cc887bb 125
<> 160:d5399cc887bb 126 #undef ENFILE
<> 160:d5399cc887bb 127 #define ENFILE 23 /* Too many open files in system */
<> 160:d5399cc887bb 128
<> 160:d5399cc887bb 129 #undef EMFILE
<> 160:d5399cc887bb 130 #define EMFILE 24 /* File descriptor value too large */
<> 160:d5399cc887bb 131
AnnaBridge 167:e84263d55307 132 #undef ESPIPE
AnnaBridge 167:e84263d55307 133 #define ESPIPE 29 /* Invalid seek */
AnnaBridge 167:e84263d55307 134
<> 160:d5399cc887bb 135 #undef ENOSYS
<> 160:d5399cc887bb 136 #define ENOSYS 38 /* Function not implemented */
<> 160:d5399cc887bb 137
AnnaBridge 167:e84263d55307 138 #undef EOVERFLOW
AnnaBridge 167:e84263d55307 139 #define EOVERFLOW 75 /* Value too large to be stored in data type */
AnnaBridge 167:e84263d55307 140
<> 160:d5399cc887bb 141 /* Missing stat.h defines.
<> 160:d5399cc887bb 142 * The following are sys/stat.h definitions not currently present in the ARMCC
<> 160:d5399cc887bb 143 * errno.h. Note, ARMCC errno.h defines some symbol values differing from
<> 160:d5399cc887bb 144 * GCC_ARM/IAR/standard POSIX definitions. Guard against this and future
<> 160:d5399cc887bb 145 * changes by changing the symbol definition for filesystem use. */
<> 160:d5399cc887bb 146 #define _IFDIR 0040000 /* directory */
<> 160:d5399cc887bb 147 #define _IFREG 0100000 /* regular */
<> 160:d5399cc887bb 148
<> 160:d5399cc887bb 149 #define S_IFDIR _IFDIR
<> 160:d5399cc887bb 150 #define S_IFREG _IFREG
<> 160:d5399cc887bb 151
<> 160:d5399cc887bb 152 #define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
<> 160:d5399cc887bb 153 #define S_IRUSR 0000400 /* read permission, owner */
<> 160:d5399cc887bb 154 #define S_IWUSR 0000200 /* write permission, owner */
<> 160:d5399cc887bb 155 #define S_IXUSR 0000100/* execute/search permission, owner */
<> 160:d5399cc887bb 156 #define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
<> 160:d5399cc887bb 157 #define S_IRGRP 0000040 /* read permission, group */
<> 160:d5399cc887bb 158 #define S_IWGRP 0000020 /* write permission, grougroup */
<> 160:d5399cc887bb 159 #define S_IXGRP 0000010/* execute/search permission, group */
<> 160:d5399cc887bb 160 #define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
<> 160:d5399cc887bb 161 #define S_IROTH 0000004 /* read permission, other */
<> 160:d5399cc887bb 162 #define S_IWOTH 0000002 /* write permission, other */
<> 160:d5399cc887bb 163 #define S_IXOTH 0000001/* execute/search permission, other */
<> 160:d5399cc887bb 164
<> 160:d5399cc887bb 165 #endif /* defined(__ARMCC_VERSION) || defined(__ICCARM__) */
<> 160:d5399cc887bb 166
<> 160:d5399cc887bb 167
<> 160:d5399cc887bb 168 /* The following are dirent.h definitions are declared here to garuntee
<> 160:d5399cc887bb 169 * consistency where structure may be different with different toolchains */
<> 160:d5399cc887bb 170 struct dirent {
<> 160:d5399cc887bb 171 char d_name[NAME_MAX+1];
<> 160:d5399cc887bb 172 uint8_t d_type;
<> 160:d5399cc887bb 173 };
<> 160:d5399cc887bb 174
<> 160:d5399cc887bb 175 enum {
<> 160:d5399cc887bb 176 DT_UNKNOWN, // The file type could not be determined.
<> 160:d5399cc887bb 177 DT_FIFO, // This is a named pipe (FIFO).
<> 160:d5399cc887bb 178 DT_CHR, // This is a character device.
<> 160:d5399cc887bb 179 DT_DIR, // This is a directory.
<> 160:d5399cc887bb 180 DT_BLK, // This is a block device.
<> 160:d5399cc887bb 181 DT_REG, // This is a regular file.
<> 160:d5399cc887bb 182 DT_LNK, // This is a symbolic link.
<> 160:d5399cc887bb 183 DT_SOCK, // This is a UNIX domain socket.
<> 160:d5399cc887bb 184 };
<> 160:d5399cc887bb 185
<> 160:d5399cc887bb 186 #endif /* RETARGET_H */