fgetwln.c (4ae83079a75ae7a3304c18afc190f437317c23ac) | fgetwln.c (d34d90a89d0d34657f1de602abb861bba1a571d8) |
---|---|
1/*- 2 * Copyright (c) 2002-2004 Tim J. Robbins. 3 * All rights reserved. 4 * 5 * Copyright (c) 2011 The FreeBSD Foundation 6 * All rights reserved. 7 * Portions of this software were developed by David Chisnall 8 * under sponsorship from the FreeBSD Foundation. --- 19 unchanged lines hidden (view full) --- 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32#include <sys/cdefs.h> 33__FBSDID("$FreeBSD$"); 34 35#include "namespace.h" | 1/*- 2 * Copyright (c) 2002-2004 Tim J. Robbins. 3 * All rights reserved. 4 * 5 * Copyright (c) 2011 The FreeBSD Foundation 6 * All rights reserved. 7 * Portions of this software were developed by David Chisnall 8 * under sponsorship from the FreeBSD Foundation. --- 19 unchanged lines hidden (view full) --- 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32#include <sys/cdefs.h> 33__FBSDID("$FreeBSD$"); 34 35#include "namespace.h" |
36#include <errno.h> | |
37#include <stdio.h> 38#include <wchar.h> 39#include "un-namespace.h" 40#include "libc_private.h" 41#include "local.h" 42#include "xlocale_private.h" 43 44wchar_t *fgetwln_l(FILE * __restrict, size_t *, locale_t); 45 46wchar_t * 47fgetwln_l(FILE * __restrict fp, size_t *lenp, locale_t locale) 48{ 49 wint_t wc; 50 size_t len; | 36#include <stdio.h> 37#include <wchar.h> 38#include "un-namespace.h" 39#include "libc_private.h" 40#include "local.h" 41#include "xlocale_private.h" 42 43wchar_t *fgetwln_l(FILE * __restrict, size_t *, locale_t); 44 45wchar_t * 46fgetwln_l(FILE * __restrict fp, size_t *lenp, locale_t locale) 47{ 48 wint_t wc; 49 size_t len; |
51 int saverrno; | |
52 FIX_LOCALE(locale); 53 54 FLOCKFILE(fp); 55 ORIENT(fp, 1); 56 57 len = 0; | 50 FIX_LOCALE(locale); 51 52 FLOCKFILE(fp); 53 ORIENT(fp, 1); 54 55 len = 0; |
58 saverrno = errno; 59 errno = 0; | 56 /* WEOF or error: return partial line, see fgetln(3). */ |
60 while ((wc = __fgetwc(fp, locale)) != WEOF) { 61#define GROW 512 62 if (len * sizeof(wchar_t) >= fp->_lb._size && | 57 while ((wc = __fgetwc(fp, locale)) != WEOF) { 58#define GROW 512 59 if (len * sizeof(wchar_t) >= fp->_lb._size && |
63 __slbexpand(fp, (len + GROW) * sizeof(wchar_t))) | 60 __slbexpand(fp, (len + GROW) * sizeof(wchar_t))) { 61 fp->_flags |= __SERR; |
64 goto error; | 62 goto error; |
63 } |
|
65 *((wchar_t *)fp->_lb._base + len++) = wc; 66 if (wc == L'\n') 67 break; | 64 *((wchar_t *)fp->_lb._base + len++) = wc; 65 if (wc == L'\n') 66 break; |
68 errno = 0; | |
69 } | 67 } |
70 if (wc == WEOF && errno != 0) 71 goto error; 72 if (errno == 0) 73 errno = saverrno; | |
74 if (len == 0) | 68 if (len == 0) |
75 goto eof; | 69 goto error; |
76 77 FUNLOCKFILE(fp); 78 *lenp = len; 79 return ((wchar_t *)fp->_lb._base); 80 81error: | 70 71 FUNLOCKFILE(fp); 72 *lenp = len; 73 return ((wchar_t *)fp->_lb._base); 74 75error: |
82 fp->_flags |= __SERR; 83eof: | |
84 FUNLOCKFILE(fp); 85 *lenp = 0; 86 return (NULL); 87} 88 89wchar_t * 90fgetwln(FILE * __restrict fp, size_t *lenp) 91{ 92 return fgetwln_l(fp, lenp, __get_locale()); 93} | 76 FUNLOCKFILE(fp); 77 *lenp = 0; 78 return (NULL); 79} 80 81wchar_t * 82fgetwln(FILE * __restrict fp, size_t *lenp) 83{ 84 return fgetwln_l(fp, lenp, __get_locale()); 85} |