23
23
#include " platform/PlatformMutex.h"
24
24
#include " platform/mbed_error.h"
25
25
#include " platform/mbed_stats.h"
26
+ #if MBED_CONF_FILESYSTEM_PRESENT
26
27
#include " filesystem/FileSystem.h"
27
28
#include " filesystem/File.h"
28
29
#include " filesystem/Dir.h"
30
+ #endif
29
31
#include < stdlib.h>
30
32
#include < string.h>
31
33
#if DEVICE_STDIO_MESSAGES
@@ -84,7 +86,9 @@ uint32_t mbed_heap_size = 0;
84
86
* (or rather index+3, as filehandles 0-2 are stdin/out/err).
85
87
*/
86
88
static FileLike *filehandles[OPEN_MAX];
89
+ #if MBED_CONF_FILESYSTEM_PRESENT
87
90
static File fileobjects[OPEN_MAX];
91
+ #endif
88
92
static SingletonPtr<PlatformMutex> filehandle_mutex;
89
93
90
94
namespace mbed {
@@ -236,6 +240,7 @@ extern "C" FILEHANDLE PREFIX(_open)(const char* name, int openmode) {
236
240
return -1 ;
237
241
} else if (path.isFile ()) {
238
242
res = path.file ();
243
+ #if MBED_CONF_FILESYSTEM_PRESENT
239
244
} else {
240
245
FileSystem *fs = path.fileSystem ();
241
246
if (fs == NULL ) {
@@ -252,6 +257,7 @@ extern "C" FILEHANDLE PREFIX(_open)(const char* name, int openmode) {
252
257
} else {
253
258
res = &fileobjects[fh_i];
254
259
}
260
+ #endif
255
261
}
256
262
}
257
263
@@ -462,6 +468,7 @@ extern "C" int _fstat(int fd, struct stat *st) {
462
468
463
469
namespace std {
464
470
extern " C" int remove (const char *path) {
471
+ #if MBED_CONF_FILESYSTEM_PRESENT
465
472
errno = EBADF;
466
473
FilePath fp (path);
467
474
FileSystem *fs = fp.fileSystem ();
@@ -474,9 +481,14 @@ extern "C" int remove(const char *path) {
474
481
} else {
475
482
return 0 ;
476
483
}
484
+ #else
485
+ errno = ENOSYS;
486
+ return -1 ;
487
+ #endif
477
488
}
478
489
479
490
extern " C" int rename (const char *oldname, const char *newname) {
491
+ #if MBED_CONF_FILESYSTEM_PRESENT
480
492
errno = EBADF;
481
493
FilePath fpOld (oldname);
482
494
FilePath fpNew (newname);
@@ -493,6 +505,10 @@ extern "C" int rename(const char *oldname, const char *newname) {
493
505
} else {
494
506
return 0 ;
495
507
}
508
+ #else
509
+ errno = ENOSYS;
510
+ return -1 ;
511
+ #endif
496
512
}
497
513
498
514
extern " C" char *tmpnam (char *s) {
@@ -513,6 +529,7 @@ extern "C" char *_sys_command_string(char *cmd, int len) {
513
529
#endif
514
530
515
531
extern " C" DIR *opendir (const char *path) {
532
+ #if MBED_CONF_FILESYSTEM_PRESENT
516
533
errno = EBADF;
517
534
518
535
FilePath fp (path);
@@ -528,9 +545,14 @@ extern "C" DIR *opendir(const char *path) {
528
545
}
529
546
530
547
return dir;
548
+ #else
549
+ errno = ENOSYS;
550
+ return 0 ;
551
+ #endif
531
552
}
532
553
533
554
extern " C" struct dirent *readdir (DIR *dir) {
555
+ #if MBED_CONF_FILESYSTEM_PRESENT
534
556
static struct dirent ent;
535
557
int err = dir->read (ent.d_name , NAME_MAX, &ent.d_type );
536
558
if (err < 0 ) {
@@ -539,31 +561,54 @@ extern "C" struct dirent *readdir(DIR *dir) {
539
561
}
540
562
541
563
return &ent;
564
+ #else
565
+ errno = ENOSYS;
566
+ return 0 ;
567
+ #endif
542
568
}
543
569
544
570
extern " C" int closedir (DIR *dir) {
571
+ #if MBED_CONF_FILESYSTEM_PRESENT
545
572
int err = dir->close ();
546
573
if (err < 0 ) {
547
574
errno = -err;
548
575
return -1 ;
549
576
} else {
550
577
return 0 ;
551
578
}
579
+ #else
580
+ errno = ENOSYS;
581
+ return -1 ;
582
+ #endif
552
583
}
553
584
554
585
extern " C" void rewinddir (DIR *dir) {
586
+ #if MBED_CONF_FILESYSTEM_PRESENT
555
587
dir->rewind ();
588
+ #else
589
+ errno = ENOSYS;
590
+ #endif
556
591
}
557
592
558
593
extern " C" off_t telldir (DIR *dir) {
594
+ #if MBED_CONF_FILESYSTEM_PRESENT
559
595
return dir->tell ();
596
+ #else
597
+ errno = ENOSYS;
598
+ return 0 ;
599
+ #endif
560
600
}
561
601
562
602
extern " C" void seekdir (DIR *dir, off_t off) {
603
+ #if MBED_CONF_FILESYSTEM_PRESENT
563
604
dir->seek (off);
605
+ #else
606
+ errno = ENOSYS;
607
+ #endif
564
608
}
565
609
566
610
extern " C" int mkdir (const char *path, mode_t mode) {
611
+ #if MBED_CONF_FILESYSTEM_PRESENT
567
612
FilePath fp (path);
568
613
FileSystem *fs = fp.fileSystem ();
569
614
if (fs == NULL ) return -1 ;
@@ -575,9 +620,14 @@ extern "C" int mkdir(const char *path, mode_t mode) {
575
620
} else {
576
621
return 0 ;
577
622
}
623
+ #else
624
+ errno = ENOSYS;
625
+ return -1 ;
626
+ #endif
578
627
}
579
628
580
629
extern " C" int stat (const char *path, struct stat *st) {
630
+ #if MBED_CONF_FILESYSTEM_PRESENT
581
631
FilePath fp (path);
582
632
FileSystem *fs = fp.fileSystem ();
583
633
if (fs == NULL ) return -1 ;
@@ -589,6 +639,10 @@ extern "C" int stat(const char *path, struct stat *st) {
589
639
} else {
590
640
return 0 ;
591
641
}
642
+ #else
643
+ errno = ENOSYS;
644
+ return -1 ;
645
+ #endif
592
646
}
593
647
594
648
#if defined(TOOLCHAIN_GCC)
0 commit comments