OSDN Git Service

(split) Import translated manuals from JM CVS Repository.
[linuxjm/LDP_man-pages.git] / original / man3 / gets.3
1 .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\" License.
23 .\" Modified Wed Jul 28 11:12:07 1993 by Rik Faith (faith@cs.unc.edu)
24 .\" Modified Fri Sep  8 15:48:13 1995 by Andries Brouwer (aeb@cwi.nl)
25 .TH GETS 3  2008-08-06 "GNU" "Linux Programmer's Manual"
26 .SH NAME
27 fgetc, fgets, getc, getchar, gets, ungetc \- input of characters and strings
28 .SH SYNOPSIS
29 .nf
30 .B #include <stdio.h>
31 .sp
32 .BI "int fgetc(FILE *" stream );
33
34 .BI "char *fgets(char *" "s" ", int " "size" ", FILE *" "stream" );
35
36 .BI "int getc(FILE *" stream );
37
38 .B "int getchar(void);"
39
40 .BI "char *gets(char *" "s" );
41
42 .BI "int ungetc(int " c ", FILE *" stream );
43 .fi
44 .SH DESCRIPTION
45 .BR fgetc ()
46 reads the next character from
47 .I stream
48 and returns it as an
49 .I unsigned char
50 cast to an
51 .IR int ,
52 or
53 .B EOF
54 on end of file or error.
55 .PP
56 .BR getc ()
57 is equivalent to
58 .BR fgetc ()
59 except that it may be implemented as a macro which evaluates
60 .I stream
61 more than once.
62 .PP
63 .BR getchar ()
64 is equivalent to
65 .BI "getc(" stdin ) \fR.
66 .PP
67 .BR gets ()
68 reads a line from
69 .I stdin
70 into the buffer pointed to by
71 .I s
72 until either a terminating newline or
73 .BR EOF ,
74 which it replaces with
75 .BR \(aq\e0\(aq .
76 No check for buffer overrun is performed (see BUGS below).
77 .PP
78 .BR fgets ()
79 reads in at most one less than
80 .I size
81 characters from
82 .I stream
83 and stores them into the buffer pointed to by
84 .IR s .
85 Reading stops after an
86 .B EOF
87 or a newline.
88 If a newline is read, it is stored into the buffer.
89 A
90 .B \(aq\e0\(aq
91 is stored after the last character in the buffer.
92 .PP
93 .BR ungetc ()
94 pushes
95 .I c
96 back to
97 .IR stream ,
98 cast to
99 .IR "unsigned char" ,
100 where it is available for subsequent read operations.
101 Pushed-back characters
102 will be returned in reverse order; only one pushback is guaranteed.
103 .PP
104 Calls to the functions described here can be mixed with each other and with
105 calls to other input functions from the
106 .I stdio
107 library for the same input stream.
108 .PP
109 For nonlocking counterparts, see
110 .BR unlocked_stdio (3).
111 .SH "RETURN VALUE"
112 .BR fgetc (),
113 .BR getc ()
114 and
115 .BR getchar ()
116 return the character read as an
117 .I unsigned char
118 cast to an
119 .I int
120 or
121 .B EOF
122 on end of file or error.
123 .PP
124 .BR gets ()
125 and
126 .BR fgets ()
127 return
128 .I s
129 on success, and NULL
130 on error or when end of file occurs while no characters have been read.
131 .PP
132 .BR ungetc ()
133 returns
134 .I c
135 on success, or
136 .B EOF
137 on error.
138 .SH "CONFORMING TO"
139 C89, C99, POSIX.1-2001.
140 LSB deprecates
141 .BR gets ().
142 POSIX.1-2008 removes the specification of
143 .BR gets ().
144 .SH BUGS
145 Never use
146 .BR gets ().
147 Because it is impossible to tell without knowing the data in advance how many
148 characters
149 .BR gets ()
150 will read, and because
151 .BR gets ()
152 will continue to store characters past the end of the buffer,
153 it is extremely dangerous to use.
154 It has been used to break computer security.
155 Use
156 .BR fgets ()
157 instead.
158 .PP
159 It is not advisable to mix calls to input functions from the
160 .I stdio
161 library with low-level calls to
162 .BR read (2)
163 for the file descriptor associated with the input stream; the results
164 will be undefined and very probably not what you want.
165 .SH "SEE ALSO"
166 .BR read (2),
167 .BR write (2),
168 .BR ferror (3),
169 .BR fgetwc (3),
170 .BR fgetws (3),
171 .BR fopen (3),
172 .BR fread (3),
173 .BR fseek (3),
174 .BR getline (3),
175 .BR getwchar (3),
176 .BR puts (3),
177 .BR scanf (3),
178 .BR ungetwc (3),
179 .BR unlocked_stdio (3)