this library has few changes from the original library, for effects of this work.

Dependents:   OBC3_1_h

Committer:
FannyCalle
Date:
Mon May 21 15:10:37 2018 +0000
Revision:
0:8214896432e0
el sd hay que revisar;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
FannyCalle 0:8214896432e0 1 /* mbed Microcontroller Library
FannyCalle 0:8214896432e0 2 * Copyright (c) 2006-2012 ARM Limited
FannyCalle 0:8214896432e0 3 *
FannyCalle 0:8214896432e0 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
FannyCalle 0:8214896432e0 5 * of this software and associated documentation files (the "Software"), to deal
FannyCalle 0:8214896432e0 6 * in the Software without restriction, including without limitation the rights
FannyCalle 0:8214896432e0 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
FannyCalle 0:8214896432e0 8 * copies of the Software, and to permit persons to whom the Software is
FannyCalle 0:8214896432e0 9 * furnished to do so, subject to the following conditions:
FannyCalle 0:8214896432e0 10 *
FannyCalle 0:8214896432e0 11 * The above copyright notice and this permission notice shall be included in
FannyCalle 0:8214896432e0 12 * all copies or substantial portions of the Software.
FannyCalle 0:8214896432e0 13 *
FannyCalle 0:8214896432e0 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
FannyCalle 0:8214896432e0 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FannyCalle 0:8214896432e0 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
FannyCalle 0:8214896432e0 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
FannyCalle 0:8214896432e0 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
FannyCalle 0:8214896432e0 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
FannyCalle 0:8214896432e0 20 * SOFTWARE.
FannyCalle 0:8214896432e0 21 */
FannyCalle 0:8214896432e0 22 #include <string.h>
FannyCalle 0:8214896432e0 23 #include "ff.h"
FannyCalle 0:8214896432e0 24 #include "FATDirHandle.h"
FannyCalle 0:8214896432e0 25
FannyCalle 0:8214896432e0 26 using namespace mbed;
FannyCalle 0:8214896432e0 27
FannyCalle 0:8214896432e0 28 FATDirHandle::FATDirHandle(const FATFS_DIR &the_dir) {
FannyCalle 0:8214896432e0 29 dir = the_dir;
FannyCalle 0:8214896432e0 30 }
FannyCalle 0:8214896432e0 31
FannyCalle 0:8214896432e0 32 int FATDirHandle::closedir() {
FannyCalle 0:8214896432e0 33 int retval = f_closedir(&dir);
FannyCalle 0:8214896432e0 34 delete this;
FannyCalle 0:8214896432e0 35 return retval;
FannyCalle 0:8214896432e0 36 }
FannyCalle 0:8214896432e0 37
FannyCalle 0:8214896432e0 38 struct dirent *FATDirHandle::readdir() {
FannyCalle 0:8214896432e0 39 FILINFO finfo;
FannyCalle 0:8214896432e0 40
FannyCalle 0:8214896432e0 41 #if _USE_LFN
FannyCalle 0:8214896432e0 42 finfo.lfname = cur_entry.d_name;
FannyCalle 0:8214896432e0 43 finfo.lfsize = sizeof(cur_entry.d_name);
FannyCalle 0:8214896432e0 44 #endif // _USE_LFN
FannyCalle 0:8214896432e0 45
FannyCalle 0:8214896432e0 46 FRESULT res = f_readdir(&dir, &finfo);
FannyCalle 0:8214896432e0 47
FannyCalle 0:8214896432e0 48 #if _USE_LFN
FannyCalle 0:8214896432e0 49 if(res != 0 || finfo.fname[0]==0) {
FannyCalle 0:8214896432e0 50 return NULL;
FannyCalle 0:8214896432e0 51 } else {
FannyCalle 0:8214896432e0 52 if(cur_entry.d_name[0]==0) {
FannyCalle 0:8214896432e0 53 // No long filename so use short filename.
FannyCalle 0:8214896432e0 54 memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname));
FannyCalle 0:8214896432e0 55 }
FannyCalle 0:8214896432e0 56 return &cur_entry;
FannyCalle 0:8214896432e0 57 }
FannyCalle 0:8214896432e0 58 #else
FannyCalle 0:8214896432e0 59 if(res != 0 || finfo.fname[0]==0) {
FannyCalle 0:8214896432e0 60 return NULL;
FannyCalle 0:8214896432e0 61 } else {
FannyCalle 0:8214896432e0 62 memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname));
FannyCalle 0:8214896432e0 63 return &cur_entry;
FannyCalle 0:8214896432e0 64 }
FannyCalle 0:8214896432e0 65 #endif /* _USE_LFN */
FannyCalle 0:8214896432e0 66 }
FannyCalle 0:8214896432e0 67
FannyCalle 0:8214896432e0 68 void FATDirHandle::rewinddir() {
FannyCalle 0:8214896432e0 69 dir.index = 0;
FannyCalle 0:8214896432e0 70 }
FannyCalle 0:8214896432e0 71
FannyCalle 0:8214896432e0 72 off_t FATDirHandle::telldir() {
FannyCalle 0:8214896432e0 73 return dir.index;
FannyCalle 0:8214896432e0 74 }
FannyCalle 0:8214896432e0 75
FannyCalle 0:8214896432e0 76 void FATDirHandle::seekdir(off_t location) {
FannyCalle 0:8214896432e0 77 dir.index = location;
FannyCalle 0:8214896432e0 78 }
FannyCalle 0:8214896432e0 79