Mercurial > hg > octave-jordi > gnulib-hg
annotate lib/vdprintf.c @ 14379:2330aac2ae54
maint: adjust cpp indentation to reflect nesting depth
I.e., in a block of code that begins with an unnested "#if",
put one space between the "#" in column 1 and following token.
For example,
-#include <sys/vfs.h>
+# include <sys/vfs.h>
Do this only in .c files that are part of a module I maintain.
* lib/linkat.c: Filter through cppi.
* lib/nanosleep.c: Likewise.
* lib/openat.c: Likewise.
* lib/openat-die.c: Likewise.
* lib/dup3.c: Likewise.
* lib/fchownat.c: Likewise.
* lib/flock.c: Likewise.
* lib/fsync.c: Likewise.
* lib/fts.c: Likewise.
* lib/getpass.c: Likewise.
* lib/gettimeofday.c: Likewise.
* lib/userspec.c: Likewise.
* Makefile (sc_cpp_indent_check): New rule, to check this.
author | Jim Meyering <meyering@redhat.com> |
---|---|
date | Sun, 20 Feb 2011 23:02:43 +0100 |
parents | 97fc9a21a8fb |
children | 8250f2777afc |
rev | line source |
---|---|
11033
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Formatted output to a file descriptor. |
14079
97fc9a21a8fb
maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents:
12559
diff
changeset
|
2 Copyright (C) 2009-2011 Free Software Foundation, Inc. |
11033
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3 |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
7 (at your option) any later version. |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 #ifdef HAVE_CONFIG_H |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 # include <config.h> |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 #endif |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 /* Specification. */ |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 #include <stdio.h> |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 #include <errno.h> |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 #include <limits.h> |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
26 #include <stdarg.h> |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
27 #include <stdlib.h> |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
28 |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 #include "full-write.h" |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 #include "vasnprintf.h" |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
31 |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 int |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 vdprintf (int fd, const char *format, va_list args) |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 { |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 char buf[2000]; |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 char *output; |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
37 size_t len; |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
38 size_t lenbuf = sizeof (buf); |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 output = vasnprintf (buf, &lenbuf, format, args); |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
41 len = lenbuf; |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 if (!output) |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
44 return -1; |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
45 |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 if (full_write (fd, output, len) < len) |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
47 { |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 if (output != buf) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11033
diff
changeset
|
49 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11033
diff
changeset
|
50 int saved_errno = errno; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11033
diff
changeset
|
51 free (output); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11033
diff
changeset
|
52 errno = saved_errno; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11033
diff
changeset
|
53 } |
11033
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 return -1; |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 } |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 |
12449
eccd5d7c7a69
*printf: Fix memory leak.
Joel E. Denny <jdenny@clemson.edu>
parents:
12421
diff
changeset
|
57 if (output != buf) |
eccd5d7c7a69
*printf: Fix memory leak.
Joel E. Denny <jdenny@clemson.edu>
parents:
12421
diff
changeset
|
58 free (output); |
eccd5d7c7a69
*printf: Fix memory leak.
Joel E. Denny <jdenny@clemson.edu>
parents:
12421
diff
changeset
|
59 |
11033
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 if (len > INT_MAX) |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
61 { |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
62 errno = EOVERFLOW; |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
63 return -1; |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
64 } |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
65 |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
66 return len; |
049c445485ee
New modules 'vdprintf', 'vdprintf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
67 } |