test

Committer:
elijahsj
Date:
Mon Nov 09 00:33:19 2020 -0500
Revision:
2:4364577b5ad8
Parent:
1:8a094db1347f
copied mbed library

Who changed what in which revision?

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