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