]> git.ipfire.org Git - thirdparty/glibc.git/blame - libio/wfiledoalloc.c
Use <> for include of kernel-features.h.
[thirdparty/glibc.git] / libio / wfiledoalloc.c
CommitLineData
c8a89e7d 1/* Copyright (C) 1993, 1997, 1999, 2000, 2002, 2006, 2012
1e88bd0f 2 Free Software Foundation, Inc.
41bdb6e2 3 This file is part of the GNU C Library.
d64b6ad0 4
41bdb6e2
AJ
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
d64b6ad0 9
41bdb6e2
AJ
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
d64b6ad0 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 13 Lesser General Public License for more details.
d64b6ad0 14
41bdb6e2
AJ
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA.
d64b6ad0 19
41bdb6e2
AJ
20 As a special exception, if you link the code in this file with
21 files compiled with a GNU compiler to produce an executable,
22 that does not cause the resulting executable to be covered by
23 the GNU Lesser General Public License. This exception does not
24 however invalidate any other reasons why the executable file
25 might be covered by the GNU Lesser General Public License.
26 This exception applies to code released by its copyright holders
27 in files containing the exception. */
d64b6ad0
UD
28
29/*
aeb25823
AJ
30 Copyright (C) 1990 The Regents of the University of California.
31 All rights reserved.
32
33 Redistribution and use in source and binary forms, with or without
34 modification, are permitted provided that the following conditions
35 are met:
36
37 1. Redistributions of source code must retain the above copyright
38 notice, this list of conditions and the following disclaimer.
39 2. Redistributions in binary form must reproduce the above copyright
40 notice, this list of conditions and the following disclaimer in the
41 documentation and/or other materials provided with the distribution.
42 4. Neither the name of the University nor the names of its contributors
43 may be used to endorse or promote products derived from this software
44 without specific prior written permission.
45
46 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 SUCH DAMAGE.*/
d64b6ad0
UD
57
58/* Modified for GNU iostream by Per Bothner 1991, 1992. */
59
60#ifndef _POSIX_SOURCE
61# define _POSIX_SOURCE
62#endif
63#include "libioP.h"
64#include <sys/types.h>
65#include <sys/stat.h>
d64b6ad0
UD
66#include <stdlib.h>
67#include <unistd.h>
d64b6ad0
UD
68
69#ifdef _LIBC
70# undef isatty
71# define isatty(Fd) __isatty (Fd)
72#endif
73
74/*
75 * Allocate a file buffer, or switch to unbuffered I/O.
76 * Per the ANSI C standard, ALL tty devices default to line buffered.
77 *
78 * As a side effect, we set __SOPT or __SNPT (en/dis-able fseek
79 * optimisation) right after the _fstat() that finds the buffer size.
80 */
81
82int
83_IO_wfile_doallocate (fp)
84 _IO_FILE *fp;
85{
86 _IO_size_t size;
d64b6ad0 87 wchar_t *p;
d64b6ad0
UD
88
89 /* Allocate room for the external buffer. */
9c38a689 90 if (fp->_IO_buf_base == NULL)
77fe0b9c 91 INTUSE(_IO_file_doallocate) (fp);
d64b6ad0 92
1e88bd0f
UD
93 /* If narrow buffer is user allocated (set by setvbuf etc.),
94 use that size as the size of the wide buffer, when it is
95 allocated by _IO_file_doallocate, multiply that by size
96 of the wide character. */
97 size = fp->_IO_buf_end - fp->_IO_buf_base;
98 if ((fp->_flags & _IO_USER_BUF))
99 size = (size + sizeof (wchar_t) - 1) / sizeof (wchar_t);
5bef2820 100 ALLOC_WBUF (p, size * sizeof (wchar_t), EOF);
77fe0b9c 101 INTUSE(_IO_wsetb) (fp, p, p + size, 1);
d64b6ad0
UD
102 return 1;
103}