Skip to content

Commit 7ca4eab

Browse files
committed
Filesystem: Fixed integration with mbed 2 builds
1 parent b9122c7 commit 7ca4eab

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

drivers/FilePath.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020

2121
#include "drivers/FileSystemLike.h"
2222
#include "drivers/FileLike.h"
23-
#include "filesystem/FileSystem.h"
2423

2524
namespace mbed {
2625
/** \addtogroup drivers */
2726
/** @{*/
2827

28+
class FileSystem;
29+
2930
class FilePath {
3031
public:
3132
FilePath(const char* file_path);

platform/mbed_retarget.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
#include "platform/PlatformMutex.h"
2424
#include "platform/mbed_error.h"
2525
#include "platform/mbed_stats.h"
26+
#if MBED_CONF_FILESYSTEM_PRESENT
2627
#include "filesystem/FileSystem.h"
2728
#include "filesystem/File.h"
2829
#include "filesystem/Dir.h"
30+
#endif
2931
#include <stdlib.h>
3032
#include <string.h>
3133
#if DEVICE_STDIO_MESSAGES
@@ -84,7 +86,9 @@ uint32_t mbed_heap_size = 0;
8486
* (or rather index+3, as filehandles 0-2 are stdin/out/err).
8587
*/
8688
static FileLike *filehandles[OPEN_MAX];
89+
#if MBED_CONF_FILESYSTEM_PRESENT
8790
static File fileobjects[OPEN_MAX];
91+
#endif
8892
static SingletonPtr<PlatformMutex> filehandle_mutex;
8993

9094
namespace mbed {
@@ -236,6 +240,7 @@ extern "C" FILEHANDLE PREFIX(_open)(const char* name, int openmode) {
236240
return -1;
237241
} else if (path.isFile()) {
238242
res = path.file();
243+
#if MBED_CONF_FILESYSTEM_PRESENT
239244
} else {
240245
FileSystem *fs = path.fileSystem();
241246
if (fs == NULL) {
@@ -252,6 +257,7 @@ extern "C" FILEHANDLE PREFIX(_open)(const char* name, int openmode) {
252257
} else {
253258
res = &fileobjects[fh_i];
254259
}
260+
#endif
255261
}
256262
}
257263

@@ -462,6 +468,7 @@ extern "C" int _fstat(int fd, struct stat *st) {
462468

463469
namespace std {
464470
extern "C" int remove(const char *path) {
471+
#if MBED_CONF_FILESYSTEM_PRESENT
465472
errno = EBADF;
466473
FilePath fp(path);
467474
FileSystem *fs = fp.fileSystem();
@@ -474,9 +481,14 @@ extern "C" int remove(const char *path) {
474481
} else {
475482
return 0;
476483
}
484+
#else
485+
errno = ENOSYS;
486+
return -1;
487+
#endif
477488
}
478489

479490
extern "C" int rename(const char *oldname, const char *newname) {
491+
#if MBED_CONF_FILESYSTEM_PRESENT
480492
errno = EBADF;
481493
FilePath fpOld(oldname);
482494
FilePath fpNew(newname);
@@ -493,6 +505,10 @@ extern "C" int rename(const char *oldname, const char *newname) {
493505
} else {
494506
return 0;
495507
}
508+
#else
509+
errno = ENOSYS;
510+
return -1;
511+
#endif
496512
}
497513

498514
extern "C" char *tmpnam(char *s) {
@@ -513,6 +529,7 @@ extern "C" char *_sys_command_string(char *cmd, int len) {
513529
#endif
514530

515531
extern "C" DIR *opendir(const char *path) {
532+
#if MBED_CONF_FILESYSTEM_PRESENT
516533
errno = EBADF;
517534

518535
FilePath fp(path);
@@ -528,9 +545,14 @@ extern "C" DIR *opendir(const char *path) {
528545
}
529546

530547
return dir;
548+
#else
549+
errno = ENOSYS;
550+
return 0;
551+
#endif
531552
}
532553

533554
extern "C" struct dirent *readdir(DIR *dir) {
555+
#if MBED_CONF_FILESYSTEM_PRESENT
534556
static struct dirent ent;
535557
int err = dir->read(ent.d_name, NAME_MAX, &ent.d_type);
536558
if (err < 0) {
@@ -539,31 +561,54 @@ extern "C" struct dirent *readdir(DIR *dir) {
539561
}
540562

541563
return &ent;
564+
#else
565+
errno = ENOSYS;
566+
return 0;
567+
#endif
542568
}
543569

544570
extern "C" int closedir(DIR *dir) {
571+
#if MBED_CONF_FILESYSTEM_PRESENT
545572
int err = dir->close();
546573
if (err < 0) {
547574
errno = -err;
548575
return -1;
549576
} else {
550577
return 0;
551578
}
579+
#else
580+
errno = ENOSYS;
581+
return -1;
582+
#endif
552583
}
553584

554585
extern "C" void rewinddir(DIR *dir) {
586+
#if MBED_CONF_FILESYSTEM_PRESENT
555587
dir->rewind();
588+
#else
589+
errno = ENOSYS;
590+
#endif
556591
}
557592

558593
extern "C" off_t telldir(DIR *dir) {
594+
#if MBED_CONF_FILESYSTEM_PRESENT
559595
return dir->tell();
596+
#else
597+
errno = ENOSYS;
598+
return 0;
599+
#endif
560600
}
561601

562602
extern "C" void seekdir(DIR *dir, off_t off) {
603+
#if MBED_CONF_FILESYSTEM_PRESENT
563604
dir->seek(off);
605+
#else
606+
errno = ENOSYS;
607+
#endif
564608
}
565609

566610
extern "C" int mkdir(const char *path, mode_t mode) {
611+
#if MBED_CONF_FILESYSTEM_PRESENT
567612
FilePath fp(path);
568613
FileSystem *fs = fp.fileSystem();
569614
if (fs == NULL) return -1;
@@ -575,9 +620,14 @@ extern "C" int mkdir(const char *path, mode_t mode) {
575620
} else {
576621
return 0;
577622
}
623+
#else
624+
errno = ENOSYS;
625+
return -1;
626+
#endif
578627
}
579628

580629
extern "C" int stat(const char *path, struct stat *st) {
630+
#if MBED_CONF_FILESYSTEM_PRESENT
581631
FilePath fp(path);
582632
FileSystem *fs = fp.fileSystem();
583633
if (fs == NULL) return -1;
@@ -589,6 +639,10 @@ extern "C" int stat(const char *path, struct stat *st) {
589639
} else {
590640
return 0;
591641
}
642+
#else
643+
errno = ENOSYS;
644+
return -1;
645+
#endif
592646
}
593647

594648
#if defined(TOOLCHAIN_GCC)

0 commit comments

Comments
 (0)