* Why is st_size defined as a signed int?
@ 2021-04-27 14:01 Peng Yu
2021-04-27 16:06 ` Mike Frysinger
2021-04-27 17:05 ` Andrew Bell
0 siblings, 2 replies; 3+ messages in thread
From: Peng Yu @ 2021-04-27 14:01 UTC (permalink / raw)
To: libc-help
Hi,
https://github.com/bminor/glibc/blob/master/bits/stat.h#L47
I see st_size is defined as __off_t, which should be a signed int. But
can a file size be negative. If not, why not use an unsigned int to
represent the file size? Thanks.
--
Regards,
Peng
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Why is st_size defined as a signed int?
2021-04-27 14:01 Why is st_size defined as a signed int? Peng Yu
@ 2021-04-27 16:06 ` Mike Frysinger
2021-04-27 17:05 ` Andrew Bell
1 sibling, 0 replies; 3+ messages in thread
From: Mike Frysinger @ 2021-04-27 16:06 UTC (permalink / raw)
To: Peng Yu; +Cc: libc-help
On 27 Apr 2021 09:01, Peng Yu via Libc-help wrote:
> https://github.com/bminor/glibc/blob/master/bits/stat.h#L47
>
> I see st_size is defined as __off_t, which should be a signed int. But
> can a file size be negative. If not, why not use an unsigned int to
> represent the file size? Thanks.
it's an offset, not a size. lseek can legitimately be negative.
otherwise, at this point, the interfaces are ossified by POSIX, and glibc
simply has to match whatever it has.
-mike
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Why is st_size defined as a signed int?
2021-04-27 14:01 Why is st_size defined as a signed int? Peng Yu
2021-04-27 16:06 ` Mike Frysinger
@ 2021-04-27 17:05 ` Andrew Bell
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Bell @ 2021-04-27 17:05 UTC (permalink / raw)
To: Peng Yu; +Cc: libc-help
On Tue, Apr 27, 2021 at 12:46 PM Peng Yu via Libc-help <
libc-help@sourceware.org> wrote:
> Hi,
>
> https://github.com/bminor/glibc/blob/master/bits/stat.h#L47
>
> I see st_size is defined as __off_t, which should be a signed int. But
> can a file size be negative. If not, why not use an unsigned int to
> represent the file size?
This is required by the POSIX standard.
--
Andrew Bell
andrew.bell.ia@gmail.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-04-27 17:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-27 14:01 Why is st_size defined as a signed int? Peng Yu
2021-04-27 16:06 ` Mike Frysinger
2021-04-27 17:05 ` Andrew Bell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).