bug-gnulib
[Top][All Lists]
Advanced

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

Re: yesno module consumes too much input


From: Bruno Haible
Subject: Re: yesno module consumes too much input
Date: Sat, 18 Aug 2007 19:38:51 +0200
User-agent: KMail/1.5.4

Hi Eric,

> How about the following patch?
>       * lib/closein.c (close_stdin_only): New function.
>       (close_stdin): Make closing stdout optional.
>       * lib/closein.h (close_stdin_only): Add declaration.

This API of closein.h can easily lead to bugs: Say, one piece of code does

     atexit (close_stdin);

and expects it to clean up stdin + stdout. And another piece of code does

     close_stdin_only (true);
     atexit (close_stdin);

in because it wants to ensure that stdin gets cleaned up. The result is that
stdout will not be cleaned up although the first piece of code has asked for
it!

Additionally, the naming of the functions is now messy. 'close_stdin'
cleans up stdin and sometimes stdout. 'close_stdin_only' sounds like it closes
something, but actually it is a setter. And the other setter,
'close_stdin_set_file_name', uses a different naming convention.

To make this API more easy to understand, how about this?
  1) Rename the function 'close_stdin' to 'close_stdin_stdout',
  2) Add a function 'close_stdin', which closes stdin only. In the
     implementation, arrange that when 'close_stdin' and 'close_stdin_stdout'
     are both called, the stdin part is done only once.
  3) Don't add a 'close_stdin_only' setter.

Bruno





reply via email to

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