Daniel Vizcaya
/
04_RTOS_Embebidos
Entrega 3er corte - sistemas embebidos
mbed-os/features/filesystem/File.cpp@0:6ad07c9019fd, 2018-05-30 (annotated)
- Committer:
- Bethory
- Date:
- Wed May 30 00:01:50 2018 +0000
- Revision:
- 0:6ad07c9019fd
Codigo de tales para todos los pasculaes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Bethory | 0:6ad07c9019fd | 1 | /* mbed Microcontroller Library |
Bethory | 0:6ad07c9019fd | 2 | * Copyright (c) 2015 ARM Limited |
Bethory | 0:6ad07c9019fd | 3 | * |
Bethory | 0:6ad07c9019fd | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Bethory | 0:6ad07c9019fd | 5 | * you may not use this file except in compliance with the License. |
Bethory | 0:6ad07c9019fd | 6 | * You may obtain a copy of the License at |
Bethory | 0:6ad07c9019fd | 7 | * |
Bethory | 0:6ad07c9019fd | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Bethory | 0:6ad07c9019fd | 9 | * |
Bethory | 0:6ad07c9019fd | 10 | * Unless required by applicable law or agreed to in writing, software |
Bethory | 0:6ad07c9019fd | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Bethory | 0:6ad07c9019fd | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Bethory | 0:6ad07c9019fd | 13 | * See the License for the specific language governing permissions and |
Bethory | 0:6ad07c9019fd | 14 | * limitations under the License. |
Bethory | 0:6ad07c9019fd | 15 | */ |
Bethory | 0:6ad07c9019fd | 16 | |
Bethory | 0:6ad07c9019fd | 17 | #include "File.h" |
Bethory | 0:6ad07c9019fd | 18 | #include "mbed.h" |
Bethory | 0:6ad07c9019fd | 19 | #include <errno.h> |
Bethory | 0:6ad07c9019fd | 20 | |
Bethory | 0:6ad07c9019fd | 21 | |
Bethory | 0:6ad07c9019fd | 22 | File::File() |
Bethory | 0:6ad07c9019fd | 23 | : _fs(0), _file(0) |
Bethory | 0:6ad07c9019fd | 24 | { |
Bethory | 0:6ad07c9019fd | 25 | } |
Bethory | 0:6ad07c9019fd | 26 | |
Bethory | 0:6ad07c9019fd | 27 | File::File(FileSystem *fs, const char *path, int flags) |
Bethory | 0:6ad07c9019fd | 28 | : _fs(0), _file(0) |
Bethory | 0:6ad07c9019fd | 29 | { |
Bethory | 0:6ad07c9019fd | 30 | open(fs, path, flags); |
Bethory | 0:6ad07c9019fd | 31 | } |
Bethory | 0:6ad07c9019fd | 32 | |
Bethory | 0:6ad07c9019fd | 33 | File::~File() |
Bethory | 0:6ad07c9019fd | 34 | { |
Bethory | 0:6ad07c9019fd | 35 | if (_fs) { |
Bethory | 0:6ad07c9019fd | 36 | close(); |
Bethory | 0:6ad07c9019fd | 37 | } |
Bethory | 0:6ad07c9019fd | 38 | } |
Bethory | 0:6ad07c9019fd | 39 | |
Bethory | 0:6ad07c9019fd | 40 | int File::open(FileSystem *fs, const char *path, int flags) |
Bethory | 0:6ad07c9019fd | 41 | { |
Bethory | 0:6ad07c9019fd | 42 | if (_fs) { |
Bethory | 0:6ad07c9019fd | 43 | return -EINVAL; |
Bethory | 0:6ad07c9019fd | 44 | } |
Bethory | 0:6ad07c9019fd | 45 | |
Bethory | 0:6ad07c9019fd | 46 | int err = fs->file_open(&_file, path, flags); |
Bethory | 0:6ad07c9019fd | 47 | if (!err) { |
Bethory | 0:6ad07c9019fd | 48 | _fs = fs; |
Bethory | 0:6ad07c9019fd | 49 | } |
Bethory | 0:6ad07c9019fd | 50 | |
Bethory | 0:6ad07c9019fd | 51 | return err; |
Bethory | 0:6ad07c9019fd | 52 | } |
Bethory | 0:6ad07c9019fd | 53 | |
Bethory | 0:6ad07c9019fd | 54 | int File::close() |
Bethory | 0:6ad07c9019fd | 55 | { |
Bethory | 0:6ad07c9019fd | 56 | if (!_fs) { |
Bethory | 0:6ad07c9019fd | 57 | return -EINVAL; |
Bethory | 0:6ad07c9019fd | 58 | } |
Bethory | 0:6ad07c9019fd | 59 | |
Bethory | 0:6ad07c9019fd | 60 | int err = _fs->file_close(_file); |
Bethory | 0:6ad07c9019fd | 61 | _fs = 0; |
Bethory | 0:6ad07c9019fd | 62 | return err; |
Bethory | 0:6ad07c9019fd | 63 | } |
Bethory | 0:6ad07c9019fd | 64 | |
Bethory | 0:6ad07c9019fd | 65 | ssize_t File::read(void *buffer, size_t len) |
Bethory | 0:6ad07c9019fd | 66 | { |
Bethory | 0:6ad07c9019fd | 67 | MBED_ASSERT(_fs); |
Bethory | 0:6ad07c9019fd | 68 | return _fs->file_read(_file, buffer, len); |
Bethory | 0:6ad07c9019fd | 69 | } |
Bethory | 0:6ad07c9019fd | 70 | |
Bethory | 0:6ad07c9019fd | 71 | ssize_t File::write(const void *buffer, size_t len) |
Bethory | 0:6ad07c9019fd | 72 | { |
Bethory | 0:6ad07c9019fd | 73 | MBED_ASSERT(_fs); |
Bethory | 0:6ad07c9019fd | 74 | return _fs->file_write(_file, buffer, len); |
Bethory | 0:6ad07c9019fd | 75 | } |
Bethory | 0:6ad07c9019fd | 76 | |
Bethory | 0:6ad07c9019fd | 77 | int File::sync() |
Bethory | 0:6ad07c9019fd | 78 | { |
Bethory | 0:6ad07c9019fd | 79 | MBED_ASSERT(_fs); |
Bethory | 0:6ad07c9019fd | 80 | return _fs->file_sync(_file); |
Bethory | 0:6ad07c9019fd | 81 | } |
Bethory | 0:6ad07c9019fd | 82 | |
Bethory | 0:6ad07c9019fd | 83 | int File::isatty() |
Bethory | 0:6ad07c9019fd | 84 | { |
Bethory | 0:6ad07c9019fd | 85 | MBED_ASSERT(_fs); |
Bethory | 0:6ad07c9019fd | 86 | return _fs->file_isatty(_file); |
Bethory | 0:6ad07c9019fd | 87 | } |
Bethory | 0:6ad07c9019fd | 88 | |
Bethory | 0:6ad07c9019fd | 89 | off_t File::seek(off_t offset, int whence) |
Bethory | 0:6ad07c9019fd | 90 | { |
Bethory | 0:6ad07c9019fd | 91 | MBED_ASSERT(_fs); |
Bethory | 0:6ad07c9019fd | 92 | return _fs->file_seek(_file, offset, whence); |
Bethory | 0:6ad07c9019fd | 93 | } |
Bethory | 0:6ad07c9019fd | 94 | |
Bethory | 0:6ad07c9019fd | 95 | off_t File::tell() |
Bethory | 0:6ad07c9019fd | 96 | { |
Bethory | 0:6ad07c9019fd | 97 | MBED_ASSERT(_fs); |
Bethory | 0:6ad07c9019fd | 98 | return _fs->file_tell(_file); |
Bethory | 0:6ad07c9019fd | 99 | } |
Bethory | 0:6ad07c9019fd | 100 | |
Bethory | 0:6ad07c9019fd | 101 | void File::rewind() |
Bethory | 0:6ad07c9019fd | 102 | { |
Bethory | 0:6ad07c9019fd | 103 | MBED_ASSERT(_fs); |
Bethory | 0:6ad07c9019fd | 104 | return _fs->file_rewind(_file); |
Bethory | 0:6ad07c9019fd | 105 | } |
Bethory | 0:6ad07c9019fd | 106 | |
Bethory | 0:6ad07c9019fd | 107 | off_t File::size() |
Bethory | 0:6ad07c9019fd | 108 | { |
Bethory | 0:6ad07c9019fd | 109 | MBED_ASSERT(_fs); |
Bethory | 0:6ad07c9019fd | 110 | return _fs->file_size(_file); |
Bethory | 0:6ad07c9019fd | 111 | } |
Bethory | 0:6ad07c9019fd | 112 |