Committer:
ganlikun
Date:
Mon Oct 24 15:19:39 2022 +0000
Revision:
0:06036f8bee2d
11

Who changed what in which revision?

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