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:
Thu Nov 29 15:41:14 2012 +0000
Revision:
1:62685faffa05
Parent:
0:fd0d7bdfcdc2
Child:
2:143cac498751
Update sources to [Rev 49]

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:fd0d7bdfcdc2 1 /* mbed Microcontroller Library
mbed_official 0:fd0d7bdfcdc2 2 * Copyright (c) 2006-2012 ARM Limited
mbed_official 0:fd0d7bdfcdc2 3 *
mbed_official 0:fd0d7bdfcdc2 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
mbed_official 0:fd0d7bdfcdc2 5 * of this software and associated documentation files (the "Software"), to deal
mbed_official 0:fd0d7bdfcdc2 6 * in the Software without restriction, including without limitation the rights
mbed_official 0:fd0d7bdfcdc2 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mbed_official 0:fd0d7bdfcdc2 8 * copies of the Software, and to permit persons to whom the Software is
mbed_official 0:fd0d7bdfcdc2 9 * furnished to do so, subject to the following conditions:
mbed_official 0:fd0d7bdfcdc2 10 *
mbed_official 0:fd0d7bdfcdc2 11 * The above copyright notice and this permission notice shall be included in
mbed_official 0:fd0d7bdfcdc2 12 * all copies or substantial portions of the Software.
mbed_official 0:fd0d7bdfcdc2 13 *
mbed_official 0:fd0d7bdfcdc2 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mbed_official 0:fd0d7bdfcdc2 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mbed_official 0:fd0d7bdfcdc2 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mbed_official 0:fd0d7bdfcdc2 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mbed_official 0:fd0d7bdfcdc2 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mbed_official 0:fd0d7bdfcdc2 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
mbed_official 0:fd0d7bdfcdc2 20 * SOFTWARE.
mbed_official 0:fd0d7bdfcdc2 21 */
mbed_official 0:fd0d7bdfcdc2 22 #include "platform.h"
mbed_official 0:fd0d7bdfcdc2 23 #include "FileHandle.h"
mbed_official 0:fd0d7bdfcdc2 24 #include "FileSystemLike.h"
mbed_official 0:fd0d7bdfcdc2 25 #include "serial_api.h"
mbed_official 0:fd0d7bdfcdc2 26 #include <errno.h>
mbed_official 0:fd0d7bdfcdc2 27
mbed_official 0:fd0d7bdfcdc2 28 #ifdef __ARMCC_VERSION
mbed_official 0:fd0d7bdfcdc2 29 # include <rt_sys.h>
mbed_official 0:fd0d7bdfcdc2 30 # define PREFIX(x) _sys##x
mbed_official 0:fd0d7bdfcdc2 31 # define OPEN_MAX _SYS_OPEN
mbed_official 0:fd0d7bdfcdc2 32 # ifdef __MICROLIB
mbed_official 0:fd0d7bdfcdc2 33 # pragma import(__use_full_stdio)
mbed_official 0:fd0d7bdfcdc2 34 # endif
mbed_official 0:fd0d7bdfcdc2 35
mbed_official 0:fd0d7bdfcdc2 36 #else
mbed_official 0:fd0d7bdfcdc2 37 # include <sys/stat.h>
mbed_official 0:fd0d7bdfcdc2 38 # include <sys/unistd.h>
mbed_official 0:fd0d7bdfcdc2 39 # include <sys/syslimits.h>
mbed_official 0:fd0d7bdfcdc2 40 # define PREFIX(x) x
mbed_official 0:fd0d7bdfcdc2 41 #endif
mbed_official 0:fd0d7bdfcdc2 42
mbed_official 0:fd0d7bdfcdc2 43 using namespace mbed;
mbed_official 0:fd0d7bdfcdc2 44
mbed_official 0:fd0d7bdfcdc2 45 extern const char __stdin_name[] = "/stdin";
mbed_official 0:fd0d7bdfcdc2 46 extern const char __stdout_name[] = "/stdout";
mbed_official 0:fd0d7bdfcdc2 47 extern const char __stderr_name[] = "/stderr";
mbed_official 0:fd0d7bdfcdc2 48
mbed_official 0:fd0d7bdfcdc2 49 /* newlib has the filehandle field in the FILE struct as a short, so
mbed_official 0:fd0d7bdfcdc2 50 * we can't just return a Filehandle* from _open and instead have to
mbed_official 0:fd0d7bdfcdc2 51 * put it in a filehandles array and return the index into that array
mbed_official 0:fd0d7bdfcdc2 52 * (or rather index+3, as filehandles 0-2 are stdin/out/err).
mbed_official 0:fd0d7bdfcdc2 53 */
mbed_official 0:fd0d7bdfcdc2 54 static FileHandle *filehandles[OPEN_MAX];
mbed_official 0:fd0d7bdfcdc2 55
mbed_official 0:fd0d7bdfcdc2 56 FileHandle::~FileHandle() {
mbed_official 0:fd0d7bdfcdc2 57 /* Remove all open filehandles for this */
mbed_official 0:fd0d7bdfcdc2 58 for (unsigned int fh_i = 0; fh_i < sizeof(filehandles)/sizeof(*filehandles); fh_i++) {
mbed_official 0:fd0d7bdfcdc2 59 if (filehandles[fh_i] == this) {
mbed_official 0:fd0d7bdfcdc2 60 filehandles[fh_i] = NULL;
mbed_official 0:fd0d7bdfcdc2 61 }
mbed_official 0:fd0d7bdfcdc2 62 }
mbed_official 0:fd0d7bdfcdc2 63 }
mbed_official 0:fd0d7bdfcdc2 64
mbed_official 0:fd0d7bdfcdc2 65 #if DEVICE_SERIAL
mbed_official 0:fd0d7bdfcdc2 66 extern int stdio_uart_inited;
mbed_official 0:fd0d7bdfcdc2 67 extern serial_t stdio_uart;
mbed_official 0:fd0d7bdfcdc2 68 #endif
mbed_official 0:fd0d7bdfcdc2 69
mbed_official 0:fd0d7bdfcdc2 70 static void init_serial() {
mbed_official 0:fd0d7bdfcdc2 71 #if DEVICE_SERIAL
mbed_official 0:fd0d7bdfcdc2 72 if (stdio_uart_inited) return;
mbed_official 0:fd0d7bdfcdc2 73 serial_init(&stdio_uart, STDIO_UART_TX, STDIO_UART_RX);
mbed_official 0:fd0d7bdfcdc2 74 serial_format(&stdio_uart, 8, ParityNone, 1);
mbed_official 0:fd0d7bdfcdc2 75 serial_baud(&stdio_uart, 9600);
mbed_official 0:fd0d7bdfcdc2 76 #endif
mbed_official 0:fd0d7bdfcdc2 77 }
mbed_official 0:fd0d7bdfcdc2 78
mbed_official 0:fd0d7bdfcdc2 79 #ifdef __ARMCC_VERSION
mbed_official 0:fd0d7bdfcdc2 80 static int rvct_openmode_to_posix(int openmode) {
mbed_official 0:fd0d7bdfcdc2 81 /* RVCT openmode -> POSIX flags */
mbed_official 0:fd0d7bdfcdc2 82 int tmpmode = openmode;
mbed_official 0:fd0d7bdfcdc2 83 if (tmpmode & OPEN_PLUS) {
mbed_official 0:fd0d7bdfcdc2 84 openmode = O_RDWR;
mbed_official 0:fd0d7bdfcdc2 85 } else if(tmpmode & OPEN_W) {
mbed_official 0:fd0d7bdfcdc2 86 openmode = O_WRONLY;
mbed_official 0:fd0d7bdfcdc2 87 } else if(tmpmode & OPEN_A) {
mbed_official 0:fd0d7bdfcdc2 88 openmode = O_WRONLY|O_APPEND;
mbed_official 0:fd0d7bdfcdc2 89 } else {
mbed_official 0:fd0d7bdfcdc2 90 openmode = O_RDONLY;
mbed_official 0:fd0d7bdfcdc2 91 }
mbed_official 0:fd0d7bdfcdc2 92 /* a, w, a+, w+ all create if file does not already exist */
mbed_official 0:fd0d7bdfcdc2 93 if (tmpmode & (OPEN_A|OPEN_W)) {
mbed_official 0:fd0d7bdfcdc2 94 openmode |= O_CREAT;
mbed_official 0:fd0d7bdfcdc2 95 }
mbed_official 0:fd0d7bdfcdc2 96 /* w and w+ truncate */
mbed_official 0:fd0d7bdfcdc2 97 if (tmpmode & OPEN_W) {
mbed_official 0:fd0d7bdfcdc2 98 openmode |= O_TRUNC;
mbed_official 0:fd0d7bdfcdc2 99 }
mbed_official 0:fd0d7bdfcdc2 100 return openmode;
mbed_official 0:fd0d7bdfcdc2 101 }
mbed_official 0:fd0d7bdfcdc2 102 #endif
mbed_official 0:fd0d7bdfcdc2 103
mbed_official 0:fd0d7bdfcdc2 104 extern "C" FILEHANDLE PREFIX(_open)(const char* name, int openmode) {
mbed_official 0:fd0d7bdfcdc2 105 /* Use the posix convention that stdin,out,err are filehandles 0,1,2.
mbed_official 0:fd0d7bdfcdc2 106 */
mbed_official 0:fd0d7bdfcdc2 107 if (std::strcmp(name, __stdin_name) == 0) {
mbed_official 0:fd0d7bdfcdc2 108 init_serial();
mbed_official 0:fd0d7bdfcdc2 109 return 0;
mbed_official 0:fd0d7bdfcdc2 110 } else if (std::strcmp(name, __stdout_name) == 0) {
mbed_official 0:fd0d7bdfcdc2 111 init_serial();
mbed_official 0:fd0d7bdfcdc2 112 return 1;
mbed_official 0:fd0d7bdfcdc2 113 } else if (std::strcmp(name,__stderr_name) == 0) {
mbed_official 0:fd0d7bdfcdc2 114 init_serial();
mbed_official 0:fd0d7bdfcdc2 115 return 2;
mbed_official 0:fd0d7bdfcdc2 116 }
mbed_official 0:fd0d7bdfcdc2 117
mbed_official 0:fd0d7bdfcdc2 118 // find the first empty slot in filehandles
mbed_official 0:fd0d7bdfcdc2 119 unsigned int fh_i;
mbed_official 0:fd0d7bdfcdc2 120 for (fh_i = 0; fh_i < sizeof(filehandles)/sizeof(*filehandles); fh_i++) {
mbed_official 0:fd0d7bdfcdc2 121 if (filehandles[fh_i] == NULL) break;
mbed_official 0:fd0d7bdfcdc2 122 }
mbed_official 0:fd0d7bdfcdc2 123 if (fh_i >= sizeof(filehandles)/sizeof(*filehandles)) {
mbed_official 0:fd0d7bdfcdc2 124 return -1;
mbed_official 0:fd0d7bdfcdc2 125 }
mbed_official 0:fd0d7bdfcdc2 126
mbed_official 0:fd0d7bdfcdc2 127 FileHandle *res;
mbed_official 0:fd0d7bdfcdc2 128
mbed_official 0:fd0d7bdfcdc2 129 /* FILENAME: ":0x12345678" describes a FileLike* */
mbed_official 0:fd0d7bdfcdc2 130 if (name[0] == ':') {
mbed_official 0:fd0d7bdfcdc2 131 void *p;
mbed_official 0:fd0d7bdfcdc2 132 sscanf(name, ":%p", &p);
mbed_official 0:fd0d7bdfcdc2 133 res = (FileHandle*)p;
mbed_official 0:fd0d7bdfcdc2 134
mbed_official 0:fd0d7bdfcdc2 135 /* FILENAME: "/file_system/file_name" */
mbed_official 0:fd0d7bdfcdc2 136 } else {
mbed_official 0:fd0d7bdfcdc2 137 FilePath path(name);
mbed_official 0:fd0d7bdfcdc2 138
mbed_official 0:fd0d7bdfcdc2 139 FileSystemLike *fs = path.fileSystem();
mbed_official 0:fd0d7bdfcdc2 140 if (fs == NULL) return -1;
mbed_official 0:fd0d7bdfcdc2 141
mbed_official 0:fd0d7bdfcdc2 142 #ifdef __ARMCC_VERSION
mbed_official 0:fd0d7bdfcdc2 143 openmode = rvct_openmode_to_posix(openmode);
mbed_official 0:fd0d7bdfcdc2 144 #endif
mbed_official 0:fd0d7bdfcdc2 145 res = fs->open(path.fileName(), openmode); /* NULL if fails */
mbed_official 0:fd0d7bdfcdc2 146 }
mbed_official 0:fd0d7bdfcdc2 147
mbed_official 0:fd0d7bdfcdc2 148 if (res == NULL) return -1;
mbed_official 0:fd0d7bdfcdc2 149 filehandles[fh_i] = res;
mbed_official 0:fd0d7bdfcdc2 150 return fh_i + 3; // +3 as filehandles 0-2 are stdin/out/err
mbed_official 0:fd0d7bdfcdc2 151 }
mbed_official 0:fd0d7bdfcdc2 152
mbed_official 0:fd0d7bdfcdc2 153 extern "C" int PREFIX(_close)(FILEHANDLE fh) {
mbed_official 0:fd0d7bdfcdc2 154 if (fh < 3) return 0;
mbed_official 0:fd0d7bdfcdc2 155
mbed_official 0:fd0d7bdfcdc2 156 FileHandle* fhc = filehandles[fh-3];
mbed_official 0:fd0d7bdfcdc2 157 filehandles[fh-3] = NULL;
mbed_official 0:fd0d7bdfcdc2 158 if (fhc == NULL) return -1;
mbed_official 0:fd0d7bdfcdc2 159
mbed_official 0:fd0d7bdfcdc2 160 return fhc->close();
mbed_official 0:fd0d7bdfcdc2 161 }
mbed_official 0:fd0d7bdfcdc2 162
mbed_official 0:fd0d7bdfcdc2 163 extern "C" int PREFIX(_write)(FILEHANDLE fh, const unsigned char* buffer, unsigned int length, int mode) {
mbed_official 0:fd0d7bdfcdc2 164 int n; // n is the number of bytes written
mbed_official 0:fd0d7bdfcdc2 165 if (fh < 3) {
mbed_official 0:fd0d7bdfcdc2 166 #if DEVICE_SERIAL
mbed_official 0:fd0d7bdfcdc2 167 if (!stdio_uart_inited) init_serial();
mbed_official 0:fd0d7bdfcdc2 168 for (unsigned int i = 0; i < length; i++) {
mbed_official 0:fd0d7bdfcdc2 169 serial_putc(&stdio_uart, buffer[i]);
mbed_official 0:fd0d7bdfcdc2 170 }
mbed_official 0:fd0d7bdfcdc2 171 #endif
mbed_official 0:fd0d7bdfcdc2 172 n = length;
mbed_official 0:fd0d7bdfcdc2 173 } else {
mbed_official 0:fd0d7bdfcdc2 174 FileHandle* fhc = filehandles[fh-3];
mbed_official 0:fd0d7bdfcdc2 175 if (fhc == NULL) return -1;
mbed_official 0:fd0d7bdfcdc2 176
mbed_official 0:fd0d7bdfcdc2 177 n = fhc->write(buffer, length);
mbed_official 0:fd0d7bdfcdc2 178 }
mbed_official 0:fd0d7bdfcdc2 179 #ifdef __ARMCC_VERSION
mbed_official 0:fd0d7bdfcdc2 180 return length-n;
mbed_official 0:fd0d7bdfcdc2 181 #else
mbed_official 0:fd0d7bdfcdc2 182 return n;
mbed_official 0:fd0d7bdfcdc2 183 #endif
mbed_official 0:fd0d7bdfcdc2 184 }
mbed_official 0:fd0d7bdfcdc2 185
mbed_official 0:fd0d7bdfcdc2 186 extern "C" int PREFIX(_read)(FILEHANDLE fh, unsigned char* buffer, unsigned int length, int mode) {
mbed_official 0:fd0d7bdfcdc2 187 int n; // n is the number of bytes read
mbed_official 0:fd0d7bdfcdc2 188 if (fh < 3) {
mbed_official 0:fd0d7bdfcdc2 189 // only read a character at a time from stdin
mbed_official 0:fd0d7bdfcdc2 190 #if DEVICE_SERIAL
mbed_official 0:fd0d7bdfcdc2 191 *buffer = serial_getc(&stdio_uart);
mbed_official 0:fd0d7bdfcdc2 192 #endif
mbed_official 0:fd0d7bdfcdc2 193 n = 1;
mbed_official 0:fd0d7bdfcdc2 194 } else {
mbed_official 0:fd0d7bdfcdc2 195 FileHandle* fhc = filehandles[fh-3];
mbed_official 0:fd0d7bdfcdc2 196 if (fhc == NULL) return -1;
mbed_official 0:fd0d7bdfcdc2 197
mbed_official 0:fd0d7bdfcdc2 198 n = fhc->read(buffer, length);
mbed_official 0:fd0d7bdfcdc2 199 }
mbed_official 0:fd0d7bdfcdc2 200 #ifdef __ARMCC_VERSION
mbed_official 0:fd0d7bdfcdc2 201 return length-n;
mbed_official 0:fd0d7bdfcdc2 202 #else
mbed_official 0:fd0d7bdfcdc2 203 return n;
mbed_official 0:fd0d7bdfcdc2 204 #endif
mbed_official 0:fd0d7bdfcdc2 205 }
mbed_official 0:fd0d7bdfcdc2 206
mbed_official 0:fd0d7bdfcdc2 207 #ifdef __ARMCC_VERSION
mbed_official 0:fd0d7bdfcdc2 208 extern "C" int PREFIX(_istty)(FILEHANDLE fh)
mbed_official 0:fd0d7bdfcdc2 209 #else
mbed_official 0:fd0d7bdfcdc2 210 extern "C" int isatty(FILEHANDLE fh)
mbed_official 0:fd0d7bdfcdc2 211 #endif
mbed_official 0:fd0d7bdfcdc2 212 {
mbed_official 0:fd0d7bdfcdc2 213 /* stdin, stdout and stderr should be tty */
mbed_official 0:fd0d7bdfcdc2 214 if (fh < 3) return 1;
mbed_official 0:fd0d7bdfcdc2 215
mbed_official 0:fd0d7bdfcdc2 216 FileHandle* fhc = filehandles[fh-3];
mbed_official 0:fd0d7bdfcdc2 217 if (fhc == NULL) return -1;
mbed_official 0:fd0d7bdfcdc2 218
mbed_official 0:fd0d7bdfcdc2 219 return fhc->isatty();
mbed_official 0:fd0d7bdfcdc2 220 }
mbed_official 0:fd0d7bdfcdc2 221
mbed_official 0:fd0d7bdfcdc2 222 #ifdef __ARMCC_VERSION
mbed_official 0:fd0d7bdfcdc2 223 extern "C" int PREFIX(_seek)(FILEHANDLE fh, long position) {
mbed_official 0:fd0d7bdfcdc2 224 if (fh < 3) return 0;
mbed_official 0:fd0d7bdfcdc2 225
mbed_official 0:fd0d7bdfcdc2 226 FileHandle* fhc = filehandles[fh-3];
mbed_official 0:fd0d7bdfcdc2 227 if (fhc == NULL || fhc->lseek(position, SEEK_SET) == -1) return -1;
mbed_official 0:fd0d7bdfcdc2 228
mbed_official 0:fd0d7bdfcdc2 229 return 0;
mbed_official 0:fd0d7bdfcdc2 230 }
mbed_official 0:fd0d7bdfcdc2 231 #else
mbed_official 0:fd0d7bdfcdc2 232 extern "C" int _lseek(FILEHANDLE fh, int offset, int whence) {
mbed_official 0:fd0d7bdfcdc2 233 if (fh < 3) return 0;
mbed_official 0:fd0d7bdfcdc2 234
mbed_official 0:fd0d7bdfcdc2 235 FileHandle *fhc = filehandles[fh-3];
mbed_official 0:fd0d7bdfcdc2 236 if (fhc == NULL) return -1;
mbed_official 0:fd0d7bdfcdc2 237
mbed_official 0:fd0d7bdfcdc2 238 return fhc->lseek(offset, whence);
mbed_official 0:fd0d7bdfcdc2 239 }
mbed_official 0:fd0d7bdfcdc2 240 #endif
mbed_official 0:fd0d7bdfcdc2 241
mbed_official 0:fd0d7bdfcdc2 242 #ifdef __ARMCC_VERSION
mbed_official 0:fd0d7bdfcdc2 243 extern "C" int PREFIX(_ensure)(FILEHANDLE fh) {
mbed_official 0:fd0d7bdfcdc2 244 if (fh < 3) return 0;
mbed_official 0:fd0d7bdfcdc2 245
mbed_official 0:fd0d7bdfcdc2 246 FileHandle* fhc = filehandles[fh-3];
mbed_official 0:fd0d7bdfcdc2 247 if (fhc == NULL) return -1;
mbed_official 0:fd0d7bdfcdc2 248
mbed_official 0:fd0d7bdfcdc2 249 return fhc->fsync();
mbed_official 0:fd0d7bdfcdc2 250 }
mbed_official 0:fd0d7bdfcdc2 251
mbed_official 0:fd0d7bdfcdc2 252 extern "C" long PREFIX(_flen)(FILEHANDLE fh) {
mbed_official 0:fd0d7bdfcdc2 253 if (fh < 3) return 0;
mbed_official 0:fd0d7bdfcdc2 254
mbed_official 0:fd0d7bdfcdc2 255 FileHandle* fhc = filehandles[fh-3];
mbed_official 0:fd0d7bdfcdc2 256 if (fhc == NULL) return -1;
mbed_official 0:fd0d7bdfcdc2 257
mbed_official 0:fd0d7bdfcdc2 258 return fhc->flen();
mbed_official 0:fd0d7bdfcdc2 259 }
mbed_official 0:fd0d7bdfcdc2 260 #endif
mbed_official 0:fd0d7bdfcdc2 261
mbed_official 0:fd0d7bdfcdc2 262
mbed_official 0:fd0d7bdfcdc2 263 #ifndef __ARMCC_VERSION
mbed_official 0:fd0d7bdfcdc2 264 extern "C" int _fstat(int fd, struct stat *st) {
mbed_official 0:fd0d7bdfcdc2 265 if ((STDOUT_FILENO == fd) || (STDERR_FILENO == fd) || (STDIN_FILENO == fd)) {
mbed_official 0:fd0d7bdfcdc2 266 st->st_mode = S_IFCHR;
mbed_official 0:fd0d7bdfcdc2 267 return 0;
mbed_official 0:fd0d7bdfcdc2 268 }
mbed_official 0:fd0d7bdfcdc2 269
mbed_official 0:fd0d7bdfcdc2 270 errno = EBADF;
mbed_official 0:fd0d7bdfcdc2 271 return -1;
mbed_official 0:fd0d7bdfcdc2 272 }
mbed_official 0:fd0d7bdfcdc2 273 #endif
mbed_official 0:fd0d7bdfcdc2 274
mbed_official 0:fd0d7bdfcdc2 275 namespace std {
mbed_official 0:fd0d7bdfcdc2 276 extern "C" int remove(const char *path) {
emilmont 1:62685faffa05 277 FilePath fp(path);
emilmont 1:62685faffa05 278 FileSystemLike *fs = fp.fileSystem();
mbed_official 0:fd0d7bdfcdc2 279 if (fs == NULL) return -1;
mbed_official 0:fd0d7bdfcdc2 280
emilmont 1:62685faffa05 281 return fs->remove(fp.fileName());
mbed_official 0:fd0d7bdfcdc2 282 }
mbed_official 0:fd0d7bdfcdc2 283
mbed_official 0:fd0d7bdfcdc2 284 extern "C" int rename(const char *oldname, const char *newname) {
mbed_official 0:fd0d7bdfcdc2 285 return -1;
mbed_official 0:fd0d7bdfcdc2 286 }
mbed_official 0:fd0d7bdfcdc2 287
mbed_official 0:fd0d7bdfcdc2 288 extern "C" char *tmpnam(char *s) {
mbed_official 0:fd0d7bdfcdc2 289 return NULL;
mbed_official 0:fd0d7bdfcdc2 290 }
mbed_official 0:fd0d7bdfcdc2 291
mbed_official 0:fd0d7bdfcdc2 292 extern "C" FILE *tmpfile() {
mbed_official 0:fd0d7bdfcdc2 293 return NULL;
mbed_official 0:fd0d7bdfcdc2 294 }
mbed_official 0:fd0d7bdfcdc2 295 } // namespace std
mbed_official 0:fd0d7bdfcdc2 296
mbed_official 0:fd0d7bdfcdc2 297 #ifdef __ARMCC_VERSION
mbed_official 0:fd0d7bdfcdc2 298 extern "C" char *_sys_command_string(char *cmd, int len) {
mbed_official 0:fd0d7bdfcdc2 299 return NULL;
mbed_official 0:fd0d7bdfcdc2 300 }
mbed_official 0:fd0d7bdfcdc2 301 #endif
mbed_official 0:fd0d7bdfcdc2 302
mbed_official 0:fd0d7bdfcdc2 303 extern "C" DIR *opendir(const char *path) {
mbed_official 0:fd0d7bdfcdc2 304 /* root dir is FileSystemLike */
mbed_official 0:fd0d7bdfcdc2 305 if (path[0] == '/' && path[1] == 0) {
mbed_official 0:fd0d7bdfcdc2 306 return FileSystemLike::opendir();
mbed_official 0:fd0d7bdfcdc2 307 }
mbed_official 0:fd0d7bdfcdc2 308
emilmont 1:62685faffa05 309 FilePath fp(path);
emilmont 1:62685faffa05 310 FileSystemLike* fs = fp.fileSystem();
mbed_official 0:fd0d7bdfcdc2 311 if (fs == NULL) return NULL;
mbed_official 0:fd0d7bdfcdc2 312
emilmont 1:62685faffa05 313 return fs->opendir(fp.fileName());
mbed_official 0:fd0d7bdfcdc2 314 }
mbed_official 0:fd0d7bdfcdc2 315
mbed_official 0:fd0d7bdfcdc2 316 extern "C" struct dirent *readdir(DIR *dir) {
mbed_official 0:fd0d7bdfcdc2 317 return dir->readdir();
mbed_official 0:fd0d7bdfcdc2 318 }
mbed_official 0:fd0d7bdfcdc2 319
mbed_official 0:fd0d7bdfcdc2 320 extern "C" int closedir(DIR *dir) {
mbed_official 0:fd0d7bdfcdc2 321 return dir->closedir();
mbed_official 0:fd0d7bdfcdc2 322 }
mbed_official 0:fd0d7bdfcdc2 323
mbed_official 0:fd0d7bdfcdc2 324 extern "C" void rewinddir(DIR *dir) {
mbed_official 0:fd0d7bdfcdc2 325 dir->rewinddir();
mbed_official 0:fd0d7bdfcdc2 326 }
mbed_official 0:fd0d7bdfcdc2 327
mbed_official 0:fd0d7bdfcdc2 328 extern "C" off_t telldir(DIR *dir) {
mbed_official 0:fd0d7bdfcdc2 329 return dir->telldir();
mbed_official 0:fd0d7bdfcdc2 330 }
mbed_official 0:fd0d7bdfcdc2 331
mbed_official 0:fd0d7bdfcdc2 332 extern "C" void seekdir(DIR *dir, off_t off) {
mbed_official 0:fd0d7bdfcdc2 333 dir->seekdir(off);
mbed_official 0:fd0d7bdfcdc2 334 }
mbed_official 0:fd0d7bdfcdc2 335
mbed_official 0:fd0d7bdfcdc2 336 extern "C" int mkdir(const char *path, mode_t mode) {
emilmont 1:62685faffa05 337 FilePath fp(path);
emilmont 1:62685faffa05 338 FileSystemLike *fs = fp.fileSystem();
mbed_official 0:fd0d7bdfcdc2 339 if (fs == NULL) return -1;
mbed_official 0:fd0d7bdfcdc2 340
emilmont 1:62685faffa05 341 return fs->mkdir(fp.fileName(), mode);
mbed_official 0:fd0d7bdfcdc2 342 }
mbed_official 0:fd0d7bdfcdc2 343
mbed_official 0:fd0d7bdfcdc2 344 #if defined(TOOLCHAIN_GCC_CR) || defined(TOOLCHAIN_GCC_CS) || defined(TOOLCHAIN_GCC_ARM)
mbed_official 0:fd0d7bdfcdc2 345 /* prevents the exception handling name demangling code getting pulled in */
mbed_official 0:fd0d7bdfcdc2 346 #include "error.h"
mbed_official 0:fd0d7bdfcdc2 347 namespace __gnu_cxx {
mbed_official 0:fd0d7bdfcdc2 348 void __verbose_terminate_handler() {
mbed_official 0:fd0d7bdfcdc2 349 error("Exception");
mbed_official 0:fd0d7bdfcdc2 350 }
mbed_official 0:fd0d7bdfcdc2 351 }
mbed_official 0:fd0d7bdfcdc2 352 #endif
mbed_official 0:fd0d7bdfcdc2 353
mbed_official 0:fd0d7bdfcdc2 354 // Make sure we are pulling in the retargeting module at link time
mbed_official 0:fd0d7bdfcdc2 355 volatile int stdio_retargeting_module;