]>
Commit | Line | Data |
---|---|---|
04277e02 | 1 | /* Copyright (C) 1993-2019 Free Software Foundation, Inc. |
41bdb6e2 | 2 | This file is part of the GNU C Library. |
d64b6ad0 | 3 | |
41bdb6e2 AJ |
4 | The GNU C Library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Lesser General Public | |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
d64b6ad0 | 8 | |
41bdb6e2 AJ |
9 | The GNU C Library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
d64b6ad0 | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
41bdb6e2 | 12 | Lesser General Public License for more details. |
d64b6ad0 | 13 | |
41bdb6e2 | 14 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
15 | License along with the GNU C Library; if not, see |
16 | <http://www.gnu.org/licenses/>. | |
d64b6ad0 | 17 | |
41bdb6e2 AJ |
18 | As a special exception, if you link the code in this file with |
19 | files compiled with a GNU compiler to produce an executable, | |
20 | that does not cause the resulting executable to be covered by | |
21 | the GNU Lesser General Public License. This exception does not | |
22 | however invalidate any other reasons why the executable file | |
23 | might be covered by the GNU Lesser General Public License. | |
24 | This exception applies to code released by its copyright holders | |
25 | in files containing the exception. */ | |
d64b6ad0 UD |
26 | |
27 | /* | |
aeb25823 AJ |
28 | Copyright (C) 1990 The Regents of the University of California. |
29 | All rights reserved. | |
9c84384c | 30 | |
aeb25823 AJ |
31 | Redistribution and use in source and binary forms, with or without |
32 | modification, are permitted provided that the following conditions | |
33 | are met: | |
34 | ||
35 | 1. Redistributions of source code must retain the above copyright | |
36 | notice, this list of conditions and the following disclaimer. | |
37 | 2. Redistributions in binary form must reproduce the above copyright | |
38 | notice, this list of conditions and the following disclaimer in the | |
39 | documentation and/or other materials provided with the distribution. | |
40 | 4. Neither the name of the University nor the names of its contributors | |
41 | may be used to endorse or promote products derived from this software | |
42 | without specific prior written permission. | |
9c84384c | 43 | |
aeb25823 AJ |
44 | THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
45 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
46 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
47 | ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
48 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
49 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
50 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
51 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
52 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
53 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
54 | SUCH DAMAGE.*/ | |
d64b6ad0 UD |
55 | |
56 | /* Modified for GNU iostream by Per Bothner 1991, 1992. */ | |
57 | ||
d64b6ad0 | 58 | #include "libioP.h" |
d64b6ad0 | 59 | #include <stdlib.h> |
d64b6ad0 | 60 | |
abc40bb2 | 61 | /* Allocate a file buffer, or switch to unbuffered I/O. */ |
d64b6ad0 | 62 | int |
9964a145 | 63 | _IO_wfile_doallocate (FILE *fp) |
d64b6ad0 | 64 | { |
9964a145 | 65 | size_t size; |
d64b6ad0 | 66 | wchar_t *p; |
d64b6ad0 UD |
67 | |
68 | /* Allocate room for the external buffer. */ | |
9c38a689 | 69 | if (fp->_IO_buf_base == NULL) |
d18ea0c5 | 70 | _IO_file_doallocate (fp); |
d64b6ad0 | 71 | |
1e88bd0f UD |
72 | /* If narrow buffer is user allocated (set by setvbuf etc.), |
73 | use that size as the size of the wide buffer, when it is | |
74 | allocated by _IO_file_doallocate, multiply that by size | |
75 | of the wide character. */ | |
76 | size = fp->_IO_buf_end - fp->_IO_buf_base; | |
77 | if ((fp->_flags & _IO_USER_BUF)) | |
78 | size = (size + sizeof (wchar_t) - 1) / sizeof (wchar_t); | |
8a29509d PP |
79 | p = malloc (size * sizeof (wchar_t)); |
80 | if (__glibc_unlikely (p == NULL)) | |
81 | return EOF; | |
d18ea0c5 | 82 | _IO_wsetb (fp, p, p + size, 1); |
d64b6ad0 UD |
83 | return 1; |
84 | } |