1
0
Fork 0
forked from len0rd/rockbox

Added the filesize() function

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3473 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Linus Nielsen Feltzing 2003-03-18 00:39:57 +00:00
parent 55fc6df874
commit e98bad5b38
6 changed files with 36 additions and 0 deletions

View file

@ -591,3 +591,15 @@ int lseek(int fd, int offset, int whence)
return pos; return pos;
} }
int filesize(int fd)
{
struct filedesc* file = &openfiles[fd];
if ( !file->busy ) {
errno = EBADF;
return -1;
}
return file->size;
}

View file

@ -64,6 +64,7 @@ extern int write(int fd, void* buf, int count);
extern int remove(const char* pathname); extern int remove(const char* pathname);
extern int rename(const char* path, const char* newname); extern int rename(const char* path, const char* newname);
extern int ftruncate(int fd, unsigned int size); extern int ftruncate(int fd, unsigned int size);
extern int filesize(int fd);
#endif /* SIMULATOR */ #endif /* SIMULATOR */
#endif /* __MINGW32__ */ #endif /* __MINGW32__ */

View file

@ -23,11 +23,14 @@
#include <string.h> #include <string.h>
int win32_rename(char *oldpath, char *newpath); int win32_rename(char *oldpath, char *newpath);
int win32_filesize(int fd);
#define rename(x,y) win32_rename(x,y) #define rename(x,y) win32_rename(x,y)
#define filesize(x,y) win32_filesize(x,y)
#include "../../firmware/include/file.h" #include "../../firmware/include/file.h"
#undef rename #undef rename
#undef filesize
#endif #endif

View file

@ -36,3 +36,12 @@ int win32_rename(char *oldpath, char* newpath)
} }
return -1; return -1;
} }
int win32_filesize(int fd)
{
int old = lseek(fd, 0, SEEK_CUR);
int size = lseek(fd, 0, SEEK_END);
lseek(fd, old, SEEK_SET);
return(size);
}

View file

@ -25,12 +25,14 @@
int x11_open(char *name, int opts); int x11_open(char *name, int opts);
int x11_close(int fd); int x11_close(int fd);
int x11_filesize(int fd);
int x11_creat(char *name, int mode); int x11_creat(char *name, int mode);
int x11_remove(char *name); int x11_remove(char *name);
int x11_rename(char *oldpath, char *newpath); int x11_rename(char *oldpath, char *newpath);
#define open(x,y) x11_open(x,y) #define open(x,y) x11_open(x,y)
#define close(x) x11_close(x) #define close(x) x11_close(x)
#define filesize(x) x11_filesize(x)
#define creat(x,y) x11_creat(x,y) #define creat(x,y) x11_creat(x,y)
#define remove(x) x11_remove(x) #define remove(x) x11_remove(x)
#define rename(x,y) x11_rename(x,y) #define rename(x,y) x11_rename(x,y)

View file

@ -156,6 +156,15 @@ int x11_rename(char *oldpath, char* newpath)
return -1; return -1;
} }
int x11_filesize(int fd)
{
int old = lseek(fd, 0, SEEK_CUR);
int size = lseek(fd, 0, SEEK_END);
lseek(fd, old, SEEK_SET);
return(size);
}
void fat_size(unsigned int* size, unsigned int* free) void fat_size(unsigned int* size, unsigned int* free)
{ {
struct statfs fs; struct statfs fs;