xref: /original-bsd/lib/libc/stdio/ungetc.3 (revision 05bf53f3)
1.\" Copyright (c) 1990, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Chris Torek and the American National Standards Committee X3,
6.\" on Information Processing Systems.
7.\"
8.\" %sccs.include.redist.man%
9.\"
10.\"     @(#)ungetc.3	8.1 (Berkeley) 06/04/93
11.\"
12.Dd
13.Dt UNGETC 3
14.Os
15.Sh NAME
16.Nm ungetc
17.Nd un-get character from input stream
18.Sh SYNOPSIS
19.Fd #include <stdio.h>
20.Ft int
21.Fn ungetc "int c" "FILE *stream"
22.Sh DESCRIPTION
23The
24.Fn ungetc
25function pushes the character
26.Fa c
27(converted to an unsigned char)
28back onto the input stream pointed to by
29.Fa stream .
30The pushed-backed characters will be returned by subsequent reads on the
31stream (in reverse order).
32A successful intervening call, using the same stream, to one of the file
33positioning functions
34.Po
35.Xr fseek 3 ,
36.Xr fsetpos 3 ,
37or
38.Xr rewind 3
39.Pc
40will discard the pushed back characters.
41.Pp
42One character of push-back is guaranteed,
43but as long as there is
44sufficient memory, an effectively infinite amount of pushback is allowed.
45.Pp
46If a character is successfully pushed-back,
47the end-of-file indicator for the stream is cleared.
48.Sh RETURN VALUES
49The
50.Fn ungetc
51function
52returns
53the character pushed-back after the conversion, or
54.Dv EOF
55if the operation fails.
56If the value of the argument
57.Fa c
58character equals
59.Dv EOF ,
60the operation will fail and the stream will remain unchanged.
61.Sh SEE ALSO
62.Xr getc 3 ,
63.Xr fseek 3 ,
64.Xr setvbuf 3
65.Sh STANDARDS
66The
67.Fn ungetc
68function conforms to
69.St -ansiC .
70