UNGETWC(3POSIX)
π UNGETWC(3POSIX) β the POSIX Programmer's Manual glow-up π
okay bestie, quick vibe check before we dive in: this page is part of the POSIX Programmer's Manual, so heads up that the Linux implementation of this interface may differ from what's written here (if you're on Linux, go peek at the matching Linux man page for the real tea), or honestly the interface might not even be implemented on Linux at all. π
β¨ 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. no cap, always double-check which flavor of Unix you're standing on π
πΈ NAME πΈ
ungetwc β push wide-character code back into the input stream
it's giving "oops, put it back" energy and I'm obsessed π¦
π SYNOPSIS π
#include <stdio.h>
#include <wchar.h>
wint_t ungetwc(wint_t wc, FILE *stream);
π DESCRIPTION π
So the functionality described on this reference page is aligned with the ISO C standard. Any conflict between the requirements described here and the ISO C standard is unintentional β fr fr, not on purpose. This volume of POSIX.1β2017 defers to the ISO C standard. periodt.
The ungetwc() function shall push the character corresponding to the wide-character code specified by wc back onto the input stream pointed to by stream. Think of it like un-sending a text so you can read it again. β¨
The pushed-back characters shall be returned by subsequent reads on that stream in the reverse order of their pushing β yes bestie, it's a stack, last one in is first one out, iconic behavior.
A successful intervening call (with the stream pointed to by stream) to a file-positioning function (fseek(), fseeko(), fsetpos(), or rewind()) or fflush() shall discard any pushed-back characters for the stream. The external storage corresponding to the stream is unchanged β so nothing weird happens to your actual file, promise.
At least one character of push-back shall be provided. But if ungetwc() 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, don't spam it π«Ά
If the value ofwcequals that of the macroWEOF, the operation shall fail and the input stream shall be left unchanged. WEOF is the vibe-killer, not a character, do not pass it in.
A successful call to ungetwc() shall clear the end-of-file indicator for the stream. π
The value of the file-position indicator for the stream after all pushed-back characters have been read, or discarded by calling fseek(), fseeko(), fsetpos(), or rewind() (but not fflush()), shall be the same as it was before the characters were pushed back. The file-position indicator is decremented (by one or more) by each successful call to ungetwc(); if its value was 0 before a call, its value is unspecified after the call. π yeah, unspecified β that's undefined-adjacent territory, tread carefully.
π₯ RETURN VALUE π₯
Upon successful completion, ungetwc() shall return the wide-character code corresponding to the pushed-back character. Otherwise, it shall return WEOF. that's it, that's the whole deal π
π ERRORS π
The ungetwc() function may fail if:
EILSEQβ An invalid character sequence is detected, or a wide-character code does not correspond to a valid character. not me getting a character that simply isn't a character π
The following sections are informative. (translation: the real requirements are done, everything below is bonus lore β¨)
π§ EXAMPLES π§
None.
π APPLICATION USAGE π
None.
π RATIONALE π
None.
π FUTURE DIRECTIONS π
None.
π« SEE ALSO π«
- Section 2.5, Standard I/O Streams
fseek()fsetpos()read()rewind()setbuf()
The Base Definitions volume of POSIX.1β2017:
<stdio.h><wchar.h>
π COPYRIGHT π
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 bestie, we ate and left no crumbs π
IEEE/The Open Group β 2017 β UNGETWC(3POSIX) π stay hydrated, push your characters back responsibly, and remember: the file-position indicator doesn't care about your feelings. mwah π«Άβ¨
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms