Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-dev by
mbed_retarget.h
00001 /* 00002 * mbed Microcontroller Library 00003 * Copyright (c) 2006-2016 ARM Limited 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 */ 00018 00019 #ifndef RETARGET_H 00020 #define RETARGET_H 00021 00022 #if __cplusplus 00023 #include <cstdio> 00024 #endif //__cplusplus 00025 #include <stdint.h> 00026 #include <stddef.h> 00027 00028 /* We can get the following standard types from sys/types for gcc, but we 00029 * need to define the types ourselves for the other compilers that normally 00030 * target embedded systems */ 00031 #if defined(__ARMCC_VERSION) || defined(__ICCARM__) 00032 typedef signed int ssize_t; ///< Signed size type, usually encodes negative errors 00033 typedef signed long off_t; ///< Offset in a data stream 00034 typedef unsigned int mode_t; ///< Mode for opening files 00035 typedef unsigned int dev_t; ///< Device ID type 00036 typedef unsigned long ino_t; ///< File serial number 00037 typedef unsigned int nlink_t; ///< Number of links to a file 00038 typedef unsigned int uid_t; ///< User ID 00039 typedef unsigned int gid_t; ///< Group ID 00040 00041 #define O_RDONLY 0 ///< Open for reading 00042 #define O_WRONLY 1 ///< Open for writing 00043 #define O_RDWR 2 ///< Open for reading and writing 00044 #define O_CREAT 0x0200 ///< Create file if it does not exist 00045 #define O_TRUNC 0x0400 ///< Truncate file to zero length 00046 #define O_EXCL 0x0800 ///< Fail if file exists 00047 #define O_APPEND 0x0008 ///< Set file offset to end of file prior to each write 00048 00049 #define NAME_MAX 255 ///< Maximum size of a name in a file path 00050 00051 #include <time.h> 00052 00053 #else 00054 00055 #include <sys/fcntl.h> 00056 #include <sys/types.h> 00057 #include <sys/syslimits.h> 00058 00059 #endif 00060 00061 /** \addtogroup platform */ 00062 /** @{*/ 00063 /** 00064 * \defgroup platform_retarget Retarget functions 00065 * @{ 00066 */ 00067 00068 /* DIR declarations must also be here */ 00069 #if __cplusplus 00070 namespace mbed { 00071 00072 class FileHandle; 00073 class DirHandle; 00074 std::FILE *mbed_fdopen(FileHandle *fh, const char *mode); 00075 00076 } 00077 typedef mbed::DirHandle DIR; 00078 #else 00079 typedef struct Dir DIR; 00080 #endif 00081 00082 #if __cplusplus 00083 extern "C" { 00084 #endif 00085 DIR *opendir(const char*); 00086 struct dirent *readdir(DIR *); 00087 int closedir(DIR*); 00088 void rewinddir(DIR*); 00089 long telldir(DIR*); 00090 void seekdir(DIR*, long); 00091 int mkdir(const char *name, mode_t n); 00092 #if __cplusplus 00093 }; 00094 #endif 00095 00096 00097 #if defined(__ARMCC_VERSION) || defined(__ICCARM__) 00098 /* The intent of this section is to unify the errno error values to match 00099 * the POSIX definitions for the GCC_ARM, ARMCC and IAR compilers. This is 00100 * necessary because the ARMCC/IAR errno.h, or sys/stat.h are missing some 00101 * symbol definitions used by the POSIX filesystem API to return errno codes. 00102 * Note also that ARMCC errno.h defines some symbol values differently from 00103 * the GCC_ARM/IAR/standard POSIX definitions. The definitions guard against 00104 * this and future changes by changing the symbol definition as shown below. 00105 */ 00106 #undef EPERM 00107 #define EPERM 1 /* Operation not permitted */ 00108 #undef ENOENT 00109 #define ENOENT 2 /* No such file or directory */ 00110 #undef ESRCH 00111 #define ESRCH 3 /* No such process */ 00112 #undef EINTR 00113 #define EINTR 4 /* Interrupted system call */ 00114 #undef EIO 00115 #define EIO 5 /* I/O error */ 00116 #undef ENXIO 00117 #define ENXIO 6 /* No such device or address */ 00118 #undef E2BIG 00119 #define E2BIG 7 /* Argument list too long */ 00120 #undef ENOEXEC 00121 #define ENOEXEC 8 /* Exec format error */ 00122 #undef EBADF 00123 #define EBADF 9 /* Bad file number */ 00124 #undef ECHILD 00125 #define ECHILD 10 /* No child processes */ 00126 #undef EAGAIN 00127 #define EAGAIN 11 /* Try again */ 00128 #undef ENOMEM 00129 #define ENOMEM 12 /* Out of memory */ 00130 #undef EACCES 00131 #define EACCES 13 /* Permission denied */ 00132 #undef EFAULT 00133 #define EFAULT 14 /* Bad address */ 00134 #undef ENOTBLK 00135 #define ENOTBLK 15 /* Block device required */ 00136 #undef EBUSY 00137 #define EBUSY 16 /* Device or resource busy */ 00138 #undef EEXIST 00139 #define EEXIST 17 /* File exists */ 00140 #undef EXDEV 00141 #define EXDEV 18 /* Cross-device link */ 00142 #undef ENODEV 00143 #define ENODEV 19 /* No such device */ 00144 #undef ENOTDIR 00145 #define ENOTDIR 20 /* Not a directory */ 00146 #undef EISDIR 00147 #define EISDIR 21 /* Is a directory */ 00148 #undef EINVAL 00149 #define EINVAL 22 /* Invalid argument */ 00150 #undef ENFILE 00151 #define ENFILE 23 /* File table overflow */ 00152 #undef EMFILE 00153 #define EMFILE 24 /* Too many open files */ 00154 #undef ENOTTY 00155 #define ENOTTY 25 /* Not a typewriter */ 00156 #undef ETXTBSY 00157 #define ETXTBSY 26 /* Text file busy */ 00158 #undef EFBIG 00159 #define EFBIG 27 /* File too large */ 00160 #undef ENOSPC 00161 #define ENOSPC 28 /* No space left on device */ 00162 #undef ESPIPE 00163 #define ESPIPE 29 /* Illegal seek */ 00164 #undef EROFS 00165 #define EROFS 30 /* Read-only file system */ 00166 #undef EMLINK 00167 #define EMLINK 31 /* Too many links */ 00168 #undef EPIPE 00169 #define EPIPE 32 /* Broken pipe */ 00170 #undef EDOM 00171 #define EDOM 33 /* Math argument out of domain of func */ 00172 #undef ERANGE 00173 #define ERANGE 34 /* Math result not representable */ 00174 #undef EDEADLK 00175 #define EDEADLK 35 /* Resource deadlock would occur */ 00176 #undef ENAMETOOLONG 00177 #define ENAMETOOLONG 36 /* File name too long */ 00178 #undef ENOLCK 00179 #define ENOLCK 37 /* No record locks available */ 00180 #undef ENOSYS 00181 #define ENOSYS 38 /* Function not implemented */ 00182 #undef ENOTEMPTY 00183 #define ENOTEMPTY 39 /* Directory not empty */ 00184 #undef ELOOP 00185 #define ELOOP 40 /* Too many symbolic links encountered */ 00186 #undef EWOULDBLOCK 00187 #define EWOULDBLOCK EAGAIN /* Operation would block */ 00188 #undef ENOMSG 00189 #define ENOMSG 42 /* No message of desired type */ 00190 #undef EIDRM 00191 #define EIDRM 43 /* Identifier removed */ 00192 #undef ECHRNG 00193 #define ECHRNG 44 /* Channel number out of range */ 00194 #undef EL2NSYNC 00195 #define EL2NSYNC 45 /* Level 2 not synchronized */ 00196 #undef EL3HLT 00197 #define EL3HLT 46 /* Level 3 halted */ 00198 #undef EL3RST 00199 #define EL3RST 47 /* Level 3 reset */ 00200 #undef ELNRNG 00201 #define ELNRNG 48 /* Link number out of range */ 00202 #undef EUNATCH 00203 #define EUNATCH 49 /* Protocol driver not attached */ 00204 #undef ENOCSI 00205 #define ENOCSI 50 /* No CSI structure available */ 00206 #undef EL2HLT 00207 #define EL2HLT 51 /* Level 2 halted */ 00208 #undef EBADE 00209 #define EBADE 52 /* Invalid exchange */ 00210 #undef EBADR 00211 #define EBADR 53 /* Invalid request descriptor */ 00212 #undef EXFULL 00213 #define EXFULL 54 /* Exchange full */ 00214 #undef ENOANO 00215 #define ENOANO 55 /* No anode */ 00216 #undef EBADRQC 00217 #define EBADRQC 56 /* Invalid request code */ 00218 #undef EBADSLT 00219 #define EBADSLT 57 /* Invalid slot */ 00220 #undef EDEADLOCK 00221 #define EDEADLOCK EDEADLK /* Resource deadlock would occur */ 00222 #undef EBFONT 00223 #define EBFONT 59 /* Bad font file format */ 00224 #undef ENOSTR 00225 #define ENOSTR 60 /* Device not a stream */ 00226 #undef ENODATA 00227 #define ENODATA 61 /* No data available */ 00228 #undef ETIME 00229 #define ETIME 62 /* Timer expired */ 00230 #undef ENOSR 00231 #define ENOSR 63 /* Out of streams resources */ 00232 #undef ENONET 00233 #define ENONET 64 /* Machine is not on the network */ 00234 #undef ENOPKG 00235 #define ENOPKG 65 /* Package not installed */ 00236 #undef EREMOTE 00237 #define EREMOTE 66 /* Object is remote */ 00238 #undef ENOLINK 00239 #define ENOLINK 67 /* Link has been severed */ 00240 #undef EADV 00241 #define EADV 68 /* Advertise error */ 00242 #undef ESRMNT 00243 #define ESRMNT 69 /* Srmount error */ 00244 #undef ECOMM 00245 #define ECOMM 70 /* Communication error on send */ 00246 #undef EPROTO 00247 #define EPROTO 71 /* Protocol error */ 00248 #undef EMULTIHOP 00249 #define EMULTIHOP 72 /* Multihop attempted */ 00250 #undef EDOTDOT 00251 #define EDOTDOT 73 /* RFS specific error */ 00252 #undef EBADMSG 00253 #define EBADMSG 74 /* Not a data message */ 00254 #undef EOVERFLOW 00255 #define EOVERFLOW 75 /* Value too large for defined data type */ 00256 #undef ENOTUNIQ 00257 #define ENOTUNIQ 76 /* Name not unique on network */ 00258 #undef EBADFD 00259 #define EBADFD 77 /* File descriptor in bad state */ 00260 #undef EREMCHG 00261 #define EREMCHG 78 /* Remote address changed */ 00262 #undef ELIBACC 00263 #define ELIBACC 79 /* Can not access a needed shared library */ 00264 #undef ELIBBAD 00265 #define ELIBBAD 80 /* Accessing a corrupted shared library */ 00266 #undef ELIBSCN 00267 #define ELIBSCN 81 /* .lib section in a.out corrupted */ 00268 #undef ELIBMAX 00269 #define ELIBMAX 82 /* Attempting to link in too many shared libraries */ 00270 #undef ELIBEXEC 00271 #define ELIBEXEC 83 /* Cannot exec a shared library directly */ 00272 #undef EILSEQ 00273 #define EILSEQ 84 /* Illegal byte sequence */ 00274 #undef ERESTART 00275 #define ERESTART 85 /* Interrupted system call should be restarted */ 00276 #undef ESTRPIPE 00277 #define ESTRPIPE 86 /* Streams pipe error */ 00278 #undef EUSERS 00279 #define EUSERS 87 /* Too many users */ 00280 #undef ENOTSOCK 00281 #define ENOTSOCK 88 /* Socket operation on non-socket */ 00282 #undef EDESTADDRREQ 00283 #define EDESTADDRREQ 89 /* Destination address required */ 00284 #undef EMSGSIZE 00285 #define EMSGSIZE 90 /* Message too long */ 00286 #undef EPROTOTYPE 00287 #define EPROTOTYPE 91 /* Protocol wrong type for socket */ 00288 #undef ENOPROTOOPT 00289 #define ENOPROTOOPT 92 /* Protocol not available */ 00290 #undef EPROTONOSUPPORT 00291 #define EPROTONOSUPPORT 93 /* Protocol not supported */ 00292 #undef ESOCKTNOSUPPORT 00293 #define ESOCKTNOSUPPORT 94 /* Socket type not supported */ 00294 #undef EOPNOTSUPP 00295 #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ 00296 #undef EPFNOSUPPORT 00297 #define EPFNOSUPPORT 96 /* Protocol family not supported */ 00298 #undef EAFNOSUPPORT 00299 #define EAFNOSUPPORT 97 /* Address family not supported by protocol */ 00300 #undef EADDRINUSE 00301 #define EADDRINUSE 98 /* Address already in use */ 00302 #undef EADDRNOTAVAIL 00303 #define EADDRNOTAVAIL 99 /* Cannot assign requested address */ 00304 #undef ENETDOWN 00305 #define ENETDOWN 100 /* Network is down */ 00306 #undef ENETUNREACH 00307 #define ENETUNREACH 101 /* Network is unreachable */ 00308 #undef ENETRESET 00309 #define ENETRESET 102 /* Network dropped connection because of reset */ 00310 #undef ECONNABORTED 00311 #define ECONNABORTED 103 /* Software caused connection abort */ 00312 #undef ECONNRESET 00313 #define ECONNRESET 104 /* Connection reset by peer */ 00314 #undef ENOBUFS 00315 #define ENOBUFS 105 /* No buffer space available */ 00316 #undef EISCONN 00317 #define EISCONN 106 /* Transport endpoint is already connected */ 00318 #undef ENOTCONN 00319 #define ENOTCONN 107 /* Transport endpoint is not connected */ 00320 #undef ESHUTDOWN 00321 #define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */ 00322 #undef ETOOMANYREFS 00323 #define ETOOMANYREFS 109 /* Too many references: cannot splice */ 00324 #undef ETIMEDOUT 00325 #define ETIMEDOUT 110 /* Connection timed out */ 00326 #undef ECONNREFUSED 00327 #define ECONNREFUSED 111 /* Connection refused */ 00328 #undef EHOSTDOWN 00329 #define EHOSTDOWN 112 /* Host is down */ 00330 #undef EHOSTUNREACH 00331 #define EHOSTUNREACH 113 /* No route to host */ 00332 #undef EALREADY 00333 #define EALREADY 114 /* Operation already in progress */ 00334 #undef EINPROGRESS 00335 #define EINPROGRESS 115 /* Operation now in progress */ 00336 #undef ESTALE 00337 #define ESTALE 116 /* Stale NFS file handle */ 00338 #undef EUCLEAN 00339 #define EUCLEAN 117 /* Structure needs cleaning */ 00340 #undef ENOTNAM 00341 #define ENOTNAM 118 /* Not a XENIX named type file */ 00342 #undef ENAVAIL 00343 #define ENAVAIL 119 /* No XENIX semaphores available */ 00344 #undef EISNAM 00345 #define EISNAM 120 /* Is a named type file */ 00346 #undef EREMOTEIO 00347 #define EREMOTEIO 121 /* Remote I/O error */ 00348 #undef EDQUOT 00349 #define EDQUOT 122 /* Quota exceeded */ 00350 #undef ENOMEDIUM 00351 #define ENOMEDIUM 123 /* No medium found */ 00352 #undef EMEDIUMTYPE 00353 #define EMEDIUMTYPE 124 /* Wrong medium type */ 00354 #undef ECANCELED 00355 #define ECANCELED 125 /* Operation Canceled */ 00356 #undef ENOKEY 00357 #define ENOKEY 126 /* Required key not available */ 00358 #undef EKEYEXPIRED 00359 #define EKEYEXPIRED 127 /* Key has expired */ 00360 #undef EKEYREVOKED 00361 #define EKEYREVOKED 128 /* Key has been revoked */ 00362 #undef EKEYREJECTED 00363 #define EKEYREJECTED 129 /* Key was rejected by service */ 00364 #undef EOWNERDEAD 00365 #define EOWNERDEAD 130 /* Owner died */ 00366 #undef ENOTRECOVERABLE 00367 #define ENOTRECOVERABLE 131 /* State not recoverable */ 00368 #endif 00369 00370 #if defined(__ARMCC_VERSION) || defined(__ICCARM__) 00371 /* Missing stat.h defines. 00372 * The following are sys/stat.h definitions not currently present in the ARMCC 00373 * errno.h. Note, ARMCC errno.h defines some symbol values differing from 00374 * GCC_ARM/IAR/standard POSIX definitions. Guard against this and future 00375 * changes by changing the symbol definition for filesystem use. 00376 */ 00377 #define _IFMT 0170000 //< type of file 00378 #define _IFSOCK 0140000 //< socket 00379 #define _IFLNK 0120000 //< symbolic link 00380 #define _IFREG 0100000 //< regular 00381 #define _IFBLK 0060000 //< block special 00382 #define _IFDIR 0040000 //< directory 00383 #define _IFCHR 0020000 //< character special 00384 #define _IFIFO 0010000 //< fifo special 00385 00386 #define S_IFMT _IFMT //< type of file 00387 #define S_IFSOCK _IFSOCK //< socket 00388 #define S_IFLNK _IFLNK //< symbolic link 00389 #define S_IFREG _IFREG //< regular 00390 #define S_IFBLK _IFBLK //< block special 00391 #define S_IFDIR _IFDIR //< directory 00392 #define S_IFCHR _IFCHR //< character special 00393 #define S_IFIFO _IFIFO //< fifo special 00394 00395 #define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR) 00396 #define S_IRUSR 0000400 ///< read permission, owner 00397 #define S_IWUSR 0000200 ///< write permission, owner 00398 #define S_IXUSR 0000100 ///< execute/search permission, owner 00399 #define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP) 00400 #define S_IRGRP 0000040 ///< read permission, group 00401 #define S_IWGRP 0000020 ///< write permission, grougroup 00402 #define S_IXGRP 0000010 ///< execute/search permission, group 00403 #define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH) 00404 #define S_IROTH 0000004 ///< read permission, other 00405 #define S_IWOTH 0000002 ///< write permission, other 00406 #define S_IXOTH 0000001 ///< execute/search permission, other 00407 00408 /* Refer to sys/stat standard 00409 * Note: Not all fields may be supported by the underlying filesystem 00410 */ 00411 struct stat { 00412 dev_t st_dev; ///< Device ID containing file 00413 ino_t st_ino; ///< File serial number 00414 mode_t st_mode; ///< Mode of file 00415 nlink_t st_nlink; ///< Number of links to file 00416 00417 uid_t st_uid; ///< User ID 00418 gid_t st_gid; ///< Group ID 00419 00420 off_t st_size; ///< Size of file in bytes 00421 00422 time_t st_atime; ///< Time of last access 00423 time_t st_mtime; ///< Time of last data modification 00424 time_t st_ctime; ///< Time of last status change 00425 }; 00426 00427 #endif /* defined(__ARMCC_VERSION) || defined(__ICCARM__) */ 00428 00429 00430 /* The following are dirent.h definitions are declared here to garuntee 00431 * consistency where structure may be different with different toolchains 00432 */ 00433 struct dirent { 00434 char d_name[NAME_MAX+1]; ///< Name of file 00435 uint8_t d_type; ///< Type of file 00436 }; 00437 00438 enum { 00439 DT_UNKNOWN, ///< The file type could not be determined. 00440 DT_FIFO, ///< This is a named pipe (FIFO). 00441 DT_CHR, ///< This is a character device. 00442 DT_DIR, ///< This is a directory. 00443 DT_BLK, ///< This is a block device. 00444 DT_REG, ///< This is a regular file. 00445 DT_LNK, ///< This is a symbolic link. 00446 DT_SOCK, ///< This is a UNIX domain socket. 00447 }; 00448 00449 /**@}*/ 00450 00451 /**@}*/ 00452 00453 #endif /* RETARGET_H */
Generated on Tue Jul 12 2022 20:08:03 by
1.7.2
