fix for mbed lib issue 3 (i2c problem) see also https://mbed.org/users/mbed_official/code/mbed/issues/3 affected implementations: LPC812, LPC11U24, LPC1768, LPC2368, LPC4088

Fork of mbed-src by mbed official

Committer:
emilmont
Date:
Mon Feb 18 11:44:18 2013 +0000
Revision:
2:143cac498751
Parent:
1:62685faffa05
Child:
5:ab1c572cb536
Update mbed sources to Rev 59

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:fd0d7bdfcdc2 1 /* mbed Microcontroller Library
emilmont 2:143cac498751 2 * Copyright (c) 2006-2013 ARM Limited
mbed_official 0:fd0d7bdfcdc2 3 *
emilmont 2:143cac498751 4 * Licensed under the Apache License, Version 2.0 (the "License");
emilmont 2:143cac498751 5 * you may not use this file except in compliance with the License.
emilmont 2:143cac498751 6 * You may obtain a copy of the License at
mbed_official 0:fd0d7bdfcdc2 7 *
emilmont 2:143cac498751 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 0:fd0d7bdfcdc2 9 *
emilmont 2:143cac498751 10 * Unless required by applicable law or agreed to in writing, software
emilmont 2:143cac498751 11 * distributed under the License is distributed on an "AS IS" BASIS,
emilmont 2:143cac498751 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
emilmont 2:143cac498751 13 * See the License for the specific language governing permissions and
emilmont 2:143cac498751 14 * limitations under the License.
mbed_official 0:fd0d7bdfcdc2 15 */
mbed_official 0:fd0d7bdfcdc2 16 #include "platform.h"
mbed_official 0:fd0d7bdfcdc2 17 #include "FileHandle.h"
mbed_official 0:fd0d7bdfcdc2 18 #include "FileSystemLike.h"
emilmont 2:143cac498751 19 #include "FilePath.h"
mbed_official 0:fd0d7bdfcdc2 20 #include "serial_api.h"
mbed_official 0:fd0d7bdfcdc2 21 #include <errno.h>
mbed_official 0:fd0d7bdfcdc2 22
emilmont 2:143cac498751 23 #if defined(__ARMCC_VERSION)
mbed_official 0:fd0d7bdfcdc2 24 # include <rt_sys.h>
mbed_official 0:fd0d7bdfcdc2 25 # define PREFIX(x) _sys##x
mbed_official 0:fd0d7bdfcdc2 26 # define OPEN_MAX _SYS_OPEN
mbed_official 0:fd0d7bdfcdc2 27 # ifdef __MICROLIB
mbed_official 0:fd0d7bdfcdc2 28 # pragma import(__use_full_stdio)
mbed_official 0:fd0d7bdfcdc2 29 # endif
mbed_official 0:fd0d7bdfcdc2 30
emilmont 2:143cac498751 31 #elif defined(__ICCARM__)
emilmont 2:143cac498751 32 # include <yfuns.h>
emilmont 2:143cac498751 33 # define PREFIX(x) _##x
emilmont 2:143cac498751 34 # define OPEN_MAX 16
emilmont 2:143cac498751 35
emilmont 2:143cac498751 36 # define STDIN_FILENO 0
emilmont 2:143cac498751 37 # define STDOUT_FILENO 1
emilmont 2:143cac498751 38 # define STDERR_FILENO 2
emilmont 2:143cac498751 39
mbed_official 0:fd0d7bdfcdc2 40 #else
mbed_official 0:fd0d7bdfcdc2 41 # include <sys/stat.h>
mbed_official 0:fd0d7bdfcdc2 42 # include <sys/unistd.h>
mbed_official 0:fd0d7bdfcdc2 43 # include <sys/syslimits.h>
mbed_official 0:fd0d7bdfcdc2 44 # define PREFIX(x) x
mbed_official 0:fd0d7bdfcdc2 45 #endif
mbed_official 0:fd0d7bdfcdc2 46
mbed_official 0:fd0d7bdfcdc2 47 using namespace mbed;
mbed_official 0:fd0d7bdfcdc2 48
mbed_official 0:fd0d7bdfcdc2 49 extern const char __stdin_name[] = "/stdin";
mbed_official 0:fd0d7bdfcdc2 50 extern const char __stdout_name[] = "/stdout";
mbed_official 0:fd0d7bdfcdc2 51 extern const char __stderr_name[] = "/stderr";
mbed_official 0:fd0d7bdfcdc2 52
mbed_official 0:fd0d7bdfcdc2 53 /* newlib has the filehandle field in the FILE struct as a short, so
mbed_official 0:fd0d7bdfcdc2 54 * we can't just return a Filehandle* from _open and instead have to
mbed_official 0:fd0d7bdfcdc2 55 * put it in a filehandles array and return the index into that array
mbed_official 0:fd0d7bdfcdc2 56 * (or rather index+3, as filehandles 0-2 are stdin/out/err).
mbed_official 0:fd0d7bdfcdc2 57 */
mbed_official 0:fd0d7bdfcdc2 58 static FileHandle *filehandles[OPEN_MAX];
mbed_official 0:fd0d7bdfcdc2 59
mbed_official 0:fd0d7bdfcdc2 60 FileHandle::~FileHandle() {
mbed_official 0:fd0d7bdfcdc2 61 /* Remove all open filehandles for this */
mbed_official 0:fd0d7bdfcdc2 62 for (unsigned int fh_i = 0; fh_i < sizeof(filehandles)/sizeof(*filehandles); fh_i++) {
mbed_official 0:fd0d7bdfcdc2 63 if (filehandles[fh_i] == this) {
mbed_official 0:fd0d7bdfcdc2 64 filehandles[fh_i] = NULL;
mbed_official 0:fd0d7bdfcdc2 65 }
mbed_official 0:fd0d7bdfcdc2 66 }
mbed_official 0:fd0d7bdfcdc2 67 }
mbed_official 0:fd0d7bdfcdc2 68
mbed_official 0:fd0d7bdfcdc2 69 #if DEVICE_SERIAL
mbed_official 0:fd0d7bdfcdc2 70 extern int stdio_uart_inited;
mbed_official 0:fd0d7bdfcdc2 71 extern serial_t stdio_uart;
mbed_official 0:fd0d7bdfcdc2 72 #endif
mbed_official 0:fd0d7bdfcdc2 73
mbed_official 0:fd0d7bdfcdc2 74 static void init_serial() {
mbed_official 0:fd0d7bdfcdc2 75 #if DEVICE_SERIAL
mbed_official 0:fd0d7bdfcdc2 76 if (stdio_uart_inited) return;
mbed_official 0:fd0d7bdfcdc2 77 serial_init(&stdio_uart, STDIO_UART_TX, STDIO_UART_RX);
mbed_official 0:fd0d7bdfcdc2 78 serial_format(&stdio_uart, 8, ParityNone, 1);
mbed_official 0:fd0d7bdfcdc2 79 serial_baud(&stdio_uart, 9600);
mbed_official 0:fd0d7bdfcdc2 80 #endif
mbed_official 0:fd0d7bdfcdc2 81 }
mbed_official 0:fd0d7bdfcdc2 82
emilmont 2:143cac498751 83 static inline int openmode_to_posix(int openmode) {
emilmont 2:143cac498751 84 int posix = openmode;
mbed_official 0:fd0d7bdfcdc2 85 #ifdef __ARMCC_VERSION
emilmont 2:143cac498751 86 if (openmode & OPEN_PLUS) {
emilmont 2:143cac498751 87 posix = O_RDWR;
emilmont 2:143cac498751 88 } else if(openmode & OPEN_W) {
emilmont 2:143cac498751 89 posix = O_WRONLY;
emilmont 2:143cac498751 90 } else if(openmode & OPEN_A) {
emilmont 2:143cac498751 91 posix = O_WRONLY|O_APPEND;
mbed_official 0:fd0d7bdfcdc2 92 } else {
emilmont 2:143cac498751 93 posix = O_RDONLY;
mbed_official 0:fd0d7bdfcdc2 94 }
mbed_official 0:fd0d7bdfcdc2 95 /* a, w, a+, w+ all create if file does not already exist */
emilmont 2:143cac498751 96 if (openmode & (OPEN_A|OPEN_W)) {
emilmont 2:143cac498751 97 posix |= O_CREAT;
mbed_official 0:fd0d7bdfcdc2 98 }
mbed_official 0:fd0d7bdfcdc2 99 /* w and w+ truncate */
emilmont 2:143cac498751 100 if (openmode & OPEN_W) {
emilmont 2:143cac498751 101 posix |= O_TRUNC;
mbed_official 0:fd0d7bdfcdc2 102 }
emilmont 2:143cac498751 103 #elif defined(__ICCARM__)
emilmont 2:143cac498751 104 switch (openmode & _LLIO_RDWRMASK) {
emilmont 2:143cac498751 105 case _LLIO_RDONLY: posix = O_RDONLY; break;
emilmont 2:143cac498751 106 case _LLIO_WRONLY: posix = O_WRONLY; break;
emilmont 2:143cac498751 107 case _LLIO_RDWR : posix = O_RDWR ; break;
emilmont 2:143cac498751 108 }
emilmont 2:143cac498751 109 if (openmode & _LLIO_CREAT ) posix |= O_CREAT;
emilmont 2:143cac498751 110 if (openmode & _LLIO_APPEND) posix |= O_APPEND;
emilmont 2:143cac498751 111 if (openmode & _LLIO_TRUNC ) posix |= O_TRUNC;
emilmont 2:143cac498751 112 #endif
emilmont 2:143cac498751 113 return posix;
mbed_official 0:fd0d7bdfcdc2 114 }
mbed_official 0:fd0d7bdfcdc2 115
mbed_official 0:fd0d7bdfcdc2 116 extern "C" FILEHANDLE PREFIX(_open)(const char* name, int openmode) {
mbed_official 0:fd0d7bdfcdc2 117 /* Use the posix convention that stdin,out,err are filehandles 0,1,2.
mbed_official 0:fd0d7bdfcdc2 118 */
mbed_official 0:fd0d7bdfcdc2 119 if (std::strcmp(name, __stdin_name) == 0) {
mbed_official 0:fd0d7bdfcdc2 120 init_serial();
mbed_official 0:fd0d7bdfcdc2 121 return 0;
mbed_official 0:fd0d7bdfcdc2 122 } else if (std::strcmp(name, __stdout_name) == 0) {
mbed_official 0:fd0d7bdfcdc2 123 init_serial();
mbed_official 0:fd0d7bdfcdc2 124 return 1;
mbed_official 0:fd0d7bdfcdc2 125 } else if (std::strcmp(name,__stderr_name) == 0) {
mbed_official 0:fd0d7bdfcdc2 126 init_serial();
mbed_official 0:fd0d7bdfcdc2 127 return 2;
mbed_official 0:fd0d7bdfcdc2 128 }
emilmont 2:143cac498751 129
mbed_official 0:fd0d7bdfcdc2 130 // find the first empty slot in filehandles
mbed_official 0:fd0d7bdfcdc2 131 unsigned int fh_i;
mbed_official 0:fd0d7bdfcdc2 132 for (fh_i = 0; fh_i < sizeof(filehandles)/sizeof(*filehandles); fh_i++) {
mbed_official 0:fd0d7bdfcdc2 133 if (filehandles[fh_i] == NULL) break;
mbed_official 0:fd0d7bdfcdc2 134 }
mbed_official 0:fd0d7bdfcdc2 135 if (fh_i >= sizeof(filehandles)/sizeof(*filehandles)) {
mbed_official 0:fd0d7bdfcdc2 136 return -1;
mbed_official 0:fd0d7bdfcdc2 137 }
emilmont 2:143cac498751 138
mbed_official 0:fd0d7bdfcdc2 139 FileHandle *res;
emilmont 2:143cac498751 140
mbed_official 0:fd0d7bdfcdc2 141 /* FILENAME: ":0x12345678" describes a FileLike* */
mbed_official 0:fd0d7bdfcdc2 142 if (name[0] == ':') {
mbed_official 0:fd0d7bdfcdc2 143 void *p;
mbed_official 0:fd0d7bdfcdc2 144 sscanf(name, ":%p", &p);
mbed_official 0:fd0d7bdfcdc2 145 res = (FileHandle*)p;
emilmont 2:143cac498751 146
mbed_official 0:fd0d7bdfcdc2 147 /* FILENAME: "/file_system/file_name" */
mbed_official 0:fd0d7bdfcdc2 148 } else {
mbed_official 0:fd0d7bdfcdc2 149 FilePath path(name);
emilmont 2:143cac498751 150
emilmont 2:143cac498751 151 if (path.isFile()) {
emilmont 2:143cac498751 152 res = path.file();
emilmont 2:143cac498751 153 } else {
emilmont 2:143cac498751 154 FileSystemLike *fs = path.fileSystem();
emilmont 2:143cac498751 155 if (fs == NULL) return -1;
emilmont 2:143cac498751 156 int posix_mode = openmode_to_posix(openmode);
emilmont 2:143cac498751 157 res = fs->open(path.fileName(), posix_mode); /* NULL if fails */
emilmont 2:143cac498751 158 }
mbed_official 0:fd0d7bdfcdc2 159 }
emilmont 2:143cac498751 160
mbed_official 0:fd0d7bdfcdc2 161 if (res == NULL) return -1;
mbed_official 0:fd0d7bdfcdc2 162 filehandles[fh_i] = res;
emilmont 2:143cac498751 163
mbed_official 0:fd0d7bdfcdc2 164 return fh_i + 3; // +3 as filehandles 0-2 are stdin/out/err
mbed_official 0:fd0d7bdfcdc2 165 }
mbed_official 0:fd0d7bdfcdc2 166
mbed_official 0:fd0d7bdfcdc2 167 extern "C" int PREFIX(_close)(FILEHANDLE fh) {
mbed_official 0:fd0d7bdfcdc2 168 if (fh < 3) return 0;
emilmont 2:143cac498751 169
mbed_official 0:fd0d7bdfcdc2 170 FileHandle* fhc = filehandles[fh-3];
mbed_official 0:fd0d7bdfcdc2 171 filehandles[fh-3] = NULL;
mbed_official 0:fd0d7bdfcdc2 172 if (fhc == NULL) return -1;
emilmont 2:143cac498751 173
mbed_official 0:fd0d7bdfcdc2 174 return fhc->close();
mbed_official 0:fd0d7bdfcdc2 175 }
mbed_official 0:fd0d7bdfcdc2 176
emilmont 2:143cac498751 177 #if defined(__ICCARM__)
emilmont 2:143cac498751 178 extern "C" size_t __write (int fh, const unsigned char *buffer, size_t length) {
emilmont 2:143cac498751 179 #else
emilmont 2:143cac498751 180 extern "C" int PREFIX(_write)(FILEHANDLE fh, const unsigned char *buffer, unsigned int length, int mode) {
emilmont 2:143cac498751 181 #endif
mbed_official 0:fd0d7bdfcdc2 182 int n; // n is the number of bytes written
mbed_official 0:fd0d7bdfcdc2 183 if (fh < 3) {
mbed_official 0:fd0d7bdfcdc2 184 #if DEVICE_SERIAL
mbed_official 0:fd0d7bdfcdc2 185 if (!stdio_uart_inited) init_serial();
mbed_official 0:fd0d7bdfcdc2 186 for (unsigned int i = 0; i < length; i++) {
mbed_official 0:fd0d7bdfcdc2 187 serial_putc(&stdio_uart, buffer[i]);
mbed_official 0:fd0d7bdfcdc2 188 }
mbed_official 0:fd0d7bdfcdc2 189 #endif
mbed_official 0:fd0d7bdfcdc2 190 n = length;
mbed_official 0:fd0d7bdfcdc2 191 } else {
mbed_official 0:fd0d7bdfcdc2 192 FileHandle* fhc = filehandles[fh-3];
mbed_official 0:fd0d7bdfcdc2 193 if (fhc == NULL) return -1;
emilmont 2:143cac498751 194
mbed_official 0:fd0d7bdfcdc2 195 n = fhc->write(buffer, length);
mbed_official 0:fd0d7bdfcdc2 196 }
mbed_official 0:fd0d7bdfcdc2 197 #ifdef __ARMCC_VERSION
mbed_official 0:fd0d7bdfcdc2 198 return length-n;
mbed_official 0:fd0d7bdfcdc2 199 #else
mbed_official 0:fd0d7bdfcdc2 200 return n;
emilmont 2:143cac498751 201 #endif
mbed_official 0:fd0d7bdfcdc2 202 }
mbed_official 0:fd0d7bdfcdc2 203
emilmont 2:143cac498751 204 #if defined(__ICCARM__)
emilmont 2:143cac498751 205 extern "C" size_t __read (int fh, unsigned char *buffer, size_t length) {
emilmont 2:143cac498751 206 #else
emilmont 2:143cac498751 207 extern "C" int PREFIX(_read)(FILEHANDLE fh, unsigned char *buffer, unsigned int length, int mode) {
emilmont 2:143cac498751 208 #endif
mbed_official 0:fd0d7bdfcdc2 209 int n; // n is the number of bytes read
mbed_official 0:fd0d7bdfcdc2 210 if (fh < 3) {
mbed_official 0:fd0d7bdfcdc2 211 // only read a character at a time from stdin
mbed_official 0:fd0d7bdfcdc2 212 #if DEVICE_SERIAL
mbed_official 0:fd0d7bdfcdc2 213 *buffer = serial_getc(&stdio_uart);
mbed_official 0:fd0d7bdfcdc2 214 #endif
mbed_official 0:fd0d7bdfcdc2 215 n = 1;
mbed_official 0:fd0d7bdfcdc2 216 } else {
mbed_official 0:fd0d7bdfcdc2 217 FileHandle* fhc = filehandles[fh-3];
mbed_official 0:fd0d7bdfcdc2 218 if (fhc == NULL) return -1;
emilmont 2:143cac498751 219
mbed_official 0:fd0d7bdfcdc2 220 n = fhc->read(buffer, length);
mbed_official 0:fd0d7bdfcdc2 221 }
mbed_official 0:fd0d7bdfcdc2 222 #ifdef __ARMCC_VERSION
mbed_official 0:fd0d7bdfcdc2 223 return length-n;
mbed_official 0:fd0d7bdfcdc2 224 #else
mbed_official 0:fd0d7bdfcdc2 225 return n;
emilmont 2:143cac498751 226 #endif
mbed_official 0:fd0d7bdfcdc2 227 }
mbed_official 0:fd0d7bdfcdc2 228
mbed_official 0:fd0d7bdfcdc2 229 #ifdef __ARMCC_VERSION
mbed_official 0:fd0d7bdfcdc2 230 extern "C" int PREFIX(_istty)(FILEHANDLE fh)
mbed_official 0:fd0d7bdfcdc2 231 #else
emilmont 2:143cac498751 232 extern "C" int _isatty(FILEHANDLE fh)
mbed_official 0:fd0d7bdfcdc2 233 #endif
mbed_official 0:fd0d7bdfcdc2 234 {
mbed_official 0:fd0d7bdfcdc2 235 /* stdin, stdout and stderr should be tty */
mbed_official 0:fd0d7bdfcdc2 236 if (fh < 3) return 1;
emilmont 2:143cac498751 237
mbed_official 0:fd0d7bdfcdc2 238 FileHandle* fhc = filehandles[fh-3];
mbed_official 0:fd0d7bdfcdc2 239 if (fhc == NULL) return -1;
emilmont 2:143cac498751 240
mbed_official 0:fd0d7bdfcdc2 241 return fhc->isatty();
mbed_official 0:fd0d7bdfcdc2 242 }
mbed_official 0:fd0d7bdfcdc2 243
emilmont 2:143cac498751 244 extern "C"
emilmont 2:143cac498751 245 #if defined(__ARMCC_VERSION)
emilmont 2:143cac498751 246 int _sys_seek(FILEHANDLE fh, long position)
emilmont 2:143cac498751 247 #elif defined(__ICCARM__)
emilmont 2:143cac498751 248 long __lseek(int fh, long offset, int whence)
mbed_official 0:fd0d7bdfcdc2 249 #else
emilmont 2:143cac498751 250 int _lseek(FILEHANDLE fh, int offset, int whence)
emilmont 2:143cac498751 251 #endif
emilmont 2:143cac498751 252 {
mbed_official 0:fd0d7bdfcdc2 253 if (fh < 3) return 0;
emilmont 2:143cac498751 254
emilmont 2:143cac498751 255 FileHandle* fhc = filehandles[fh-3];
mbed_official 0:fd0d7bdfcdc2 256 if (fhc == NULL) return -1;
emilmont 2:143cac498751 257
emilmont 2:143cac498751 258 #if defined(__ARMCC_VERSION)
emilmont 2:143cac498751 259 return fhc->lseek(position, SEEK_SET);
emilmont 2:143cac498751 260 #else
mbed_official 0:fd0d7bdfcdc2 261 return fhc->lseek(offset, whence);
emilmont 2:143cac498751 262 #endif
mbed_official 0:fd0d7bdfcdc2 263 }
mbed_official 0:fd0d7bdfcdc2 264
mbed_official 0:fd0d7bdfcdc2 265 #ifdef __ARMCC_VERSION
mbed_official 0:fd0d7bdfcdc2 266 extern "C" int PREFIX(_ensure)(FILEHANDLE fh) {
mbed_official 0:fd0d7bdfcdc2 267 if (fh < 3) return 0;
emilmont 2:143cac498751 268
mbed_official 0:fd0d7bdfcdc2 269 FileHandle* fhc = filehandles[fh-3];
mbed_official 0:fd0d7bdfcdc2 270 if (fhc == NULL) return -1;
emilmont 2:143cac498751 271
mbed_official 0:fd0d7bdfcdc2 272 return fhc->fsync();
mbed_official 0:fd0d7bdfcdc2 273 }
mbed_official 0:fd0d7bdfcdc2 274
mbed_official 0:fd0d7bdfcdc2 275 extern "C" long PREFIX(_flen)(FILEHANDLE fh) {
mbed_official 0:fd0d7bdfcdc2 276 if (fh < 3) return 0;
emilmont 2:143cac498751 277
mbed_official 0:fd0d7bdfcdc2 278 FileHandle* fhc = filehandles[fh-3];
mbed_official 0:fd0d7bdfcdc2 279 if (fhc == NULL) return -1;
emilmont 2:143cac498751 280
mbed_official 0:fd0d7bdfcdc2 281 return fhc->flen();
mbed_official 0:fd0d7bdfcdc2 282 }
mbed_official 0:fd0d7bdfcdc2 283 #endif
mbed_official 0:fd0d7bdfcdc2 284
mbed_official 0:fd0d7bdfcdc2 285
emilmont 2:143cac498751 286 #if !defined(__ARMCC_VERSION) && !defined(__ICCARM__)
mbed_official 0:fd0d7bdfcdc2 287 extern "C" int _fstat(int fd, struct stat *st) {
mbed_official 0:fd0d7bdfcdc2 288 if ((STDOUT_FILENO == fd) || (STDERR_FILENO == fd) || (STDIN_FILENO == fd)) {
mbed_official 0:fd0d7bdfcdc2 289 st->st_mode = S_IFCHR;
mbed_official 0:fd0d7bdfcdc2 290 return 0;
mbed_official 0:fd0d7bdfcdc2 291 }
emilmont 2:143cac498751 292
mbed_official 0:fd0d7bdfcdc2 293 errno = EBADF;
mbed_official 0:fd0d7bdfcdc2 294 return -1;
mbed_official 0:fd0d7bdfcdc2 295 }
mbed_official 0:fd0d7bdfcdc2 296 #endif
mbed_official 0:fd0d7bdfcdc2 297
mbed_official 0:fd0d7bdfcdc2 298 namespace std {
mbed_official 0:fd0d7bdfcdc2 299 extern "C" int remove(const char *path) {
emilmont 1:62685faffa05 300 FilePath fp(path);
emilmont 1:62685faffa05 301 FileSystemLike *fs = fp.fileSystem();
mbed_official 0:fd0d7bdfcdc2 302 if (fs == NULL) return -1;
emilmont 2:143cac498751 303
emilmont 1:62685faffa05 304 return fs->remove(fp.fileName());
mbed_official 0:fd0d7bdfcdc2 305 }
mbed_official 0:fd0d7bdfcdc2 306
mbed_official 0:fd0d7bdfcdc2 307 extern "C" int rename(const char *oldname, const char *newname) {
mbed_official 0:fd0d7bdfcdc2 308 return -1;
mbed_official 0:fd0d7bdfcdc2 309 }
mbed_official 0:fd0d7bdfcdc2 310
mbed_official 0:fd0d7bdfcdc2 311 extern "C" char *tmpnam(char *s) {
mbed_official 0:fd0d7bdfcdc2 312 return NULL;
mbed_official 0:fd0d7bdfcdc2 313 }
mbed_official 0:fd0d7bdfcdc2 314
mbed_official 0:fd0d7bdfcdc2 315 extern "C" FILE *tmpfile() {
mbed_official 0:fd0d7bdfcdc2 316 return NULL;
mbed_official 0:fd0d7bdfcdc2 317 }
mbed_official 0:fd0d7bdfcdc2 318 } // namespace std
mbed_official 0:fd0d7bdfcdc2 319
mbed_official 0:fd0d7bdfcdc2 320 #ifdef __ARMCC_VERSION
mbed_official 0:fd0d7bdfcdc2 321 extern "C" char *_sys_command_string(char *cmd, int len) {
mbed_official 0:fd0d7bdfcdc2 322 return NULL;
mbed_official 0:fd0d7bdfcdc2 323 }
mbed_official 0:fd0d7bdfcdc2 324 #endif
mbed_official 0:fd0d7bdfcdc2 325
mbed_official 0:fd0d7bdfcdc2 326 extern "C" DIR *opendir(const char *path) {
mbed_official 0:fd0d7bdfcdc2 327 /* root dir is FileSystemLike */
mbed_official 0:fd0d7bdfcdc2 328 if (path[0] == '/' && path[1] == 0) {
mbed_official 0:fd0d7bdfcdc2 329 return FileSystemLike::opendir();
mbed_official 0:fd0d7bdfcdc2 330 }
emilmont 2:143cac498751 331
emilmont 1:62685faffa05 332 FilePath fp(path);
emilmont 1:62685faffa05 333 FileSystemLike* fs = fp.fileSystem();
mbed_official 0:fd0d7bdfcdc2 334 if (fs == NULL) return NULL;
emilmont 2:143cac498751 335
emilmont 1:62685faffa05 336 return fs->opendir(fp.fileName());
mbed_official 0:fd0d7bdfcdc2 337 }
mbed_official 0:fd0d7bdfcdc2 338
mbed_official 0:fd0d7bdfcdc2 339 extern "C" struct dirent *readdir(DIR *dir) {
mbed_official 0:fd0d7bdfcdc2 340 return dir->readdir();
mbed_official 0:fd0d7bdfcdc2 341 }
mbed_official 0:fd0d7bdfcdc2 342
mbed_official 0:fd0d7bdfcdc2 343 extern "C" int closedir(DIR *dir) {
mbed_official 0:fd0d7bdfcdc2 344 return dir->closedir();
mbed_official 0:fd0d7bdfcdc2 345 }
mbed_official 0:fd0d7bdfcdc2 346
mbed_official 0:fd0d7bdfcdc2 347 extern "C" void rewinddir(DIR *dir) {
mbed_official 0:fd0d7bdfcdc2 348 dir->rewinddir();
mbed_official 0:fd0d7bdfcdc2 349 }
mbed_official 0:fd0d7bdfcdc2 350
mbed_official 0:fd0d7bdfcdc2 351 extern "C" off_t telldir(DIR *dir) {
mbed_official 0:fd0d7bdfcdc2 352 return dir->telldir();
mbed_official 0:fd0d7bdfcdc2 353 }
mbed_official 0:fd0d7bdfcdc2 354
mbed_official 0:fd0d7bdfcdc2 355 extern "C" void seekdir(DIR *dir, off_t off) {
mbed_official 0:fd0d7bdfcdc2 356 dir->seekdir(off);
mbed_official 0:fd0d7bdfcdc2 357 }
mbed_official 0:fd0d7bdfcdc2 358
mbed_official 0:fd0d7bdfcdc2 359 extern "C" int mkdir(const char *path, mode_t mode) {
emilmont 1:62685faffa05 360 FilePath fp(path);
emilmont 1:62685faffa05 361 FileSystemLike *fs = fp.fileSystem();
mbed_official 0:fd0d7bdfcdc2 362 if (fs == NULL) return -1;
emilmont 2:143cac498751 363
emilmont 1:62685faffa05 364 return fs->mkdir(fp.fileName(), mode);
mbed_official 0:fd0d7bdfcdc2 365 }
mbed_official 0:fd0d7bdfcdc2 366
mbed_official 0:fd0d7bdfcdc2 367 #if defined(TOOLCHAIN_GCC_CR) || defined(TOOLCHAIN_GCC_CS) || defined(TOOLCHAIN_GCC_ARM)
mbed_official 0:fd0d7bdfcdc2 368 /* prevents the exception handling name demangling code getting pulled in */
mbed_official 0:fd0d7bdfcdc2 369 #include "error.h"
mbed_official 0:fd0d7bdfcdc2 370 namespace __gnu_cxx {
mbed_official 0:fd0d7bdfcdc2 371 void __verbose_terminate_handler() {
mbed_official 0:fd0d7bdfcdc2 372 error("Exception");
mbed_official 0:fd0d7bdfcdc2 373 }
mbed_official 0:fd0d7bdfcdc2 374 }
mbed_official 0:fd0d7bdfcdc2 375 #endif
mbed_official 0:fd0d7bdfcdc2 376
mbed_official 0:fd0d7bdfcdc2 377 // Make sure we are pulling in the retargeting module at link time
mbed_official 0:fd0d7bdfcdc2 378 volatile int stdio_retargeting_module;