1 /* mbed Microcontroller Library - FATFileHandle
2 * Copyright (c) 2008, sford
5 #include "FATFileHandle.h"
10 #include "FATFileSystem.h"
15 static const char *FR_ERRORS
[] = {
33 FATFileHandle::FATFileHandle(FIL_t fh
) {
37 int FATFileHandle::close() {
39 int retval
= f_close(&_fh
);
44 ssize_t
FATFileHandle::write(const void* buffer
, size_t length
) {
45 FFSDEBUG("write(%d)\n", length
);
47 FRESULT res
= f_write(&_fh
, buffer
, length
, &n
);
49 FFSDEBUG("f_write() failed (%d, %s)", res
, FR_ERRORS
[res
]);
55 ssize_t
FATFileHandle::read(void* buffer
, size_t length
) {
56 FFSDEBUG("read(%d)\n", length
);
58 FRESULT res
= f_read(&_fh
, buffer
, length
, &n
);
60 FFSDEBUG("f_read() failed (%d, %s)\n", res
, FR_ERRORS
[res
]);
66 int FATFileHandle::isatty() {
70 off_t
FATFileHandle::lseek(off_t position
, int whence
) {
71 FFSDEBUG("lseek(%i,%i)\n",position
,whence
);
72 if(whence
== SEEK_END
) {
73 position
+= _fh
.fsize
;
74 } else if(whence
==SEEK_CUR
) {
77 FRESULT res
= f_lseek(&_fh
, position
);
79 FFSDEBUG("lseek failed (%d, %s)\n", res
, FR_ERRORS
[res
]);
82 FFSDEBUG("lseek OK, returning %i\n", _fh
.fptr
);
87 int FATFileHandle::fsync() {
88 FFSDEBUG("fsync()\n");
89 FRESULT res
= f_sync(&_fh
);
91 FFSDEBUG("f_sync() failed (%d, %s)\n", res
, FR_ERRORS
[res
]);
97 off_t
FATFileHandle::flen() {