Mercurial > hg > octave-lojdl > gnulib-hg
annotate lib/verror.c @ 17464:290d581e2e24
autoupdate
author | Karl Berry <karl@freefriends.org> |
---|---|
date | Sat, 10 Aug 2013 07:10:55 -0700 |
parents | e542fd46ad6f |
children |
rev | line source |
---|---|
7092 | 1 /* va_list error handler for noninteractive utilities |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
16235
diff
changeset
|
2 Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc. |
7092 | 3 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9112
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
7092 | 5 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9112
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9112
diff
changeset
|
7 (at your option) any later version. |
7092 | 8 |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9112
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9112
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
7092 | 16 |
17 /* Written by Eric Blake. */ | |
18 | |
7372
8e5e6419e8f9
* verror.c: Include <config.h> unconditionally.
Eric Blake <ebb9@byu.net>
parents:
7095
diff
changeset
|
19 #include <config.h> |
7092 | 20 |
21 #include "verror.h" | |
22 #include "xvasprintf.h" | |
23 | |
24 #include <errno.h> | |
25 #include <stdarg.h> | |
26 #include <stdlib.h> | |
27 | |
28 #if ENABLE_NLS | |
29 # include "gettext.h" | |
9112
8b2acf250f22
Add missing definition of _ macro.
Bruno Haible <bruno@clisp.org>
parents:
7372
diff
changeset
|
30 # define _(msgid) gettext (msgid) |
7092 | 31 #endif |
32 | |
33 #ifndef _ | |
34 # define _(String) String | |
35 #endif | |
36 | |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
37 /* Print a message with 'vfprintf (stderr, FORMAT, ARGS)'; |
7092 | 38 if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM). |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
39 If STATUS is nonzero, terminate the program with 'exit (STATUS)'. |
7092 | 40 Use the globals error_print_progname and error_message_count similarly |
41 to error(). */ | |
42 void | |
43 verror (int status, int errnum, const char *format, va_list args) | |
44 { | |
45 verror_at_line (status, errnum, NULL, 0, format, args); | |
46 } | |
47 | |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
48 /* Print a message with 'vfprintf (stderr, FORMAT, ARGS)'; |
7092 | 49 if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM). |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
50 If STATUS is nonzero, terminate the program with 'exit (STATUS)'. |
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
51 If FNAME is not NULL, prepend the message with "FNAME:LINENO:". |
7092 | 52 Use the globals error_print_progname, error_message_count, and |
53 error_one_per_line similarly to error_at_line(). */ | |
54 void | |
55 verror_at_line (int status, int errnum, const char *file, | |
56 unsigned int line_number, const char *format, va_list args) | |
57 { | |
58 char *message = xvasprintf (format, args); | |
59 if (message) | |
7095
c645fbe36091
* verror.c (verror_at_line): Work around glibc bug 2997, so that
Eric Blake <ebb9@byu.net>
parents:
7092
diff
changeset
|
60 { |
c645fbe36091
* verror.c (verror_at_line): Work around glibc bug 2997, so that
Eric Blake <ebb9@byu.net>
parents:
7092
diff
changeset
|
61 /* Until http://sourceware.org/bugzilla/show_bug.cgi?id=2997 is fixed, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
62 glibc violates GNU Coding Standards when the file argument to |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
63 error_at_line is NULL. */ |
7095
c645fbe36091
* verror.c (verror_at_line): Work around glibc bug 2997, so that
Eric Blake <ebb9@byu.net>
parents:
7092
diff
changeset
|
64 if (file) |
c645fbe36091
* verror.c (verror_at_line): Work around glibc bug 2997, so that
Eric Blake <ebb9@byu.net>
parents:
7092
diff
changeset
|
65 error_at_line (status, errnum, file, line_number, "%s", message); |
c645fbe36091
* verror.c (verror_at_line): Work around glibc bug 2997, so that
Eric Blake <ebb9@byu.net>
parents:
7092
diff
changeset
|
66 else |
c645fbe36091
* verror.c (verror_at_line): Work around glibc bug 2997, so that
Eric Blake <ebb9@byu.net>
parents:
7092
diff
changeset
|
67 error (status, errnum, "%s", message); |
c645fbe36091
* verror.c (verror_at_line): Work around glibc bug 2997, so that
Eric Blake <ebb9@byu.net>
parents:
7092
diff
changeset
|
68 } |
7092 | 69 else |
70 { | |
71 /* EOVERFLOW, EINVAL, and EILSEQ from xvasprintf are signs of | |
72 serious programmer errors. */ | |
73 error (0, errno, _("unable to display error message")); | |
74 abort (); | |
75 } | |
76 free (message); | |
77 } |