1132242Stjr/*- 2132242Stjr * Copyright (c) 2002-2004 Tim J. Robbins. 3132242Stjr * All rights reserved. 4132242Stjr * 5227753Stheraven * Copyright (c) 2011 The FreeBSD Foundation 6227753Stheraven * All rights reserved. 7227753Stheraven * Portions of this software were developed by David Chisnall 8227753Stheraven * under sponsorship from the FreeBSD Foundation. 9227753Stheraven * 10132242Stjr * Redistribution and use in source and binary forms, with or without 11132242Stjr * modification, are permitted provided that the following conditions 12132242Stjr * are met: 13132242Stjr * 1. Redistributions of source code must retain the above copyright 14132242Stjr * notice, this list of conditions and the following disclaimer. 15132242Stjr * 2. Redistributions in binary form must reproduce the above copyright 16132242Stjr * notice, this list of conditions and the following disclaimer in the 17132242Stjr * documentation and/or other materials provided with the distribution. 18132242Stjr * 19132242Stjr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20132242Stjr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21132242Stjr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22132242Stjr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23132242Stjr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24132242Stjr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25132242Stjr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26132242Stjr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27132242Stjr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28132242Stjr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29132242Stjr * SUCH DAMAGE. 30132242Stjr */ 31132242Stjr 32132242Stjr#include <sys/cdefs.h> 33132242Stjr__FBSDID("$FreeBSD: releng/11.0/lib/libc/stdio/fgetwln.c 288032 2015-09-20 20:27:57Z rodrigc $"); 34132242Stjr 35132242Stjr#include "namespace.h" 36132242Stjr#include <stdio.h> 37132242Stjr#include <wchar.h> 38132242Stjr#include "un-namespace.h" 39132242Stjr#include "libc_private.h" 40132242Stjr#include "local.h" 41227753Stheraven#include "xlocale_private.h" 42132242Stjr 43288032Srodrigcwchar_t *fgetwln_l(FILE * __restrict, size_t *, locale_t); 44288006Srodrigc 45132242Stjrwchar_t * 46227753Stheravenfgetwln_l(FILE * __restrict fp, size_t *lenp, locale_t locale) 47132242Stjr{ 48132242Stjr wint_t wc; 49132242Stjr size_t len; 50227753Stheraven FIX_LOCALE(locale); 51132242Stjr 52132242Stjr FLOCKFILE(fp); 53132242Stjr ORIENT(fp, 1); 54132242Stjr 55132242Stjr len = 0; 56227753Stheraven while ((wc = __fgetwc(fp, locale)) != WEOF) { 57132242Stjr#define GROW 512 58132242Stjr if (len * sizeof(wchar_t) >= fp->_lb._size && 59132242Stjr __slbexpand(fp, (len + GROW) * sizeof(wchar_t))) 60132242Stjr goto error; 61133223Stjr *((wchar_t *)fp->_lb._base + len++) = wc; 62132242Stjr if (wc == L'\n') 63132242Stjr break; 64132242Stjr } 65132242Stjr if (len == 0) 66132242Stjr goto error; 67132242Stjr 68132242Stjr FUNLOCKFILE(fp); 69132242Stjr *lenp = len; 70132242Stjr return ((wchar_t *)fp->_lb._base); 71132242Stjr 72132242Stjrerror: 73132242Stjr FUNLOCKFILE(fp); 74132242Stjr *lenp = 0; 75132242Stjr return (NULL); 76132242Stjr} 77227753Stheravenwchar_t * 78227753Stheravenfgetwln(FILE * __restrict fp, size_t *lenp) 79227753Stheraven{ 80227753Stheraven return fgetwln_l(fp, lenp, __get_locale()); 81227753Stheraven} 82