Dependencies: PinDetect TextLCD mbed mRotaryEncoder
FATFileSystem/Interface/FATFileHandle.cpp@0:afb2650fb49a, 2012-02-13 (annotated)
- Committer:
- cicklaus
- Date:
- Mon Feb 13 02:11:20 2012 +0000
- Revision:
- 0:afb2650fb49a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cicklaus | 0:afb2650fb49a | 1 | /* mbed Microcontroller Library - FATFileHandle |
cicklaus | 0:afb2650fb49a | 2 | Copyright (c) 2008, sford */ |
cicklaus | 0:afb2650fb49a | 3 | |
cicklaus | 0:afb2650fb49a | 4 | //Modified by Thomas Hamilton, Copyright 2010 |
cicklaus | 0:afb2650fb49a | 5 | |
cicklaus | 0:afb2650fb49a | 6 | #include "FATFileHandle.h" |
cicklaus | 0:afb2650fb49a | 7 | |
cicklaus | 0:afb2650fb49a | 8 | FATFileHandle::FATFileHandle(FAT_FIL InputFilStr) |
cicklaus | 0:afb2650fb49a | 9 | { |
cicklaus | 0:afb2650fb49a | 10 | FileObject = InputFilStr; |
cicklaus | 0:afb2650fb49a | 11 | } |
cicklaus | 0:afb2650fb49a | 12 | |
cicklaus | 0:afb2650fb49a | 13 | ssize_t FATFileHandle::write(const void* buffer, size_t length) |
cicklaus | 0:afb2650fb49a | 14 | { |
cicklaus | 0:afb2650fb49a | 15 | UINT ByteWritten; |
cicklaus | 0:afb2650fb49a | 16 | if (f_write(&FileObject, buffer, (UINT)length, &ByteWritten)) |
cicklaus | 0:afb2650fb49a | 17 | { |
cicklaus | 0:afb2650fb49a | 18 | return -1; |
cicklaus | 0:afb2650fb49a | 19 | } |
cicklaus | 0:afb2650fb49a | 20 | else |
cicklaus | 0:afb2650fb49a | 21 | { |
cicklaus | 0:afb2650fb49a | 22 | return (ssize_t)ByteWritten; |
cicklaus | 0:afb2650fb49a | 23 | } |
cicklaus | 0:afb2650fb49a | 24 | } |
cicklaus | 0:afb2650fb49a | 25 | |
cicklaus | 0:afb2650fb49a | 26 | int FATFileHandle::close() |
cicklaus | 0:afb2650fb49a | 27 | { |
cicklaus | 0:afb2650fb49a | 28 | if (f_close(&FileObject)) |
cicklaus | 0:afb2650fb49a | 29 | { |
cicklaus | 0:afb2650fb49a | 30 | return -1; |
cicklaus | 0:afb2650fb49a | 31 | } |
cicklaus | 0:afb2650fb49a | 32 | else |
cicklaus | 0:afb2650fb49a | 33 | { |
cicklaus | 0:afb2650fb49a | 34 | delete this; |
cicklaus | 0:afb2650fb49a | 35 | return 0; |
cicklaus | 0:afb2650fb49a | 36 | } |
cicklaus | 0:afb2650fb49a | 37 | } |
cicklaus | 0:afb2650fb49a | 38 | |
cicklaus | 0:afb2650fb49a | 39 | ssize_t FATFileHandle::read(void* buffer, size_t length) |
cicklaus | 0:afb2650fb49a | 40 | { |
cicklaus | 0:afb2650fb49a | 41 | UINT ByteRead; |
cicklaus | 0:afb2650fb49a | 42 | if (f_read(&FileObject, buffer, (UINT)length, &ByteRead)) |
cicklaus | 0:afb2650fb49a | 43 | { |
cicklaus | 0:afb2650fb49a | 44 | return -1; |
cicklaus | 0:afb2650fb49a | 45 | } |
cicklaus | 0:afb2650fb49a | 46 | else |
cicklaus | 0:afb2650fb49a | 47 | { |
cicklaus | 0:afb2650fb49a | 48 | return (ssize_t)ByteRead; |
cicklaus | 0:afb2650fb49a | 49 | } |
cicklaus | 0:afb2650fb49a | 50 | } |
cicklaus | 0:afb2650fb49a | 51 | |
cicklaus | 0:afb2650fb49a | 52 | int FATFileHandle::isatty() |
cicklaus | 0:afb2650fb49a | 53 | { |
cicklaus | 0:afb2650fb49a | 54 | return 0; |
cicklaus | 0:afb2650fb49a | 55 | } |
cicklaus | 0:afb2650fb49a | 56 | |
cicklaus | 0:afb2650fb49a | 57 | off_t FATFileHandle::lseek(off_t offset, int whence) |
cicklaus | 0:afb2650fb49a | 58 | { |
cicklaus | 0:afb2650fb49a | 59 | switch (whence) |
cicklaus | 0:afb2650fb49a | 60 | { |
cicklaus | 0:afb2650fb49a | 61 | case SEEK_CUR: offset += FileObject.fptr; break; |
cicklaus | 0:afb2650fb49a | 62 | case SEEK_END: offset += FileObject.fsize; break; |
cicklaus | 0:afb2650fb49a | 63 | } |
cicklaus | 0:afb2650fb49a | 64 | if (f_lseek(&FileObject, (DWORD)offset)) |
cicklaus | 0:afb2650fb49a | 65 | { |
cicklaus | 0:afb2650fb49a | 66 | return -1; |
cicklaus | 0:afb2650fb49a | 67 | } |
cicklaus | 0:afb2650fb49a | 68 | else |
cicklaus | 0:afb2650fb49a | 69 | { |
cicklaus | 0:afb2650fb49a | 70 | return (off_t)FileObject.fptr; |
cicklaus | 0:afb2650fb49a | 71 | } |
cicklaus | 0:afb2650fb49a | 72 | } |
cicklaus | 0:afb2650fb49a | 73 | |
cicklaus | 0:afb2650fb49a | 74 | int FATFileHandle::fsync() |
cicklaus | 0:afb2650fb49a | 75 | { |
cicklaus | 0:afb2650fb49a | 76 | if (f_sync(&FileObject)) |
cicklaus | 0:afb2650fb49a | 77 | { |
cicklaus | 0:afb2650fb49a | 78 | return -1; |
cicklaus | 0:afb2650fb49a | 79 | } |
cicklaus | 0:afb2650fb49a | 80 | else |
cicklaus | 0:afb2650fb49a | 81 | { |
cicklaus | 0:afb2650fb49a | 82 | return 0; |
cicklaus | 0:afb2650fb49a | 83 | } |
cicklaus | 0:afb2650fb49a | 84 | } |
cicklaus | 0:afb2650fb49a | 85 | |
cicklaus | 0:afb2650fb49a | 86 | off_t FATFileHandle::flen() |
cicklaus | 0:afb2650fb49a | 87 | { |
cicklaus | 0:afb2650fb49a | 88 | return (off_t)FileObject.fsize; |
cicklaus | 0:afb2650fb49a | 89 | } |