Pinned to some recent date

Committer:
Simon Cooksey
Date:
Thu Nov 17 16:43:53 2016 +0000
Revision:
0:fb7af294d5d9
Initial commit

Who changed what in which revision?

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