From 68640edf90c84c3d4494f0852f6236e1929a4603 Mon Sep 17 00:00:00 2001 From: Björn Stenberg Date: Mon, 11 Nov 2002 14:40:18 +0000 Subject: Added ftruncate(). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2827 a1c6a512-1295-4272-9138-f99709370657 --- firmware/common/file.c | 27 ++++++++++++++++++++++++++- firmware/common/file.h | 1 + 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'firmware/common') 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) case O_WRONLY: openfiles[fd].write = true; break; - + default: DEBUGF("Only O_RDONLY and O_WRONLY is supported\n"); errno = EROFS; @@ -214,6 +214,31 @@ int remove(const char* name) return rc; } +int ftruncate(int fd, unsigned int size) +{ + int rc, sector; + + sector = size / SECTOR_SIZE; + if (size % SECTOR_SIZE) + sector++; + + rc = fat_seek(&(openfiles[fd].fatfile), sector); + if (rc < 0) { + errno = EIO; + return -1; + } + + rc = fat_truncate(&(openfiles[fd].fatfile)); + if (rc < 0) { + errno = EIO; + return -2; + } + + openfiles[fd].size = size; + + return 0; +} + static int readwrite(int fd, void* buf, int count, bool write) { 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); extern int write(int fd, void* buf, int count); extern int remove(const char* pathname); extern int rename(const char* oldname, const char* newname); +extern int ftruncate(int fd, unsigned int size); #else #ifdef WIN32 -- cgit v1.2.3