UNGETWC(3P)

๐Ÿ’– UNGETWC(3P) โ€” the POSIX Programmer's Manual glow-up ๐Ÿ’–

okay bestie, welcome to ungetwc(3P) from the POSIX Programmer's Manual. quick lil vibe check before we dive in:

๐Ÿซถ heads up! 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 even be implemented on Linux. so likeโ€ฆ check ur own system, mkay? ๐Ÿ’…

โœจ NAME โœจ

ungetwc โ€” push wide-character code back into the input stream ๐ŸŒ€

the way it just un-reads a characterโ€ฆ it's giving rewind energy, no cap.


๐ŸŒธ 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 โ€” it's not that deep. 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. ๐Ÿซฐ

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 whole LIFO situation, stack behavior, iconic.

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. ๐Ÿ—‘๏ธ poof, gone. the external storage corresponding to the stream is unchanged tho โ€” nothing actually got written anywhere.

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, bestie. it's not infinite.

if the value of wc equals that of the macro WEOF, the operation shall fail and the input stream shall be left unchanged. ๐Ÿ’€ no take-backs on that one, it just won't work.

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. so it's a full circle moment, we love to see it. ๐Ÿ”

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 โ€” we don't make the rules.


๐Ÿ‘‘ RETURN VALUE ๐Ÿ‘‘

upon successful completion, ungetwc() shall return the wide-character code corresponding to the pushed-back character. slay. โœจ

otherwise, it shall return WEOF. ๐Ÿ’”


๐Ÿ”ฅ 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. ๐Ÿšฉ

the following sections are informative. (translation: the tea below is extra, not requirements ๐Ÿ’…)


๐Ÿ’œ EXAMPLES ๐Ÿ’œ

None.

we got nothing for u here, bestie. literally none. ๐Ÿ™ˆ


๐ŸŒˆ APPLICATION USAGE ๐ŸŒˆ

None.

nope, also none. ๐Ÿ˜Œ


๐Ÿ“ RATIONALE ๐Ÿ“

None.

none again โ€” the reasoning is a mystery even to us. ๐Ÿงš


โญ FUTURE DIRECTIONS โญ

None.

crystal ball saysโ€ฆ nothing. ๐Ÿ”ฎ


๐ŸŽ€ SEE ALSO ๐ŸŽ€

  • Section 2.5, Standard I/O Streams
  • fseek()
  • fsetpos()
  • read()
  • rewind()
  • setbuf()

and from the Base Definitions volume of POSIX.1โ€2017:

  • <stdio.h>
  • <wchar.h>

go read those too, they're lowkey important for the full picture. ๐Ÿซถ


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!! ๐ŸŽ‰ this diva was brought to you by IEEE/The Open Group, 2017, under the name UNGETWC(3P). mwah ๐Ÿ’‹ thanks for reading, now go push some wide chars back fr fr ๐Ÿ’…โœจ

๐Ÿ“ฆ where this page comes from