user1290696 user1290696 - 1 year ago 98
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..
Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download