UNGETC(3P)
β¨ ungetc β bestie, we're putting that byte BACK β¨
okay so real quick before we dive in: this is a page from the POSIX Programmer's Manual π. Heads up tho β the Linux implementation of this interface may differ (so pls go check the corresponding Linux manual page for the deets on Linux behavior), or honestly the interface might not even be implemented on Linux at all. π iykyk.
πΈ PROLOG πΈ
- This manual page is part of the POSIX Programmer's Manual.
- The Linux implementation of this interface may differ β consult the corresponding Linux manual page for details of Linux behavior.
- Or the interface may not be implemented on Linux.
π NAME π
ungetc β push byte back into input stream
like. the un-reading. the giving-it-back. iconic behavior fr fr π
π SYNOPSIS π
#include <stdio.h>
int ungetc(int c, FILE *stream);
π¦ DESCRIPTION π¦
so the functionality described on this reference page is aligned with the ISO C standard. if there's any conflict between the requirements described here and the ISO C standard, that conflict is unintentional. This volume of POSIX.1β2017 defers to the ISO C standard. periodt. β¨
The ungetc() function shall push the byte specified by c (converted to an unsigned char) back onto the input stream pointed to by stream. π
The pushed-back bytes shall be returned by subsequent reads on that stream in the reverse order of their pushing. so like, last one in, first one out β a little stack moment, we love to see it.
A successful intervening call (with the stream pointed to by stream) to a file-positioning function β that's fseek(), fseeko(), fsetpos(), or rewind() β or fflush() shall discard any pushed-back bytes for the stream. ποΈ
The external storage corresponding to the stream shall be unchanged. no cap. we are NOT touching the actual file.
One byte of push-back shall be provided. so you get one (1). if ungetc() is called too many times on the same stream without an intervening read or file-positioning operation on that stream, the operation may fail. π so like, pace yourself bestie.
If the value of c equals that of the macro EOF, the operation shall fail and the input stream shall be left unchanged. π not the EOF jumpscare.
A successful call to ungetc() shall clear the end-of-file indicator for the stream. π
The value of the file-position indicator for the stream after all pushed-back bytes have been read, or discarded by calling fseek(), fseeko(), fsetpos(), or rewind() (but not fflush()), shall be the same as it was before the bytes were pushed back. β¨
The file-position indicator is decremented by each successful call to ungetc(); if its value was 0 before a call, its value is unspecified after the call. π« yeah. undefined-ish. be careful out there.
π RETURN VALUE π
Upon successful completion, ungetc() shall return the byte pushed back after conversion. otherwise? it shall return EOF. that's it that's the whole vibe check. π
π ERRORS π
No errors are defined. β¨ nothing to report, we're thriving.
The following sections are informative. π (so like, the tea is optional from here on out)
π EXAMPLES π
None. π¦
π§ APPLICATION USAGE π§
None. πΈ
π RATIONALE π
None. β¨
π₯ FUTURE DIRECTIONS π₯
None. π
β SEE ALSO β
- Section 2.5, Standard I/O Streams
fseek()getc()fsetpos()read()rewind()setbuf()
The Base Definitions volume of POSIX.1β2017, <stdio.h>
π COPYRIGHT π
okay legal bestie moment, gotta say it exactly:
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
π«Ά and that's the whole page!! mwah. go push a byte back, you absolute main character. π
IEEE/The Open Group πΈ 2017 πΈ UNGETC(3P) β ok that's the source, the version, and the date, signing off bestie, love u, bye!! π β¨π
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms