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

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.