Fork of Smoothie to port to mbed non-LPC targets.

Dependencies:   mbed

Fork of Smoothie by Stéphane Cachat

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 DIR_t &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 #if _USE_LFN
00026     static char lfn[_MAX_LFN * (_LFN_UNICODE ? 2 : 1) + 1];
00027     finfo.lfname = lfn;
00028     finfo.lfsize = sizeof(lfn);
00029 #endif
00030     FRESULT res = f_readdir(&dir, &finfo);
00031     if(res != 0 || finfo.fname[0]==0) {
00032         return NULL;
00033     } else {
00034         char* fn;
00035         int stringSize = 0;
00036 #if _USE_LFN
00037         fn = *finfo.lfname ? finfo.lfname : finfo.fname;
00038         stringSize = finfo.lfsize;
00039 #else
00040         fn = fno.fname;
00041         stringSize =  sizeof(finfo.fname);
00042 #endif
00043         memcpy(cur_entry.d_name, fn, stringSize);
00044         return &cur_entry;
00045     }
00046 }
00047 
00048 void FATDirHandle::rewinddir() {
00049     dir.index = 0;
00050 }
00051 
00052 off_t FATDirHandle::telldir() {
00053     return dir.index;
00054 }
00055 
00056 void FATDirHandle::seekdir(off_t location) {
00057     dir.index = location;
00058 }
00059 
00060 }
00061