Fork of Adam Green's library with .cpp fix for current compiler

Dependents:   MSCUsbHost mpod_nhk_english mpod_picasa_photoframe mpod_nhk_english_spxml ... more

Fork of FatFileSystem by Adam Green

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FATDirHandle.cpp Source File

FATDirHandle.cpp

00001 /* mbed Microcontroller Library - FATDirHandle
00002  * Copyright (c) 2008, sford
00003  */
00004  
00005 #include <stdio.h>
00006 #include <stdlib.h>
00007 #include <string.h>
00008 #include "ff.h"
00009 #include "FATDirHandle.h"
00010 #include "FATFileSystem.h"
00011 
00012 namespace mbed {
00013 
00014 FATDirHandle::FATDirHandle(const FATFS_DIR &the_dir) {
00015     dir = the_dir;
00016 }
00017 
00018 int FATDirHandle::closedir() {
00019     delete this;
00020     return 0;
00021 }
00022 
00023 struct dirent *FATDirHandle::readdir() {
00024     FILINFO finfo;
00025 
00026 #if _USE_LFN
00027     finfo.lfname = cur_entry.d_name;
00028     finfo.lfsize = sizeof(cur_entry.d_name);
00029 #endif // _USE_LFN
00030 
00031     FRESULT res = f_readdir(&dir, &finfo);
00032 
00033 #if _USE_LFN
00034     if(res != 0 || finfo.fname[0]==0) {
00035         return NULL;
00036     } else {
00037         if(cur_entry.d_name[0]==0) {
00038             // No long filename so use short filename.
00039             memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname));
00040         }
00041         return &cur_entry;
00042     }
00043 #else
00044     if(res != 0 || finfo.fname[0]==0) {
00045         return NULL;
00046     } else {
00047         memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname));
00048         return &cur_entry;
00049     }
00050 #endif /* _USE_LFN */
00051 }
00052 
00053 void FATDirHandle::rewinddir() {
00054     dir.index = 0;
00055 }
00056 
00057 off_t FATDirHandle::telldir() {
00058     return dir.index;
00059 }
00060 
00061 void FATDirHandle::seekdir(off_t location) {
00062     dir.index = location;
00063 }
00064 
00065 }
00066