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