<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>LPCXpresso IDE中的主题 Re: Possible bug samewhere in Newlibnano</title>
    <link>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565495#M18042</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Rian,&lt;/P&gt;&lt;P&gt;the situation is strange, looks as the linker suppress __wrap_main and __real_main without any apparent reason because retarget.cpp is built and linked and the only things changing the situation are optimization that could suppress them, instead debug options without any optimization shouldn't. But for me it didn't work in debug and works in release mode... so it is more difficult to understand.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I duplicated a new debug mode based on release mode and then I modified the options to include debug informations... in this way the problem appears, it is very strange.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 04 Aug 2016 13:08:51 GMT</pubDate>
    <dc:creator>massimomanca</dc:creator>
    <dc:date>2016-08-04T13:08:51Z</dc:date>
    <item>
      <title>Possible bug samewhere in Newlibnano</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565486#M18033</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am building a project based on mbed. I downloaded the last mbed source code from mbed-dev than I compile it as a static library and link it to my application project. I build the library for debug and release. If in my application I link the release library everything works but if I link the debug library... I have this error:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Building target: MBED1768TestColibriNew.axf&lt;/P&gt;&lt;P&gt;Invoking: MCU C++ Linker&lt;/P&gt;&lt;P&gt;arm-none-eabi-c++ -nostdlib -L"C:\Dati\ProjectsWorkspaceEmb\LpcXpresso8\MBED1768Colibri\MBED1768TestColibriNew" -L"C:\Dati\ProjectsWorkspaceEmb\LpcXpresso8\MBED1768Colibri\GenericC++Lib\Debug" -L"C:\Dati\ProjectsWorkspaceEmb\LpcXpresso8\MBED1768Colibri\mbed-dev\Debug" -Xlinker -Map="MBED1768TestColibriNew.map" -Xlinker --gc-sections -mcpu=cortex-m3 -mthumb -T LPC1768.ld -o "MBED1768TestColibriNew.axf"&amp;nbsp; ./ErrorCodes.o ./TestAltimeter.o ./TestBitFieldEnum.o ./TestDebug.o ./TestDebugNew.o ./TestEndian.o ./TestErrorHandler.o ./TestEthernet.o ./TestGSM.o ./TestGenMath.o ./TestHost.o ./TestI2C.o ./TestImu.o ./TestInet.o ./TestIni.o ./TestIpAddr.o ./TestLM75B.o ./TestLcd.o ./TestLocalFileSystem.o ./TestLogger.o ./TestLoggerVcd.o ./TestMPL3115A2.o ./TestMySql.o ./TestPost.o ./TestRGB.o ./TestSDFileSystem.o ./TestSingleton.o ./TestSscanf.o ./bist.o ./fusion.o ./i2cext.o ./main.o ./post.o ./process.o ./rgb.o&amp;nbsp;&amp;nbsp; -lmbed-dev -lGenC++Lib&lt;/P&gt;&lt;P&gt;C:\Users\massimo\AppData\Local\Temp\ccBse0di.ltrans2.ltrans.o: In function `__wrap_main':&lt;/P&gt;&lt;P&gt;&amp;lt;artificial&amp;gt;:(.text+0x4a4): undefined reference to `__real_main'&lt;/P&gt;&lt;P&gt;collect2.exe: error: ld returned 1 exit status&lt;/P&gt;&lt;P&gt;make: *** [MBED1768TestColibriNew.axf] Error 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;05:00:58 Build Finished (took 37s.33ms)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;__wrap_main and __real_main would be defined internaly in newlibnano.&lt;/P&gt;&lt;P&gt;The strange situation is that if I set the Debug configuration changing optimisations to optimize for size and change the debugging options to none the project is correctly built. So seems to me that the error I found is related how I compile my project and this is not so good.&lt;/P&gt;&lt;P&gt;Anyone experienced the same problem? Any suggestion is welcome!!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Aug 2016 03:18:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565486#M18033</guid>
      <dc:creator>massimomanca</dc:creator>
      <dc:date>2016-08-03T03:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: Possible bug samewhere in Newlibnano</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565487#M18034</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;AFAIK, __wrap_main and __real_main are defined by MBED and nothing to do with newlibnano. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;See this thread on the MBED forums:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;A href="https://developer.mbed.org/questions/5996/undefined-reference-to-__wrap_main-GCC-E/" title="https://developer.mbed.org/questions/5996/undefined-reference-to-__wrap_main-GCC-E/"&gt;undefined reference to `__wrap_main' GCC Embedded - Question | mbed&lt;/A&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Aug 2016 07:42:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565487#M18034</guid>
      <dc:creator>avt</dc:creator>
      <dc:date>2016-08-03T07:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: Possible bug samewhere in Newlibnano</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565488#M18035</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are right, they are both defined in retarget.cpp file of mbed library. The strange thing is that their definition and declaration seems not depending by optimization or debugging flags... they should be always compiled.&lt;/P&gt;&lt;P&gt;But seems they are "sensitive" to the library used (using Newlib the project compiles correctly also in debug mode) and optimization and debugging options. So I supposed they may be defined also in NewlibNano for any reason. After that today I downloaded NewlibNano in source code form and I saw they are not defined inside it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I read the thread pointed by you, in that case seems that recompiling mbed library solved the problem. Unofrtunately is not my case, also recompiling it nothing changes. I will continue to find a solution. Thanks for your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Aug 2016 14:25:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565488#M18035</guid>
      <dc:creator>massimomanca</dc:creator>
      <dc:date>2016-08-03T14:25:18Z</dc:date>
    </item>
    <item>
      <title>Re: Possible bug samewhere in Newlibnano</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565489#M18036</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Perhaps you could post the retarget.cpp so we can take a look?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Aug 2016 15:13:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565489#M18036</guid>
      <dc:creator>avt</dc:creator>
      <dc:date>2016-08-03T15:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: Possible bug samewhere in Newlibnano</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565490#M18037</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, sure. How can I add the source file? Do I need to copy and paste here?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Aug 2016 15:37:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565490#M18037</guid>
      <dc:creator>massimomanca</dc:creator>
      <dc:date>2016-08-03T15:37:06Z</dc:date>
    </item>
    <item>
      <title>Re: Possible bug samewhere in Newlibnano</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565491#M18038</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can add attachments, &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Aug 2016 17:12:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565491#M18038</guid>
      <dc:creator>avt</dc:creator>
      <dc:date>2016-08-03T17:12:25Z</dc:date>
    </item>
    <item>
      <title>Re: Possible bug samewhere in Newlibnano</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565492#M18039</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is retarget.cpp the interesting lines are around line 435 (I marked the block with a lot of slashes)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* mbed Microcontroller Library&lt;/P&gt;&lt;P&gt; * Copyright (c) 2006-2015 ARM Limited&lt;/P&gt;&lt;P&gt; *&lt;/P&gt;&lt;P&gt; * Licensed under the Apache License, Version 2.0 (the "License");&lt;/P&gt;&lt;P&gt; * you may not use this file except in compliance with the License.&lt;/P&gt;&lt;P&gt; * You may obtain a copy of the License at&lt;/P&gt;&lt;P&gt; *&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt; *&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.apache.org%2Flicenses%2FLICENSE-2.0" rel="nofollow" target="_blank"&gt;http://www.apache.org/licenses/LICENSE-2.0&lt;/A&gt;&lt;/P&gt;&lt;P&gt; *&lt;/P&gt;&lt;P&gt; * Unless required by applicable law or agreed to in writing, software&lt;/P&gt;&lt;P&gt; * distributed under the License is distributed on an "AS IS" BASIS,&lt;/P&gt;&lt;P&gt; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.&lt;/P&gt;&lt;P&gt; * See the License for the specific language governing permissions and&lt;/P&gt;&lt;P&gt; * limitations under the License.&lt;/P&gt;&lt;P&gt; */&lt;/P&gt;&lt;P&gt;#include "include/platform.h"&lt;/P&gt;&lt;P&gt;#include "include/FileHandle.h"&lt;/P&gt;&lt;P&gt;#include "include/FileSystemLike.h"&lt;/P&gt;&lt;P&gt;#include "include/FilePath.h"&lt;/P&gt;&lt;P&gt;#include "hal/serial_api.h"&lt;/P&gt;&lt;P&gt;#include "include/toolchain.h"&lt;/P&gt;&lt;P&gt;#include "include/semihost_api.h"&lt;/P&gt;&lt;P&gt;#include "include/mbed_interface.h"&lt;/P&gt;&lt;P&gt;#if DEVICE_STDIO_MESSAGES&lt;/P&gt;&lt;P&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;#include &amp;lt;errno.h&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#if defined(__ARMCC_VERSION)&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp; include &amp;lt;rt_sys.h&amp;gt;&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp; define PREFIX(x)&amp;nbsp;&amp;nbsp;&amp;nbsp; _sys##x&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp; define OPEN_MAX&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _SYS_OPEN&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp; ifdef __MICROLIB&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pragma import(__use_full_stdio)&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp; endif&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#elif defined(__ICCARM__)&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp; include &amp;lt;yfuns.h&amp;gt;&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp; define PREFIX(x)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _##x&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp; define OPEN_MAX&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 16&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp; define STDIN_FILENO&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp; define STDOUT_FILENO&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp; define STDERR_FILENO&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#else&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp; include &amp;lt;sys/stat.h&amp;gt;&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp; include &amp;lt;sys/unistd.h&amp;gt;&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp; include &amp;lt;sys/syslimits.h&amp;gt;&lt;/P&gt;&lt;P&gt;#&amp;nbsp;&amp;nbsp; define PREFIX(x)&amp;nbsp;&amp;nbsp;&amp;nbsp; x&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;using namespace mbed;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#if defined(__MICROLIB) &amp;amp;&amp;amp; (__ARMCC_VERSION&amp;gt;5030000)&lt;/P&gt;&lt;P&gt;// Before version 5.03, we were using a patched version of microlib with proper names&lt;/P&gt;&lt;P&gt;extern const char __stdin_name[]&amp;nbsp; = ":tt";&lt;/P&gt;&lt;P&gt;extern const char __stdout_name[] = ":tt";&lt;/P&gt;&lt;P&gt;extern const char __stderr_name[] = ":tt";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#else&lt;/P&gt;&lt;P&gt;extern const char __stdin_name[]&amp;nbsp; = "/stdin";&lt;/P&gt;&lt;P&gt;extern const char __stdout_name[] = "/stdout";&lt;/P&gt;&lt;P&gt;extern const char __stderr_name[] = "/stderr";&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* newlib has the filehandle field in the FILE struct as a short, so&lt;/P&gt;&lt;P&gt; * we can't just return a Filehandle* from _open and instead have to&lt;/P&gt;&lt;P&gt; * put it in a filehandles array and return the index into that array&lt;/P&gt;&lt;P&gt; * (or rather index+3, as filehandles 0-2 are stdin/out/err).&lt;/P&gt;&lt;P&gt; */&lt;/P&gt;&lt;P&gt;static FileHandle *filehandles[OPEN_MAX];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FileHandle::~FileHandle() {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Remove all open filehandles for this */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (unsigned int fh_i = 0; fh_i &amp;lt; sizeof(filehandles)/sizeof(*filehandles); fh_i++) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (filehandles[fh_i] == this) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; filehandles[fh_i] = NULL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#if DEVICE_SERIAL&lt;/P&gt;&lt;P&gt;extern int stdio_uart_inited;&lt;/P&gt;&lt;P&gt;extern serial_t stdio_uart;&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;static void init_serial() {&lt;/P&gt;&lt;P&gt;#if DEVICE_SERIAL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (stdio_uart_inited) return;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; serial_init(&amp;amp;stdio_uart, STDIO_UART_TX, STDIO_UART_RX);&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;static inline int openmode_to_posix(int openmode) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int posix = openmode;&lt;/P&gt;&lt;P&gt;#ifdef __ARMCC_VERSION&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (openmode &amp;amp; OPEN_PLUS) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; posix = O_RDWR;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } else if(openmode &amp;amp; OPEN_W) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; posix = O_WRONLY;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } else if(openmode &amp;amp; OPEN_A) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; posix = O_WRONLY|O_APPEND;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } else {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; posix = O_RDONLY;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* a, w, a+, w+ all create if file does not already exist */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (openmode &amp;amp; (OPEN_A|OPEN_W)) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; posix |= O_CREAT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* w and w+ truncate */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (openmode &amp;amp; OPEN_W) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; posix |= O_TRUNC;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;#elif defined(__ICCARM__)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; switch (openmode &amp;amp; _LLIO_RDWRMASK) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case _LLIO_RDONLY: posix = O_RDONLY; break;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case _LLIO_WRONLY: posix = O_WRONLY; break;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case _LLIO_RDWR&amp;nbsp; : posix = O_RDWR&amp;nbsp; ; break;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (openmode &amp;amp; _LLIO_CREAT ) posix |= O_CREAT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (openmode &amp;amp; _LLIO_APPEND) posix |= O_APPEND;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (openmode &amp;amp; _LLIO_TRUNC ) posix |= O_TRUNC;&lt;/P&gt;&lt;P&gt;#elif defined(TOOLCHAIN_GCC)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; posix &amp;amp;= ~O_BINARY;&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return posix;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;extern "C" FILEHANDLE PREFIX(_open)(const char* name, int openmode) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #if defined(__MICROLIB) &amp;amp;&amp;amp; (__ARMCC_VERSION&amp;gt;5030000)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Before version 5.03, we were using a patched version of microlib with proper names&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // This is the workaround that the microlib author suggested us&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; static int n = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!std::strcmp(name, ":tt")) return n++;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #else&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Use the posix convention that stdin,out,err are filehandles 0,1,2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (std::strcmp(name, __stdin_name) == 0) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; init_serial();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } else if (std::strcmp(name, __stdout_name) == 0) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; init_serial();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } else if (std::strcmp(name, __stderr_name) == 0) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; init_serial();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #endif&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // find the first empty slot in filehandles&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; unsigned int fh_i;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (fh_i = 0; fh_i &amp;lt; sizeof(filehandles)/sizeof(*filehandles); fh_i++) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (filehandles[fh_i] == NULL) break;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fh_i &amp;gt;= sizeof(filehandles)/sizeof(*filehandles)) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return -1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FileHandle *res;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* FILENAME: ":0x12345678" describes a FileLike* */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (name[0] == ':') {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void *p;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sscanf(name, ":%p", &amp;amp;p);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; res = (FileHandle*)p;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* FILENAME: "/file_system/file_name" */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } else {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FilePath path(name);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!path.exists())&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return -1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if (path.isFile()) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; res = path.file();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } else {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FileSystemLike *fs = path.fileSystem();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fs == NULL) return -1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int posix_mode = openmode_to_posix(openmode);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; res = fs-&amp;gt;open(path.fileName(), posix_mode); /* NULL if fails */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (res == NULL) return -1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; filehandles[fh_i] = res;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return fh_i + 3; // +3 as filehandles 0-2 are stdin/out/err&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;extern "C" int PREFIX(_close)(FILEHANDLE fh) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fh &amp;lt; 3) return 0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FileHandle* fhc = filehandles[fh-3];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; filehandles[fh-3] = NULL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fhc == NULL) return -1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return fhc-&amp;gt;close();&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#if defined(__ICCARM__)&lt;/P&gt;&lt;P&gt;extern "C" size_t&amp;nbsp;&amp;nbsp;&amp;nbsp; __write (int&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fh, const unsigned char *buffer, size_t length) {&lt;/P&gt;&lt;P&gt;#else&lt;/P&gt;&lt;P&gt;extern "C" int PREFIX(_write)(FILEHANDLE fh, const unsigned char *buffer, unsigned int length, int mode) {&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int n; // n is the number of bytes written&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fh &amp;lt; 3) {&lt;/P&gt;&lt;P&gt;#if DEVICE_SERIAL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!stdio_uart_inited) init_serial();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (unsigned int i = 0; i &amp;lt; length; i++) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; serial_putc(&amp;amp;stdio_uart, buffer[i]);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n = length;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } else {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FileHandle* fhc = filehandles[fh-3];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fhc == NULL) return -1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n = fhc-&amp;gt;write(buffer, length);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;#ifdef __ARMCC_VERSION&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return length-n;&lt;/P&gt;&lt;P&gt;#else&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return n;&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#if defined(__ICCARM__)&lt;/P&gt;&lt;P&gt;extern "C" size_t&amp;nbsp;&amp;nbsp;&amp;nbsp; __read (int&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fh, unsigned char *buffer, size_t&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; length) {&lt;/P&gt;&lt;P&gt;#else&lt;/P&gt;&lt;P&gt;extern "C" int PREFIX(_read)(FILEHANDLE fh, unsigned char *buffer, unsigned int length, int mode) {&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int n; // n is the number of bytes read&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fh &amp;lt; 3) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // only read a character at a time from stdin&lt;/P&gt;&lt;P&gt;#if DEVICE_SERIAL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!stdio_uart_inited) init_serial();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *buffer = serial_getc(&amp;amp;stdio_uart);&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } else {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FileHandle* fhc = filehandles[fh-3];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fhc == NULL) return -1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n = fhc-&amp;gt;read(buffer, length);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;#ifdef __ARMCC_VERSION&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return length-n;&lt;/P&gt;&lt;P&gt;#else&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return n;&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#ifdef __ARMCC_VERSION&lt;/P&gt;&lt;P&gt;extern "C" int PREFIX(_istty)(FILEHANDLE fh)&lt;/P&gt;&lt;P&gt;#else&lt;/P&gt;&lt;P&gt;extern "C" int _isatty(FILEHANDLE fh)&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* stdin, stdout and stderr should be tty */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fh &amp;lt; 3) return 1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FileHandle* fhc = filehandles[fh-3];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fhc == NULL) return -1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return fhc-&amp;gt;isatty();&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;extern "C"&lt;/P&gt;&lt;P&gt;#if defined(__ARMCC_VERSION)&lt;/P&gt;&lt;P&gt;int _sys_seek(FILEHANDLE fh, long position)&lt;/P&gt;&lt;P&gt;#elif defined(__ICCARM__)&lt;/P&gt;&lt;P&gt;long __lseek(int fh, long offset, int whence)&lt;/P&gt;&lt;P&gt;#else&lt;/P&gt;&lt;P&gt;int _lseek(FILEHANDLE fh, int offset, int whence)&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fh &amp;lt; 3) return 0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FileHandle* fhc = filehandles[fh-3];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fhc == NULL) return -1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#if defined(__ARMCC_VERSION)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return fhc-&amp;gt;lseek(position, SEEK_SET);&lt;/P&gt;&lt;P&gt;#else&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return fhc-&amp;gt;lseek(offset, whence);&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#ifdef __ARMCC_VERSION&lt;/P&gt;&lt;P&gt;extern "C" int PREFIX(_ensure)(FILEHANDLE fh) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fh &amp;lt; 3) return 0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FileHandle* fhc = filehandles[fh-3];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fhc == NULL) return -1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return fhc-&amp;gt;fsync();&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;extern "C" long PREFIX(_flen)(FILEHANDLE fh) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fh &amp;lt; 3) return 0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FileHandle* fhc = filehandles[fh-3];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fhc == NULL) return -1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return fhc-&amp;gt;flen();&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#if !defined(__ARMCC_VERSION) &amp;amp;&amp;amp; !defined(__ICCARM__)&lt;/P&gt;&lt;P&gt;extern "C" int _fstat(int fd, struct stat *st) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ((STDOUT_FILENO == fd) || (STDERR_FILENO == fd) || (STDIN_FILENO == fd)) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; st-&amp;gt;st_mode = S_IFCHR;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&amp;nbsp; 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; errno = EBADF;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return -1;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;namespace std {&lt;/P&gt;&lt;P&gt;extern "C" int remove(const char *path) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FilePath fp(path);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FileSystemLike *fs = fp.fileSystem();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fs == NULL) return -1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return fs-&amp;gt;remove(fp.fileName());&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;extern "C" int rename(const char *oldname, const char *newname) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FilePath fpOld(oldname);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FilePath fpNew(newname);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FileSystemLike *fsOld = fpOld.fileSystem();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FileSystemLike *fsNew = fpNew.fileSystem();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* rename only if both files are on the same FS */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fsOld != fsNew || fsOld == NULL) return -1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return fsOld-&amp;gt;rename(fpOld.fileName(), fpNew.fileName());&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;extern "C" char *tmpnam(char *s) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return NULL;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;extern "C" FILE *tmpfile() {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return NULL;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;} // namespace std&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#ifdef __ARMCC_VERSION&lt;/P&gt;&lt;P&gt;extern "C" char *_sys_command_string(char *cmd, int len) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return NULL;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;extern "C" DIR *opendir(const char *path) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* root dir is FileSystemLike */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (path[0] == '/' &amp;amp;&amp;amp; path[1] == 0) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return FileSystemLike::opendir();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FilePath fp(path);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FileSystemLike* fs = fp.fileSystem();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fs == NULL) return NULL;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return fs-&amp;gt;opendir(fp.fileName());&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;extern "C" struct dirent *readdir(DIR *dir) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return dir-&amp;gt;readdir();&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;extern "C" int closedir(DIR *dir) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return dir-&amp;gt;closedir();&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;extern "C" void rewinddir(DIR *dir) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dir-&amp;gt;rewinddir();&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;extern "C" off_t telldir(DIR *dir) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return dir-&amp;gt;telldir();&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;extern "C" void seekdir(DIR *dir, off_t off) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dir-&amp;gt;seekdir(off);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;extern "C" int mkdir(const char *path, mode_t mode) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FilePath fp(path);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FileSystemLike *fs = fp.fileSystem();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fs == NULL) return -1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return fs-&amp;gt;mkdir(fp.fileName(), mode);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#if defined(TOOLCHAIN_GCC)&lt;/P&gt;&lt;P&gt;/* prevents the exception handling name demangling code getting pulled in */&lt;/P&gt;&lt;P&gt;#include "include/mbed_error.h"&lt;/P&gt;&lt;P&gt;namespace __gnu_cxx {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void __verbose_terminate_handler() {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; error("Exception");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;extern "C" WEAK void __cxa_pure_virtual(void);&lt;/P&gt;&lt;P&gt;extern "C" WEAK void __cxa_pure_virtual(void) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; exit(1);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// ****************************************************************************&lt;/P&gt;&lt;P&gt;// mbed_main is a function that is called before main()&lt;/P&gt;&lt;P&gt;// mbed_sdk_init() is also a function that is called before main(), but unlike&lt;/P&gt;&lt;P&gt;// mbed_main(), it is not meant for user code, but for the SDK itself to perform&lt;/P&gt;&lt;P&gt;// initializations before main() is called.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;extern "C" WEAK void mbed_main(void);&lt;/P&gt;&lt;P&gt;extern "C" WEAK void mbed_main(void) {&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;extern "C" WEAK void mbed_sdk_init(void);&lt;/P&gt;&lt;P&gt;extern "C" WEAK void mbed_sdk_init(void) {&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#if defined(TOOLCHAIN_ARM)&lt;/P&gt;&lt;P&gt;extern "C" int $Super$$main(void);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;extern "C" int $Sub$$main(void) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mbed_sdk_init();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mbed_main();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return $Super$$main();&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;#elif defined(TOOLCHAIN_GCC)////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;/P&gt;&lt;P&gt;extern "C" int __real_main(void);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;extern "C" int __wrap_main(void) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mbed_sdk_init();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mbed_main();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return __real_main();&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;#elif defined(TOOLCHAIN_IAR)////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////&lt;/P&gt;&lt;P&gt;// IAR doesn't have the $Super/$Sub mechanism of armcc, nor something equivalent&lt;/P&gt;&lt;P&gt;// to ld's --wrap. It does have a --redirect, but that doesn't help, since redirecting&lt;/P&gt;&lt;P&gt;// 'main' to another symbol looses the original 'main' symbol. However, its startup&lt;/P&gt;&lt;P&gt;// code will call a function to setup argc and argv (__iar_argc_argv) if it is defined.&lt;/P&gt;&lt;P&gt;// Since mbed doesn't use argc/argv, we use this function to call our mbed_main.&lt;/P&gt;&lt;P&gt;extern "C" void __iar_argc_argv() {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mbed_sdk_init();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mbed_main();&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Provide implementation of _sbrk (low-level dynamic memory allocation&lt;/P&gt;&lt;P&gt;// routine) for GCC_ARM which compares new heap pointer with MSP instead of&lt;/P&gt;&lt;P&gt;// SP.&amp;nbsp; This make it compatible with RTX RTOS thread stacks.&lt;/P&gt;&lt;P&gt;#if defined(TOOLCHAIN_GCC_ARM)&lt;/P&gt;&lt;P&gt;// Linker defined symbol used by _sbrk to indicate where heap should start.&lt;/P&gt;&lt;P&gt;extern "C" int __end__;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#if defined(TARGET_CORTEX_A)&lt;/P&gt;&lt;P&gt;extern "C" uint32_t&amp;nbsp; __HeapLimit;&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Turn off the errno macro and use actual global variable instead.&lt;/P&gt;&lt;P&gt;#undef errno&lt;/P&gt;&lt;P&gt;extern "C" int errno;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// For ARM7 only&lt;/P&gt;&lt;P&gt;register unsigned char * stack_ptr __asm ("sp");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Dynamic memory allocation related syscall.&lt;/P&gt;&lt;P&gt;extern "C" caddr_t _sbrk(int incr) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; static unsigned char* heap = (unsigned char*)&amp;amp;__end__;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; unsigned char*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; prev_heap = heap;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; unsigned char*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new_heap = heap + incr;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#if defined(TARGET_ARM7)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (new_heap &amp;gt;= stack_ptr) {&lt;/P&gt;&lt;P&gt;#elif defined(TARGET_CORTEX_A)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (new_heap &amp;gt;= (unsigned char*)&amp;amp;__HeapLimit) {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* __HeapLimit is end of heap section */&lt;/P&gt;&lt;P&gt;#else&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (new_heap &amp;gt;= (unsigned char*)__get_MSP()) {&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; errno = ENOMEM;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return (caddr_t)-1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; heap = new_heap;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return (caddr_t) prev_heap;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#if defined TOOLCHAIN_GCC_ARM&lt;/P&gt;&lt;P&gt;extern "C" void _exit(int return_code) {&lt;/P&gt;&lt;P&gt;#else&lt;/P&gt;&lt;P&gt;namespace std {&lt;/P&gt;&lt;P&gt;extern "C" void exit(int return_code) {&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#if DEVICE_STDIO_MESSAGES&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fflush(stdout);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fflush(stderr);&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#if DEVICE_SEMIHOST&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (mbed_interface_connected()) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; semihost_exit();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (return_code) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mbed_die();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (1);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#if !defined(TOOLCHAIN_GCC_ARM)&lt;/P&gt;&lt;P&gt;} //namespace std&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;namespace mbed {&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void mbed_set_unbuffered_stream(FILE *_file) {&lt;/P&gt;&lt;P&gt;#if defined (__ICCARM__)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char buf[2];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; std::setvbuf(_file,buf,_IONBF,NULL);&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;#else&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; setbuf(_file, NULL);&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;int mbed_getc(FILE *_file){&lt;/P&gt;&lt;P&gt;#if defined (__ICCARM__)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*This is only valid for unbuffered streams*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int res = std::fgetc(_file);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (res&amp;gt;=0){&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _file-&amp;gt;_Mode = (unsigned short)(_file-&amp;gt;_Mode &amp;amp; ~ 0x1000);/* Unset read mode */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _file-&amp;gt;_Rend = _file-&amp;gt;_Wend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _file-&amp;gt;_Next = _file-&amp;gt;_Wend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return res;&lt;/P&gt;&lt;P&gt;#else&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return std::fgetc(_file);&lt;/P&gt;&lt;P&gt;#endif&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;char* mbed_gets(char*s, int size, FILE *_file){&lt;/P&gt;&lt;P&gt;#if defined (__ICCARM__)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*This is only valid for unbuffered streams*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char *str = fgets(s,size,_file);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (str!=NULL){&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _file-&amp;gt;_Mode = (unsigned short)(_file-&amp;gt;_Mode &amp;amp; ~ 0x1000);/* Unset read mode */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _file-&amp;gt;_Rend = _file-&amp;gt;_Wend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _file-&amp;gt;_Next = _file-&amp;gt;_Wend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return str;&lt;/P&gt;&lt;P&gt;#else&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return std::fgets(s,size,_file);&lt;/P&gt;&lt;P&gt;#endif&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;} // namespace mbed&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Aug 2016 17:52:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565492#M18039</guid>
      <dc:creator>massimomanca</dc:creator>
      <dc:date>2016-08-03T17:52:28Z</dc:date>
    </item>
    <item>
      <title>Re: Possible bug samewhere in Newlibnano</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565493#M18040</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't see anything wrong with retarget.cpp&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, looking at your original post, I see that you are NOT linking with retarget.o, and this is the reason that you are getting the link errors... Have you excluded it from the build? Or is there some other reason why it is not being linked? Anyway, it is a project problem and nothing wrong with the source code or the library.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Aug 2016 06:24:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565493#M18040</guid>
      <dc:creator>avt</dc:creator>
      <dc:date>2016-08-04T06:24:58Z</dc:date>
    </item>
    <item>
      <title>Re: Possible bug samewhere in Newlibnano</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565494#M18041</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It happened to me on LPC824, possible not the same but just a thought. (Using Newlibs nano).&lt;/P&gt;&lt;P&gt;When switching to production state (going for -Os or -O3) my DMA driver (part with originally NXP demo apps and #defines) was not working correctly, sometimes crashes with hardware fault.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After some investigations, we found that (possibly) some originally definitions are wrong (missing volatile or some) and we just don't have time to repair. Since we found a lot of bugs in NXP libs (wrong register masks, copy-paste, etc) we conclude that quick &amp;amp; dirty fix was to use __attribute (-O0) at critical functions and see later on.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Aug 2016 06:47:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565494#M18041</guid>
      <dc:creator>rianzu</dc:creator>
      <dc:date>2016-08-04T06:47:00Z</dc:date>
    </item>
    <item>
      <title>Re: Possible bug samewhere in Newlibnano</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565495#M18042</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Rian,&lt;/P&gt;&lt;P&gt;the situation is strange, looks as the linker suppress __wrap_main and __real_main without any apparent reason because retarget.cpp is built and linked and the only things changing the situation are optimization that could suppress them, instead debug options without any optimization shouldn't. But for me it didn't work in debug and works in release mode... so it is more difficult to understand.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I duplicated a new debug mode based on release mode and then I modified the options to include debug informations... in this way the problem appears, it is very strange.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Aug 2016 13:08:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565495#M18042</guid>
      <dc:creator>massimomanca</dc:creator>
      <dc:date>2016-08-04T13:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: Possible bug samewhere in Newlibnano</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565496#M18043</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please post your non-working project, as an exported zip file, so we can see what you have done wrong.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that you can ATTACH a file (rather than pasting the text into the post). Do this by switching to the advanced editor and then using the Attach button (on the bottom of the editor window).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Aug 2016 13:19:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565496#M18043</guid>
      <dc:creator>avt</dc:creator>
      <dc:date>2016-08-04T13:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: Possible bug samewhere in Newlibnano</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565497#M18044</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I know, it may seem a stupid question but I don't find how to attach a file.... whre have I to look?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Aug 2016 15:54:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565497#M18044</guid>
      <dc:creator>massimomanca</dc:creator>
      <dc:date>2016-08-04T15:54:25Z</dc:date>
    </item>
    <item>
      <title>Re: Possible bug samewhere in Newlibnano</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565498#M18045</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If not optimizations issues (that could be easily verified by forcing -O0 in either DEBUG or RELEASE) you may have a missing (or altered) compiler / linker flag in DEBUG mode. Check out all C/C++ settings and just for test, duplicate RELEASE and manually force to debug with DEBUG directive flag or just create a new one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also had some Eclipse (bad) experiences that were solved only by creating a new project with the same sources. Sometimes in .metadata folder disaster strikes :smileyhappy:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Maybe it's worth to see that cr_init or something for your MCU (asm) is indeed linked into project in DEBUG mode.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Aug 2016 16:03:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565498#M18045</guid>
      <dc:creator>rianzu</dc:creator>
      <dc:date>2016-08-04T16:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: Possible bug samewhere in Newlibnano</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565499#M18046</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wouldn't modify the mbed source code but I think my modification may be useful, more portable and more clear for everyone:&lt;/P&gt;&lt;P&gt;this is the original retarget.cpp code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;extern "C" WEAK void mbed_main(void);&lt;/P&gt;&lt;P&gt;extern "C" WEAK void mbed_main(void)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;extern "C" WEAK void mbed_sdk_init(void);&lt;/P&gt;&lt;P&gt;extern "C" WEAK void mbed_sdk_init(void)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; extern "C" int __real_main(void);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; extern "C" int __wrap_main(void)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mbed_sdk_init();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mbed_main();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return __real_main();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;there are other implementation of __wrap_main()&amp;nbsp; with different names for ARM and IAR compilers but there is no reason to complicate in this way a stupid simple piece of code because in startup.cpp after ram segment initialization in the reset handler there is this code I modified just a little and it works and where there is no call to __wrap_main() (originally in else body only libc init and main calls). It is simpler and portable without strange things on it, if something different is needed is necessary to realize non empty mbed_sdk_init() and mbed_main() (empty weak bodies in retarget.cpp):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;SystemInit();&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;if(software_init_hook) // give control to the RTOS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;software_init_hook(); // this will also call __libc_init_array&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;else&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;{&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;__libc_init_array();&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;mbed_sdk_init();&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;mbed_main();&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;main();&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp; &lt;/TD&gt;&lt;TD&gt;}&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;may be I will modify in a more elegant way but at the moment it works and I can complete my tests.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Aug 2016 16:08:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565499#M18046</guid>
      <dc:creator>massimomanca</dc:creator>
      <dc:date>2016-08-04T16:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: Possible bug samewhere in Newlibnano</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565500#M18047</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you like and you can send me your source code I would be happy to test and debug a little bit it because I also use LPC824 without many problems. Your code will be treated as your private code as you send it to any NXP field at maximum confidential level.&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Massimo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Aug 2016 16:11:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565500#M18047</guid>
      <dc:creator>massimomanca</dc:creator>
      <dc:date>2016-08-04T16:11:29Z</dc:date>
    </item>
    <item>
      <title>Re: Possible bug samewhere in Newlibnano</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565501#M18048</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I already checked in that way, think that when you use an IDE, quite frequently I tested it before for a couple of months.&lt;/P&gt;&lt;P&gt;There are really no source code or compiler/linker options involved other that a combination of debugging and optimization options. The crazy thing is that it worked with higher optimization levels and no debugging options so exactly the worst conditions and didn't work with the more permissive debug conditions.&lt;/P&gt;&lt;P&gt;So it may be a compiler issue removing death code that... honestly it is death code...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Aug 2016 16:26:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565501#M18048</guid>
      <dc:creator>massimomanca</dc:creator>
      <dc:date>2016-08-04T16:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: Possible bug samewhere in Newlibnano</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565502#M18049</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Without seeing your project, who knows? If you can post it, somebody may be able to offer some advice, without it you are on your own. Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Aug 2016 08:42:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Possible-bug-samewhere-in-Newlibnano/m-p/565502#M18049</guid>
      <dc:creator>avt</dc:creator>
      <dc:date>2016-08-05T08:42:11Z</dc:date>
    </item>
  </channel>
</rss>

