diff --git a/libraries/mbed/api/FilePath.h b/libraries/mbed/api/FilePath.h index 2e335bfeb6..3de1205048 100644 --- a/libraries/mbed/api/FilePath.h +++ b/libraries/mbed/api/FilePath.h @@ -34,6 +34,7 @@ public: bool isFile(void); FileLike* file(void); + bool exists(void); private: const char* file_name; diff --git a/libraries/mbed/common/FilePath.cpp b/libraries/mbed/common/FilePath.cpp index 7dbf710656..09147a2699 100644 --- a/libraries/mbed/common/FilePath.cpp +++ b/libraries/mbed/common/FilePath.cpp @@ -36,9 +36,6 @@ FilePath::FilePath(const char* file_path) : file_name(NULL), fb(NULL) { file_name++; } - FileBase::lookup(file_system, len); - - fb = FileBase::lookup(file_system, len); } @@ -47,6 +44,8 @@ const char* FilePath::fileName(void) { } bool FilePath::isFileSystem(void) { + if (NULL == fb) + return false; return (fb->getPathType() == FileSystemPathType); } @@ -58,6 +57,8 @@ FileSystemLike* FilePath::fileSystem(void) { } bool FilePath::isFile(void) { + if (NULL == fb) + return false; return (fb->getPathType() == FilePathType); } @@ -68,4 +69,8 @@ FileLike* FilePath::file(void) { return NULL; } +bool FilePath::exists(void) { + return fb != NULL; +} + } // namespace mbed diff --git a/libraries/mbed/common/retarget.cpp b/libraries/mbed/common/retarget.cpp index 987e5e4242..90a5dbe0e9 100644 --- a/libraries/mbed/common/retarget.cpp +++ b/libraries/mbed/common/retarget.cpp @@ -163,7 +163,9 @@ extern "C" FILEHANDLE PREFIX(_open)(const char* name, int openmode) { } else { FilePath path(name); - if (path.isFile()) { + if (!path.exists()) + return -1; + else if (path.isFile()) { res = path.file(); } else { FileSystemLike *fs = path.fileSystem();