mbed_retarget.h 21 KB

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