Skip to content

Commit 2131624

Browse files
committed
Speed up cimg::fsize
1 parent 3b13d06 commit 2131624

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

CImg.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5795,18 +5795,31 @@ namespace cimg_library {
57955795
**/
57965796
inline cimg_int64 fsize(std::FILE *const file) {
57975797
if (!file) return (cimg_int64)-1;
5798+
#if cimg_OS==1
5799+
int fd = fileno(file);
5800+
struct stat st;
5801+
if (fstat(fd,&st) < 0) return (cimg_int64)-1;
5802+
return (cimg_int64)st.st_size;
5803+
#else
57985804
const cimg_long pos = std::ftell(file);
57995805
cimg::fseek(file,0,SEEK_END);
58005806
const cimg_int64 siz = (cimg_int64)std::ftell(file);
58015807
cimg::fseek(file,pos,SEEK_SET);
58025808
return siz;
5809+
#endif
58035810
}
58045811

58055812
inline cimg_int64 fsize(const char *const filename) {
5813+
#if cimg_OS==1
5814+
struct stat st;
5815+
if (stat(filename,&st) < 0) return (cimg_int64)-1;
5816+
return (cimg_int64)st.st_size;
5817+
#else
58065818
std::FILE *const file = cimg::std_fopen(filename,"rb");
58075819
const cimg_int64 siz = fsize(file);
58085820
cimg::fclose(file);
58095821
return siz;
5822+
#endif
58105823
}
58115824

58125825

0 commit comments

Comments
 (0)