shorten file size function by using the new CFS_SEEK_END.

This commit is contained in:
nvt-se 2009-05-15 23:04:15 +00:00
parent bcc5084564
commit 2b1053f0e3

View File

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: deluge.c,v 1.6 2009/04/07 14:07:39 nvt-se Exp $
* $Id: deluge.c,v 1.7 2009/05/15 23:04:15 nvt-se Exp $
*/
/**
@ -183,23 +183,14 @@ init_page(struct deluge_object *obj, int pagenum, int have)
static int
file_size(const char *file)
{
int fd, r, size;
char buf[32];
int fd, size;
fd = cfs_open(file, CFS_READ);
if(fd < 0) {
return -1;
}
size = 0;
do {
r = cfs_read(fd, buf, sizeof(buf));
if(r < 0) {
cfs_close(fd);
return -1;
}
size += r;
} while(r > 0);
size = cfs_seek(fd, 0, CFS_SEEK_END);
cfs_close(fd);
return size;