user1290696 user1290696 - 3 months ago 10x
Linux Question

Why is the st_size field in struct stat signed?

is defined as being an

is defined as being a signed integer type.

Why is
defined as a signed type? Can it be negative? What does it mean if it is negative?

R.. R..

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