stat.2: Improve discussion of 'st_size' for /proc and /sys files

Reported-by: Ursache Vladimir <f35f22fan@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
Michael Kerrisk 2016-08-29 08:47:39 +12:00
parent 370f8e34c4
commit 9dbc4adbce
1 changed files with 13 additions and 5 deletions

View File

@ -784,13 +784,21 @@ will generally not trigger automounter action, whereas
will (but see
.BR fstatat (2)).
For most files under the
For many pseudofiles that are autogenerated by the kernel,
.BR stat ()
does not return an accurate value in the
.IR st_size
field.
For example, the value 0 is returned for many files under the
.I /proc
directory,
.BR stat ()
does not return the file size in the
.I st_size
field; instead the field is returned with the value 0.
while various files under
.IR /sys
report a size of 4096 bytes, even though the file content is smaller.
For such files, one should simply try to read as many bytes as possible
(and append \(aq\e0\(aq to the returned buffer
if it is to be interpreted as a string).
.\"
.SS Timestamp fields
Older kernels and older standards did not support nanosecond timestamp
fields.