mbed-os5 only for TYBLE16
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
platform/source/FilePath.cpp@1:9db0e321a9f4, 2019-12-31 (annotated)
- Committer:
- kenjiArai
- Date:
- Tue Dec 31 06:02:27 2019 +0000
- Revision:
- 1:9db0e321a9f4
- Parent:
- platform/FilePath.cpp@0:5b88d5760320
updated based on mbed-os5.15.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 0:5b88d5760320 | 1 | /* mbed Microcontroller Library |
kenjiArai | 0:5b88d5760320 | 2 | * Copyright (c) 2006-2013 ARM Limited |
kenjiArai | 0:5b88d5760320 | 3 | * SPDX-License-Identifier: Apache-2.0 |
kenjiArai | 0:5b88d5760320 | 4 | * |
kenjiArai | 0:5b88d5760320 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kenjiArai | 0:5b88d5760320 | 6 | * you may not use this file except in compliance with the License. |
kenjiArai | 0:5b88d5760320 | 7 | * You may obtain a copy of the License at |
kenjiArai | 0:5b88d5760320 | 8 | * |
kenjiArai | 0:5b88d5760320 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
kenjiArai | 0:5b88d5760320 | 10 | * |
kenjiArai | 0:5b88d5760320 | 11 | * Unless required by applicable law or agreed to in writing, software |
kenjiArai | 0:5b88d5760320 | 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
kenjiArai | 0:5b88d5760320 | 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kenjiArai | 0:5b88d5760320 | 14 | * See the License for the specific language governing permissions and |
kenjiArai | 0:5b88d5760320 | 15 | * limitations under the License. |
kenjiArai | 0:5b88d5760320 | 16 | */ |
kenjiArai | 0:5b88d5760320 | 17 | #include "platform/FilePath.h" |
kenjiArai | 0:5b88d5760320 | 18 | |
kenjiArai | 0:5b88d5760320 | 19 | namespace mbed { |
kenjiArai | 0:5b88d5760320 | 20 | |
kenjiArai | 0:5b88d5760320 | 21 | FilePath::FilePath(const char *file_path) : file_name(NULL), fb(NULL) |
kenjiArai | 0:5b88d5760320 | 22 | { |
kenjiArai | 0:5b88d5760320 | 23 | // skip slashes |
kenjiArai | 0:5b88d5760320 | 24 | file_path += strspn(file_path, "/"); |
kenjiArai | 0:5b88d5760320 | 25 | |
kenjiArai | 0:5b88d5760320 | 26 | const char *file_system = file_path; |
kenjiArai | 0:5b88d5760320 | 27 | file_name = file_system; |
kenjiArai | 0:5b88d5760320 | 28 | int len = 0; |
kenjiArai | 0:5b88d5760320 | 29 | while (true) { |
kenjiArai | 0:5b88d5760320 | 30 | char c = *file_name; |
kenjiArai | 0:5b88d5760320 | 31 | if (c == '/') { // end of object name |
kenjiArai | 0:5b88d5760320 | 32 | file_name++; // point to one char after the '/' |
kenjiArai | 0:5b88d5760320 | 33 | break; |
kenjiArai | 0:5b88d5760320 | 34 | } |
kenjiArai | 0:5b88d5760320 | 35 | if (c == 0) { // end of object name, with no filename |
kenjiArai | 0:5b88d5760320 | 36 | break; |
kenjiArai | 0:5b88d5760320 | 37 | } |
kenjiArai | 0:5b88d5760320 | 38 | len++; |
kenjiArai | 0:5b88d5760320 | 39 | file_name++; |
kenjiArai | 0:5b88d5760320 | 40 | } |
kenjiArai | 0:5b88d5760320 | 41 | |
kenjiArai | 0:5b88d5760320 | 42 | MBED_ASSERT(len != 0); |
kenjiArai | 0:5b88d5760320 | 43 | fb = FileBase::lookup(file_system, len); |
kenjiArai | 0:5b88d5760320 | 44 | } |
kenjiArai | 0:5b88d5760320 | 45 | |
kenjiArai | 0:5b88d5760320 | 46 | const char *FilePath::fileName(void) |
kenjiArai | 0:5b88d5760320 | 47 | { |
kenjiArai | 0:5b88d5760320 | 48 | return file_name; |
kenjiArai | 0:5b88d5760320 | 49 | } |
kenjiArai | 0:5b88d5760320 | 50 | |
kenjiArai | 0:5b88d5760320 | 51 | bool FilePath::isFileSystem(void) |
kenjiArai | 0:5b88d5760320 | 52 | { |
kenjiArai | 0:5b88d5760320 | 53 | if (NULL == fb) { |
kenjiArai | 0:5b88d5760320 | 54 | return false; |
kenjiArai | 0:5b88d5760320 | 55 | } |
kenjiArai | 0:5b88d5760320 | 56 | return (fb->getPathType() == FileSystemPathType); |
kenjiArai | 0:5b88d5760320 | 57 | } |
kenjiArai | 0:5b88d5760320 | 58 | |
kenjiArai | 0:5b88d5760320 | 59 | FileSystemLike *FilePath::fileSystem(void) |
kenjiArai | 0:5b88d5760320 | 60 | { |
kenjiArai | 0:5b88d5760320 | 61 | if (isFileSystem()) { |
kenjiArai | 0:5b88d5760320 | 62 | return static_cast<FileSystemLike *>(fb); |
kenjiArai | 0:5b88d5760320 | 63 | } |
kenjiArai | 0:5b88d5760320 | 64 | return NULL; |
kenjiArai | 0:5b88d5760320 | 65 | } |
kenjiArai | 0:5b88d5760320 | 66 | |
kenjiArai | 0:5b88d5760320 | 67 | bool FilePath::isFile(void) |
kenjiArai | 0:5b88d5760320 | 68 | { |
kenjiArai | 0:5b88d5760320 | 69 | if (NULL == fb) { |
kenjiArai | 0:5b88d5760320 | 70 | return false; |
kenjiArai | 0:5b88d5760320 | 71 | } |
kenjiArai | 0:5b88d5760320 | 72 | return (fb->getPathType() == FilePathType); |
kenjiArai | 0:5b88d5760320 | 73 | } |
kenjiArai | 0:5b88d5760320 | 74 | |
kenjiArai | 0:5b88d5760320 | 75 | FileLike *FilePath::file(void) |
kenjiArai | 0:5b88d5760320 | 76 | { |
kenjiArai | 0:5b88d5760320 | 77 | if (isFile()) { |
kenjiArai | 0:5b88d5760320 | 78 | return (FileLike *)fb; |
kenjiArai | 0:5b88d5760320 | 79 | } |
kenjiArai | 0:5b88d5760320 | 80 | return NULL; |
kenjiArai | 0:5b88d5760320 | 81 | } |
kenjiArai | 0:5b88d5760320 | 82 | |
kenjiArai | 0:5b88d5760320 | 83 | bool FilePath::exists(void) |
kenjiArai | 0:5b88d5760320 | 84 | { |
kenjiArai | 0:5b88d5760320 | 85 | return fb != NULL; |
kenjiArai | 0:5b88d5760320 | 86 | } |
kenjiArai | 0:5b88d5760320 | 87 | |
kenjiArai | 0:5b88d5760320 | 88 | } // namespace mbed |