diff options
-rw-r--r-- | firmware/common/file.c | 12 | ||||
-rw-r--r-- | firmware/include/file.h | 1 | ||||
-rw-r--r-- | uisimulator/win32/file.h | 3 | ||||
-rw-r--r-- | uisimulator/win32/io.c | 9 | ||||
-rw-r--r-- | uisimulator/x11/file.h | 2 | ||||
-rw-r--r-- | uisimulator/x11/io.c | 9 |
6 files changed, 36 insertions, 0 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c index d2cad7c647..8c0f9a8951 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c | |||
@@ -591,3 +591,15 @@ int lseek(int fd, int offset, int whence) | |||
591 | 591 | ||
592 | return pos; | 592 | return pos; |
593 | } | 593 | } |
594 | |||
595 | int filesize(int fd) | ||
596 | { | ||
597 | struct filedesc* file = &openfiles[fd]; | ||
598 | |||
599 | if ( !file->busy ) { | ||
600 | errno = EBADF; | ||
601 | return -1; | ||
602 | } | ||
603 | |||
604 | return file->size; | ||
605 | } | ||
diff --git a/firmware/include/file.h b/firmware/include/file.h index 75c55bbac9..1a2f8e55be 100644 --- a/firmware/include/file.h +++ b/firmware/include/file.h | |||
@@ -64,6 +64,7 @@ extern int write(int fd, void* buf, int count); | |||
64 | extern int remove(const char* pathname); | 64 | extern int remove(const char* pathname); |
65 | extern int rename(const char* path, const char* newname); | 65 | extern int rename(const char* path, const char* newname); |
66 | extern int ftruncate(int fd, unsigned int size); | 66 | extern int ftruncate(int fd, unsigned int size); |
67 | extern int filesize(int fd); | ||
67 | #endif /* SIMULATOR */ | 68 | #endif /* SIMULATOR */ |
68 | #endif /* __MINGW32__ */ | 69 | #endif /* __MINGW32__ */ |
69 | 70 | ||
diff --git a/uisimulator/win32/file.h b/uisimulator/win32/file.h index 3cda3b9d8c..7dd7c8e94c 100644 --- a/uisimulator/win32/file.h +++ b/uisimulator/win32/file.h | |||
@@ -23,11 +23,14 @@ | |||
23 | #include <string.h> | 23 | #include <string.h> |
24 | 24 | ||
25 | int win32_rename(char *oldpath, char *newpath); | 25 | int win32_rename(char *oldpath, char *newpath); |
26 | int win32_filesize(int fd); | ||
26 | 27 | ||
27 | #define rename(x,y) win32_rename(x,y) | 28 | #define rename(x,y) win32_rename(x,y) |
29 | #define filesize(x,y) win32_filesize(x,y) | ||
28 | 30 | ||
29 | #include "../../firmware/include/file.h" | 31 | #include "../../firmware/include/file.h" |
30 | 32 | ||
31 | #undef rename | 33 | #undef rename |
34 | #undef filesize | ||
32 | 35 | ||
33 | #endif | 36 | #endif |
diff --git a/uisimulator/win32/io.c b/uisimulator/win32/io.c index 974fdadbbd..ac85bb193e 100644 --- a/uisimulator/win32/io.c +++ b/uisimulator/win32/io.c | |||
@@ -36,3 +36,12 @@ int win32_rename(char *oldpath, char* newpath) | |||
36 | } | 36 | } |
37 | return -1; | 37 | return -1; |
38 | } | 38 | } |
39 | |||
40 | int win32_filesize(int fd) | ||
41 | { | ||
42 | int old = lseek(fd, 0, SEEK_CUR); | ||
43 | int size = lseek(fd, 0, SEEK_END); | ||
44 | lseek(fd, old, SEEK_SET); | ||
45 | |||
46 | return(size); | ||
47 | } | ||
diff --git a/uisimulator/x11/file.h b/uisimulator/x11/file.h index cf77eea4ba..f11f5056c9 100644 --- a/uisimulator/x11/file.h +++ b/uisimulator/x11/file.h | |||
@@ -25,12 +25,14 @@ | |||
25 | 25 | ||
26 | int x11_open(char *name, int opts); | 26 | int x11_open(char *name, int opts); |
27 | int x11_close(int fd); | 27 | int x11_close(int fd); |
28 | int x11_filesize(int fd); | ||
28 | int x11_creat(char *name, int mode); | 29 | int x11_creat(char *name, int mode); |
29 | int x11_remove(char *name); | 30 | int x11_remove(char *name); |
30 | int x11_rename(char *oldpath, char *newpath); | 31 | int x11_rename(char *oldpath, char *newpath); |
31 | 32 | ||
32 | #define open(x,y) x11_open(x,y) | 33 | #define open(x,y) x11_open(x,y) |
33 | #define close(x) x11_close(x) | 34 | #define close(x) x11_close(x) |
35 | #define filesize(x) x11_filesize(x) | ||
34 | #define creat(x,y) x11_creat(x,y) | 36 | #define creat(x,y) x11_creat(x,y) |
35 | #define remove(x) x11_remove(x) | 37 | #define remove(x) x11_remove(x) |
36 | #define rename(x,y) x11_rename(x,y) | 38 | #define rename(x,y) x11_rename(x,y) |
diff --git a/uisimulator/x11/io.c b/uisimulator/x11/io.c index bc9c99fa10..c33a42d636 100644 --- a/uisimulator/x11/io.c +++ b/uisimulator/x11/io.c | |||
@@ -156,6 +156,15 @@ int x11_rename(char *oldpath, char* newpath) | |||
156 | return -1; | 156 | return -1; |
157 | } | 157 | } |
158 | 158 | ||
159 | int x11_filesize(int fd) | ||
160 | { | ||
161 | int old = lseek(fd, 0, SEEK_CUR); | ||
162 | int size = lseek(fd, 0, SEEK_END); | ||
163 | lseek(fd, old, SEEK_SET); | ||
164 | |||
165 | return(size); | ||
166 | } | ||
167 | |||
159 | void fat_size(unsigned int* size, unsigned int* free) | 168 | void fat_size(unsigned int* size, unsigned int* free) |
160 | { | 169 | { |
161 | struct statfs fs; | 170 | struct statfs fs; |