mbed-dev-f303

Committer:
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4
Date:
Tue Jun 14 09:21:18 2022 +0000
Revision:
0:bdf663c61a82
lib

Who changed what in which revision?

UserRevisionLine numberNew contents of line
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 1 /* mbed Microcontroller Library
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 2 * Copyright (c) 2006-2013 ARM Limited
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 3 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 4 * Licensed under the Apache License, Version 2.0 (the "License");
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 5 * you may not use this file except in compliance with the License.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 6 * You may obtain a copy of the License at
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 7 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 8 * http://www.apache.org/licenses/LICENSE-2.0
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 9 *
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 10 * Unless required by applicable law or agreed to in writing, software
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 11 * distributed under the License is distributed on an "AS IS" BASIS,
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 13 * See the License for the specific language governing permissions and
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 14 * limitations under the License.
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 15 */
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 16 #include "platform/FilePath.h"
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 17
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 18 namespace mbed {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 19
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 20 FilePath::FilePath(const char* file_path) : file_name(NULL), fb(NULL) {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 21 if ((file_path[0] != '/') || (file_path[1] == 0)) return;
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 22
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 23 const char* file_system = &file_path[1];
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 24 file_name = file_system;
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 25 int len = 0;
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 26 while (true) {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 27 char c = *file_name;
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 28 if (c == '/') { // end of object name
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 29 file_name++; // point to one char after the '/'
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 30 break;
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 31 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 32 if (c == 0) { // end of object name, with no filename
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 33 break;
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 34 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 35 len++;
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 36 file_name++;
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 37 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 38
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 39 fb = FileBase::lookup(file_system, len);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 40 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 41
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 42 const char* FilePath::fileName(void) {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 43 return file_name;
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 44 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 45
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 46 bool FilePath::isFileSystem(void) {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 47 if (NULL == fb)
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 48 return false;
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 49 return (fb->getPathType() == FileSystemPathType);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 50 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 51
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 52 FileSystemLike* FilePath::fileSystem(void) {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 53 if (isFileSystem()) {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 54 return static_cast<FileSystemLike*>(fb);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 55 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 56 return NULL;
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 57 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 58
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 59 bool FilePath::isFile(void) {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 60 if (NULL == fb)
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 61 return false;
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 62 return (fb->getPathType() == FilePathType);
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 63 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 64
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 65 FileLike* FilePath::file(void) {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 66 if (isFile()) {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 67 return (FileLike*)fb;
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 68 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 69 return NULL;
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 70 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 71
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 72 bool FilePath::exists(void) {
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 73 return fb != NULL;
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 74 }
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 75
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 76 } // namespace mbed
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4 0:bdf663c61a82 77