[PATCH v3] ungetc: Guarantee single char pushback

Siddhesh Poyarekar siddhesh@sourceware.org
Mon Dec 9 12:41:00 GMT 2024


On 2024-12-08 20:40, Maciej W. Rozycki wrote:
> On Fri, 6 Dec 2024, Siddhesh Poyarekar wrote:
> 
>> The C standard requires that ungetc guarantees at least one pushback, so
>> put a single byte pushback buffer in the FILE struct to enable that.
> 
>   So what would the problem be if we instead replaced:
> 
>    int _flags2;
> 
> with
> 
>    short int _flags2;
>    char _short_backupbuf[1];
>    char _unused;

I don't see an actual problem other than that of an application maybe 
using the upper bits of _flags2 for their own logic.  One could make the 
same argument for unused2, but the defence there is that there's 
precedent of struct expansion into unused2; the same can't be said about 
_flags2.

I personally don't care to retain such abuses, so it seems OK to shrink 
_flags2.  Florian, what do you think?

Thanks,
Sid


More information about the Libc-alpha mailing list