xref: /titanic_44/usr/src/lib/libc/port/stdio/scanf.c (revision 18c2aff776a775d34a4c9893a4c72e0434d68e36)
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 2004 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) 1988 AT&T	*/
30 /*	  All Rights Reserved  	*/
31 
32 
33 #include "synonyms.h"
34 #include "file64.h"
35 #include "mtlib.h"
36 #include <stdio.h>
37 #include <stdarg.h>
38 #include <string.h>
39 #include <thread.h>
40 #include <synch.h>
41 #include "libc.h"
42 #include "stdiom.h"
43 #include "mse.h"
44 #include <stdio_ext.h>
45 
46 /*VARARGS1*/
47 int
48 scanf(const char *fmt, ...)
49 {
50 	int ret;
51 	va_list ap;
52 
53 	va_start(ap, fmt);
54 	ret = vscanf(fmt, ap);
55 	va_end(ap);
56 
57 	return (ret);
58 }
59 
60 /*VARARGS2*/
61 int
62 fscanf(FILE *iop, const char *fmt, ...)
63 {
64 	int ret;
65 	va_list ap;
66 
67 	va_start(ap, fmt);
68 	ret = vfscanf(iop, fmt, ap);
69 	va_end(ap);
70 
71 	return (ret);
72 }
73 
74 /*VARARGS2*/
75 int
76 sscanf(const char *str, const char *fmt, ...)
77 {
78 	int ret;
79 	va_list ap;
80 
81 	va_start(ap, fmt);
82 	ret = vsscanf(str, fmt, ap);
83 	va_end(ap);
84 
85 	return (ret);
86 }
87 
88 #ifndef _LP64
89 
90 /*
91  * 32-bit shadow functions _scanf_c89(), _fscanf_c89(), _sscanf_c89()
92  * included here.
93  * When using the c89 compiler to build 32-bit applications, the size
94  * of intmax_t is 32-bits, otherwise the size of intmax_t is 64-bits.
95  * The shadow function uses 32-bit size of intmax_t for %j conversion.
96  * The #pragma redefine_extname in <stdio.h> selects the proper routine
97  * at compile time for the user application.
98  * NOTE: the shadow function only exists in the 32-bit library.
99  */
100 
101 int
102 _scanf_c89(const char *fmt, ...)
103 {
104 	int ret;
105 	va_list ap;
106 
107 	va_start(ap, fmt);
108 	ret = _vscanf_c89(fmt, ap);
109 	va_end(ap);
110 
111 	return (ret);
112 }
113 
114 int
115 _fscanf_c89(FILE *iop, const char *fmt, ...)
116 {
117 	int ret;
118 	va_list ap;
119 
120 	va_start(ap, fmt);
121 	ret = _vfscanf_c89(iop, fmt, ap);
122 	va_end(ap);
123 
124 	return (ret);
125 }
126 
127 int
128 _sscanf_c89(const char *str, const char *fmt, ...)
129 {
130 	int ret;
131 	va_list ap;
132 
133 	va_start(ap, fmt);
134 	ret = _vsscanf_c89(str, fmt, ap);
135 	va_end(ap);
136 
137 	return (ret);
138 }
139 
140 #endif	/* _LP64 */
141