bug-gnulib
[Top][All Lists]
Advanced

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

[bug-gnulib] Re: base64


From: Simon Josefsson
Subject: [bug-gnulib] Re: base64
Date: Thu, 25 Nov 2004 15:37:06 +0100
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (gnu/linux)

Stepan Kasal <address@hidden> writes:

> Hi Jim,
>
> On Thu, Nov 25, 2004 at 03:25:34PM +0100, Jim Meyering wrote:
>> There should be parentheses around each RHS:
>> 
>>   #define BASE64_CEILING_DIV(n, k) ((n + (k-1)) / k)
>>   #define BASE64_LENGTH(inlen) (BASE64_CEILING_DIV(inlen, 3) * 4)
>
> Thank you for correcting me.  To make BASE64_CEILING_DIV generally usable,
> one would have to do:
>
>     #define BASE64_CEILING_DIV(n, k) (((n) + ((k)-1)) / (k))
>     #define BASE64_LENGTH(inlen) (BASE64_CEILING_DIV(inlen, 3) * 4)
>
> but perhaps we can settle with:
>
>     #define _BASE64_CEILING_DIV(n, k) ((n + (k-1)) / k)
>     #define BASE64_LENGTH(inlen) (_BASE64_CEILING_DIV(inlen, 3) * 4)

What advantage does this have over

#define BASE64_LENGTH(inlen) ((((inlen) + 2) / 3) * 4)

The latter seems simpler to me.

Perhaps the macro name should be BASE64_EXPAND_LENGTH, and there could
be another macro BASE64_COLLAPSE_MAX_LENGTH to compute the longest
possible base64 decoded output.  (The correct output length depend on
the number of '=' pads in the input.)





reply via email to

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