Size of file and size of stream may not match. For example, when you open file in text mode, OS can translate multi-byte EOL sequences into single char. This is usually visible on Windows, but if you have a Windows file on Linux, the effect can be the same.
sys/stat.h returning wrong size
문제
I am using
- unistd.h
- sys/stat.h
and what is interesting is that st_size
is bigger than the value returned after read()
?
st.st_size
returns 644
- read()
returns 606
,
Any thoughts?
해결책
다른 팁
The memory is allocated in multiples of blocks (st_blocks). The remaining bytes you noticed are due to block alignment.
If you check the value of st.st_blocks
you will see that it is a good divisor for 644
, while not to 606.
So, if you want to know the real size occupied with data, do not use st_size
.
제휴하지 않습니다 StackOverflow