xref: /onnv-gate/usr/src/lib/libc/port/i18n/__fgetws_xpg5.c (revision 0:68f95e015346)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*	Copyright (c) 1986 AT&T	*/
30 /*	  All Rights Reserved  	*/
31 
32 
33 /*	This module is created for NLS on Sep.03.86		*/
34 
35 /*
36  * Fgetws reads multibyte characters from the "iop", converts
37  * them to process codes, and places them in the wchar_t
38  * array pointed to by "ptr". Fgetws reads until n-1 process
39  * codes are transferred to "ptr", or EOF.
40  */
41 
42 #include "lint.h"
43 #include "file64.h"
44 #include "mse_int.h"
45 #include <stdlib.h>
46 #include <stdio.h>
47 #include <widec.h>
48 #include <errno.h>
49 #include "mtlib.h"
50 #include "stdiom.h"
51 #include "libc.h"
52 #include "mse.h"
53 
54 wchar_t *
__fgetws_xpg5(wchar_t * ptr,int size,FILE * iop)55 __fgetws_xpg5(wchar_t *ptr, int size, FILE *iop)
56 {
57 	wchar_t	*ptr0 = ptr;
58 	int	c;
59 	void	*lc;
60 	wint_t	(*fp_fgetwc)(void *, FILE *);
61 	rmutex_t	*lk;
62 
63 	FLOCKFILE(lk, iop);
64 
65 	if (_set_orientation_wide(iop, &lc,
66 	    (void (*(*))(void))&fp_fgetwc, FP_FGETWC) == -1) {
67 		errno = EBADF;
68 		FUNLOCKFILE(lk);
69 		return (NULL);
70 	}
71 
72 	for (size--; size > 0; size--) {
73 		if ((c = fp_fgetwc(lc, iop)) == EOF) {
74 			if (ptr == ptr0) {
75 				FUNLOCKFILE(lk);
76 				return (NULL);
77 			}
78 			break;
79 		}
80 		*ptr++ = c;
81 		if (c == '\n')
82 			break;
83 	}
84 	*ptr = 0;
85 	FUNLOCKFILE(lk);
86 	return (ptr0);
87 }
88