Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Patch for giga- and terabyte size specifiers



On Wed, 19 Feb 2014 14:12:03 +0100
Manuel Presnitz <mpy@xxxxxxx> wrote:
> I thought it is time to have globbing size specifiers at hand also for
> gigabytes, and while at it for terabytes, too.  As that seemed pretty
> straight forward, I tried to do the modification myself.

Generally looks fine, thanks...

> +#if defined(ZSH_64_BIT_TYPE) || defined(LONG_IS_64_BIT)
> +    case TT_GIGABYTES:
> +        scaled += 1073741823l;
> +        scaled /= 1073741824l;
> +        break;
> +    case TT_TERABYTES:
> +        scaled += 1099511627775l;
> +        scaled /= 1099511627776l;
> +        break;
> +#endif

I suppose we need to be a bit careful here since we don't know the
64-bit type is long, so the suffix may not be right and we might get
overflow of the constant.

I'm not sure if we get away with e.g.

(zlong)1099511627775

--- my C basics aren't up to remembering whether the compiler is
required to look at the type of a cast when interpreting a constant,
but I have a suspicion it isn't.

Otherwise, I guess we need something like...

#if defined(ZSH_64_BIT_TYPE) || defined(LONG_IS_64_BIT)
#ifdef LONG_IS_64_BIT
#define ZLONG_CONST(x)  x ## l
#else
#define ZLONG_CONST(x)  x ## ll
#endif
    case TT_GIGABYTES:
        scaled += ZLONG_CONST(1073741823);
        scaled /= ZLONG_CONST(1073741824);
        break;
    case TT_TERABYTES:
        scaled += ZLONG_CONST(1099511627775);
        scaled /= ZLONG_CONST(1099511627776);
        break;
#endif

although probably even that doesn't work for the mysterious "quad" type
mentioned in some bits of the shell.  Or maybe I'm being too pernickety.

(I have a feeling this is all done much better in D :-/)

pws



Messages sorted by: Reverse Date, Date, Thread, Author