st_size
is defined as being an off_t
.
off_t
is defined as being a signed integer type.
Why is st_size
defined as a signed type? Can it be negative? What does it mean if it is negative?
st_size is defined as being an off_t . off_t is defined as being a signed integer type.
The st_size field gives the size of the file (if it is a regular file or a symbolic link) in bytes. The size of a symbolic link is the length of the pathname it contains, without a terminating null byte. The st_blocks field indicates the number of blocks allocated to the file, 512-byte units.
Stat system call is a system call in Linux to check the status of a file such as to check when the file was accessed. The stat() system call actually returns file attributes. The file attributes of an inode are basically returned by Stat() function. An inode contains the metadata of the file.
The best reason I can think of is to avoid introducing an unsigned version of off_t
as an extra type; POSIX already has a ridiculous abundance of integer types with similar uses.
Aside from that, being able to store -1 in st_size
when size is not a concept that makes sense is probably useful; I'm not sure if any implementations do this, and I can't find where POSIX puts any requirements on the contents of st_size
except for regular files and symlinks...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With