Mercurial > hg > octave-kai > gnulib-hg
annotate lib/xprintf.c @ 9398:9d8f7facb7a6
Also wrap vf?printf.
* lib/xprintf.h (xvprintf, xvfprintf): New declarations.
* lib/xprintf.c (xprintf, xfprintf): Work for C89.
(xvprintf, xvfprintf): New functions.
Signed-off-by: Eric Blake <ebb9@byu.net>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Mon, 22 Oct 2007 14:09:16 -0600 (2007-10-22) |
parents | f3d25691c7ac |
children | 8e698de353f7 |
rev | line source |
---|---|
9364 | 1 /* printf wrappers that fail immediately for non-file-related errors |
2 Copyright (C) 2007 Free Software Foundation, Inc. | |
3 | |
4 This program is free software: you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 3 of the License, or | |
7 (at your option) any later version. | |
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 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
16 | |
9374
f3d25691c7ac
* lib/xprintf.c: Include <config.h> unconditionally.
Jim Meyering <meyering@redhat.com>
parents:
9372
diff
changeset
|
17 #include <config.h> |
9364 | 18 |
19 #include "xprintf.h" | |
20 | |
21 #include <errno.h> | |
22 | |
23 #include "error.h" | |
24 #include "exitfail.h" | |
25 #include "gettext.h" | |
26 | |
27 /* written by Jim Meyering */ | |
28 | |
9366
dbb64cb4aed9
* lib/xprintf.c: Don't bother testing specific errno values. Just test ferror.
Jim Meyering <meyering@redhat.com>
parents:
9365
diff
changeset
|
29 /* Just like printf, but call error if it fails without setting |
dbb64cb4aed9
* lib/xprintf.c: Don't bother testing specific errno values. Just test ferror.
Jim Meyering <meyering@redhat.com>
parents:
9365
diff
changeset
|
30 the error indicator. */ |
9364 | 31 int |
32 xprintf (char const *restrict format, ...) | |
33 { | |
34 va_list args; | |
9398 | 35 int err; |
9364 | 36 va_start (args, format); |
9398 | 37 err = xvprintf (format, args); |
38 va_end (args); | |
39 | |
40 return err; | |
41 } | |
42 | |
43 /* Just like vprintf, but call error if it fails without setting | |
44 the error indicator. */ | |
45 int | |
46 xvprintf (char const *restrict format, va_list args) | |
47 { | |
9364 | 48 int err = vprintf (format, args); |
9366
dbb64cb4aed9
* lib/xprintf.c: Don't bother testing specific errno values. Just test ferror.
Jim Meyering <meyering@redhat.com>
parents:
9365
diff
changeset
|
49 if (err < 0 && ! ferror (stdout)) |
9372 | 50 error (exit_failure, errno, gettext ("cannot perform formatted output")); |
9364 | 51 |
52 return err; | |
53 } | |
54 | |
9366
dbb64cb4aed9
* lib/xprintf.c: Don't bother testing specific errno values. Just test ferror.
Jim Meyering <meyering@redhat.com>
parents:
9365
diff
changeset
|
55 /* Just like fprintf, but call error if it fails without setting |
dbb64cb4aed9
* lib/xprintf.c: Don't bother testing specific errno values. Just test ferror.
Jim Meyering <meyering@redhat.com>
parents:
9365
diff
changeset
|
56 the error indicator. */ |
9364 | 57 int |
58 xfprintf (FILE *restrict stream, char const *restrict format, ...) | |
59 { | |
60 va_list args; | |
9398 | 61 int err; |
9364 | 62 va_start (args, format); |
9398 | 63 err = xvfprintf (stream, format, args); |
9372 | 64 va_end (args); |
9364 | 65 |
66 return err; | |
67 } | |
9398 | 68 |
69 /* Just like vfprintf, but call error if it fails without setting | |
70 the error indicator. */ | |
71 int | |
72 xvfprintf (FILE *restrict stream, char const *restrict format, va_list args) | |
73 { | |
74 int err = vfprintf (stream, format, args); | |
75 if (err < 0 && ! ferror (stream)) | |
76 error (exit_failure, errno, gettext ("cannot perform formatted output")); | |
77 | |
78 return err; | |
79 } |