mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Committer:
AnnaBridge
Date:
Thu Apr 19 17:12:19 2018 +0100
Revision:
184:08ed48f1de7f
Parent:
180:96ed750bd169
Child:
186:707f6e361f3e
mbed-dev library. Release version 161

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 184:08ed48f1de7f 24 #else
AnnaBridge 184:08ed48f1de7f 25 #include <stdio.h>
AnnaBridge 167:e84263d55307 26 #endif //__cplusplus
<> 160:d5399cc887bb 27 #include <stdint.h>
<> 160:d5399cc887bb 28 #include <stddef.h>
<> 160:d5399cc887bb 29
<> 160:d5399cc887bb 30 /* We can get the following standard types from sys/types for gcc, but we
<> 160:d5399cc887bb 31 * need to define the types ourselves for the other compilers that normally
<> 160:d5399cc887bb 32 * target embedded systems */
AnnaBridge 175:af195413fb11 33 typedef signed int ssize_t; ///< Signed size type, usually encodes negative errors
AnnaBridge 175:af195413fb11 34 typedef signed long off_t; ///< Offset in a data stream
AnnaBridge 184:08ed48f1de7f 35 typedef unsigned int nfds_t; ///< Number of file descriptors
AnnaBridge 184:08ed48f1de7f 36 typedef unsigned long long fsblkcnt_t; ///< Count of file system blocks
Anna Bridge 180:96ed750bd169 37 #if defined(__ARMCC_VERSION) || !defined(__GNUC__)
AnnaBridge 175:af195413fb11 38 typedef unsigned int mode_t; ///< Mode for opening files
AnnaBridge 175:af195413fb11 39 typedef unsigned int dev_t; ///< Device ID type
AnnaBridge 175:af195413fb11 40 typedef unsigned long ino_t; ///< File serial number
AnnaBridge 175:af195413fb11 41 typedef unsigned int nlink_t; ///< Number of links to a file
AnnaBridge 175:af195413fb11 42 typedef unsigned int uid_t; ///< User ID
AnnaBridge 175:af195413fb11 43 typedef unsigned int gid_t; ///< Group ID
Anna Bridge 180:96ed750bd169 44 #endif
<> 160:d5399cc887bb 45
AnnaBridge 175:af195413fb11 46 #define O_RDONLY 0 ///< Open for reading
AnnaBridge 175:af195413fb11 47 #define O_WRONLY 1 ///< Open for writing
AnnaBridge 175:af195413fb11 48 #define O_RDWR 2 ///< Open for reading and writing
AnnaBridge 175:af195413fb11 49 #define O_CREAT 0x0200 ///< Create file if it does not exist
AnnaBridge 175:af195413fb11 50 #define O_TRUNC 0x0400 ///< Truncate file to zero length
AnnaBridge 175:af195413fb11 51 #define O_EXCL 0x0800 ///< Fail if file exists
AnnaBridge 175:af195413fb11 52 #define O_APPEND 0x0008 ///< Set file offset to end of file prior to each write
Anna Bridge 180:96ed750bd169 53 #define O_BINARY 0x8000 ///< Open file in binary mode
<> 160:d5399cc887bb 54
<> 160:d5399cc887bb 55 #define NAME_MAX 255 ///< Maximum size of a name in a file path
<> 160:d5399cc887bb 56
AnnaBridge 184:08ed48f1de7f 57 #define STDIN_FILENO 0
AnnaBridge 184:08ed48f1de7f 58 #define STDOUT_FILENO 1
AnnaBridge 184:08ed48f1de7f 59 #define STDERR_FILENO 2
AnnaBridge 184:08ed48f1de7f 60
AnnaBridge 175:af195413fb11 61 #include <time.h>
AnnaBridge 175:af195413fb11 62
AnnaBridge 178:79309dc6340a 63 /** \addtogroup platform */
AnnaBridge 178:79309dc6340a 64 /** @{*/
AnnaBridge 178:79309dc6340a 65 /**
AnnaBridge 178:79309dc6340a 66 * \defgroup platform_retarget Retarget functions
AnnaBridge 178:79309dc6340a 67 * @{
AnnaBridge 178:79309dc6340a 68 */
<> 160:d5399cc887bb 69
<> 160:d5399cc887bb 70 /* DIR declarations must also be here */
<> 160:d5399cc887bb 71 #if __cplusplus
AnnaBridge 167:e84263d55307 72 namespace mbed {
AnnaBridge 184:08ed48f1de7f 73
AnnaBridge 167:e84263d55307 74 class FileHandle;
AnnaBridge 167:e84263d55307 75 class DirHandle;
AnnaBridge 184:08ed48f1de7f 76
AnnaBridge 184:08ed48f1de7f 77 /** Targets may implement this to change stdin, stdout, stderr.
AnnaBridge 184:08ed48f1de7f 78 *
AnnaBridge 184:08ed48f1de7f 79 * If the application hasn't provided mbed_override_console, this is called
AnnaBridge 184:08ed48f1de7f 80 * to give the target a chance to specify a FileHandle for the console.
AnnaBridge 184:08ed48f1de7f 81 *
AnnaBridge 184:08ed48f1de7f 82 * If this is not provided or returns NULL, the console will be:
AnnaBridge 184:08ed48f1de7f 83 * - UARTSerial if configuration option "platform.stdio-buffered-serial" is
AnnaBridge 184:08ed48f1de7f 84 * true and the target has DEVICE_SERIAL;
AnnaBridge 184:08ed48f1de7f 85 * - Raw HAL serial via serial_getc and serial_putc if
AnnaBridge 184:08ed48f1de7f 86 * "platform.stdio-buffered-serial" is false and the target has DEVICE_SERIAL;
AnnaBridge 184:08ed48f1de7f 87 * - stdout/stderr will be a sink and stdin will input a stream of 0s if the
AnnaBridge 184:08ed48f1de7f 88 * target does not have DEVICE_SERIAL.
AnnaBridge 184:08ed48f1de7f 89 *
AnnaBridge 184:08ed48f1de7f 90 * @param fd file descriptor - STDIN_FILENO, STDOUT_FILENO or STDERR_FILENO
AnnaBridge 184:08ed48f1de7f 91 * @return pointer to FileHandle to override normal stream otherwise NULL
AnnaBridge 184:08ed48f1de7f 92 */
AnnaBridge 184:08ed48f1de7f 93 FileHandle* mbed_target_override_console(int fd);
AnnaBridge 184:08ed48f1de7f 94
AnnaBridge 184:08ed48f1de7f 95 /** Applications may implement this to change stdin, stdout, stderr.
AnnaBridge 184:08ed48f1de7f 96 *
AnnaBridge 184:08ed48f1de7f 97 * This hook gives the application a chance to specify a custom FileHandle
AnnaBridge 184:08ed48f1de7f 98 * for the console.
AnnaBridge 184:08ed48f1de7f 99 *
AnnaBridge 184:08ed48f1de7f 100 * If this is not provided or returns NULL, the console will be specified
AnnaBridge 184:08ed48f1de7f 101 * by mbed_target_override_console, else will default to serial - see
AnnaBridge 184:08ed48f1de7f 102 * mbed_target_override_console for more details.
AnnaBridge 184:08ed48f1de7f 103 *
AnnaBridge 184:08ed48f1de7f 104 * Example:
AnnaBridge 184:08ed48f1de7f 105 * @code
AnnaBridge 184:08ed48f1de7f 106 * FileHandle* mbed::mbed_override_console(int) {
AnnaBridge 184:08ed48f1de7f 107 * static UARTSerial my_serial(D0, D1);
AnnaBridge 184:08ed48f1de7f 108 * return &my_serial;
AnnaBridge 184:08ed48f1de7f 109 * }
AnnaBridge 184:08ed48f1de7f 110 * @endcode
AnnaBridge 184:08ed48f1de7f 111
AnnaBridge 184:08ed48f1de7f 112 * @param fd file descriptor - STDIN_FILENO, STDOUT_FILENO or STDERR_FILENO
AnnaBridge 184:08ed48f1de7f 113 * @return pointer to FileHandle to override normal stream otherwise NULL
AnnaBridge 184:08ed48f1de7f 114 */
AnnaBridge 184:08ed48f1de7f 115 FileHandle* mbed_override_console(int fd);
AnnaBridge 178:79309dc6340a 116
AnnaBridge 167:e84263d55307 117 }
AnnaBridge 184:08ed48f1de7f 118
AnnaBridge 167:e84263d55307 119 typedef mbed::DirHandle DIR;
<> 161:2cc1468da177 120 #else
<> 161:2cc1468da177 121 typedef struct Dir DIR;
<> 161:2cc1468da177 122 #endif
<> 160:d5399cc887bb 123
<> 160:d5399cc887bb 124 /* The intent of this section is to unify the errno error values to match
<> 160:d5399cc887bb 125 * the POSIX definitions for the GCC_ARM, ARMCC and IAR compilers. This is
<> 160:d5399cc887bb 126 * necessary because the ARMCC/IAR errno.h, or sys/stat.h are missing some
<> 160:d5399cc887bb 127 * symbol definitions used by the POSIX filesystem API to return errno codes.
<> 160:d5399cc887bb 128 * Note also that ARMCC errno.h defines some symbol values differently from
<> 160:d5399cc887bb 129 * the GCC_ARM/IAR/standard POSIX definitions. The definitions guard against
AnnaBridge 175:af195413fb11 130 * this and future changes by changing the symbol definition as shown below.
AnnaBridge 175:af195413fb11 131 */
AnnaBridge 175:af195413fb11 132 #undef EPERM
AnnaBridge 175:af195413fb11 133 #define EPERM 1 /* Operation not permitted */
AnnaBridge 175:af195413fb11 134 #undef ENOENT
AnnaBridge 175:af195413fb11 135 #define ENOENT 2 /* No such file or directory */
AnnaBridge 175:af195413fb11 136 #undef ESRCH
AnnaBridge 175:af195413fb11 137 #define ESRCH 3 /* No such process */
AnnaBridge 175:af195413fb11 138 #undef EINTR
AnnaBridge 175:af195413fb11 139 #define EINTR 4 /* Interrupted system call */
AnnaBridge 175:af195413fb11 140 #undef EIO
AnnaBridge 175:af195413fb11 141 #define EIO 5 /* I/O error */
AnnaBridge 175:af195413fb11 142 #undef ENXIO
AnnaBridge 175:af195413fb11 143 #define ENXIO 6 /* No such device or address */
AnnaBridge 175:af195413fb11 144 #undef E2BIG
AnnaBridge 175:af195413fb11 145 #define E2BIG 7 /* Argument list too long */
AnnaBridge 175:af195413fb11 146 #undef ENOEXEC
AnnaBridge 175:af195413fb11 147 #define ENOEXEC 8 /* Exec format error */
AnnaBridge 175:af195413fb11 148 #undef EBADF
AnnaBridge 175:af195413fb11 149 #define EBADF 9 /* Bad file number */
AnnaBridge 175:af195413fb11 150 #undef ECHILD
AnnaBridge 175:af195413fb11 151 #define ECHILD 10 /* No child processes */
AnnaBridge 175:af195413fb11 152 #undef EAGAIN
AnnaBridge 175:af195413fb11 153 #define EAGAIN 11 /* Try again */
AnnaBridge 175:af195413fb11 154 #undef ENOMEM
AnnaBridge 175:af195413fb11 155 #define ENOMEM 12 /* Out of memory */
AnnaBridge 175:af195413fb11 156 #undef EACCES
AnnaBridge 175:af195413fb11 157 #define EACCES 13 /* Permission denied */
AnnaBridge 175:af195413fb11 158 #undef EFAULT
AnnaBridge 175:af195413fb11 159 #define EFAULT 14 /* Bad address */
AnnaBridge 175:af195413fb11 160 #undef ENOTBLK
AnnaBridge 175:af195413fb11 161 #define ENOTBLK 15 /* Block device required */
AnnaBridge 175:af195413fb11 162 #undef EBUSY
AnnaBridge 175:af195413fb11 163 #define EBUSY 16 /* Device or resource busy */
AnnaBridge 175:af195413fb11 164 #undef EEXIST
AnnaBridge 175:af195413fb11 165 #define EEXIST 17 /* File exists */
AnnaBridge 175:af195413fb11 166 #undef EXDEV
AnnaBridge 175:af195413fb11 167 #define EXDEV 18 /* Cross-device link */
AnnaBridge 175:af195413fb11 168 #undef ENODEV
AnnaBridge 175:af195413fb11 169 #define ENODEV 19 /* No such device */
AnnaBridge 175:af195413fb11 170 #undef ENOTDIR
AnnaBridge 175:af195413fb11 171 #define ENOTDIR 20 /* Not a directory */
AnnaBridge 175:af195413fb11 172 #undef EISDIR
AnnaBridge 175:af195413fb11 173 #define EISDIR 21 /* Is a directory */
AnnaBridge 175:af195413fb11 174 #undef EINVAL
AnnaBridge 175:af195413fb11 175 #define EINVAL 22 /* Invalid argument */
AnnaBridge 175:af195413fb11 176 #undef ENFILE
AnnaBridge 175:af195413fb11 177 #define ENFILE 23 /* File table overflow */
AnnaBridge 175:af195413fb11 178 #undef EMFILE
AnnaBridge 175:af195413fb11 179 #define EMFILE 24 /* Too many open files */
AnnaBridge 175:af195413fb11 180 #undef ENOTTY
AnnaBridge 175:af195413fb11 181 #define ENOTTY 25 /* Not a typewriter */
AnnaBridge 175:af195413fb11 182 #undef ETXTBSY
AnnaBridge 175:af195413fb11 183 #define ETXTBSY 26 /* Text file busy */
AnnaBridge 175:af195413fb11 184 #undef EFBIG
AnnaBridge 175:af195413fb11 185 #define EFBIG 27 /* File too large */
AnnaBridge 175:af195413fb11 186 #undef ENOSPC
AnnaBridge 175:af195413fb11 187 #define ENOSPC 28 /* No space left on device */
AnnaBridge 175:af195413fb11 188 #undef ESPIPE
AnnaBridge 175:af195413fb11 189 #define ESPIPE 29 /* Illegal seek */
AnnaBridge 175:af195413fb11 190 #undef EROFS
AnnaBridge 175:af195413fb11 191 #define EROFS 30 /* Read-only file system */
AnnaBridge 175:af195413fb11 192 #undef EMLINK
AnnaBridge 175:af195413fb11 193 #define EMLINK 31 /* Too many links */
AnnaBridge 175:af195413fb11 194 #undef EPIPE
AnnaBridge 175:af195413fb11 195 #define EPIPE 32 /* Broken pipe */
AnnaBridge 175:af195413fb11 196 #undef EDOM
AnnaBridge 175:af195413fb11 197 #define EDOM 33 /* Math argument out of domain of func */
AnnaBridge 175:af195413fb11 198 #undef ERANGE
AnnaBridge 175:af195413fb11 199 #define ERANGE 34 /* Math result not representable */
AnnaBridge 175:af195413fb11 200 #undef EDEADLK
AnnaBridge 175:af195413fb11 201 #define EDEADLK 35 /* Resource deadlock would occur */
AnnaBridge 175:af195413fb11 202 #undef ENAMETOOLONG
AnnaBridge 175:af195413fb11 203 #define ENAMETOOLONG 36 /* File name too long */
AnnaBridge 175:af195413fb11 204 #undef ENOLCK
AnnaBridge 175:af195413fb11 205 #define ENOLCK 37 /* No record locks available */
AnnaBridge 175:af195413fb11 206 #undef ENOSYS
AnnaBridge 175:af195413fb11 207 #define ENOSYS 38 /* Function not implemented */
AnnaBridge 175:af195413fb11 208 #undef ENOTEMPTY
AnnaBridge 175:af195413fb11 209 #define ENOTEMPTY 39 /* Directory not empty */
AnnaBridge 175:af195413fb11 210 #undef ELOOP
AnnaBridge 175:af195413fb11 211 #define ELOOP 40 /* Too many symbolic links encountered */
AnnaBridge 175:af195413fb11 212 #undef EWOULDBLOCK
AnnaBridge 175:af195413fb11 213 #define EWOULDBLOCK EAGAIN /* Operation would block */
AnnaBridge 175:af195413fb11 214 #undef ENOMSG
AnnaBridge 175:af195413fb11 215 #define ENOMSG 42 /* No message of desired type */
AnnaBridge 175:af195413fb11 216 #undef EIDRM
AnnaBridge 175:af195413fb11 217 #define EIDRM 43 /* Identifier removed */
AnnaBridge 175:af195413fb11 218 #undef ECHRNG
AnnaBridge 175:af195413fb11 219 #define ECHRNG 44 /* Channel number out of range */
AnnaBridge 175:af195413fb11 220 #undef EL2NSYNC
AnnaBridge 175:af195413fb11 221 #define EL2NSYNC 45 /* Level 2 not synchronized */
AnnaBridge 175:af195413fb11 222 #undef EL3HLT
AnnaBridge 175:af195413fb11 223 #define EL3HLT 46 /* Level 3 halted */
AnnaBridge 175:af195413fb11 224 #undef EL3RST
AnnaBridge 175:af195413fb11 225 #define EL3RST 47 /* Level 3 reset */
AnnaBridge 175:af195413fb11 226 #undef ELNRNG
AnnaBridge 175:af195413fb11 227 #define ELNRNG 48 /* Link number out of range */
AnnaBridge 175:af195413fb11 228 #undef EUNATCH
AnnaBridge 175:af195413fb11 229 #define EUNATCH 49 /* Protocol driver not attached */
AnnaBridge 175:af195413fb11 230 #undef ENOCSI
AnnaBridge 175:af195413fb11 231 #define ENOCSI 50 /* No CSI structure available */
AnnaBridge 175:af195413fb11 232 #undef EL2HLT
AnnaBridge 175:af195413fb11 233 #define EL2HLT 51 /* Level 2 halted */
AnnaBridge 175:af195413fb11 234 #undef EBADE
AnnaBridge 175:af195413fb11 235 #define EBADE 52 /* Invalid exchange */
AnnaBridge 175:af195413fb11 236 #undef EBADR
AnnaBridge 175:af195413fb11 237 #define EBADR 53 /* Invalid request descriptor */
AnnaBridge 175:af195413fb11 238 #undef EXFULL
AnnaBridge 175:af195413fb11 239 #define EXFULL 54 /* Exchange full */
AnnaBridge 175:af195413fb11 240 #undef ENOANO
AnnaBridge 175:af195413fb11 241 #define ENOANO 55 /* No anode */
AnnaBridge 175:af195413fb11 242 #undef EBADRQC
AnnaBridge 175:af195413fb11 243 #define EBADRQC 56 /* Invalid request code */
AnnaBridge 175:af195413fb11 244 #undef EBADSLT
AnnaBridge 175:af195413fb11 245 #define EBADSLT 57 /* Invalid slot */
AnnaBridge 175:af195413fb11 246 #undef EDEADLOCK
AnnaBridge 175:af195413fb11 247 #define EDEADLOCK EDEADLK /* Resource deadlock would occur */
AnnaBridge 175:af195413fb11 248 #undef EBFONT
AnnaBridge 175:af195413fb11 249 #define EBFONT 59 /* Bad font file format */
AnnaBridge 175:af195413fb11 250 #undef ENOSTR
AnnaBridge 175:af195413fb11 251 #define ENOSTR 60 /* Device not a stream */
AnnaBridge 175:af195413fb11 252 #undef ENODATA
AnnaBridge 175:af195413fb11 253 #define ENODATA 61 /* No data available */
AnnaBridge 175:af195413fb11 254 #undef ETIME
AnnaBridge 175:af195413fb11 255 #define ETIME 62 /* Timer expired */
AnnaBridge 175:af195413fb11 256 #undef ENOSR
AnnaBridge 175:af195413fb11 257 #define ENOSR 63 /* Out of streams resources */
AnnaBridge 175:af195413fb11 258 #undef ENONET
AnnaBridge 175:af195413fb11 259 #define ENONET 64 /* Machine is not on the network */
AnnaBridge 175:af195413fb11 260 #undef ENOPKG
AnnaBridge 175:af195413fb11 261 #define ENOPKG 65 /* Package not installed */
AnnaBridge 175:af195413fb11 262 #undef EREMOTE
AnnaBridge 175:af195413fb11 263 #define EREMOTE 66 /* Object is remote */
AnnaBridge 175:af195413fb11 264 #undef ENOLINK
AnnaBridge 175:af195413fb11 265 #define ENOLINK 67 /* Link has been severed */
AnnaBridge 175:af195413fb11 266 #undef EADV
AnnaBridge 175:af195413fb11 267 #define EADV 68 /* Advertise error */
AnnaBridge 175:af195413fb11 268 #undef ESRMNT
AnnaBridge 175:af195413fb11 269 #define ESRMNT 69 /* Srmount error */
AnnaBridge 175:af195413fb11 270 #undef ECOMM
AnnaBridge 175:af195413fb11 271 #define ECOMM 70 /* Communication error on send */
AnnaBridge 175:af195413fb11 272 #undef EPROTO
AnnaBridge 175:af195413fb11 273 #define EPROTO 71 /* Protocol error */
AnnaBridge 175:af195413fb11 274 #undef EMULTIHOP
AnnaBridge 175:af195413fb11 275 #define EMULTIHOP 72 /* Multihop attempted */
AnnaBridge 175:af195413fb11 276 #undef EDOTDOT
AnnaBridge 175:af195413fb11 277 #define EDOTDOT 73 /* RFS specific error */
AnnaBridge 175:af195413fb11 278 #undef EBADMSG
AnnaBridge 175:af195413fb11 279 #define EBADMSG 74 /* Not a data message */
AnnaBridge 175:af195413fb11 280 #undef EOVERFLOW
AnnaBridge 175:af195413fb11 281 #define EOVERFLOW 75 /* Value too large for defined data type */
AnnaBridge 175:af195413fb11 282 #undef ENOTUNIQ
AnnaBridge 175:af195413fb11 283 #define ENOTUNIQ 76 /* Name not unique on network */
AnnaBridge 175:af195413fb11 284 #undef EBADFD
AnnaBridge 175:af195413fb11 285 #define EBADFD 77 /* File descriptor in bad state */
AnnaBridge 175:af195413fb11 286 #undef EREMCHG
AnnaBridge 175:af195413fb11 287 #define EREMCHG 78 /* Remote address changed */
AnnaBridge 175:af195413fb11 288 #undef ELIBACC
AnnaBridge 175:af195413fb11 289 #define ELIBACC 79 /* Can not access a needed shared library */
AnnaBridge 175:af195413fb11 290 #undef ELIBBAD
AnnaBridge 175:af195413fb11 291 #define ELIBBAD 80 /* Accessing a corrupted shared library */
AnnaBridge 175:af195413fb11 292 #undef ELIBSCN
AnnaBridge 175:af195413fb11 293 #define ELIBSCN 81 /* .lib section in a.out corrupted */
AnnaBridge 175:af195413fb11 294 #undef ELIBMAX
AnnaBridge 175:af195413fb11 295 #define ELIBMAX 82 /* Attempting to link in too many shared libraries */
AnnaBridge 175:af195413fb11 296 #undef ELIBEXEC
AnnaBridge 175:af195413fb11 297 #define ELIBEXEC 83 /* Cannot exec a shared library directly */
AnnaBridge 175:af195413fb11 298 #undef EILSEQ
AnnaBridge 175:af195413fb11 299 #define EILSEQ 84 /* Illegal byte sequence */
AnnaBridge 175:af195413fb11 300 #undef ERESTART
AnnaBridge 175:af195413fb11 301 #define ERESTART 85 /* Interrupted system call should be restarted */
AnnaBridge 175:af195413fb11 302 #undef ESTRPIPE
AnnaBridge 175:af195413fb11 303 #define ESTRPIPE 86 /* Streams pipe error */
AnnaBridge 175:af195413fb11 304 #undef EUSERS
AnnaBridge 175:af195413fb11 305 #define EUSERS 87 /* Too many users */
AnnaBridge 175:af195413fb11 306 #undef ENOTSOCK
AnnaBridge 175:af195413fb11 307 #define ENOTSOCK 88 /* Socket operation on non-socket */
AnnaBridge 175:af195413fb11 308 #undef EDESTADDRREQ
AnnaBridge 175:af195413fb11 309 #define EDESTADDRREQ 89 /* Destination address required */
AnnaBridge 175:af195413fb11 310 #undef EMSGSIZE
AnnaBridge 175:af195413fb11 311 #define EMSGSIZE 90 /* Message too long */
AnnaBridge 175:af195413fb11 312 #undef EPROTOTYPE
AnnaBridge 175:af195413fb11 313 #define EPROTOTYPE 91 /* Protocol wrong type for socket */
AnnaBridge 175:af195413fb11 314 #undef ENOPROTOOPT
AnnaBridge 175:af195413fb11 315 #define ENOPROTOOPT 92 /* Protocol not available */
AnnaBridge 175:af195413fb11 316 #undef EPROTONOSUPPORT
AnnaBridge 175:af195413fb11 317 #define EPROTONOSUPPORT 93 /* Protocol not supported */
AnnaBridge 175:af195413fb11 318 #undef ESOCKTNOSUPPORT
AnnaBridge 175:af195413fb11 319 #define ESOCKTNOSUPPORT 94 /* Socket type not supported */
AnnaBridge 175:af195413fb11 320 #undef EOPNOTSUPP
AnnaBridge 175:af195413fb11 321 #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
AnnaBridge 175:af195413fb11 322 #undef EPFNOSUPPORT
AnnaBridge 175:af195413fb11 323 #define EPFNOSUPPORT 96 /* Protocol family not supported */
AnnaBridge 175:af195413fb11 324 #undef EAFNOSUPPORT
AnnaBridge 175:af195413fb11 325 #define EAFNOSUPPORT 97 /* Address family not supported by protocol */
AnnaBridge 175:af195413fb11 326 #undef EADDRINUSE
AnnaBridge 175:af195413fb11 327 #define EADDRINUSE 98 /* Address already in use */
AnnaBridge 175:af195413fb11 328 #undef EADDRNOTAVAIL
AnnaBridge 175:af195413fb11 329 #define EADDRNOTAVAIL 99 /* Cannot assign requested address */
AnnaBridge 175:af195413fb11 330 #undef ENETDOWN
AnnaBridge 175:af195413fb11 331 #define ENETDOWN 100 /* Network is down */
AnnaBridge 175:af195413fb11 332 #undef ENETUNREACH
AnnaBridge 175:af195413fb11 333 #define ENETUNREACH 101 /* Network is unreachable */
AnnaBridge 175:af195413fb11 334 #undef ENETRESET
AnnaBridge 175:af195413fb11 335 #define ENETRESET 102 /* Network dropped connection because of reset */
AnnaBridge 175:af195413fb11 336 #undef ECONNABORTED
AnnaBridge 175:af195413fb11 337 #define ECONNABORTED 103 /* Software caused connection abort */
AnnaBridge 175:af195413fb11 338 #undef ECONNRESET
AnnaBridge 175:af195413fb11 339 #define ECONNRESET 104 /* Connection reset by peer */
AnnaBridge 175:af195413fb11 340 #undef ENOBUFS
AnnaBridge 175:af195413fb11 341 #define ENOBUFS 105 /* No buffer space available */
AnnaBridge 175:af195413fb11 342 #undef EISCONN
AnnaBridge 175:af195413fb11 343 #define EISCONN 106 /* Transport endpoint is already connected */
AnnaBridge 175:af195413fb11 344 #undef ENOTCONN
AnnaBridge 175:af195413fb11 345 #define ENOTCONN 107 /* Transport endpoint is not connected */
AnnaBridge 175:af195413fb11 346 #undef ESHUTDOWN
AnnaBridge 175:af195413fb11 347 #define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
AnnaBridge 175:af195413fb11 348 #undef ETOOMANYREFS
AnnaBridge 175:af195413fb11 349 #define ETOOMANYREFS 109 /* Too many references: cannot splice */
AnnaBridge 175:af195413fb11 350 #undef ETIMEDOUT
AnnaBridge 175:af195413fb11 351 #define ETIMEDOUT 110 /* Connection timed out */
AnnaBridge 175:af195413fb11 352 #undef ECONNREFUSED
AnnaBridge 175:af195413fb11 353 #define ECONNREFUSED 111 /* Connection refused */
AnnaBridge 175:af195413fb11 354 #undef EHOSTDOWN
AnnaBridge 175:af195413fb11 355 #define EHOSTDOWN 112 /* Host is down */
AnnaBridge 175:af195413fb11 356 #undef EHOSTUNREACH
AnnaBridge 175:af195413fb11 357 #define EHOSTUNREACH 113 /* No route to host */
AnnaBridge 175:af195413fb11 358 #undef EALREADY
AnnaBridge 175:af195413fb11 359 #define EALREADY 114 /* Operation already in progress */
AnnaBridge 175:af195413fb11 360 #undef EINPROGRESS
AnnaBridge 175:af195413fb11 361 #define EINPROGRESS 115 /* Operation now in progress */
AnnaBridge 175:af195413fb11 362 #undef ESTALE
AnnaBridge 175:af195413fb11 363 #define ESTALE 116 /* Stale NFS file handle */
AnnaBridge 175:af195413fb11 364 #undef EUCLEAN
AnnaBridge 175:af195413fb11 365 #define EUCLEAN 117 /* Structure needs cleaning */
AnnaBridge 175:af195413fb11 366 #undef ENOTNAM
AnnaBridge 175:af195413fb11 367 #define ENOTNAM 118 /* Not a XENIX named type file */
AnnaBridge 175:af195413fb11 368 #undef ENAVAIL
AnnaBridge 175:af195413fb11 369 #define ENAVAIL 119 /* No XENIX semaphores available */
AnnaBridge 175:af195413fb11 370 #undef EISNAM
AnnaBridge 175:af195413fb11 371 #define EISNAM 120 /* Is a named type file */
AnnaBridge 175:af195413fb11 372 #undef EREMOTEIO
AnnaBridge 175:af195413fb11 373 #define EREMOTEIO 121 /* Remote I/O error */
AnnaBridge 175:af195413fb11 374 #undef EDQUOT
AnnaBridge 175:af195413fb11 375 #define EDQUOT 122 /* Quota exceeded */
AnnaBridge 175:af195413fb11 376 #undef ENOMEDIUM
AnnaBridge 175:af195413fb11 377 #define ENOMEDIUM 123 /* No medium found */
AnnaBridge 175:af195413fb11 378 #undef EMEDIUMTYPE
AnnaBridge 175:af195413fb11 379 #define EMEDIUMTYPE 124 /* Wrong medium type */
AnnaBridge 175:af195413fb11 380 #undef ECANCELED
AnnaBridge 175:af195413fb11 381 #define ECANCELED 125 /* Operation Canceled */
AnnaBridge 175:af195413fb11 382 #undef ENOKEY
AnnaBridge 175:af195413fb11 383 #define ENOKEY 126 /* Required key not available */
AnnaBridge 175:af195413fb11 384 #undef EKEYEXPIRED
AnnaBridge 175:af195413fb11 385 #define EKEYEXPIRED 127 /* Key has expired */
AnnaBridge 175:af195413fb11 386 #undef EKEYREVOKED
AnnaBridge 175:af195413fb11 387 #define EKEYREVOKED 128 /* Key has been revoked */
AnnaBridge 175:af195413fb11 388 #undef EKEYREJECTED
AnnaBridge 175:af195413fb11 389 #define EKEYREJECTED 129 /* Key was rejected by service */
AnnaBridge 175:af195413fb11 390 #undef EOWNERDEAD
AnnaBridge 175:af195413fb11 391 #define EOWNERDEAD 130 /* Owner died */
AnnaBridge 175:af195413fb11 392 #undef ENOTRECOVERABLE
AnnaBridge 175:af195413fb11 393 #define ENOTRECOVERABLE 131 /* State not recoverable */
<> 160:d5399cc887bb 394
<> 160:d5399cc887bb 395 /* Missing stat.h defines.
<> 160:d5399cc887bb 396 * The following are sys/stat.h definitions not currently present in the ARMCC
<> 160:d5399cc887bb 397 * errno.h. Note, ARMCC errno.h defines some symbol values differing from
<> 160:d5399cc887bb 398 * GCC_ARM/IAR/standard POSIX definitions. Guard against this and future
AnnaBridge 175:af195413fb11 399 * changes by changing the symbol definition for filesystem use.
AnnaBridge 175:af195413fb11 400 */
AnnaBridge 175:af195413fb11 401 #define _IFMT 0170000 //< type of file
AnnaBridge 175:af195413fb11 402 #define _IFSOCK 0140000 //< socket
AnnaBridge 175:af195413fb11 403 #define _IFLNK 0120000 //< symbolic link
AnnaBridge 175:af195413fb11 404 #define _IFREG 0100000 //< regular
AnnaBridge 175:af195413fb11 405 #define _IFBLK 0060000 //< block special
AnnaBridge 175:af195413fb11 406 #define _IFDIR 0040000 //< directory
AnnaBridge 175:af195413fb11 407 #define _IFCHR 0020000 //< character special
AnnaBridge 175:af195413fb11 408 #define _IFIFO 0010000 //< fifo special
<> 160:d5399cc887bb 409
AnnaBridge 175:af195413fb11 410 #define S_IFMT _IFMT //< type of file
AnnaBridge 175:af195413fb11 411 #define S_IFSOCK _IFSOCK //< socket
AnnaBridge 175:af195413fb11 412 #define S_IFLNK _IFLNK //< symbolic link
AnnaBridge 175:af195413fb11 413 #define S_IFREG _IFREG //< regular
AnnaBridge 175:af195413fb11 414 #define S_IFBLK _IFBLK //< block special
AnnaBridge 175:af195413fb11 415 #define S_IFDIR _IFDIR //< directory
AnnaBridge 175:af195413fb11 416 #define S_IFCHR _IFCHR //< character special
AnnaBridge 175:af195413fb11 417 #define S_IFIFO _IFIFO //< fifo special
<> 160:d5399cc887bb 418
<> 160:d5399cc887bb 419 #define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
AnnaBridge 175:af195413fb11 420 #define S_IRUSR 0000400 ///< read permission, owner
AnnaBridge 175:af195413fb11 421 #define S_IWUSR 0000200 ///< write permission, owner
AnnaBridge 175:af195413fb11 422 #define S_IXUSR 0000100 ///< execute/search permission, owner
<> 160:d5399cc887bb 423 #define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
AnnaBridge 175:af195413fb11 424 #define S_IRGRP 0000040 ///< read permission, group
AnnaBridge 184:08ed48f1de7f 425 #define S_IWGRP 0000020 ///< write permission, group
AnnaBridge 175:af195413fb11 426 #define S_IXGRP 0000010 ///< execute/search permission, group
<> 160:d5399cc887bb 427 #define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
AnnaBridge 175:af195413fb11 428 #define S_IROTH 0000004 ///< read permission, other
AnnaBridge 175:af195413fb11 429 #define S_IWOTH 0000002 ///< write permission, other
AnnaBridge 175:af195413fb11 430 #define S_IXOTH 0000001 ///< execute/search permission, other
AnnaBridge 175:af195413fb11 431
AnnaBridge 175:af195413fb11 432 /* Refer to sys/stat standard
AnnaBridge 175:af195413fb11 433 * Note: Not all fields may be supported by the underlying filesystem
AnnaBridge 175:af195413fb11 434 */
AnnaBridge 175:af195413fb11 435 struct stat {
AnnaBridge 175:af195413fb11 436 dev_t st_dev; ///< Device ID containing file
AnnaBridge 175:af195413fb11 437 ino_t st_ino; ///< File serial number
AnnaBridge 175:af195413fb11 438 mode_t st_mode; ///< Mode of file
AnnaBridge 175:af195413fb11 439 nlink_t st_nlink; ///< Number of links to file
AnnaBridge 175:af195413fb11 440
AnnaBridge 175:af195413fb11 441 uid_t st_uid; ///< User ID
AnnaBridge 175:af195413fb11 442 gid_t st_gid; ///< Group ID
AnnaBridge 175:af195413fb11 443
AnnaBridge 175:af195413fb11 444 off_t st_size; ///< Size of file in bytes
AnnaBridge 175:af195413fb11 445
AnnaBridge 175:af195413fb11 446 time_t st_atime; ///< Time of last access
AnnaBridge 175:af195413fb11 447 time_t st_mtime; ///< Time of last data modification
AnnaBridge 175:af195413fb11 448 time_t st_ctime; ///< Time of last status change
AnnaBridge 175:af195413fb11 449 };
<> 160:d5399cc887bb 450
AnnaBridge 184:08ed48f1de7f 451 struct statvfs {
AnnaBridge 184:08ed48f1de7f 452 unsigned long f_bsize; ///< Filesystem block size
AnnaBridge 184:08ed48f1de7f 453 unsigned long f_frsize; ///< Fragment size (block size)
AnnaBridge 184:08ed48f1de7f 454
AnnaBridge 184:08ed48f1de7f 455 fsblkcnt_t f_blocks; ///< Number of blocks
AnnaBridge 184:08ed48f1de7f 456 fsblkcnt_t f_bfree; ///< Number of free blocks
AnnaBridge 184:08ed48f1de7f 457 fsblkcnt_t f_bavail; ///< Number of free blocks for unprivileged users
AnnaBridge 184:08ed48f1de7f 458
AnnaBridge 184:08ed48f1de7f 459 unsigned long f_fsid; ///< Filesystem ID
AnnaBridge 184:08ed48f1de7f 460
AnnaBridge 184:08ed48f1de7f 461 unsigned long f_namemax; ///< Maximum filename length
Anna Bridge 180:96ed750bd169 462 };
<> 160:d5399cc887bb 463
AnnaBridge 184:08ed48f1de7f 464 /* The following are dirent.h definitions are declared here to guarantee
AnnaBridge 175:af195413fb11 465 * consistency where structure may be different with different toolchains
AnnaBridge 175:af195413fb11 466 */
<> 160:d5399cc887bb 467 struct dirent {
AnnaBridge 175:af195413fb11 468 char d_name[NAME_MAX+1]; ///< Name of file
AnnaBridge 175:af195413fb11 469 uint8_t d_type; ///< Type of file
<> 160:d5399cc887bb 470 };
<> 160:d5399cc887bb 471
<> 160:d5399cc887bb 472 enum {
AnnaBridge 175:af195413fb11 473 DT_UNKNOWN, ///< The file type could not be determined.
AnnaBridge 175:af195413fb11 474 DT_FIFO, ///< This is a named pipe (FIFO).
AnnaBridge 175:af195413fb11 475 DT_CHR, ///< This is a character device.
AnnaBridge 175:af195413fb11 476 DT_DIR, ///< This is a directory.
AnnaBridge 175:af195413fb11 477 DT_BLK, ///< This is a block device.
AnnaBridge 175:af195413fb11 478 DT_REG, ///< This is a regular file.
AnnaBridge 175:af195413fb11 479 DT_LNK, ///< This is a symbolic link.
AnnaBridge 175:af195413fb11 480 DT_SOCK, ///< This is a UNIX domain socket.
<> 160:d5399cc887bb 481 };
<> 160:d5399cc887bb 482
AnnaBridge 184:08ed48f1de7f 483 struct pollfd {
AnnaBridge 184:08ed48f1de7f 484 int fd;
AnnaBridge 184:08ed48f1de7f 485 short events;
AnnaBridge 184:08ed48f1de7f 486 short revents;
AnnaBridge 184:08ed48f1de7f 487 };
AnnaBridge 184:08ed48f1de7f 488
AnnaBridge 184:08ed48f1de7f 489 /* POSIX-compatible I/O functions */
AnnaBridge 184:08ed48f1de7f 490 #if __cplusplus
AnnaBridge 184:08ed48f1de7f 491 extern "C" {
AnnaBridge 184:08ed48f1de7f 492 #endif
AnnaBridge 184:08ed48f1de7f 493 int open(const char *path, int oflag, ...);
AnnaBridge 184:08ed48f1de7f 494 #ifndef __IAR_SYSTEMS_ICC__ /* IAR provides fdopen itself */
AnnaBridge 184:08ed48f1de7f 495 #if __cplusplus
AnnaBridge 184:08ed48f1de7f 496 std::FILE* fdopen(int fildes, const char *mode);
AnnaBridge 184:08ed48f1de7f 497 #else
AnnaBridge 184:08ed48f1de7f 498 FILE* fdopen(int fildes, const char *mode);
AnnaBridge 184:08ed48f1de7f 499 #endif
AnnaBridge 184:08ed48f1de7f 500 #endif
AnnaBridge 184:08ed48f1de7f 501 ssize_t write(int fildes, const void *buf, size_t nbyte);
AnnaBridge 184:08ed48f1de7f 502 ssize_t read(int fildes, void *buf, size_t nbyte);
AnnaBridge 184:08ed48f1de7f 503 off_t lseek(int fildes, off_t offset, int whence);
AnnaBridge 184:08ed48f1de7f 504 int isatty(int fildes);
AnnaBridge 184:08ed48f1de7f 505 int fsync(int fildes);
AnnaBridge 184:08ed48f1de7f 506 int fstat(int fh, struct stat *st);
AnnaBridge 184:08ed48f1de7f 507 int poll(struct pollfd fds[], nfds_t nfds, int timeout);
AnnaBridge 184:08ed48f1de7f 508 int close(int fildes);
AnnaBridge 184:08ed48f1de7f 509 int stat(const char *path, struct stat *st);
AnnaBridge 184:08ed48f1de7f 510 int statvfs(const char *path, struct statvfs *buf);
AnnaBridge 184:08ed48f1de7f 511 DIR *opendir(const char*);
AnnaBridge 184:08ed48f1de7f 512 struct dirent *readdir(DIR *);
AnnaBridge 184:08ed48f1de7f 513 int closedir(DIR*);
AnnaBridge 184:08ed48f1de7f 514 void rewinddir(DIR*);
AnnaBridge 184:08ed48f1de7f 515 long telldir(DIR*);
AnnaBridge 184:08ed48f1de7f 516 void seekdir(DIR*, long);
AnnaBridge 184:08ed48f1de7f 517 int mkdir(const char *name, mode_t n);
AnnaBridge 184:08ed48f1de7f 518 #if __cplusplus
AnnaBridge 184:08ed48f1de7f 519 }; // extern "C"
AnnaBridge 184:08ed48f1de7f 520
AnnaBridge 184:08ed48f1de7f 521 namespace mbed {
AnnaBridge 184:08ed48f1de7f 522
AnnaBridge 184:08ed48f1de7f 523 /** This call is an analogue to POSIX fdopen().
AnnaBridge 184:08ed48f1de7f 524 *
AnnaBridge 184:08ed48f1de7f 525 * It associates a C stream to an already-opened FileHandle, to allow you to
AnnaBridge 184:08ed48f1de7f 526 * use C printf/scanf/fwrite etc. The provided FileHandle must remain open -
AnnaBridge 184:08ed48f1de7f 527 * it will be closed by the C library when fclose(FILE) is called.
AnnaBridge 184:08ed48f1de7f 528 *
AnnaBridge 184:08ed48f1de7f 529 * The net effect is fdopen(bind_to_fd(fh), mode), with error handling.
AnnaBridge 184:08ed48f1de7f 530 *
AnnaBridge 184:08ed48f1de7f 531 * @param fh a pointer to an opened FileHandle
AnnaBridge 184:08ed48f1de7f 532 * @param mode operation upon the file descriptor, e.g., "w+"
AnnaBridge 184:08ed48f1de7f 533 *
AnnaBridge 184:08ed48f1de7f 534 * @returns a pointer to FILE
AnnaBridge 184:08ed48f1de7f 535 */
AnnaBridge 184:08ed48f1de7f 536 std::FILE* fdopen(mbed::FileHandle *fh, const char *mode);
AnnaBridge 184:08ed48f1de7f 537
AnnaBridge 184:08ed48f1de7f 538 /** Bind an mbed FileHandle to a POSIX file descriptor
AnnaBridge 184:08ed48f1de7f 539 *
AnnaBridge 184:08ed48f1de7f 540 * This is similar to fdopen, but only operating at the POSIX layer - it
AnnaBridge 184:08ed48f1de7f 541 * associates a POSIX integer file descriptor with a FileHandle, to allow you
AnnaBridge 184:08ed48f1de7f 542 * to use POSIX read/write calls etc. The provided FileHandle must remain open -
AnnaBridge 184:08ed48f1de7f 543 * it will be closed when close(int) is called.
AnnaBridge 184:08ed48f1de7f 544 *
AnnaBridge 184:08ed48f1de7f 545 * @param fh a pointer to an opened FileHandle
AnnaBridge 184:08ed48f1de7f 546 *
AnnaBridge 184:08ed48f1de7f 547 * @return an integer file descriptor, or negative if no descriptors available
AnnaBridge 184:08ed48f1de7f 548 */
AnnaBridge 184:08ed48f1de7f 549 int bind_to_fd(mbed::FileHandle *fh);
AnnaBridge 184:08ed48f1de7f 550
AnnaBridge 184:08ed48f1de7f 551 } // namespace mbed
AnnaBridge 184:08ed48f1de7f 552
AnnaBridge 184:08ed48f1de7f 553 #endif // __cplusplus
AnnaBridge 184:08ed48f1de7f 554
AnnaBridge 178:79309dc6340a 555 /**@}*/
AnnaBridge 178:79309dc6340a 556
AnnaBridge 178:79309dc6340a 557 /**@}*/
AnnaBridge 178:79309dc6340a 558
<> 160:d5399cc887bb 559 #endif /* RETARGET_H */