Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the st_size field in struct stat signed?

Tags:

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?

like image 585
user1290696 Avatar asked Sep 05 '12 06:09

user1290696


People also ask

What is the type of St_size?

st_size is defined as being an off_t . off_t is defined as being a signed integer type.

What is St_size?

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.

What is stat structure Linux?

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.


1 Answers

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

like image 60
R.. GitHub STOP HELPING ICE Avatar answered Sep 20 '22 16:09

R.. GitHub STOP HELPING ICE