diff options
author | Björn Stenberg <bjorn@haxx.se> | 2002-11-11 14:40:18 +0000 |
---|---|---|
committer | Björn Stenberg <bjorn@haxx.se> | 2002-11-11 14:40:18 +0000 |
commit | 68640edf90c84c3d4494f0852f6236e1929a4603 (patch) | |
tree | fe74712bcebdfcc21ef272d83528209ce6e69fbb /firmware/common | |
parent | 228605dc7bfac86604166d5e3bbabb72ae40b78b (diff) | |
download | rockbox-68640edf90c84c3d4494f0852f6236e1929a4603.tar.gz rockbox-68640edf90c84c3d4494f0852f6236e1929a4603.zip |
Added ftruncate().
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2827 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/common')
-rw-r--r-- | firmware/common/file.c | 27 | ||||
-rw-r--r-- | firmware/common/file.h | 1 |
2 files changed, 27 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 | ||
217 | int 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 | |||
217 | static int readwrite(int fd, void* buf, int count, bool write) | 242 | static int readwrite(int fd, void* buf, int count, bool write) |
218 | { | 243 | { |
219 | int sectors; | 244 | int sectors; |
diff --git a/firmware/common/file.h b/firmware/common/file.h index 7a7c63d665..59ff717d1d 100644 --- a/firmware/common/file.h +++ b/firmware/common/file.h | |||
@@ -56,6 +56,7 @@ extern int creat(const char *pathname, int mode); | |||
56 | extern int write(int fd, void* buf, int count); | 56 | extern int write(int fd, void* buf, int count); |
57 | extern int remove(const char* pathname); | 57 | extern int remove(const char* pathname); |
58 | extern int rename(const char* oldname, const char* newname); | 58 | extern int rename(const char* oldname, const char* newname); |
59 | extern int ftruncate(int fd, unsigned int size); | ||
59 | 60 | ||
60 | #else | 61 | #else |
61 | #ifdef WIN32 | 62 | #ifdef WIN32 |