xref: /illumos-gate/usr/src/lib/libc/port/stdio/scanf.c (revision 20a7641f9918de8574b8b3b47dbe35c4bfc78df1)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1988 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 #include "lint.h"
31 #include "file64.h"
32 #include "mtlib.h"
33 #include <stdio.h>
34 #include <stdarg.h>
35 #include <string.h>
36 #include <thread.h>
37 #include <synch.h>
38 #include "libc.h"
39 #include "stdiom.h"
40 #include "mse.h"
41 #include <stdio_ext.h>
42 
43 /*VARARGS1*/
44 int
45 scanf(const char *fmt, ...)
46 {
47 	int ret;
48 	va_list ap;
49 
50 	va_start(ap, fmt);
51 	ret = vscanf(fmt, ap);
52 	va_end(ap);
53 
54 	return (ret);
55 }
56 
57 /*VARARGS2*/
58 int
59 fscanf(FILE *iop, const char *fmt, ...)
60 {
61 	int ret;
62 	va_list ap;
63 
64 	va_start(ap, fmt);
65 	ret = vfscanf(iop, fmt, ap);
66 	va_end(ap);
67 
68 	return (ret);
69 }
70 
71 /*VARARGS2*/
72 int
73 sscanf(const char *str, const char *fmt, ...)
74 {
75 	int ret;
76 	va_list ap;
77 
78 	va_start(ap, fmt);
79 	ret = vsscanf(str, fmt, ap);
80 	va_end(ap);
81 
82 	return (ret);
83 }
84 
85 #ifndef _LP64
86 
87 /*
88  * 32-bit shadow functions _scanf_c89(), _fscanf_c89(), _sscanf_c89()
89  * included here.
90  * When using the c89 compiler to build 32-bit applications, the size
91  * of intmax_t is 32-bits, otherwise the size of intmax_t is 64-bits.
92  * The shadow function uses 32-bit size of intmax_t for %j conversion.
93  * The #pragma redefine_extname in <stdio.h> selects the proper routine
94  * at compile time for the user application.
95  * NOTE: the shadow function only exists in the 32-bit library.
96  */
97 
98 int
99 _scanf_c89(const char *fmt, ...)
100 {
101 	int ret;
102 	va_list ap;
103 
104 	va_start(ap, fmt);
105 	ret = _vscanf_c89(fmt, ap);
106 	va_end(ap);
107 
108 	return (ret);
109 }
110 
111 int
112 _fscanf_c89(FILE *iop, const char *fmt, ...)
113 {
114 	int ret;
115 	va_list ap;
116 
117 	va_start(ap, fmt);
118 	ret = _vfscanf_c89(iop, fmt, ap);
119 	va_end(ap);
120 
121 	return (ret);
122 }
123 
124 int
125 _sscanf_c89(const char *str, const char *fmt, ...)
126 {
127 	int ret;
128 	va_list ap;
129 
130 	va_start(ap, fmt);
131 	ret = _vsscanf_c89(str, fmt, ap);
132 	va_end(ap);
133 
134 	return (ret);
135 }
136 
137 #endif	/* _LP64 */
138