summaryrefslogtreecommitdiff
path: root/firmware/common/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/common/file.c')
-rw-r--r--firmware/common/file.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c
index b86938007b..cf8c46c5ab 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -90,7 +90,7 @@ int open(const char* pathname, int flags)
90 case O_WRONLY: 90 case O_WRONLY:
91 openfiles[fd].write = true; 91 openfiles[fd].write = true;
92 break; 92 break;
93 93
94 default: 94 default:
95 DEBUGF("Only O_RDONLY and O_WRONLY is supported\n"); 95 DEBUGF("Only O_RDONLY and O_WRONLY is supported\n");
96 errno = EROFS; 96 errno = EROFS;
@@ -214,6 +214,31 @@ int remove(const char* name)
214 return rc; 214 return rc;
215} 215}
216 216
217int ftruncate(int fd, unsigned int size)
218{
219 int rc, sector;
220
221 sector = size / SECTOR_SIZE;
222 if (size % SECTOR_SIZE)
223 sector++;
224
225 rc = fat_seek(&(openfiles[fd].fatfile), sector);
226 if (rc < 0) {
227 errno = EIO;
228 return -1;
229 }
230
231 rc = fat_truncate(&(openfiles[fd].fatfile));
232 if (rc < 0) {
233 errno = EIO;
234 return -2;
235 }
236
237 openfiles[fd].size = size;
238
239 return 0;
240}
241
217static int readwrite(int fd, void* buf, int count, bool write) 242static int readwrite(int fd, void* buf, int count, bool write)
218{ 243{
219 int sectors; 244 int sectors;