FIO19-C. Do not use fseek() and ftell() to compute the size of a regular file - SEI CERT C Coding Standard - Confluence
Is a buffered fread / read to obtain size considered a bad approach,
compared to fseek / ftell ?
FIO19-C. Do not use fseek() and ftell() to compute the size of a regular file - SEI CERT C Coding Standard - Confluence
Is a buffered fread / read to obtain size considered a bad approach,
compared to fseek / ftell ?
stat()
Stat is posix.
Even if fread / read can determine file size,
is it a good approach ?
Also one has to take into account a performance issue,
since fread / read requires a buffer.
It might be your only approach if you're going to eschew creature comforts offered by POSIX
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
c++ - How does _stat() under Windows exactly work - Stack Overflow_stat is a function that is not native to Windows. It's a helper function to ease the porting of UNIX programs to Windows. But the UNIX file model just doesn't apply to Windows, so not all fields make sense. For instance, Windows has real ACL's, not rwx bits. There's just no way to fit all the ACL information in st_mode.
May 23, 2011 at 8:50
MSalters
IBM Documentationoff_t, File offset, measured in bytes from the beginning of a file or device. off_t is normally defined as a signed, 32-bit integer. In the programming environment which enables large files, off_t is defined to be a signed, 64-bit integer.
IBM DocumentationReturned value
If successful, the ftello() function returns the calculated value.
If unsuccessful, the ftello() function returns (off_t)-1 and sets errno to one of the following values:
off_t is 32 / 64 bit integer,
and with a large file, it will overflow.
Author may be misinformed..
Last edited by kodax; 11-21-2022 at 01:59 PM.
Dribble fest.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.