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