shorten file size function by using the new CFS_SEEK_END.
This commit is contained in:
parent
bcc5084564
commit
2b1053f0e3
|
@ -28,7 +28,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* 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
|
static int
|
||||||
file_size(const char *file)
|
file_size(const char *file)
|
||||||
{
|
{
|
||||||
int fd, r, size;
|
int fd, size;
|
||||||
char buf[32];
|
|
||||||
|
|
||||||
fd = cfs_open(file, CFS_READ);
|
fd = cfs_open(file, CFS_READ);
|
||||||
if(fd < 0) {
|
if(fd < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
size = 0;
|
size = cfs_seek(fd, 0, CFS_SEEK_END);
|
||||||
do {
|
|
||||||
r = cfs_read(fd, buf, sizeof(buf));
|
|
||||||
if(r < 0) {
|
|
||||||
cfs_close(fd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
size += r;
|
|
||||||
} while(r > 0);
|
|
||||||
|
|
||||||
cfs_close(fd);
|
cfs_close(fd);
|
||||||
return size;
|
return size;
|
||||||
|
|
Loading…
Reference in a new issue