1 /* Print output of stream to given obstack.
2 Copyright (C) 1996,1997,1999,2000,2001,2002,2003,2004,2005,2006,2008
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 #include "../libio/strfile.h"
31 #include <stdio_ext.h>
34 struct _IO_obstack_file
36 struct _IO_FILE_plus file
;
37 struct obstack
*obstack
;
40 extern const struct _IO_jump_t _IO_obstack_jumps attribute_hidden
;
43 __obstack_vprintf_chk (struct obstack
*obstack
, int flags
, const char *format
,
48 struct _IO_obstack_file ofile
;
55 new_f
.ofile
.file
.file
._lock
= NULL
;
58 _IO_no_init (&new_f
.ofile
.file
.file
, _IO_USER_LOCK
, -1, NULL
, NULL
);
59 _IO_JUMPS (&new_f
.ofile
.file
) = &_IO_obstack_jumps
;
60 room
= obstack_room (obstack
);
61 size
= obstack_object_size (obstack
) + room
;
64 /* We have to handle the allocation a bit different since the
65 `_IO_str_init_static' function would handle a size of zero
66 different from what we expect. */
68 /* Get more memory. */
69 obstack_make_room (obstack
, 64);
71 /* Recompute how much room we have. */
72 room
= obstack_room (obstack
);
78 _IO_str_init_static_internal ((struct _IO_strfile_
*) &new_f
.ofile
,
79 obstack_base (obstack
),
80 size
, obstack_next_free (obstack
));
81 /* Now allocate the rest of the current chunk. */
82 assert (size
== (new_f
.ofile
.file
.file
._IO_write_end
83 - new_f
.ofile
.file
.file
._IO_write_base
));
84 assert (new_f
.ofile
.file
.file
._IO_write_ptr
85 == (new_f
.ofile
.file
.file
._IO_write_base
86 + obstack_object_size (obstack
)));
87 obstack_blank_fast (obstack
, room
);
89 new_f
.ofile
.obstack
= obstack
;
91 /* For flags > 0 (i.e. __USE_FORTIFY_LEVEL > 1) request that %n
92 can only come from read-only format strings. */
94 new_f
.ofile
.file
.file
._flags2
|= _IO_FLAGS2_FORTIFY
;
96 result
= INTUSE(_IO_vfprintf
) (&new_f
.ofile
.file
.file
, format
, args
);
98 /* Shrink the buffer to the space we really currently need. */
99 obstack_blank_fast (obstack
, (new_f
.ofile
.file
.file
._IO_write_ptr
100 - new_f
.ofile
.file
.file
._IO_write_end
));
104 libc_hidden_def (__obstack_vprintf_chk
)
108 __obstack_printf_chk (struct obstack
*obstack
, int flags
, const char *format
,
113 va_start (ap
, format
);
114 result
= __obstack_vprintf_chk (obstack
, flags
, format
, ap
);