From bb9dfa0b02f00f94168640f18491dd65f4309782 Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Wed, 9 Mar 2005 19:26:59 +0000 Subject: Simulators: more efficient implementation of sim_filesize(). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6175 a1c6a512-1295-4272-9138-f99709370657 --- uisimulator/common/io.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'uisimulator/common/io.c') diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c index 53e2022062..8f72d4f94d 100644 --- a/uisimulator/common/io.c +++ b/uisimulator/common/io.c @@ -251,11 +251,16 @@ long sim_lseek(int fildes, long offset, int whence) long sim_filesize(int fd) { - long old = lseek(fd, 0, SEEK_CUR); - long size = lseek(fd, 0, SEEK_END); - lseek(fd, old, SEEK_SET); - - return size; +#ifdef WIN32 + return _filelength(fd); +#else + struct stat buf; + + if (!fstat(fd, &buf)) + return buf.st_size; + else + return -1; +#endif } void fat_size(unsigned int* size, unsigned int* free) -- cgit v1.2.3