|
Packit |
6c4009 |
/* Print output of stream to given obstack.
|
|
Packit |
6c4009 |
Copyright (C) 1996-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <stdlib.h>
|
|
Packit |
6c4009 |
#include <libioP.h>
|
|
Packit |
6c4009 |
#include "../libio/strfile.h"
|
|
Packit |
6c4009 |
#include <assert.h>
|
|
Packit |
6c4009 |
#include <string.h>
|
|
Packit |
6c4009 |
#include <errno.h>
|
|
Packit |
6c4009 |
#include <obstack.h>
|
|
Packit |
6c4009 |
#include <stdarg.h>
|
|
Packit |
6c4009 |
#include <stdio_ext.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
struct _IO_obstack_file
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
struct _IO_FILE_plus file;
|
|
Packit |
6c4009 |
struct obstack *obstack;
|
|
Packit |
6c4009 |
};
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
extern const struct _IO_jump_t _IO_obstack_jumps libio_vtable attribute_hidden;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int
|
|
Packit |
6c4009 |
__obstack_vprintf_chk (struct obstack *obstack, int flags, const char *format,
|
|
Packit |
6c4009 |
va_list args)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
struct obstack_FILE
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
struct _IO_obstack_file ofile;
|
|
Packit |
6c4009 |
} new_f;
|
|
Packit |
6c4009 |
int result;
|
|
Packit |
6c4009 |
int size;
|
|
Packit |
6c4009 |
int room;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef _IO_MTSAFE_IO
|
|
Packit |
6c4009 |
new_f.ofile.file.file._lock = NULL;
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
_IO_no_init (&new_f.ofile.file.file, _IO_USER_LOCK, -1, NULL, NULL);
|
|
Packit |
6c4009 |
_IO_JUMPS (&new_f.ofile.file) = &_IO_obstack_jumps;
|
|
Packit |
6c4009 |
room = obstack_room (obstack);
|
|
Packit |
6c4009 |
size = obstack_object_size (obstack) + room;
|
|
Packit |
6c4009 |
if (size == 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* We have to handle the allocation a bit different since the
|
|
Packit |
6c4009 |
`_IO_str_init_static' function would handle a size of zero
|
|
Packit |
6c4009 |
different from what we expect. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Get more memory. */
|
|
Packit |
6c4009 |
obstack_make_room (obstack, 64);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Recompute how much room we have. */
|
|
Packit |
6c4009 |
room = obstack_room (obstack);
|
|
Packit |
6c4009 |
size = room;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
assert (size != 0);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
_IO_str_init_static_internal ((struct _IO_strfile_ *) &new_f.ofile,
|
|
Packit |
6c4009 |
obstack_base (obstack),
|
|
Packit |
6c4009 |
size, obstack_next_free (obstack));
|
|
Packit |
6c4009 |
/* Now allocate the rest of the current chunk. */
|
|
Packit |
6c4009 |
assert (size == (new_f.ofile.file.file._IO_write_end
|
|
Packit |
6c4009 |
- new_f.ofile.file.file._IO_write_base));
|
|
Packit |
6c4009 |
assert (new_f.ofile.file.file._IO_write_ptr
|
|
Packit |
6c4009 |
== (new_f.ofile.file.file._IO_write_base
|
|
Packit |
6c4009 |
+ obstack_object_size (obstack)));
|
|
Packit |
6c4009 |
obstack_blank_fast (obstack, room);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
new_f.ofile.obstack = obstack;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* For flags > 0 (i.e. __USE_FORTIFY_LEVEL > 1) request that %n
|
|
Packit |
6c4009 |
can only come from read-only format strings. */
|
|
Packit |
6c4009 |
if (flags > 0)
|
|
Packit |
6c4009 |
new_f.ofile.file.file._flags2 |= _IO_FLAGS2_FORTIFY;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
result = _IO_vfprintf (&new_f.ofile.file.file, format, args);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Shrink the buffer to the space we really currently need. */
|
|
Packit |
6c4009 |
obstack_blank_fast (obstack, (new_f.ofile.file.file._IO_write_ptr
|
|
Packit |
6c4009 |
- new_f.ofile.file.file._IO_write_end));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return result;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
libc_hidden_def (__obstack_vprintf_chk)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int
|
|
Packit |
6c4009 |
__obstack_printf_chk (struct obstack *obstack, int flags, const char *format,
|
|
Packit |
6c4009 |
...)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
int result;
|
|
Packit |
6c4009 |
va_list ap;
|
|
Packit |
6c4009 |
va_start (ap, format);
|
|
Packit |
6c4009 |
result = __obstack_vprintf_chk (obstack, flags, format, ap);
|
|
Packit |
6c4009 |
va_end (ap);
|
|
Packit |
6c4009 |
return result;
|
|
Packit |
6c4009 |
}
|