Mail Archives: djgpp-workers/2001/08/04/05:58:34
Hello.
I finally got round to look at this - sorry for the delay.
Martin Str|mberg wrote:
>
> According to Eli Zaretskii:
> > I'd begin by making sure that the reason is indeed the fact that
> > st_size is signed; what I said was just a hunch.
[snip]
> > If the answer is YES, then the change should be probably done in `ls'.
> > If not... well, we need another hunch.
'ls' casts st_size to an unsigned type - uintmax_t - which is defined to
be unsigned long long:
if (S_ISCHR (f->stat.st_mode) || S_ISBLK (f->stat.st_mode))
sprintf (p, "%3u, %3u ", (unsigned) major (f->stat.st_rdev),
(unsigned) minor (f->stat.st_rdev));
else
{
char hbuf[LONGEST_HUMAN_READABLE + 1];
sprintf (p, "%8s ",
human_readable ((uintmax_t) f->stat.st_size, hbuf, 1,
output_block_size < 0 ? output_block_size :
1));
}
This cast does not work. This seems strange - I would expect a cast from
signed long to unsigned long long to work. Wouldn't the value be
zero-extended to fill the unsigned long long? Does anyone have any
suggestions on how I can fix this? (I don't have any of my C reference
material here.) Typecasting to unsigned long then uintmax_t seems to work,
but I think that's a hack rather than the solution.
(I thought it might be a compiler bug at first - the same thing happens
with gcc 2.95.2, 2.95.3, 3.0.)
If I edit config.h to define uintmax_t to be unsigned long, then 'ls'
shows the right length. But that might have other side effects.
Bye, Rich =]
--
Richard Dawe
http://www.phekda.freeserve.co.uk/richdawe/
- Raw text -