bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stat signed/unsigned


From: Pádraig Brady
Subject: Re: stat signed/unsigned
Date: Tue, 6 Jan 2009 10:22:40 +0000
User-agent: Thunderbird 2.0.0.6 (X11/20071008)

Jim Meyering wrote:
> Michael Meskes <address@hidden> wrote:
>> On Wed, Dec 31, 2008 at 03:18:44PM +0100, Jim Meyering wrote:
>>> Thanks, but "man statfs" on linux-based systems shows it can be signed:
>>> ...
>> Sorry for the noise, I just used grep -r to find stuff like
>>
>> /usr/include/asm-generic/statfs.h:      __u32 f_files;
>> /usr/include/asm-generic/statfs.h:      __u64 f_files;
>> /usr/include/asm-generic/statfs.h:      __u64 f_files;
> 
> Have you seen ever stat print a negative number
> corresponding to that field?  Actually, I'll bet that
> *has* happened... and considering the semantics
> of that variable, I see no reason to print a signed value.

On a related note, I was looking at removing -Wsign-compare warnings
and noticed a lot are due to dealing with signed st_size, st_blocks etc.
I searched and found no references to where these could ever be negative,
and therefore I'm assuming that the type is only really to define the
width and should always be interpreted as unsigned.

So, I'll add an ST_SIZE() macro to system.h like:
#define ST_SIZE(statbuf) ((uintmax_t) (statbuf).st_size)
and also add the equivalent cast to ST_NBLOCKS etc.

Then any code using them could deal just with unsigned variables,
thus avoiding any -Wsign-compare warnings.

cheers,
Pádraig.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]