Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ putwc(3C) — HP-UX ANSI C A.09.00

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

fclose(3S)

ferror(3S)

fopen(3S)

getwc(3C)

fread(3S)

printf(3S)

fputws(3C)

setbuf(3S)

putwc(3C)

NAME

putwc(), putwchar(), fputwc() − put a wide character on a stream file

SYNOPSIS

#include <wchar.h>

wint_t putwc(wint_t wc, FILE *stream);

wint_t putwchar(wint_t wc);

wint_t fputwc(wint_t wc, FILE *stream);

Remarks:

These functions are compliant with the XPG4 Worldwide Portability Interface wide-character I/O functions.  They parallel the 8-bit character I/O functions defined in putc(3S).

DESCRIPTION

putwc() Writes the character corresponding to the wide character wc onto the output stream at the position where the file pointer is pointing.  putwchar(wc) is defined as putwc(wc, stdout).  putwc() and putwchar() are defined both as macros and as functions. 

fputwc() Behaves like putwc(), but is a function rather than a macro, and can therefore be used as an argument. 

Output streams, with the exception of the standard error stream stderr, are by default buffered if the output refers to a file and line-buffered if the output refers to a terminal.  The standard error output stream, stderr, is by default unbuffered, but use of freopen() (see fopen(3S)) causes it to become buffered or line-buffered. setbuf() or setvbuf() (see setbuf(3S)) can be used to change the stream’s buffering strategy.

Definitions for these functions, the type wint_t and the value WEOF are provided in the <wchar.h> header. 

EXTERNAL INFLUENCES

Locale

The LC_CTYPE category determines how wide character conversions are done. 

International Code Set Support

Single- and multi-byte character code sets are supported. 

RETURN VALUE

On success, putwc(), fputwc(), and putwchar() each return the wide character corresponding to the value they have written.  On failure, they return the constant WEOF, set the error indicator for the stream, and set errno to indicate the error. 

ERRORS

putwc(), putwchar(), and fputwc() fail if either the stream is unbuffered, or stream’s buffer needed to be flushed causing an underlying write() call to be invoked, and:

[EAGAIN] The O_NONBLOCK flag is set for the file descriptor underlying stream and the process would be delayed in the write operation. 

[EBADF] The file descriptor underlying stream is not a valid file descriptor open for writing. 

[EFBIG] An attempt was made to write to a file that exceeds the process’s file size limit or the maximum file size (see ulimit(2)).

[EINTR] A signal was caught during the write() system call. 

[EIO] The process is in a background process group and is attempting to write to its controlling terminal, TOSTOP is set, the process is neither ignoring nor blocking the SIGTTOU signal, and the process group of the process is orphaned. 

[ENOSPC] There was no free space remaining on the device containing the file. 

[EPIPE] An attempt is made to write to a pipe or FIFO that is not open for reading by any process.  A SIGPIPE signal is also sent to the process. 

[EILSEQ] The wide character wc does not correspond to a valid character. 

Additional errno values can be set by the underlying write() function (see write(2)). 

WARNINGS

putwc() and putwchar() are implemented both as library functions and as macros.  The macro versions, which are used by default, are defined in <wchar.h>.  To obtain the library function either use a #undef to remove the macro definition or, if compiling in ANSI -C mode, enclose the function name in parentheses or use the function address.  The following example illustrates each of these methods:

#include <wchar.h>
#undef putwc
...
main()
{
    wint_t (*put_wchar()) ();
...
    return_val=putwc(wc,fd);
...
    return_val=(putwc)(wc,fd1);
...
    put_wchar = putwchar;
};

Line buffering may cause confusion or malfunctioning of programs that use wide character I/O routines but use read() themselves to read from standard input.  When a large amount of computation is done after printing part of a line on an output terminal, it is necessary to fflush() (see fclose(3S)) the standard output before beginning the computation.

The macro version of putwc() incorrectly treats the argument stream with side effects.  In particular, the following call may not work as expected:

putwc(wc, *f++);

The function version of putwc() or fputwc() should be used instead. 

SEE ALSO

fclose(3S), ferror(3S), fopen(3S), getwc(3C), fread(3S), printf(3S), fputws(3C), setbuf(3S). 

STANDARDS CONFORMANCE

putwc(): XPG4

fputwc(): XPG4

putwchar(): XPG4

Hewlett-Packard Company  —  HP-UX Release 9.0: August 1992

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026