SLRE(Super Light Regular Expression library) Unit Test Code.

Dependencies:   mbed

Committer:
monpetit
Date:
Thu Jul 28 08:10:30 2016 +0000
Revision:
0:3ca3835f816e
initial commit: unit tests are passed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
monpetit 0:3ca3835f816e 1 /*-----------------------------------------------------------------------------
monpetit 0:3ca3835f816e 2 * Name: retarget_io.c
monpetit 0:3ca3835f816e 3 * Purpose: Retarget I/O
monpetit 0:3ca3835f816e 4 * Rev.: 1.1.0
monpetit 0:3ca3835f816e 5 *-----------------------------------------------------------------------------*/
monpetit 0:3ca3835f816e 6
monpetit 0:3ca3835f816e 7 /* Copyright (c) 2013 - 2015 ARM LIMITED
monpetit 0:3ca3835f816e 8
monpetit 0:3ca3835f816e 9 All rights reserved.
monpetit 0:3ca3835f816e 10 Redistribution and use in source and binary forms, with or without
monpetit 0:3ca3835f816e 11 modification, are permitted provided that the following conditions are met:
monpetit 0:3ca3835f816e 12 - Redistributions of source code must retain the above copyright
monpetit 0:3ca3835f816e 13 notice, this list of conditions and the following disclaimer.
monpetit 0:3ca3835f816e 14 - Redistributions in binary form must reproduce the above copyright
monpetit 0:3ca3835f816e 15 notice, this list of conditions and the following disclaimer in the
monpetit 0:3ca3835f816e 16 documentation and/or other materials provided with the distribution.
monpetit 0:3ca3835f816e 17 - Neither the name of ARM nor the names of its contributors may be used
monpetit 0:3ca3835f816e 18 to endorse or promote products derived from this software without
monpetit 0:3ca3835f816e 19 specific prior written permission.
monpetit 0:3ca3835f816e 20 *
monpetit 0:3ca3835f816e 21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
monpetit 0:3ca3835f816e 22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
monpetit 0:3ca3835f816e 23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
monpetit 0:3ca3835f816e 24 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
monpetit 0:3ca3835f816e 25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
monpetit 0:3ca3835f816e 26 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
monpetit 0:3ca3835f816e 27 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
monpetit 0:3ca3835f816e 28 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
monpetit 0:3ca3835f816e 29 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
monpetit 0:3ca3835f816e 30 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
monpetit 0:3ca3835f816e 31 POSSIBILITY OF SUCH DAMAGE.
monpetit 0:3ca3835f816e 32 ---------------------------------------------------------------------------*/
monpetit 0:3ca3835f816e 33
monpetit 0:3ca3835f816e 34 #include <string.h>
monpetit 0:3ca3835f816e 35 #include <stdint.h>
monpetit 0:3ca3835f816e 36 #include <stdio.h>
monpetit 0:3ca3835f816e 37 #include <stdlib.h>
monpetit 0:3ca3835f816e 38 #include <assert.h>
monpetit 0:3ca3835f816e 39 #include <rt_sys.h>
monpetit 0:3ca3835f816e 40
monpetit 0:3ca3835f816e 41 // #include "RTE_Components.h"
monpetit 0:3ca3835f816e 42 #define RTE_Compiler_IO_STDOUT /* Compiler I/O: STDOUT */
monpetit 0:3ca3835f816e 43 #define RTE_Compiler_IO_STDOUT_User /* Compiler I/O: STDOUT User */
monpetit 0:3ca3835f816e 44 #include "SEGGER_RTT.h"
monpetit 0:3ca3835f816e 45
monpetit 0:3ca3835f816e 46 #ifdef RTE_Compiler_IO_File_FS
monpetit 0:3ca3835f816e 47 #include "rl_fs_lib.h"
monpetit 0:3ca3835f816e 48 #endif
monpetit 0:3ca3835f816e 49
monpetit 0:3ca3835f816e 50
monpetit 0:3ca3835f816e 51 #ifndef STDIN_ECHO
monpetit 0:3ca3835f816e 52 #define STDIN_ECHO 0 /* STDIN: echo to STDOUT */
monpetit 0:3ca3835f816e 53 #endif
monpetit 0:3ca3835f816e 54 #ifndef STDOUT_CR_LF
monpetit 0:3ca3835f816e 55 #define STDOUT_CR_LF 0 /* STDOUT: add CR for LF */
monpetit 0:3ca3835f816e 56 #endif
monpetit 0:3ca3835f816e 57 #ifndef STDERR_CR_LF
monpetit 0:3ca3835f816e 58 #define STDERR_CR_LF 0 /* STDERR: add CR for LF */
monpetit 0:3ca3835f816e 59 #endif
monpetit 0:3ca3835f816e 60
monpetit 0:3ca3835f816e 61
monpetit 0:3ca3835f816e 62 #if (defined(RTE_Compiler_IO_TTY_ITM) || \
monpetit 0:3ca3835f816e 63 defined(RTE_Compiler_IO_STDIN_ITM) || \
monpetit 0:3ca3835f816e 64 defined(RTE_Compiler_IO_STDOUT_ITM) || \
monpetit 0:3ca3835f816e 65 defined(RTE_Compiler_IO_STDERR_ITM))
monpetit 0:3ca3835f816e 66
monpetit 0:3ca3835f816e 67 /* ITM registers */
monpetit 0:3ca3835f816e 68 #define ITM_PORT0_U8 (*((volatile uint8_t *)0xE0000000))
monpetit 0:3ca3835f816e 69 #define ITM_PORT0_U32 (*((volatile uint32_t *)0xE0000000))
monpetit 0:3ca3835f816e 70 #define ITM_TER (*((volatile uint32_t *)0xE0000E00))
monpetit 0:3ca3835f816e 71 #define ITM_TCR (*((volatile uint32_t *)0xE0000E80))
monpetit 0:3ca3835f816e 72
monpetit 0:3ca3835f816e 73 #define ITM_TCR_ITMENA_Msk (1UL << 0)
monpetit 0:3ca3835f816e 74
monpetit 0:3ca3835f816e 75 /*!< Value identifying \ref ITM_RxBuffer is ready for next character. */
monpetit 0:3ca3835f816e 76 #define ITM_RXBUFFER_EMPTY 0x5AA55AA5
monpetit 0:3ca3835f816e 77
monpetit 0:3ca3835f816e 78 /*!< Variable to receive characters. */
monpetit 0:3ca3835f816e 79 extern
monpetit 0:3ca3835f816e 80 volatile int32_t ITM_RxBuffer;
monpetit 0:3ca3835f816e 81 volatile int32_t ITM_RxBuffer = ITM_RXBUFFER_EMPTY;
monpetit 0:3ca3835f816e 82
monpetit 0:3ca3835f816e 83 /** \brief ITM Send Character
monpetit 0:3ca3835f816e 84
monpetit 0:3ca3835f816e 85 The function transmits a character via the ITM channel 0, and
monpetit 0:3ca3835f816e 86 \li Just returns when no debugger is connected that has booked the output.
monpetit 0:3ca3835f816e 87 \li Is blocking when a debugger is connected, but the previous character
monpetit 0:3ca3835f816e 88 sent has not been transmitted.
monpetit 0:3ca3835f816e 89
monpetit 0:3ca3835f816e 90 \param [in] ch Character to transmit.
monpetit 0:3ca3835f816e 91
monpetit 0:3ca3835f816e 92 \returns Character to transmit.
monpetit 0:3ca3835f816e 93 */
monpetit 0:3ca3835f816e 94 int32_t ITM_SendChar (int32_t ch);
monpetit 0:3ca3835f816e 95 int32_t ITM_SendChar (int32_t ch) {
monpetit 0:3ca3835f816e 96 if ((ITM_TCR & ITM_TCR_ITMENA_Msk) && /* ITM enabled */
monpetit 0:3ca3835f816e 97 (ITM_TER & (1UL << 0) )) { /* ITM Port #0 enabled */
monpetit 0:3ca3835f816e 98 while (ITM_PORT0_U32 == 0);
monpetit 0:3ca3835f816e 99 ITM_PORT0_U8 = (uint8_t)ch;
monpetit 0:3ca3835f816e 100 }
monpetit 0:3ca3835f816e 101 return (ch);
monpetit 0:3ca3835f816e 102 }
monpetit 0:3ca3835f816e 103
monpetit 0:3ca3835f816e 104 /** \brief ITM Receive Character
monpetit 0:3ca3835f816e 105
monpetit 0:3ca3835f816e 106 The function inputs a character via the external variable \ref ITM_RxBuffer.
monpetit 0:3ca3835f816e 107 This variable is monitored and altered by the debugger to provide input.
monpetit 0:3ca3835f816e 108
monpetit 0:3ca3835f816e 109 \return Received character.
monpetit 0:3ca3835f816e 110 \return -1 No character pending.
monpetit 0:3ca3835f816e 111 */
monpetit 0:3ca3835f816e 112 int32_t ITM_ReceiveChar (void);
monpetit 0:3ca3835f816e 113 int32_t ITM_ReceiveChar (void) {
monpetit 0:3ca3835f816e 114 int32_t ch = -1; /* no character available */
monpetit 0:3ca3835f816e 115
monpetit 0:3ca3835f816e 116 if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY) {
monpetit 0:3ca3835f816e 117 ch = ITM_RxBuffer;
monpetit 0:3ca3835f816e 118 ITM_RxBuffer = ITM_RXBUFFER_EMPTY; /* ready for next character */
monpetit 0:3ca3835f816e 119 }
monpetit 0:3ca3835f816e 120
monpetit 0:3ca3835f816e 121 return (ch);
monpetit 0:3ca3835f816e 122 }
monpetit 0:3ca3835f816e 123
monpetit 0:3ca3835f816e 124 #endif /* RTE_Compiler_IO_STDxxx_ITM */
monpetit 0:3ca3835f816e 125
monpetit 0:3ca3835f816e 126
monpetit 0:3ca3835f816e 127 /**
monpetit 0:3ca3835f816e 128 Get a character from the stdio
monpetit 0:3ca3835f816e 129
monpetit 0:3ca3835f816e 130 \return The next character from the input, or -1 on read error.
monpetit 0:3ca3835f816e 131 */
monpetit 0:3ca3835f816e 132 #if defined(RTE_Compiler_IO_STDIN)
monpetit 0:3ca3835f816e 133 #if defined(RTE_Compiler_IO_STDIN_User)
monpetit 0:3ca3835f816e 134 extern int stdin_getchar (void);
monpetit 0:3ca3835f816e 135 #elif defined(RTE_Compiler_IO_STDIN_ITM)
monpetit 0:3ca3835f816e 136 static int stdin_getchar (void) {
monpetit 0:3ca3835f816e 137 int32_t ch;
monpetit 0:3ca3835f816e 138
monpetit 0:3ca3835f816e 139 do {
monpetit 0:3ca3835f816e 140 ch = ITM_ReceiveChar();
monpetit 0:3ca3835f816e 141 } while (ch == -1);
monpetit 0:3ca3835f816e 142 return (ch);
monpetit 0:3ca3835f816e 143 }
monpetit 0:3ca3835f816e 144 #elif defined(RTE_Compiler_IO_STDIN_BKPT)
monpetit 0:3ca3835f816e 145 static int stdin_getchar (void) {
monpetit 0:3ca3835f816e 146 int32_t ch = -1;
monpetit 0:3ca3835f816e 147
monpetit 0:3ca3835f816e 148 __asm("BKPT 0");
monpetit 0:3ca3835f816e 149 return (ch);
monpetit 0:3ca3835f816e 150 }
monpetit 0:3ca3835f816e 151 #endif
monpetit 0:3ca3835f816e 152 #endif
monpetit 0:3ca3835f816e 153
monpetit 0:3ca3835f816e 154
monpetit 0:3ca3835f816e 155 /**
monpetit 0:3ca3835f816e 156 Put a character to the stdout
monpetit 0:3ca3835f816e 157
monpetit 0:3ca3835f816e 158 \param[in] ch Character to output
monpetit 0:3ca3835f816e 159 \return The character written, or -1 on write error.
monpetit 0:3ca3835f816e 160 */
monpetit 0:3ca3835f816e 161 #if defined(RTE_Compiler_IO_STDOUT)
monpetit 0:3ca3835f816e 162 #if defined(RTE_Compiler_IO_STDOUT_User)
monpetit 0:3ca3835f816e 163 // extern int stdout_putchar (int ch);
monpetit 0:3ca3835f816e 164 static int stdout_putchar (int ch)
monpetit 0:3ca3835f816e 165 {
monpetit 0:3ca3835f816e 166 unsigned char c = (unsigned char)ch;
monpetit 0:3ca3835f816e 167 SEGGER_RTT_Write(0, (const void*)&c, 1);
monpetit 0:3ca3835f816e 168 return ch;
monpetit 0:3ca3835f816e 169 }
monpetit 0:3ca3835f816e 170
monpetit 0:3ca3835f816e 171 #elif defined(RTE_Compiler_IO_STDOUT_ITM)
monpetit 0:3ca3835f816e 172 static int stdout_putchar (int ch) {
monpetit 0:3ca3835f816e 173 return (ITM_SendChar(ch));
monpetit 0:3ca3835f816e 174 }
monpetit 0:3ca3835f816e 175 #elif defined(RTE_Compiler_IO_STDOUT_BKPT)
monpetit 0:3ca3835f816e 176 static int stdout_putchar (int ch) {
monpetit 0:3ca3835f816e 177 __asm("BKPT 0");
monpetit 0:3ca3835f816e 178 return (ch);
monpetit 0:3ca3835f816e 179 }
monpetit 0:3ca3835f816e 180 #endif
monpetit 0:3ca3835f816e 181 #endif
monpetit 0:3ca3835f816e 182
monpetit 0:3ca3835f816e 183
monpetit 0:3ca3835f816e 184 /**
monpetit 0:3ca3835f816e 185 Put a character to the stderr
monpetit 0:3ca3835f816e 186
monpetit 0:3ca3835f816e 187 \param[in] ch Character to output
monpetit 0:3ca3835f816e 188 \return The character written, or -1 on write error.
monpetit 0:3ca3835f816e 189 */
monpetit 0:3ca3835f816e 190 #if defined(RTE_Compiler_IO_STDERR)
monpetit 0:3ca3835f816e 191 #if defined(RTE_Compiler_IO_STDERR_User)
monpetit 0:3ca3835f816e 192 extern int stderr_putchar (int ch);
monpetit 0:3ca3835f816e 193 #elif defined(RTE_Compiler_IO_STDERR_ITM)
monpetit 0:3ca3835f816e 194 static int stderr_putchar (int ch) {
monpetit 0:3ca3835f816e 195 return (ITM_SendChar(ch));
monpetit 0:3ca3835f816e 196 }
monpetit 0:3ca3835f816e 197 #elif defined(RTE_Compiler_IO_STDERR_BKPT)
monpetit 0:3ca3835f816e 198 static int stderr_putchar (int ch) {
monpetit 0:3ca3835f816e 199 __asm("BKPT 0");
monpetit 0:3ca3835f816e 200 return (ch);
monpetit 0:3ca3835f816e 201 }
monpetit 0:3ca3835f816e 202 #endif
monpetit 0:3ca3835f816e 203 #endif
monpetit 0:3ca3835f816e 204
monpetit 0:3ca3835f816e 205
monpetit 0:3ca3835f816e 206 #ifdef __MICROLIB
monpetit 0:3ca3835f816e 207
monpetit 0:3ca3835f816e 208
monpetit 0:3ca3835f816e 209 #ifdef RTE_Compiler_IO_STDIN
monpetit 0:3ca3835f816e 210 static int getchar_undo = 0;
monpetit 0:3ca3835f816e 211 static int getchar_ch = -1;
monpetit 0:3ca3835f816e 212 #endif
monpetit 0:3ca3835f816e 213
monpetit 0:3ca3835f816e 214
monpetit 0:3ca3835f816e 215 /**
monpetit 0:3ca3835f816e 216 Writes the character specified by c (converted to an unsigned char) to
monpetit 0:3ca3835f816e 217 the output stream pointed to by stream, at the position indicated by the
monpetit 0:3ca3835f816e 218 asociated file position indicator (if defined), and advances the
monpetit 0:3ca3835f816e 219 indicator appropriately. If the file position indicator is not defined,
monpetit 0:3ca3835f816e 220 the character is appended to the output stream.
monpetit 0:3ca3835f816e 221
monpetit 0:3ca3835f816e 222 \param[in] c Character
monpetit 0:3ca3835f816e 223 \param[in] stream Stream handle
monpetit 0:3ca3835f816e 224
monpetit 0:3ca3835f816e 225 \return The character written. If a write error occurs, the error
monpetit 0:3ca3835f816e 226 indicator is set and fputc returns EOF.
monpetit 0:3ca3835f816e 227 */
monpetit 0:3ca3835f816e 228 __attribute__((weak))
monpetit 0:3ca3835f816e 229 int fputc (int c, FILE * stream) {
monpetit 0:3ca3835f816e 230 #if (!defined(RTE_Compiler_IO_STDOUT) && !defined(RTE_Compiler_IO_STDERR))
monpetit 0:3ca3835f816e 231 (void)c;
monpetit 0:3ca3835f816e 232 (void)stream;
monpetit 0:3ca3835f816e 233 #endif
monpetit 0:3ca3835f816e 234
monpetit 0:3ca3835f816e 235 #ifdef RTE_Compiler_IO_STDOUT
monpetit 0:3ca3835f816e 236 if (stream == &__stdout) {
monpetit 0:3ca3835f816e 237 #if (STDOUT_CR_LF != 0)
monpetit 0:3ca3835f816e 238 if (c == '\n') stdout_putchar('\r');
monpetit 0:3ca3835f816e 239 #endif
monpetit 0:3ca3835f816e 240 return (stdout_putchar(c));
monpetit 0:3ca3835f816e 241 }
monpetit 0:3ca3835f816e 242 #endif
monpetit 0:3ca3835f816e 243
monpetit 0:3ca3835f816e 244 #ifdef RTE_Compiler_IO_STDERR
monpetit 0:3ca3835f816e 245 if (stream == &__stderr) {
monpetit 0:3ca3835f816e 246 #if (STDERR_CR_LF != 0)
monpetit 0:3ca3835f816e 247 if (c == '\n') stderr_putchar('\r');
monpetit 0:3ca3835f816e 248 #endif
monpetit 0:3ca3835f816e 249 return (stderr_putchar(c));
monpetit 0:3ca3835f816e 250 }
monpetit 0:3ca3835f816e 251 #endif
monpetit 0:3ca3835f816e 252
monpetit 0:3ca3835f816e 253 return (-1);
monpetit 0:3ca3835f816e 254 }
monpetit 0:3ca3835f816e 255
monpetit 0:3ca3835f816e 256
monpetit 0:3ca3835f816e 257 /**
monpetit 0:3ca3835f816e 258 Obtains the next character (if present) as an unsigned char converted to
monpetit 0:3ca3835f816e 259 an int, from the input stream pointed to by stream, and advances the
monpetit 0:3ca3835f816e 260 associated file position indicator (if defined).
monpetit 0:3ca3835f816e 261
monpetit 0:3ca3835f816e 262 \param[in] stream Stream handle
monpetit 0:3ca3835f816e 263
monpetit 0:3ca3835f816e 264 \return The next character from the input stream pointed to by stream.
monpetit 0:3ca3835f816e 265 If the stream is at end-of-file, the end-of-file indicator is
monpetit 0:3ca3835f816e 266 set and fgetc returns EOF. If a read error occurs, the error
monpetit 0:3ca3835f816e 267 indicator is set and fgetc returns EOF.
monpetit 0:3ca3835f816e 268 */
monpetit 0:3ca3835f816e 269 __attribute__((weak))
monpetit 0:3ca3835f816e 270 int fgetc (FILE * stream) {
monpetit 0:3ca3835f816e 271 #ifdef RTE_Compiler_IO_STDIN
monpetit 0:3ca3835f816e 272 int ch;
monpetit 0:3ca3835f816e 273
monpetit 0:3ca3835f816e 274 if (stream == &__stdin) {
monpetit 0:3ca3835f816e 275 if (getchar_undo) {
monpetit 0:3ca3835f816e 276 ch = getchar_ch;
monpetit 0:3ca3835f816e 277 getchar_ch = -1;
monpetit 0:3ca3835f816e 278 getchar_undo = 0;
monpetit 0:3ca3835f816e 279 return (ch);
monpetit 0:3ca3835f816e 280 }
monpetit 0:3ca3835f816e 281 ch = stdin_getchar();
monpetit 0:3ca3835f816e 282 #if (STDIN_ECHO != 0)
monpetit 0:3ca3835f816e 283 stdout_putchar(ch);
monpetit 0:3ca3835f816e 284 #endif
monpetit 0:3ca3835f816e 285 getchar_ch = ch;
monpetit 0:3ca3835f816e 286 return (ch);
monpetit 0:3ca3835f816e 287 }
monpetit 0:3ca3835f816e 288 #else
monpetit 0:3ca3835f816e 289 (void)stream;
monpetit 0:3ca3835f816e 290 #endif
monpetit 0:3ca3835f816e 291
monpetit 0:3ca3835f816e 292 return (-1);
monpetit 0:3ca3835f816e 293 }
monpetit 0:3ca3835f816e 294
monpetit 0:3ca3835f816e 295
monpetit 0:3ca3835f816e 296 /**
monpetit 0:3ca3835f816e 297 The function __backspace() is used by the scanf family of functions, and must
monpetit 0:3ca3835f816e 298 be re-implemented if you retarget the stdio arrangements at the fgetc() level.
monpetit 0:3ca3835f816e 299
monpetit 0:3ca3835f816e 300 \param[in] stream Stream handle
monpetit 0:3ca3835f816e 301
monpetit 0:3ca3835f816e 302 \return The value returned by __backspace() is either 0 (success) or EOF
monpetit 0:3ca3835f816e 303 (failure). It returns EOF only if used incorrectly, for example,
monpetit 0:3ca3835f816e 304 if no characters have been read from the stream. When used
monpetit 0:3ca3835f816e 305 correctly, __backspace() must always return 0, because the scanf
monpetit 0:3ca3835f816e 306 family of functions do not check the error return.
monpetit 0:3ca3835f816e 307 */
monpetit 0:3ca3835f816e 308 __attribute__((weak))
monpetit 0:3ca3835f816e 309 int __backspace(FILE *stream);
monpetit 0:3ca3835f816e 310 int __backspace(FILE *stream) {
monpetit 0:3ca3835f816e 311
monpetit 0:3ca3835f816e 312 #ifdef RTE_Compiler_IO_STDIN
monpetit 0:3ca3835f816e 313 if (stream == &__stdin) {
monpetit 0:3ca3835f816e 314 if (getchar_ch != -1) {
monpetit 0:3ca3835f816e 315 getchar_undo = 1;
monpetit 0:3ca3835f816e 316 return (0);
monpetit 0:3ca3835f816e 317 }
monpetit 0:3ca3835f816e 318 return (-1);
monpetit 0:3ca3835f816e 319 }
monpetit 0:3ca3835f816e 320 #else
monpetit 0:3ca3835f816e 321 (void)stream;
monpetit 0:3ca3835f816e 322 #endif
monpetit 0:3ca3835f816e 323
monpetit 0:3ca3835f816e 324 return (-1);
monpetit 0:3ca3835f816e 325 }
monpetit 0:3ca3835f816e 326
monpetit 0:3ca3835f816e 327
monpetit 0:3ca3835f816e 328 /**
monpetit 0:3ca3835f816e 329 Called from assert() and prints a message on stderr and calls abort().
monpetit 0:3ca3835f816e 330
monpetit 0:3ca3835f816e 331 \param[in] expr assert expression that was not TRUE
monpetit 0:3ca3835f816e 332 \param[in] file source file of the assertion
monpetit 0:3ca3835f816e 333 \param[in] line source line of the assertion
monpetit 0:3ca3835f816e 334 */
monpetit 0:3ca3835f816e 335 __attribute__((weak,noreturn))
monpetit 0:3ca3835f816e 336 void __aeabi_assert (const char *expr, const char *file, int line) {
monpetit 0:3ca3835f816e 337 char str[12], *p;
monpetit 0:3ca3835f816e 338
monpetit 0:3ca3835f816e 339 fputs("*** assertion failed: ", stderr);
monpetit 0:3ca3835f816e 340 fputs(expr, stderr);
monpetit 0:3ca3835f816e 341 fputs(", file ", stderr);
monpetit 0:3ca3835f816e 342 fputs(file, stderr);
monpetit 0:3ca3835f816e 343 fputs(", line ", stderr);
monpetit 0:3ca3835f816e 344
monpetit 0:3ca3835f816e 345 p = str + sizeof(str);
monpetit 0:3ca3835f816e 346 *--p = '\0';
monpetit 0:3ca3835f816e 347 *--p = '\n';
monpetit 0:3ca3835f816e 348 while (line > 0) {
monpetit 0:3ca3835f816e 349 *--p = '0' + (line % 10);
monpetit 0:3ca3835f816e 350 line /= 10;
monpetit 0:3ca3835f816e 351 }
monpetit 0:3ca3835f816e 352 fputs(p, stderr);
monpetit 0:3ca3835f816e 353
monpetit 0:3ca3835f816e 354 abort();
monpetit 0:3ca3835f816e 355 }
monpetit 0:3ca3835f816e 356
monpetit 0:3ca3835f816e 357
monpetit 0:3ca3835f816e 358 __attribute__((weak))
monpetit 0:3ca3835f816e 359 void abort(void) {
monpetit 0:3ca3835f816e 360 for (;;);
monpetit 0:3ca3835f816e 361 }
monpetit 0:3ca3835f816e 362
monpetit 0:3ca3835f816e 363
monpetit 0:3ca3835f816e 364 #else /* __MICROLIB */
monpetit 0:3ca3835f816e 365
monpetit 0:3ca3835f816e 366
monpetit 0:3ca3835f816e 367 #if (defined(RTE_Compiler_IO_STDIN) || \
monpetit 0:3ca3835f816e 368 defined(RTE_Compiler_IO_STDOUT) || \
monpetit 0:3ca3835f816e 369 defined(RTE_Compiler_IO_STDERR) || \
monpetit 0:3ca3835f816e 370 defined(RTE_Compiler_IO_File))
monpetit 0:3ca3835f816e 371 #define RETARGET_SYS
monpetit 0:3ca3835f816e 372
monpetit 0:3ca3835f816e 373 /* IO device file handles. */
monpetit 0:3ca3835f816e 374 #define FH_STDIN 0x8001
monpetit 0:3ca3835f816e 375 #define FH_STDOUT 0x8002
monpetit 0:3ca3835f816e 376 #define FH_STDERR 0x8003
monpetit 0:3ca3835f816e 377 // User defined ...
monpetit 0:3ca3835f816e 378
monpetit 0:3ca3835f816e 379 /* Standard IO device name defines. */
monpetit 0:3ca3835f816e 380 const char __stdin_name[] = ":STDIN";
monpetit 0:3ca3835f816e 381 const char __stdout_name[] = ":STDOUT";
monpetit 0:3ca3835f816e 382 const char __stderr_name[] = ":STDERR";
monpetit 0:3ca3835f816e 383
monpetit 0:3ca3835f816e 384 #endif
monpetit 0:3ca3835f816e 385
monpetit 0:3ca3835f816e 386
monpetit 0:3ca3835f816e 387 /**
monpetit 0:3ca3835f816e 388 Defined in rt_sys.h, this function opens a file.
monpetit 0:3ca3835f816e 389
monpetit 0:3ca3835f816e 390 The _sys_open() function is required by fopen() and freopen(). These
monpetit 0:3ca3835f816e 391 functions in turn are required if any file input/output function is to
monpetit 0:3ca3835f816e 392 be used.
monpetit 0:3ca3835f816e 393 The openmode parameter is a bitmap whose bits mostly correspond directly to
monpetit 0:3ca3835f816e 394 the ISO mode specification. Target-dependent extensions are possible, but
monpetit 0:3ca3835f816e 395 freopen() must also be extended.
monpetit 0:3ca3835f816e 396
monpetit 0:3ca3835f816e 397 \param[in] name File name
monpetit 0:3ca3835f816e 398 \param[in] openmode Mode specification bitmap
monpetit 0:3ca3835f816e 399
monpetit 0:3ca3835f816e 400 \return The return value is ֱ if an error occurs.
monpetit 0:3ca3835f816e 401 */
monpetit 0:3ca3835f816e 402 #ifdef RETARGET_SYS
monpetit 0:3ca3835f816e 403 __attribute__((weak))
monpetit 0:3ca3835f816e 404 FILEHANDLE _sys_open (const char *name, int openmode) {
monpetit 0:3ca3835f816e 405 #if (!defined(RTE_Compiler_IO_File))
monpetit 0:3ca3835f816e 406 (void)openmode;
monpetit 0:3ca3835f816e 407 #endif
monpetit 0:3ca3835f816e 408
monpetit 0:3ca3835f816e 409 if (name == NULL) {
monpetit 0:3ca3835f816e 410 return (-1);
monpetit 0:3ca3835f816e 411 }
monpetit 0:3ca3835f816e 412
monpetit 0:3ca3835f816e 413 if (name[0] == ':') {
monpetit 0:3ca3835f816e 414 if (strcmp(name, ":STDIN") == 0) {
monpetit 0:3ca3835f816e 415 return (FH_STDIN);
monpetit 0:3ca3835f816e 416 }
monpetit 0:3ca3835f816e 417 if (strcmp(name, ":STDOUT") == 0) {
monpetit 0:3ca3835f816e 418 return (FH_STDOUT);
monpetit 0:3ca3835f816e 419 }
monpetit 0:3ca3835f816e 420 if (strcmp(name, ":STDERR") == 0) {
monpetit 0:3ca3835f816e 421 return (FH_STDERR);
monpetit 0:3ca3835f816e 422 }
monpetit 0:3ca3835f816e 423 return (-1);
monpetit 0:3ca3835f816e 424 }
monpetit 0:3ca3835f816e 425
monpetit 0:3ca3835f816e 426 #ifdef RTE_Compiler_IO_File
monpetit 0:3ca3835f816e 427 #ifdef RTE_Compiler_IO_File_FS
monpetit 0:3ca3835f816e 428 return (__sys_open(name, openmode));
monpetit 0:3ca3835f816e 429 #endif
monpetit 0:3ca3835f816e 430 #else
monpetit 0:3ca3835f816e 431 return (-1);
monpetit 0:3ca3835f816e 432 #endif
monpetit 0:3ca3835f816e 433 }
monpetit 0:3ca3835f816e 434 #endif
monpetit 0:3ca3835f816e 435
monpetit 0:3ca3835f816e 436
monpetit 0:3ca3835f816e 437 /**
monpetit 0:3ca3835f816e 438 Defined in rt_sys.h, this function closes a file previously opened
monpetit 0:3ca3835f816e 439 with _sys_open().
monpetit 0:3ca3835f816e 440
monpetit 0:3ca3835f816e 441 This function must be defined if any input/output function is to be used.
monpetit 0:3ca3835f816e 442
monpetit 0:3ca3835f816e 443 \param[in] fh File handle
monpetit 0:3ca3835f816e 444
monpetit 0:3ca3835f816e 445 \return The return value is 0 if successful. A nonzero value indicates
monpetit 0:3ca3835f816e 446 an error.
monpetit 0:3ca3835f816e 447 */
monpetit 0:3ca3835f816e 448 #ifdef RETARGET_SYS
monpetit 0:3ca3835f816e 449 __attribute__((weak))
monpetit 0:3ca3835f816e 450 int _sys_close (FILEHANDLE fh) {
monpetit 0:3ca3835f816e 451
monpetit 0:3ca3835f816e 452 switch (fh) {
monpetit 0:3ca3835f816e 453 case FH_STDIN:
monpetit 0:3ca3835f816e 454 return (0);
monpetit 0:3ca3835f816e 455 case FH_STDOUT:
monpetit 0:3ca3835f816e 456 return (0);
monpetit 0:3ca3835f816e 457 case FH_STDERR:
monpetit 0:3ca3835f816e 458 return (0);
monpetit 0:3ca3835f816e 459 }
monpetit 0:3ca3835f816e 460
monpetit 0:3ca3835f816e 461 #ifdef RTE_Compiler_IO_File
monpetit 0:3ca3835f816e 462 #ifdef RTE_Compiler_IO_File_FS
monpetit 0:3ca3835f816e 463 return (__sys_close(fh));
monpetit 0:3ca3835f816e 464 #endif
monpetit 0:3ca3835f816e 465 #else
monpetit 0:3ca3835f816e 466 return (-1);
monpetit 0:3ca3835f816e 467 #endif
monpetit 0:3ca3835f816e 468 }
monpetit 0:3ca3835f816e 469 #endif
monpetit 0:3ca3835f816e 470
monpetit 0:3ca3835f816e 471
monpetit 0:3ca3835f816e 472 /**
monpetit 0:3ca3835f816e 473 Defined in rt_sys.h, this function writes the contents of a buffer to a file
monpetit 0:3ca3835f816e 474 previously opened with _sys_open().
monpetit 0:3ca3835f816e 475
monpetit 0:3ca3835f816e 476 \note The mode parameter is here for historical reasons. It contains
monpetit 0:3ca3835f816e 477 nothing useful and must be ignored.
monpetit 0:3ca3835f816e 478
monpetit 0:3ca3835f816e 479 \param[in] fh File handle
monpetit 0:3ca3835f816e 480 \param[in] buf Data buffer
monpetit 0:3ca3835f816e 481 \param[in] len Data length
monpetit 0:3ca3835f816e 482 \param[in] mode Ignore this parameter
monpetit 0:3ca3835f816e 483
monpetit 0:3ca3835f816e 484 \return The return value is either:
monpetit 0:3ca3835f816e 485 - a positive number representing the number of characters not
monpetit 0:3ca3835f816e 486 written (so any nonzero return value denotes a failure of
monpetit 0:3ca3835f816e 487 some sort)
monpetit 0:3ca3835f816e 488 - a negative number indicating an error.
monpetit 0:3ca3835f816e 489 */
monpetit 0:3ca3835f816e 490 #ifdef RETARGET_SYS
monpetit 0:3ca3835f816e 491 __attribute__((weak))
monpetit 0:3ca3835f816e 492 int _sys_write (FILEHANDLE fh, const uint8_t *buf, uint32_t len, int mode) {
monpetit 0:3ca3835f816e 493 #if (defined(RTE_Compiler_IO_STDOUT) || defined(RTE_Compiler_IO_STDERR))
monpetit 0:3ca3835f816e 494 int ch;
monpetit 0:3ca3835f816e 495 #elif (!defined(RTE_Compiler_IO_File))
monpetit 0:3ca3835f816e 496 (void)buf;
monpetit 0:3ca3835f816e 497 (void)len;
monpetit 0:3ca3835f816e 498 #endif
monpetit 0:3ca3835f816e 499 (void)mode;
monpetit 0:3ca3835f816e 500
monpetit 0:3ca3835f816e 501 switch (fh) {
monpetit 0:3ca3835f816e 502 case FH_STDIN:
monpetit 0:3ca3835f816e 503 return (-1);
monpetit 0:3ca3835f816e 504 case FH_STDOUT:
monpetit 0:3ca3835f816e 505 #ifdef RTE_Compiler_IO_STDOUT
monpetit 0:3ca3835f816e 506 for (; len; len--) {
monpetit 0:3ca3835f816e 507 ch = *buf++;
monpetit 0:3ca3835f816e 508 #if (STDOUT_CR_LF != 0)
monpetit 0:3ca3835f816e 509 if (ch == '\n') stdout_putchar('\r');
monpetit 0:3ca3835f816e 510 #endif
monpetit 0:3ca3835f816e 511 stdout_putchar(ch);
monpetit 0:3ca3835f816e 512 }
monpetit 0:3ca3835f816e 513 #endif
monpetit 0:3ca3835f816e 514 return (0);
monpetit 0:3ca3835f816e 515 case FH_STDERR:
monpetit 0:3ca3835f816e 516 #ifdef RTE_Compiler_IO_STDERR
monpetit 0:3ca3835f816e 517 for (; len; len--) {
monpetit 0:3ca3835f816e 518 ch = *buf++;
monpetit 0:3ca3835f816e 519 #if (STDERR_CR_LF != 0)
monpetit 0:3ca3835f816e 520 if (ch == '\n') stderr_putchar('\r');
monpetit 0:3ca3835f816e 521 #endif
monpetit 0:3ca3835f816e 522 stderr_putchar(ch);
monpetit 0:3ca3835f816e 523 }
monpetit 0:3ca3835f816e 524 #endif
monpetit 0:3ca3835f816e 525 return (0);
monpetit 0:3ca3835f816e 526 }
monpetit 0:3ca3835f816e 527
monpetit 0:3ca3835f816e 528 #ifdef RTE_Compiler_IO_File
monpetit 0:3ca3835f816e 529 #ifdef RTE_Compiler_IO_File_FS
monpetit 0:3ca3835f816e 530 return (__sys_write(fh, buf, len));
monpetit 0:3ca3835f816e 531 #endif
monpetit 0:3ca3835f816e 532 #else
monpetit 0:3ca3835f816e 533 return (-1);
monpetit 0:3ca3835f816e 534 #endif
monpetit 0:3ca3835f816e 535 }
monpetit 0:3ca3835f816e 536 #endif
monpetit 0:3ca3835f816e 537
monpetit 0:3ca3835f816e 538
monpetit 0:3ca3835f816e 539 /**
monpetit 0:3ca3835f816e 540 Defined in rt_sys.h, this function reads the contents of a file into a buffer.
monpetit 0:3ca3835f816e 541
monpetit 0:3ca3835f816e 542 Reading up to and including the last byte of data does not turn on the EOF
monpetit 0:3ca3835f816e 543 indicator. The EOF indicator is only reached when an attempt is made to read
monpetit 0:3ca3835f816e 544 beyond the last byte of data. The target-independent code is capable of
monpetit 0:3ca3835f816e 545 handling:
monpetit 0:3ca3835f816e 546 - the EOF indicator being returned in the same read as the remaining bytes
monpetit 0:3ca3835f816e 547 of data that precede the EOF
monpetit 0:3ca3835f816e 548 - the EOF indicator being returned on its own after the remaining bytes of
monpetit 0:3ca3835f816e 549 data have been returned in a previous read.
monpetit 0:3ca3835f816e 550
monpetit 0:3ca3835f816e 551 \note The mode parameter is here for historical reasons. It contains
monpetit 0:3ca3835f816e 552 nothing useful and must be ignored.
monpetit 0:3ca3835f816e 553
monpetit 0:3ca3835f816e 554 \param[in] fh File handle
monpetit 0:3ca3835f816e 555 \param[in] buf Data buffer
monpetit 0:3ca3835f816e 556 \param[in] len Data length
monpetit 0:3ca3835f816e 557 \param[in] mode Ignore this parameter
monpetit 0:3ca3835f816e 558
monpetit 0:3ca3835f816e 559 \return The return value is one of the following:
monpetit 0:3ca3835f816e 560 - The number of bytes not read (that is, len - result number of
monpetit 0:3ca3835f816e 561 bytes were read).
monpetit 0:3ca3835f816e 562 - An error indication.
monpetit 0:3ca3835f816e 563 - An EOF indicator. The EOF indication involves the setting of
monpetit 0:3ca3835f816e 564 0x80000000 in the normal result.
monpetit 0:3ca3835f816e 565 */
monpetit 0:3ca3835f816e 566 #ifdef RETARGET_SYS
monpetit 0:3ca3835f816e 567 __attribute__((weak))
monpetit 0:3ca3835f816e 568 int _sys_read (FILEHANDLE fh, uint8_t *buf, uint32_t len, int mode) {
monpetit 0:3ca3835f816e 569 #ifdef RTE_Compiler_IO_STDIN
monpetit 0:3ca3835f816e 570 int ch;
monpetit 0:3ca3835f816e 571 #elif (!defined(RTE_Compiler_IO_File))
monpetit 0:3ca3835f816e 572 (void)buf;
monpetit 0:3ca3835f816e 573 (void)len;
monpetit 0:3ca3835f816e 574 #endif
monpetit 0:3ca3835f816e 575 (void)mode;
monpetit 0:3ca3835f816e 576
monpetit 0:3ca3835f816e 577 switch (fh) {
monpetit 0:3ca3835f816e 578 case FH_STDIN:
monpetit 0:3ca3835f816e 579 #ifdef RTE_Compiler_IO_STDIN
monpetit 0:3ca3835f816e 580 ch = stdin_getchar();
monpetit 0:3ca3835f816e 581 if (ch < 0) {
monpetit 0:3ca3835f816e 582 return ((int)(len | 0x80000000U));
monpetit 0:3ca3835f816e 583 }
monpetit 0:3ca3835f816e 584 *buf++ = (uint8_t)ch;
monpetit 0:3ca3835f816e 585 #if (STDIN_ECHO != 0)
monpetit 0:3ca3835f816e 586 stdout_putchar(ch);
monpetit 0:3ca3835f816e 587 #endif
monpetit 0:3ca3835f816e 588 len--;
monpetit 0:3ca3835f816e 589 return ((int)(len));
monpetit 0:3ca3835f816e 590 #else
monpetit 0:3ca3835f816e 591 return ((int)(len | 0x80000000U));
monpetit 0:3ca3835f816e 592 #endif
monpetit 0:3ca3835f816e 593 case FH_STDOUT:
monpetit 0:3ca3835f816e 594 return (-1);
monpetit 0:3ca3835f816e 595 case FH_STDERR:
monpetit 0:3ca3835f816e 596 return (-1);
monpetit 0:3ca3835f816e 597 }
monpetit 0:3ca3835f816e 598
monpetit 0:3ca3835f816e 599 #ifdef RTE_Compiler_IO_File
monpetit 0:3ca3835f816e 600 #ifdef RTE_Compiler_IO_File_FS
monpetit 0:3ca3835f816e 601 return (__sys_read(fh, buf, len));
monpetit 0:3ca3835f816e 602 #endif
monpetit 0:3ca3835f816e 603 #else
monpetit 0:3ca3835f816e 604 return (-1);
monpetit 0:3ca3835f816e 605 #endif
monpetit 0:3ca3835f816e 606 }
monpetit 0:3ca3835f816e 607 #endif
monpetit 0:3ca3835f816e 608
monpetit 0:3ca3835f816e 609
monpetit 0:3ca3835f816e 610 /**
monpetit 0:3ca3835f816e 611 Defined in rt_sys.h, this function writes a character to the console. The
monpetit 0:3ca3835f816e 612 console might have been redirected. You can use this function as a last
monpetit 0:3ca3835f816e 613 resort error handling routine.
monpetit 0:3ca3835f816e 614
monpetit 0:3ca3835f816e 615 The default implementation of this function uses semihosting.
monpetit 0:3ca3835f816e 616 You can redefine this function, or __raise(), even if there is no other
monpetit 0:3ca3835f816e 617 input/output. For example, it might write an error message to a log kept
monpetit 0:3ca3835f816e 618 in nonvolatile memory.
monpetit 0:3ca3835f816e 619
monpetit 0:3ca3835f816e 620 \param[in] ch character to write
monpetit 0:3ca3835f816e 621 */
monpetit 0:3ca3835f816e 622 #if defined(RTE_Compiler_IO_TTY)
monpetit 0:3ca3835f816e 623 #if defined(RTE_Compiler_IO_TTY_User)
monpetit 0:3ca3835f816e 624 extern void ttywrch (int ch);
monpetit 0:3ca3835f816e 625 __attribute__((weak))
monpetit 0:3ca3835f816e 626 void _ttywrch (int ch) {
monpetit 0:3ca3835f816e 627 ttywrch(ch);
monpetit 0:3ca3835f816e 628 }
monpetit 0:3ca3835f816e 629 #elif defined(RTE_Compiler_IO_TTY_ITM)
monpetit 0:3ca3835f816e 630 __attribute__((weak))
monpetit 0:3ca3835f816e 631 void _ttywrch (int ch) {
monpetit 0:3ca3835f816e 632 ITM_SendChar(ch);
monpetit 0:3ca3835f816e 633 }
monpetit 0:3ca3835f816e 634 #elif defined(RTE_Compiler_IO_TTY_BKPT)
monpetit 0:3ca3835f816e 635 __attribute__((weak))
monpetit 0:3ca3835f816e 636 void _ttywrch (int ch) {
monpetit 0:3ca3835f816e 637 (void)ch;
monpetit 0:3ca3835f816e 638 __asm("BKPT 0");
monpetit 0:3ca3835f816e 639 }
monpetit 0:3ca3835f816e 640 #endif
monpetit 0:3ca3835f816e 641 #endif
monpetit 0:3ca3835f816e 642
monpetit 0:3ca3835f816e 643
monpetit 0:3ca3835f816e 644 /**
monpetit 0:3ca3835f816e 645 Defined in rt_sys.h, this function determines if a file handle identifies
monpetit 0:3ca3835f816e 646 a terminal.
monpetit 0:3ca3835f816e 647
monpetit 0:3ca3835f816e 648 When a file is connected to a terminal device, this function is used to
monpetit 0:3ca3835f816e 649 provide unbuffered behavior by default (in the absence of a call to
monpetit 0:3ca3835f816e 650 set(v)buf) and to prohibit seeking.
monpetit 0:3ca3835f816e 651
monpetit 0:3ca3835f816e 652 \param[in] fh File handle
monpetit 0:3ca3835f816e 653
monpetit 0:3ca3835f816e 654 \return The return value is one of the following values:
monpetit 0:3ca3835f816e 655 - 0: There is no interactive device.
monpetit 0:3ca3835f816e 656 - 1: There is an interactive device.
monpetit 0:3ca3835f816e 657 - other: An error occurred.
monpetit 0:3ca3835f816e 658 */
monpetit 0:3ca3835f816e 659 #ifdef RETARGET_SYS
monpetit 0:3ca3835f816e 660 __attribute__((weak))
monpetit 0:3ca3835f816e 661 int _sys_istty (FILEHANDLE fh) {
monpetit 0:3ca3835f816e 662
monpetit 0:3ca3835f816e 663 switch (fh) {
monpetit 0:3ca3835f816e 664 case FH_STDIN:
monpetit 0:3ca3835f816e 665 return (1);
monpetit 0:3ca3835f816e 666 case FH_STDOUT:
monpetit 0:3ca3835f816e 667 return (1);
monpetit 0:3ca3835f816e 668 case FH_STDERR:
monpetit 0:3ca3835f816e 669 return (1);
monpetit 0:3ca3835f816e 670 }
monpetit 0:3ca3835f816e 671
monpetit 0:3ca3835f816e 672 return (0);
monpetit 0:3ca3835f816e 673 }
monpetit 0:3ca3835f816e 674 #endif
monpetit 0:3ca3835f816e 675
monpetit 0:3ca3835f816e 676
monpetit 0:3ca3835f816e 677 /**
monpetit 0:3ca3835f816e 678 Defined in rt_sys.h, this function puts the file pointer at offset pos from
monpetit 0:3ca3835f816e 679 the beginning of the file.
monpetit 0:3ca3835f816e 680
monpetit 0:3ca3835f816e 681 This function sets the current read or write position to the new location pos
monpetit 0:3ca3835f816e 682 relative to the start of the current file fh.
monpetit 0:3ca3835f816e 683
monpetit 0:3ca3835f816e 684 \param[in] fh File handle
monpetit 0:3ca3835f816e 685 \param[in] pos File pointer offset
monpetit 0:3ca3835f816e 686
monpetit 0:3ca3835f816e 687 \return The result is:
monpetit 0:3ca3835f816e 688 - non-negative if no error occurs
monpetit 0:3ca3835f816e 689 - negative if an error occurs
monpetit 0:3ca3835f816e 690 */
monpetit 0:3ca3835f816e 691 #ifdef RETARGET_SYS
monpetit 0:3ca3835f816e 692 __attribute__((weak))
monpetit 0:3ca3835f816e 693 int _sys_seek (FILEHANDLE fh, long pos) {
monpetit 0:3ca3835f816e 694 #if (!defined(RTE_Compiler_IO_File))
monpetit 0:3ca3835f816e 695 (void)pos;
monpetit 0:3ca3835f816e 696 #endif
monpetit 0:3ca3835f816e 697
monpetit 0:3ca3835f816e 698 switch (fh) {
monpetit 0:3ca3835f816e 699 case FH_STDIN:
monpetit 0:3ca3835f816e 700 return (-1);
monpetit 0:3ca3835f816e 701 case FH_STDOUT:
monpetit 0:3ca3835f816e 702 return (-1);
monpetit 0:3ca3835f816e 703 case FH_STDERR:
monpetit 0:3ca3835f816e 704 return (-1);
monpetit 0:3ca3835f816e 705 }
monpetit 0:3ca3835f816e 706
monpetit 0:3ca3835f816e 707 #ifdef RTE_Compiler_IO_File
monpetit 0:3ca3835f816e 708 #ifdef RTE_Compiler_IO_File_FS
monpetit 0:3ca3835f816e 709 return (__sys_seek(fh, (uint32_t)pos));
monpetit 0:3ca3835f816e 710 #endif
monpetit 0:3ca3835f816e 711 #else
monpetit 0:3ca3835f816e 712 return (-1);
monpetit 0:3ca3835f816e 713 #endif
monpetit 0:3ca3835f816e 714 }
monpetit 0:3ca3835f816e 715 #endif
monpetit 0:3ca3835f816e 716
monpetit 0:3ca3835f816e 717
monpetit 0:3ca3835f816e 718 /**
monpetit 0:3ca3835f816e 719 Defined in rt_sys.h, this function returns the current length of a file.
monpetit 0:3ca3835f816e 720
monpetit 0:3ca3835f816e 721 This function is used by _sys_seek() to convert an offset relative to the
monpetit 0:3ca3835f816e 722 end of a file into an offset relative to the beginning of the file.
monpetit 0:3ca3835f816e 723 You do not have to define _sys_flen() if you do not intend to use fseek().
monpetit 0:3ca3835f816e 724 If you retarget at system _sys_*() level, you must supply _sys_flen(),
monpetit 0:3ca3835f816e 725 even if the underlying system directly supports seeking relative to the
monpetit 0:3ca3835f816e 726 end of a file.
monpetit 0:3ca3835f816e 727
monpetit 0:3ca3835f816e 728 \param[in] fh File handle
monpetit 0:3ca3835f816e 729
monpetit 0:3ca3835f816e 730 \return This function returns the current length of the file fh,
monpetit 0:3ca3835f816e 731 or a negative error indicator.
monpetit 0:3ca3835f816e 732 */
monpetit 0:3ca3835f816e 733 #ifdef RETARGET_SYS
monpetit 0:3ca3835f816e 734 __attribute__((weak))
monpetit 0:3ca3835f816e 735 long _sys_flen (FILEHANDLE fh) {
monpetit 0:3ca3835f816e 736
monpetit 0:3ca3835f816e 737 switch (fh) {
monpetit 0:3ca3835f816e 738 case FH_STDIN:
monpetit 0:3ca3835f816e 739 return (0);
monpetit 0:3ca3835f816e 740 case FH_STDOUT:
monpetit 0:3ca3835f816e 741 return (0);
monpetit 0:3ca3835f816e 742 case FH_STDERR:
monpetit 0:3ca3835f816e 743 return (0);
monpetit 0:3ca3835f816e 744 }
monpetit 0:3ca3835f816e 745
monpetit 0:3ca3835f816e 746 #ifdef RTE_Compiler_IO_File
monpetit 0:3ca3835f816e 747 #ifdef RTE_Compiler_IO_File_FS
monpetit 0:3ca3835f816e 748 return (__sys_flen(fh));
monpetit 0:3ca3835f816e 749 #endif
monpetit 0:3ca3835f816e 750 #else
monpetit 0:3ca3835f816e 751 return (0);
monpetit 0:3ca3835f816e 752 #endif
monpetit 0:3ca3835f816e 753 }
monpetit 0:3ca3835f816e 754 #endif
monpetit 0:3ca3835f816e 755
monpetit 0:3ca3835f816e 756
monpetit 0:3ca3835f816e 757 #endif /* __MICROLIB */
monpetit 0:3ca3835f816e 758
monpetit 0:3ca3835f816e 759