This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/2997] New: error_at_line vs. GNU Coding Standards


In misc/error.c, using error_at_line does not always comply with GNU Coding 
Standards, which request that messages be in the form "program: message" 
or "program:file:line: message".

$ cat err.c
sh-3.00$ cat err.c
#include <error.h>
#include <stdio.h>

static int space;

static void
epp (void)
{
  fprintf (stderr, "%s:", "program");
  if (space)
    fputc (' ', stderr);
}

int
main(int argc, char** argv)
{
  if (argc > 1)
    {
      puts ("Using error_print_progname");
      error_print_progname = epp;
      if (*argv[1])
	{
	  puts ("Printing space");
	  space = 1;
	}
      else
	puts ("Omitting space");
    }
  else
    puts ("Letting error print progname");
  error(0, 0, "message1");
  error_at_line(0, 0, NULL, 0, "message2");
  error_at_line(0, 0, "file", 1, "message3");
  return 0;
}

$ # Case 1.
$ ./err
Letting error print progname
./err: message1
./err:message2
./err:file:1: message3
$ # Oops, missing a space before message2

$ # Case 2.
$ ./err ' '
Using error_print_progname
Printing space
program: message1
program: message2
program: file:1: message3
$ # Oops, extra space before filename

$ # Case 3.
$ ./err ''
Using error_print_progname
Omitting space
program:message1
program:message2
program:file:1: message3
$ # Oops, missing space before message1 and 2


I will attach a patch for case 1, when not using error_print_progname.

But when using error_print_progname (cases 2 and 3), I'm not sure how to tackle 
the issue.  One approach would be to document that error_print_progname should 
not append a space, and change error and error_at_line to unconditionally 
provide the space.  But for programs that want to use error_print_progname as a 
nop so that output looks like "file:line: message" for the sake of emacs 
compilation mode, this would break existing programs because error_at_line 
would then be outputting " file:line: message".

Another approach would be to add a new global variable, void 
(*error_print_progname_space)(int), and use the parameter as a flag to the the 
user's callback that if the callback prints to stderr, it should end with a 
space.  Then error would invoke error_print_progname_space(1), while 
error_at_line would invoke error_print_progname_space(file == NULL).

-- 
           Summary: error_at_line vs. GNU Coding Standards
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: minor
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: ebb9 at byu dot net
                CC: glibc-bugs at sources dot redhat dot com


http://sourceware.org/bugzilla/show_bug.cgi?id=2997

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]