]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/gets.3
Added SEE ALSO pointers to wide character equivalent functions
[thirdparty/man-pages.git] / 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 1993-04-04 "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 .nl
34 .BI "char *fgets(char *" "s" ", int " "size" ", FILE *" "stream" );
35 .nl
36 .BI "int getc(FILE *" stream );
37 .nl
38 .BI "int getchar(void);"
39 .nl
40 .BI "char *gets(char *" "s" );
41 .nl
42 .BI "int ungetc(int " c ", FILE *" stream );
43 .SH DESCRIPTION
44 .BR fgetc ()
45 reads the next character from
46 .I stream
47 and returns it as an
48 .I unsigned char
49 cast to an
50 .IR int ,
51 or
52 .B EOF
53 on end of file or error.
54 .PP
55 .BR getc ()
56 is equivalent to
57 .BR fgetc ()
58 except that it may be implemented as a macro which evaluates
59 .I stream
60 more than once.
61 .PP
62 .BR getchar ()
63 is equivalent to
64 .BI "getc(" stdin ) \fR.
65 .PP
66 .BR gets ()
67 reads a line from
68 .I stdin
69 into the buffer pointed to by
70 .I s
71 until either a terminating newline or
72 .BR EOF ,
73 which it replaces with
74 .BR '\e0' .
75 No check for buffer overrun is performed (see
76 .B BUGS
77 below).
78 .PP
79 .BR fgets ()
80 reads in at most one less than
81 .I size
82 characters from
83 .I stream
84 and stores them into the buffer pointed to by
85 .IR s .
86 Reading stops after an
87 .B EOF
88 or a newline. If a newline is read, it is stored into the buffer. A
89 .B '\e0'
90 is stored after the last character in the buffer.
91 .PP
92 .BR ungetc ()
93 pushes
94 .I c
95 back to
96 .IR stream ,
97 cast to
98 .IR "unsigned char" ,
99 where it is available for subsequent read operations. Pushed-back characters
100 will be returned in reverse order; only one pushback is guaranteed.
101 .PP
102 Calls to the functions described here can be mixed with each other and with
103 calls to other input functions from the
104 .B stdio
105 library for the same input stream.
106 .PP
107 For non-locking counterparts, see
108 .BR unlocked_stdio (3).
109 .SH "RETURN VALUE"
110 .BR fgetc (),
111 .BR getc ()
112 and
113 .BR getchar ()
114 return the character read as an
115 .I unsigned char
116 cast to an
117 .I int
118 or
119 .B EOF
120 on end of file or error.
121 .PP
122 .BR gets ()
123 and
124 .BR fgets ()
125 return
126 .I s
127 on success, and NULL
128 on error or when end of file occurs while no characters have been read.
129 .PP
130 .BR ungetc ()
131 returns
132 .I c
133 on success, or
134 .B EOF
135 on error.
136 .SH "CONFORMING TO"
137 ANSI-C, POSIX.1.
138 LSB deprecates
139 .BR gets ().
140 .SH BUGS
141 Never use
142 .BR gets ().
143 Because it is impossible to tell without knowing the data in advance how many
144 characters
145 .BR gets ()
146 will read, and because
147 .BR gets ()
148 will continue to store characters past the end of the buffer, it is extremely
149 dangerous to use. It has been used to break computer security. Use
150 .BR fgets ()
151 instead.
152 .PP
153 It is not advisable to mix calls to input functions from the
154 .B stdio
155 library with low-level calls to
156 .BR read ()
157 for the file descriptor associated with the input stream; the results
158 will be undefined and very probably not what you want.
159 .SH "SEE ALSO"
160 .BR read (2),
161 .BR write (2),
162 .BR ferror (3),
163 .BR fgetwc (3),
164 .BR fgets (3),
165 .BR fopen (3),
166 .BR fread (3),
167 .BR fseek (3),
168 .BR getwchar (3),
169 .BR puts (3),
170 .BR scanf (3),
171 .BR ungetwc (3),
172 .BR unlocked_stdio (3)