Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mbed_retarget.h Source File

mbed_retarget.h

00001 /*
00002  * mbed Microcontroller Library
00003  * Copyright (c) 2006-2019 ARM Limited
00004  * SPDX-License-Identifier: Apache-2.0
00005  *
00006  * Licensed under the Apache License, Version 2.0 (the "License");
00007  * you may not use this file except in compliance with the License.
00008  * You may obtain a copy of the License at
00009  *
00010  *     http://www.apache.org/licenses/LICENSE-2.0
00011  *
00012  * Unless required by applicable law or agreed to in writing, software
00013  * distributed under the License is distributed on an "AS IS" BASIS,
00014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  * See the License for the specific language governing permissions and
00016  * limitations under the License.
00017  *
00018  */
00019 
00020 #ifndef RETARGET_H
00021 #define RETARGET_H
00022 
00023 #if __cplusplus
00024 #include <cstdio>
00025 #else
00026 #include <stdio.h>
00027 #endif //__cplusplus
00028 #include <stdint.h>
00029 #include <stddef.h>
00030 
00031 /* Include logic for errno so we can get errno defined but not bring in error_t,
00032  * including errno here prevents an include later, which would redefine our
00033  * error codes
00034  */
00035 #ifndef __error_t_defined
00036 #define __error_t_defined 1
00037 #include <errno.h>
00038 #undef __error_t_defined
00039 #else
00040 #include <errno.h>
00041 #endif
00042 
00043 /* We can get the following standard types from sys/types for gcc, but we
00044  * need to define the types ourselves for the other compilers that normally
00045  * target embedded systems */
00046 typedef signed   int  ssize_t;  ///< Signed size type, usually encodes negative errors
00047 typedef signed   long off_t;    ///< Offset in a data stream
00048 typedef unsigned int  nfds_t;   ///< Number of file descriptors
00049 typedef unsigned long long fsblkcnt_t;  ///< Count of file system blocks
00050 #if defined(__ARMCC_VERSION) || !defined(__GNUC__)
00051 typedef unsigned int  mode_t;   ///< Mode for opening files
00052 typedef unsigned int  dev_t;    ///< Device ID type
00053 typedef unsigned long ino_t;    ///< File serial number
00054 typedef unsigned int  nlink_t;  ///< Number of links to a file
00055 typedef unsigned int  uid_t;    ///< User ID
00056 typedef unsigned int  gid_t;    ///< Group ID
00057 #endif
00058 
00059 /* Flags for open() and fcntl(GETFL/SETFL)
00060  * At present, fcntl only supports reading and writing O_NONBLOCK
00061  */
00062 #define O_RDONLY 0        ///< Open for reading
00063 #define O_WRONLY 1        ///< Open for writing
00064 #define O_RDWR   2        ///< Open for reading and writing
00065 #define O_NONBLOCK 0x0004 ///< Non-blocking mode
00066 #define O_APPEND   0x0008 ///< Set file offset to end of file prior to each write
00067 #define O_CREAT    0x0200 ///< Create file if it does not exist
00068 #define O_TRUNC    0x0400 ///< Truncate file to zero length
00069 #define O_EXCL     0x0800 ///< Fail if file exists
00070 #define O_BINARY   0x8000 ///< Open file in binary mode
00071 
00072 #define O_ACCMODE   (O_RDONLY|O_WRONLY|O_RDWR)
00073 
00074 #define NAME_MAX 255    ///< Maximum size of a name in a file path
00075 
00076 #define STDIN_FILENO  0
00077 #define STDOUT_FILENO 1
00078 #define STDERR_FILENO 2
00079 
00080 #include <time.h>
00081 
00082 /** \addtogroup platform-public-api */
00083 /** @{*/
00084 
00085 #if !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
00086 /**
00087  * \defgroup platform_retarget Retarget functions
00088  * @{
00089  */
00090 
00091 /* DIR declarations must also be here */
00092 #if __cplusplus
00093 namespace mbed {
00094 class FileHandle;
00095 class DirHandle;
00096 
00097 /** Targets may implement this to change stdin, stdout, stderr.
00098  *
00099  * If the application hasn't provided mbed_override_console, this is called
00100  * to give the target a chance to specify a FileHandle for the console.
00101  *
00102  * If this is not provided or returns NULL, the console will be:
00103  *   - UARTSerial if configuration option "platform.stdio-buffered-serial" is
00104  *     true and the target has DEVICE_SERIAL;
00105  *   - Raw HAL serial via serial_getc and serial_putc if
00106  *     "platform.stdio-buffered-serial" is false and the target has DEVICE_SERIAL;
00107  *   - stdout/stderr will be a sink and stdin will input a stream of 0s if the
00108  *     target does not have DEVICE_SERIAL.
00109  *
00110  * @param fd file descriptor - STDIN_FILENO, STDOUT_FILENO or STDERR_FILENO
00111  * @return  pointer to FileHandle to override normal stream otherwise NULL
00112  */
00113 FileHandle *mbed_target_override_console(int fd);
00114 
00115 /** Applications may implement this to change stdin, stdout, stderr.
00116  *
00117  * This hook gives the application a chance to specify a custom FileHandle
00118  * for the console.
00119  *
00120  * If this is not provided or returns NULL, the console will be specified
00121  * by mbed_target_override_console, else will default to serial - see
00122  * mbed_target_override_console for more details.
00123  *
00124  * Example using UARTSerial:
00125  * @code
00126  * FileHandle *mbed::mbed_override_console(int) {
00127  *     static UARTSerial my_serial(D0, D1);
00128  *     return &my_serial;
00129  * }
00130  * @endcode
00131  *
00132  * Example using SingleWireOutput:
00133  * @code
00134  * FileHandle *mbed::mbed_override_console(int) {
00135  *     static SerialWireOutput swo;
00136  *     return &swo;
00137  * }
00138  * @endcode
00139  *
00140  * Example using arm semihosting:
00141  * @code
00142  * FileHandle *mbed::mbed_override_console(int fileno) {
00143  *    static LocalFileSystem fs("host");
00144  *    if (fileno == STDIN_FILENO) {
00145  *        static FileHandle *in_terminal;
00146  *        static int in_open_result = fs.open(&in_terminal, ":tt", O_RDONLY);
00147  *        return in_terminal;
00148  *    } else {
00149  *        static FileHandle *out_terminal;
00150  *        static int out_open_result = fs.open(&out_terminal, ":tt", O_WRONLY);
00151  *        return out_terminal;
00152  *    }
00153  * }
00154  * @endcode
00155  *
00156  * @param fd file descriptor - STDIN_FILENO, STDOUT_FILENO or STDERR_FILENO
00157  * @return  pointer to FileHandle to override normal stream otherwise NULL
00158  */
00159 FileHandle *mbed_override_console(int fd);
00160 
00161 /** Look up the Mbed file handle corresponding to a file descriptor
00162  *
00163  * This conversion function permits an application to find the underlying
00164  * FileHandle object corresponding to a POSIX file descriptor.
00165  *
00166  * This allows access to specialized behavior only available via the
00167  * FileHandle API.
00168  *
00169  * Example of saving power by disabling console input - for buffered serial,
00170  * this would release the RX interrupt handler, which would release the
00171  * deep sleep lock.
00172  * @code
00173  * mbed_file_handle(STDIN_FILENO)->enable_input(false);
00174  * @endcode
00175  *
00176  * @param fd file descriptor
00177  * @return   FileHandle pointer
00178  *           NULL if descriptor does not correspond to a FileHandle (only
00179  *           possible if it's not open with current implementation).
00180  */
00181 FileHandle *mbed_file_handle(int fd);
00182 }
00183 
00184 typedef mbed::DirHandle DIR;
00185 #else
00186 typedef struct Dir DIR;
00187 #endif
00188 #endif // !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
00189 
00190 /* The intent of this section is to unify the errno error values to match
00191  * the POSIX definitions for the GCC_ARM, ARMCC and IAR compilers. This is
00192  * necessary because the ARMCC/IAR errno.h, or sys/stat.h are missing some
00193  * symbol definitions used by the POSIX filesystem API to return errno codes.
00194  * Note also that ARMCC errno.h defines some symbol values differently from
00195  * the GCC_ARM/IAR/standard POSIX definitions. The definitions guard against
00196  * this and future changes by changing the symbol definition as shown below.
00197  */
00198 #undef  EPERM
00199 #define EPERM           1       /* Operation not permitted */
00200 #undef  ENOENT
00201 #define ENOENT          2       /* No such file or directory */
00202 #undef  ESRCH
00203 #define ESRCH           3       /* No such process */
00204 #undef  EINTR
00205 #define EINTR           4       /* Interrupted system call */
00206 #undef  EIO
00207 #define EIO             5       /* I/O error */
00208 #undef  ENXIO
00209 #define ENXIO           6       /* No such device or address */
00210 #undef  E2BIG
00211 #define E2BIG           7       /* Argument list too long */
00212 #undef  ENOEXEC
00213 #define ENOEXEC         8       /* Exec format error */
00214 #undef  EBADF
00215 #define EBADF           9       /* Bad file number */
00216 #undef  ECHILD
00217 #define ECHILD          10      /* No child processes */
00218 #undef  EAGAIN
00219 #define EAGAIN          11      /* Try again */
00220 #undef  ENOMEM
00221 #define ENOMEM          12      /* Out of memory */
00222 #undef  EACCES
00223 #define EACCES          13      /* Permission denied */
00224 #undef  EFAULT
00225 #define EFAULT          14      /* Bad address */
00226 #undef  ENOTBLK
00227 #define ENOTBLK         15      /* Block device required */
00228 #undef  EBUSY
00229 #define EBUSY           16      /* Device or resource busy */
00230 #undef  EEXIST
00231 #define EEXIST          17      /* File exists */
00232 #undef  EXDEV
00233 #define EXDEV           18      /* Cross-device link */
00234 #undef  ENODEV
00235 #define ENODEV          19      /* No such device */
00236 #undef  ENOTDIR
00237 #define ENOTDIR         20      /* Not a directory */
00238 #undef  EISDIR
00239 #define EISDIR          21      /* Is a directory */
00240 #undef  EINVAL
00241 #define EINVAL          22      /* Invalid argument */
00242 #undef  ENFILE
00243 #define ENFILE          23      /* File table overflow */
00244 #undef  EMFILE
00245 #define EMFILE          24      /* Too many open files */
00246 #undef  ENOTTY
00247 #define ENOTTY          25      /* Not a typewriter */
00248 #undef  ETXTBSY
00249 #define ETXTBSY         26      /* Text file busy */
00250 #undef  EFBIG
00251 #define EFBIG           27      /* File too large */
00252 #undef  ENOSPC
00253 #define ENOSPC          28      /* No space left on device */
00254 #undef  ESPIPE
00255 #define ESPIPE          29      /* Illegal seek */
00256 #undef  EROFS
00257 #define EROFS           30      /* Read-only file system */
00258 #undef  EMLINK
00259 #define EMLINK          31      /* Too many links */
00260 #undef  EPIPE
00261 #define EPIPE           32      /* Broken pipe */
00262 #undef  EDOM
00263 #define EDOM            33      /* Math argument out of domain of func */
00264 #undef  ERANGE
00265 #define ERANGE          34      /* Math result not representable */
00266 #undef  EDEADLK
00267 #define EDEADLK         35      /* Resource deadlock would occur */
00268 #undef  ENAMETOOLONG
00269 #define ENAMETOOLONG    36      /* File name too long */
00270 #undef  ENOLCK
00271 #define ENOLCK          37      /* No record locks available */
00272 #undef  ENOSYS
00273 #define ENOSYS          38      /* Function not implemented */
00274 #undef  ENOTEMPTY
00275 #define ENOTEMPTY       39      /* Directory not empty */
00276 #undef  ELOOP
00277 #define ELOOP           40      /* Too many symbolic links encountered */
00278 #undef  EWOULDBLOCK
00279 #define EWOULDBLOCK     EAGAIN  /* Operation would block */
00280 #undef  ENOMSG
00281 #define ENOMSG          42      /* No message of desired type */
00282 #undef  EIDRM
00283 #define EIDRM           43      /* Identifier removed */
00284 #undef  ECHRNG
00285 #define ECHRNG          44      /* Channel number out of range */
00286 #undef  EL2NSYNC
00287 #define EL2NSYNC        45      /* Level 2 not synchronized */
00288 #undef  EL3HLT
00289 #define EL3HLT          46      /* Level 3 halted */
00290 #undef  EL3RST
00291 #define EL3RST          47      /* Level 3 reset */
00292 #undef  ELNRNG
00293 #define ELNRNG          48      /* Link number out of range */
00294 #undef  EUNATCH
00295 #define EUNATCH         49      /* Protocol driver not attached */
00296 #undef  ENOCSI
00297 #define ENOCSI          50      /* No CSI structure available */
00298 #undef  EL2HLT
00299 #define EL2HLT          51      /* Level 2 halted */
00300 #undef  EBADE
00301 #define EBADE           52      /* Invalid exchange */
00302 #undef  EBADR
00303 #define EBADR           53      /* Invalid request descriptor */
00304 #undef  EXFULL
00305 #define EXFULL          54      /* Exchange full */
00306 #undef  ENOANO
00307 #define ENOANO          55      /* No anode */
00308 #undef  EBADRQC
00309 #define EBADRQC         56      /* Invalid request code */
00310 #undef  EBADSLT
00311 #define EBADSLT         57      /* Invalid slot */
00312 #undef  EDEADLOCK
00313 #define EDEADLOCK       EDEADLK /* Resource deadlock would occur */
00314 #undef  EBFONT
00315 #define EBFONT          59      /* Bad font file format */
00316 #undef  ENOSTR
00317 #define ENOSTR          60      /* Device not a stream */
00318 #undef  ENODATA
00319 #define ENODATA         61      /* No data available */
00320 #undef  ETIME
00321 #define ETIME           62      /* Timer expired */
00322 #undef  ENOSR
00323 #define ENOSR           63      /* Out of streams resources */
00324 #undef  ENONET
00325 #define ENONET          64      /* Machine is not on the network */
00326 #undef  ENOPKG
00327 #define ENOPKG          65      /* Package not installed */
00328 #undef  EREMOTE
00329 #define EREMOTE         66      /* Object is remote */
00330 #undef  ENOLINK
00331 #define ENOLINK         67      /* Link has been severed */
00332 #undef  EADV
00333 #define EADV            68      /* Advertise error */
00334 #undef  ESRMNT
00335 #define ESRMNT          69      /* Srmount error */
00336 #undef  ECOMM
00337 #define ECOMM           70      /* Communication error on send */
00338 #undef  EPROTO
00339 #define EPROTO          71      /* Protocol error */
00340 #undef  EMULTIHOP
00341 #define EMULTIHOP       72      /* Multihop attempted */
00342 #undef  EDOTDOT
00343 #define EDOTDOT         73      /* RFS specific error */
00344 #undef  EBADMSG
00345 #define EBADMSG         74      /* Not a data message */
00346 #undef  EOVERFLOW
00347 #define EOVERFLOW       75      /* Value too large for defined data type */
00348 #undef  ENOTUNIQ
00349 #define ENOTUNIQ        76      /* Name not unique on network */
00350 #undef  EBADFD
00351 #define EBADFD          77      /* File descriptor in bad state */
00352 #undef  EREMCHG
00353 #define EREMCHG         78      /* Remote address changed */
00354 #undef  ELIBACC
00355 #define ELIBACC         79      /* Can not access a needed shared library */
00356 #undef  ELIBBAD
00357 #define ELIBBAD         80      /* Accessing a corrupted shared library */
00358 #undef  ELIBSCN
00359 #define ELIBSCN         81      /* .lib section in a.out corrupted */
00360 #undef  ELIBMAX
00361 #define ELIBMAX         82      /* Attempting to link in too many shared libraries */
00362 #undef  ELIBEXEC
00363 #define ELIBEXEC        83      /* Cannot exec a shared library directly */
00364 #undef  EILSEQ
00365 #define EILSEQ          84      /* Illegal byte sequence */
00366 #undef  ERESTART
00367 #define ERESTART        85      /* Interrupted system call should be restarted */
00368 #undef  ESTRPIPE
00369 #define ESTRPIPE        86      /* Streams pipe error */
00370 #undef  EUSERS
00371 #define EUSERS          87      /* Too many users */
00372 #undef  ENOTSOCK
00373 #define ENOTSOCK        88      /* Socket operation on non-socket */
00374 #undef  EDESTADDRREQ
00375 #define EDESTADDRREQ    89      /* Destination address required */
00376 #undef  EMSGSIZE
00377 #define EMSGSIZE        90      /* Message too long */
00378 #undef  EPROTOTYPE
00379 #define EPROTOTYPE      91      /* Protocol wrong type for socket */
00380 #undef  ENOPROTOOPT
00381 #define ENOPROTOOPT     92      /* Protocol not available */
00382 #undef  EPROTONOSUPPORT
00383 #define EPROTONOSUPPORT 93      /* Protocol not supported */
00384 #undef  ESOCKTNOSUPPORT
00385 #define ESOCKTNOSUPPORT 94      /* Socket type not supported */
00386 #undef  EOPNOTSUPP
00387 #define EOPNOTSUPP      95      /* Operation not supported on transport endpoint */
00388 #undef  EPFNOSUPPORT
00389 #define EPFNOSUPPORT    96      /* Protocol family not supported */
00390 #undef  EAFNOSUPPORT
00391 #define EAFNOSUPPORT    97      /* Address family not supported by protocol */
00392 #undef  EADDRINUSE
00393 #define EADDRINUSE      98      /* Address already in use */
00394 #undef  EADDRNOTAVAIL
00395 #define EADDRNOTAVAIL   99      /* Cannot assign requested address */
00396 #undef  ENETDOWN
00397 #define ENETDOWN        100     /* Network is down */
00398 #undef  ENETUNREACH
00399 #define ENETUNREACH     101     /* Network is unreachable */
00400 #undef  ENETRESET
00401 #define ENETRESET       102     /* Network dropped connection because of reset */
00402 #undef  ECONNABORTED
00403 #define ECONNABORTED    103     /* Software caused connection abort */
00404 #undef  ECONNRESET
00405 #define ECONNRESET      104     /* Connection reset by peer */
00406 #undef  ENOBUFS
00407 #define ENOBUFS         105     /* No buffer space available */
00408 #undef  EISCONN
00409 #define EISCONN         106     /* Transport endpoint is already connected */
00410 #undef  ENOTCONN
00411 #define ENOTCONN        107     /* Transport endpoint is not connected */
00412 #undef  ESHUTDOWN
00413 #define ESHUTDOWN       108     /* Cannot send after transport endpoint shutdown */
00414 #undef  ETOOMANYREFS
00415 #define ETOOMANYREFS    109     /* Too many references: cannot splice */
00416 #undef  ETIMEDOUT
00417 #define ETIMEDOUT       110     /* Connection timed out */
00418 #undef  ECONNREFUSED
00419 #define ECONNREFUSED    111     /* Connection refused */
00420 #undef  EHOSTDOWN
00421 #define EHOSTDOWN       112     /* Host is down */
00422 #undef  EHOSTUNREACH
00423 #define EHOSTUNREACH    113     /* No route to host */
00424 #undef  EALREADY
00425 #define EALREADY        114     /* Operation already in progress */
00426 #undef  EINPROGRESS
00427 #define EINPROGRESS     115     /* Operation now in progress */
00428 #undef  ESTALE
00429 #define ESTALE          116     /* Stale NFS file handle */
00430 #undef  EUCLEAN
00431 #define EUCLEAN         117     /* Structure needs cleaning */
00432 #undef  ENOTNAM
00433 #define ENOTNAM         118     /* Not a XENIX named type file */
00434 #undef  ENAVAIL
00435 #define ENAVAIL         119     /* No XENIX semaphores available */
00436 #undef  EISNAM
00437 #define EISNAM          120     /* Is a named type file */
00438 #undef  EREMOTEIO
00439 #define EREMOTEIO       121     /* Remote I/O error */
00440 #undef  EDQUOT
00441 #define EDQUOT          122     /* Quota exceeded */
00442 #undef  ENOMEDIUM
00443 #define ENOMEDIUM       123     /* No medium found */
00444 #undef  EMEDIUMTYPE
00445 #define EMEDIUMTYPE     124     /* Wrong medium type */
00446 #undef  ECANCELED
00447 #define ECANCELED       125     /* Operation Canceled */
00448 #undef  ENOKEY
00449 #define ENOKEY          126     /* Required key not available */
00450 #undef  EKEYEXPIRED
00451 #define EKEYEXPIRED     127     /* Key has expired */
00452 #undef  EKEYREVOKED
00453 #define EKEYREVOKED     128     /* Key has been revoked */
00454 #undef  EKEYREJECTED
00455 #define EKEYREJECTED    129     /* Key was rejected by service */
00456 #undef  EOWNERDEAD
00457 #define EOWNERDEAD      130     /* Owner died */
00458 #undef  ENOTRECOVERABLE
00459 #define ENOTRECOVERABLE 131     /* State not recoverable */
00460 
00461 /* Missing stat.h defines.
00462  * The following are sys/stat.h definitions not currently present in the ARMCC
00463  * errno.h. Note, ARMCC errno.h defines some symbol values differing from
00464  * GCC_ARM/IAR/standard POSIX definitions. Guard against this and future
00465  * changes by changing the symbol definition for filesystem use.
00466  */
00467 #define     _IFMT   0170000 //< type of file
00468 #define     _IFSOCK 0140000 //< socket
00469 #define     _IFLNK  0120000 //< symbolic link
00470 #define     _IFREG  0100000 //< regular
00471 #define     _IFBLK  0060000 //< block special
00472 #define     _IFDIR  0040000 //< directory
00473 #define     _IFCHR  0020000 //< character special
00474 #define     _IFIFO  0010000 //< fifo special
00475 
00476 #define S_IFMT      _IFMT   //< type of file
00477 #define S_IFSOCK    _IFSOCK //< socket
00478 #define S_IFLNK     _IFLNK  //< symbolic link
00479 #define S_IFREG     _IFREG  //< regular
00480 #define S_IFBLK     _IFBLK  //< block special
00481 #define S_IFDIR     _IFDIR  //< directory
00482 #define S_IFCHR     _IFCHR  //< character special
00483 #define S_IFIFO     _IFIFO  //< fifo special
00484 
00485 #define S_IRWXU     (S_IRUSR | S_IWUSR | S_IXUSR)
00486 #define     S_IRUSR 0000400 ///< read permission, owner
00487 #define     S_IWUSR 0000200 ///< write permission, owner
00488 #define     S_IXUSR 0000100 ///< execute/search permission, owner
00489 #define S_IRWXG     (S_IRGRP | S_IWGRP | S_IXGRP)
00490 #define     S_IRGRP 0000040 ///< read permission, group
00491 #define     S_IWGRP 0000020 ///< write permission, group
00492 #define     S_IXGRP 0000010 ///< execute/search permission, group
00493 #define S_IRWXO     (S_IROTH | S_IWOTH | S_IXOTH)
00494 #define     S_IROTH 0000004 ///< read permission, other
00495 #define     S_IWOTH 0000002 ///< write permission, other
00496 #define     S_IXOTH 0000001 ///< execute/search permission, other
00497 
00498 /* Refer to sys/stat standard
00499  * Note: Not all fields may be supported by the underlying filesystem
00500  */
00501 struct stat {
00502     dev_t     st_dev;     ///< Device ID containing file
00503     ino_t     st_ino;     ///< File serial number
00504     mode_t    st_mode;    ///< Mode of file
00505     nlink_t   st_nlink;   ///< Number of links to file
00506 
00507     uid_t     st_uid;     ///< User ID
00508     gid_t     st_gid;     ///< Group ID
00509 
00510     off_t     st_size;    ///< Size of file in bytes
00511 
00512     time_t    st_atime;   ///< Time of last access
00513     time_t    st_mtime;   ///< Time of last data modification
00514     time_t    st_ctime;   ///< Time of last status change
00515 };
00516 
00517 struct statvfs {
00518     unsigned long  f_bsize;    ///< Filesystem block size
00519     unsigned long  f_frsize;   ///< Fragment size (block size)
00520 
00521     fsblkcnt_t     f_blocks;   ///< Number of blocks
00522     fsblkcnt_t     f_bfree;    ///< Number of free blocks
00523     fsblkcnt_t     f_bavail;   ///< Number of free blocks for unprivileged users
00524 
00525     unsigned long  f_fsid;     ///< Filesystem ID
00526 
00527     unsigned long  f_namemax;  ///< Maximum filename length
00528 };
00529 
00530 /* The following are dirent.h definitions are declared here to guarantee
00531  * consistency where structure may be different with different toolchains
00532  */
00533 struct dirent {
00534     char d_name[NAME_MAX + 1]; ///< Name of file
00535     uint8_t d_type;          ///< Type of file
00536 };
00537 
00538 enum {
00539     DT_UNKNOWN, ///< The file type could not be determined.
00540     DT_FIFO,    ///< This is a named pipe (FIFO).
00541     DT_CHR,     ///< This is a character device.
00542     DT_DIR,     ///< This is a directory.
00543     DT_BLK,     ///< This is a block device.
00544     DT_REG,     ///< This is a regular file.
00545     DT_LNK,     ///< This is a symbolic link.
00546     DT_SOCK,    ///< This is a UNIX domain socket.
00547 };
00548 
00549 /* fcntl.h defines */
00550 #define F_GETFL 3
00551 #define F_SETFL 4
00552 
00553 struct pollfd {
00554     int fd;
00555     short events;
00556     short revents;
00557 };
00558 
00559 /* POSIX-compatible I/O functions */
00560 #if __cplusplus
00561 extern "C" {
00562 #endif
00563 #if !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
00564     int open(const char *path, int oflag, ...);
00565 #ifndef __IAR_SYSTEMS_ICC__ /* IAR provides fdopen itself */
00566 #if __cplusplus
00567     std::FILE *fdopen(int fildes, const char *mode);
00568 #else
00569     FILE *fdopen(int fildes, const char *mode);
00570 #endif
00571 #endif
00572 #endif // !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
00573     ssize_t write(int fildes, const void *buf, size_t nbyte);
00574     ssize_t read(int fildes, void *buf, size_t nbyte);
00575     int fsync(int fildes);
00576     int isatty(int fildes);
00577 #if !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
00578     off_t lseek(int fildes, off_t offset, int whence);
00579     int ftruncate(int fildes, off_t length);
00580     int fstat(int fildes, struct stat *st);
00581     int fcntl(int fildes, int cmd, ...);
00582     int poll(struct pollfd fds[], nfds_t nfds, int timeout);
00583     int close(int fildes);
00584     int stat(const char *path, struct stat *st);
00585     int statvfs(const char *path, struct statvfs *buf);
00586     DIR *opendir(const char *);
00587     struct dirent *readdir(DIR *);
00588     int closedir(DIR *);
00589     void rewinddir(DIR *);
00590     long telldir(DIR *);
00591     void seekdir(DIR *, long);
00592     int mkdir(const char *name, mode_t n);
00593 #endif // !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
00594 #if __cplusplus
00595 }; // extern "C"
00596 
00597 namespace mbed {
00598 #if !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
00599 /** This call is an analogue to POSIX fdopen().
00600  *
00601  *  It associates a C stream to an already-opened FileHandle, to allow you to
00602  *  use C printf/scanf/fwrite etc. The provided FileHandle must remain open -
00603  *  it will be closed by the C library when fclose(FILE) is called.
00604  *
00605  *  The net effect is fdopen(bind_to_fd(fh), mode), with error handling.
00606  *
00607  *  @param fh       a pointer to an opened FileHandle
00608  *  @param mode     operation upon the file descriptor, e.g., "w+"
00609  *
00610  *  @returns        a pointer to FILE
00611  */
00612 std::FILE *fdopen(mbed::FileHandle *fh, const char *mode);
00613 
00614 /** Bind an mbed FileHandle to a POSIX file descriptor
00615  *
00616  * This is similar to fdopen, but only operating at the POSIX layer - it
00617  * associates a POSIX integer file descriptor with a FileHandle, to allow you
00618  * to use POSIX read/write calls etc. The provided FileHandle must remain open -
00619  * it will be closed when close(int) is called.
00620  *
00621  *  @param fh       a pointer to an opened FileHandle
00622  *
00623  *  @return         an integer file descriptor, or negative if no descriptors available
00624  */
00625 int bind_to_fd(mbed::FileHandle *fh);
00626 
00627 #else
00628 /** Targets may implement this to override how to write to the console.
00629  *
00630  * If the target has provided minimal_console_putc, this is called
00631  * to give the target a chance to specify an alternative minimal console.
00632  *
00633  * If this is not provided, serial_putc will be used if
00634  * `target.console-uart` is `true`, else there will not be an output.
00635  *
00636  *  @param c   The char to write
00637  *  @return    The written char
00638  */
00639 int minimal_console_putc(int c);
00640 
00641 /** Targets may implement this to override how to read from the console.
00642  *
00643  * If the target has provided minimal_console_getc, this is called
00644  * to give the target a chance to specify an alternative minimal console.
00645  *
00646  * If this is not provided, serial_getc will be used if
00647  * `target.console-uart` is `true`, else no input would be captured.
00648  *
00649  *  @return  The char read from the serial port
00650  */
00651 int minimal_console_getc();
00652 #endif // !MBED_CONF_PLATFORM_STDIO_MINIMAL_CONSOLE_ONLY
00653 
00654 } // namespace mbed
00655 
00656 #endif // __cplusplus
00657 
00658 /**@}*/
00659 
00660 /**@}*/
00661 
00662 #endif /* RETARGET_H */