[parted-devel] avoid printf, when easy to do

Jim Meyering jim at meyering.net
Wed Mar 7 21:10:02 CET 2007


"Debarshi 'Rishi' Ray" <debarshi.ray at gmail.com> wrote:
>> I'm ambivalent about using "puts" (which you've done correctly)
>> because of it's somewhat "hidden" semantics of adding a trailing newline.
>> Sometimes it's more maintainer/translator-friendly to use fputs and
>> include an explicit "\n" at the end of the literal string, in spite of
>> the need for the added stdout or stderr argument.
>
> Some of the messages being sent to 'stdout' seem to be error messages,
> and should have been sent to 'stderr' instead. eg., the following
> snippet in libparted/labels/vtoc.c
>        if (tmp == NULL) {
>                /* BUG: no free extent found */
> -               printf("BUG: no free FMT5 DSCB extent found!\nexiting...\n");
> +               puts ("BUG: no free FMT5 DSCB extent found!\nexiting...");
>                exit(1);
>        }
>
> We can change them if necessary to fputs(..., stderr) in a later
> delta. Comments?

Yes.  Definitely in a separate delta.
We need a global sweep through the code, changing such things.
In application code (not library code) like ui.c, it should
use the gnulib 'error' function so that all of its diagnostics
include the program_name prefix, e.g.,

    $ ./parted --help > /dev/full
    ./parted: write error: No space left on device

One can argue that library code should produce no output at all,
but we're not there yet.

This is perhaps a good argument for using the functions
that take a stream argument (e.g., fputs), rather than the
short-cut ones that don't, like puts, putchar, etc.



More information about the parted-devel mailing list