LCD1289Serial_Ethenet
Dependencies: EthernetInterface FatFileSystemCpp SDFileSystem mbed-rtos mbed
FatFileSystemCpp/FATDirHandle.cpp@0:a5367e4d8591, 2012-11-07 (annotated)
- Committer:
- shindo
- Date:
- Wed Nov 07 06:42:34 2012 +0000
- Revision:
- 0:a5367e4d8591
LCD1289Serial_Ethenet
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shindo | 0:a5367e4d8591 | 1 | /* mbed Microcontroller Library - FATDirHandle |
shindo | 0:a5367e4d8591 | 2 | * Copyright (c) 2008, sford |
shindo | 0:a5367e4d8591 | 3 | */ |
shindo | 0:a5367e4d8591 | 4 | |
shindo | 0:a5367e4d8591 | 5 | #include <stdio.h> |
shindo | 0:a5367e4d8591 | 6 | #include <stdlib.h> |
shindo | 0:a5367e4d8591 | 7 | #include <string.h> |
shindo | 0:a5367e4d8591 | 8 | #include "ff.h" |
shindo | 0:a5367e4d8591 | 9 | #include "FATDirHandle.h" |
shindo | 0:a5367e4d8591 | 10 | #include "FATFileSystem.h" |
shindo | 0:a5367e4d8591 | 11 | |
shindo | 0:a5367e4d8591 | 12 | namespace mbed { |
shindo | 0:a5367e4d8591 | 13 | |
shindo | 0:a5367e4d8591 | 14 | FATDirHandle::FATDirHandle(const FATFS_DIR &the_dir) { |
shindo | 0:a5367e4d8591 | 15 | dir = the_dir; |
shindo | 0:a5367e4d8591 | 16 | } |
shindo | 0:a5367e4d8591 | 17 | |
shindo | 0:a5367e4d8591 | 18 | int FATDirHandle::closedir() { |
shindo | 0:a5367e4d8591 | 19 | delete this; |
shindo | 0:a5367e4d8591 | 20 | return 0; |
shindo | 0:a5367e4d8591 | 21 | } |
shindo | 0:a5367e4d8591 | 22 | |
shindo | 0:a5367e4d8591 | 23 | struct dirent *FATDirHandle::readdir() { |
shindo | 0:a5367e4d8591 | 24 | FILINFO finfo; |
shindo | 0:a5367e4d8591 | 25 | |
shindo | 0:a5367e4d8591 | 26 | #if _USE_LFN |
shindo | 0:a5367e4d8591 | 27 | finfo.lfname = cur_entry.d_name; |
shindo | 0:a5367e4d8591 | 28 | finfo.lfsize = sizeof(cur_entry.d_name); |
shindo | 0:a5367e4d8591 | 29 | #endif // _USE_LFN |
shindo | 0:a5367e4d8591 | 30 | |
shindo | 0:a5367e4d8591 | 31 | FRESULT res = f_readdir(&dir, &finfo); |
shindo | 0:a5367e4d8591 | 32 | |
shindo | 0:a5367e4d8591 | 33 | #if _USE_LFN |
shindo | 0:a5367e4d8591 | 34 | if(res != 0 || finfo.fname[0]==0) { |
shindo | 0:a5367e4d8591 | 35 | return NULL; |
shindo | 0:a5367e4d8591 | 36 | } else { |
shindo | 0:a5367e4d8591 | 37 | if(cur_entry.d_name[0]==0) { |
shindo | 0:a5367e4d8591 | 38 | // No long filename so use short filename. |
shindo | 0:a5367e4d8591 | 39 | memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname)); |
shindo | 0:a5367e4d8591 | 40 | } |
shindo | 0:a5367e4d8591 | 41 | return &cur_entry; |
shindo | 0:a5367e4d8591 | 42 | } |
shindo | 0:a5367e4d8591 | 43 | #else |
shindo | 0:a5367e4d8591 | 44 | if(res != 0 || finfo.fname[0]==0) { |
shindo | 0:a5367e4d8591 | 45 | return NULL; |
shindo | 0:a5367e4d8591 | 46 | } else { |
shindo | 0:a5367e4d8591 | 47 | memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname)); |
shindo | 0:a5367e4d8591 | 48 | return &cur_entry; |
shindo | 0:a5367e4d8591 | 49 | } |
shindo | 0:a5367e4d8591 | 50 | #endif /* _USE_LFN */ |
shindo | 0:a5367e4d8591 | 51 | } |
shindo | 0:a5367e4d8591 | 52 | |
shindo | 0:a5367e4d8591 | 53 | void FATDirHandle::rewinddir() { |
shindo | 0:a5367e4d8591 | 54 | dir.index = 0; |
shindo | 0:a5367e4d8591 | 55 | } |
shindo | 0:a5367e4d8591 | 56 | |
shindo | 0:a5367e4d8591 | 57 | off_t FATDirHandle::telldir() { |
shindo | 0:a5367e4d8591 | 58 | return dir.index; |
shindo | 0:a5367e4d8591 | 59 | } |
shindo | 0:a5367e4d8591 | 60 | |
shindo | 0:a5367e4d8591 | 61 | void FATDirHandle::seekdir(off_t location) { |
shindo | 0:a5367e4d8591 | 62 | dir.index = location; |
shindo | 0:a5367e4d8591 | 63 | } |
shindo | 0:a5367e4d8591 | 64 | |
shindo | 0:a5367e4d8591 | 65 | } |
shindo | 0:a5367e4d8591 | 66 |