|
Packit |
6c4009 |
/* Copyright (C) 1993-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
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 |
As a special exception, if you link the code in this file with
|
|
Packit |
6c4009 |
files compiled with a GNU compiler to produce an executable,
|
|
Packit |
6c4009 |
that does not cause the resulting executable to be covered by
|
|
Packit |
6c4009 |
the GNU Lesser General Public License. This exception does not
|
|
Packit |
6c4009 |
however invalidate any other reasons why the executable file
|
|
Packit |
6c4009 |
might be covered by the GNU Lesser General Public License.
|
|
Packit |
6c4009 |
This exception applies to code released by its copyright holders
|
|
Packit |
6c4009 |
in files containing the exception. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
Copyright (C) 1990 The Regents of the University of California.
|
|
Packit |
6c4009 |
All rights reserved.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
Redistribution and use in source and binary forms, with or without
|
|
Packit |
6c4009 |
modification, are permitted provided that the following conditions
|
|
Packit |
6c4009 |
are met:
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
1. Redistributions of source code must retain the above copyright
|
|
Packit |
6c4009 |
notice, this list of conditions and the following disclaimer.
|
|
Packit |
6c4009 |
2. Redistributions in binary form must reproduce the above copyright
|
|
Packit |
6c4009 |
notice, this list of conditions and the following disclaimer in the
|
|
Packit |
6c4009 |
documentation and/or other materials provided with the distribution.
|
|
Packit |
6c4009 |
4. Neither the name of the University nor the names of its contributors
|
|
Packit |
6c4009 |
may be used to endorse or promote products derived from this software
|
|
Packit |
6c4009 |
without specific prior written permission.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
Packit |
6c4009 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit |
6c4009 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
Packit |
6c4009 |
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
Packit |
6c4009 |
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
Packit |
6c4009 |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
Packit |
6c4009 |
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
Packit |
6c4009 |
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
Packit |
6c4009 |
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
Packit |
6c4009 |
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
Packit |
6c4009 |
SUCH DAMAGE.*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Modified for GNU iostream by Per Bothner 1991, 1992. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include "libioP.h"
|
|
Packit |
6c4009 |
#include <stdlib.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Allocate a file buffer, or switch to unbuffered I/O. */
|
|
Packit |
6c4009 |
int
|
|
Packit |
6c4009 |
_IO_wfile_doallocate (FILE *fp)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
size_t size;
|
|
Packit |
6c4009 |
wchar_t *p;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Allocate room for the external buffer. */
|
|
Packit |
6c4009 |
if (fp->_IO_buf_base == NULL)
|
|
Packit |
6c4009 |
_IO_file_doallocate (fp);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* If narrow buffer is user allocated (set by setvbuf etc.),
|
|
Packit |
6c4009 |
use that size as the size of the wide buffer, when it is
|
|
Packit |
6c4009 |
allocated by _IO_file_doallocate, multiply that by size
|
|
Packit |
6c4009 |
of the wide character. */
|
|
Packit |
6c4009 |
size = fp->_IO_buf_end - fp->_IO_buf_base;
|
|
Packit |
6c4009 |
if ((fp->_flags & _IO_USER_BUF))
|
|
Packit |
6c4009 |
size = (size + sizeof (wchar_t) - 1) / sizeof (wchar_t);
|
|
Packit |
6c4009 |
p = malloc (size * sizeof (wchar_t));
|
|
Packit |
6c4009 |
if (__glibc_unlikely (p == NULL))
|
|
Packit |
6c4009 |
return EOF;
|
|
Packit |
6c4009 |
_IO_wsetb (fp, p, p + size, 1);
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|