Search code examples
cstatunistd.h

sys/stat.h returning wrong size


I am using

  1. unistd.h
  2. 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?


Solution

  • 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.