Scroll to navigation

wprintf(3) Library Functions Manual wprintf(3)

NOME

wprintf, fwprintf, swprintf, vwprintf, vfwprintf, vswprintf - conversão de saída formatada de caracteres largos

BIBLIOTECA

Biblioteca C Padrão (libc, -lc)

SINOPSE

#include <stdio.h>
#include <wchar.h>
int wprintf(const wchar_t *restrict format, ...);
int fwprintf(FILE *restrict stream,
             const wchar_t *restrict format, ...);
int swprintf(wchar_t wcs[restrict .maxlen], size_t maxlen,
             const wchar_t *restrict format, ...);
int vwprintf(const wchar_t *restrict format, va_list args);
int vfwprintf(FILE *restrict stream,
             const wchar_t *restrict format, va_list args);
int vswprintf(wchar_t wcs[restrict .maxlen], size_t maxlen,
             const wchar_t *restrict format, va_list args);

Requisitos de macro de teste de recursos para o glibc (consulte feature_test_macros(7)):

Todas as funções mostradas acima:


_XOPEN_SOURCE >= 500 || _ISOC99_SOURCE
|| _POSIX_C_SOURCE >= 200112L

DESCRIÇÃO

A família de funções wprintf() é a equivalente para caracteres largos à família de funções printf(3). Ela realiza a saída formatada de caracteres largos.

As funções wprintf() e vwprintf() realizam saída de caracteres largos para stdout. stdout não deve ser orientado a byte; veja fwide(3) para maiores informações.

As funções fwprintf() e vfwprintf() realizam saída de caracteres largos para fluxo. fluxo não deve ser orientado a byte; veja fwide(3) para maiores informações.

As funções swprintf() e vswprintf() realizam saída de caracteres largos para um array de caracteres largos. O programador deve garantir que há espaço suficiente para no mínimo maxlen caracteres largos em wcs.

Estas funções são como as funções printf(3), vprintf(3), fprintf(3), vfprintf(3), sprintf(3), vsprintf(3) exceto pelas seguintes diferenças:

A formato é uma string de caracteres largos.
A saída consiste de caracteres largos, não bytes.
swprintf() e vswprintf() recebem um argumento maxcomp, sprintf(3) e vsprintf(3) não recebem. (snprintf(3) e vsnprintf(3) recebem um argumento maxcomp, mas estas funções não retornam -1 quando ocorre um estouro de buffer no GNU/Linux.)

O tratamento de caracteres de conversão c e s é diferente:

Se nenhum modificador l está presente, o argumento int é convertido para um caractere largo por uma chamada a para a função btowc(3), e o caractere largo resultante é escrito. Se um modificador l está presente, o argumento wint_t (caractere largo) é escrito.
If no l modifier is present: the const char * argument is expected to be a pointer to an array of character type (pointer to a string) containing a multibyte character sequence beginning in the initial shift state. Characters from the array are converted to wide characters (each by a call to the mbrtowc(3) function with a conversion state starting in the initial state before the first byte). The resulting wide characters are written up to (but not including) the terminating null wide character (L'\0'). If a precision is specified, no more wide characters than the number specified are written. Note that the precision determines the number of wide characters written, not the number of bytes or screen positions. The array must contain a terminating null byte ('\0'), unless a precision is given and it is so small that the number of converted wide characters reaches it before the end of the array is reached. If an l modifier is present: the const wchar_t * argument is expected to be a pointer to an array of wide characters. Wide characters from the array are written up to (but not including) a terminating null wide character. If a precision is specified, no more than the number specified are written. The array must contain a terminating null wide character, unless a precision is given and it is smaller than or equal to the number of wide characters in the array.

VALOR DE RETORNO

As funções retornam o número de caracteres largos escritos, excluindo-se o caractere largo nulo de terminação no caso das funções swprintf() e vswprintf(). Elas retornam -1 quando ocorre um erro.

ATRIBUTOS

Para uma explicação dos termos usados nesta seção, consulte attributes(7).

Interface Atributo Valor
wprintf(), fwprintf(), swprintf(), vwprintf(), vfwprintf(), vswprintf() Thread safety MT-Safe locale

PADRÕES

POSIX.1-2001, POSIX.1-2008, C99.

NOTAS

O comportamento de wprintf() etc. depende da categoria LC_CTYPE da localização atual.

Se a string formato contiver caracteres largos não-ASCII, o programa funcionará corretamente apenas se a categoria LC_CTYPE da localização atual em tempo de execução for a mesma que a categoria LC_CTYPE da localização atual em tempo de compilação. Isto é porque a representação wchar_t é dependente de plataforma e da localização. (A glibc representa caracteres largos usando seu ponto de código Unicode (ISO-10646), mas outras plataformas não o fazem. Ademais, o uso de nomes de caracteres universais C99 da forma \unnnn não resolve este problema.) Portanto, em programas internacionalizados, a string formato deve consistir apenas de caracteres largos ASCII, ou deve ser compilado em tempo de execução de forma internacionalizada (ou seja, usando gettext(3) ou iconv(3), seguido de mbstowcs(3)).

VEJA TAMBÉM

fprintf(3), fputwc(3), fwide(3), printf(3), snprintf(3)

TRADUÇÃO

A tradução para português brasileiro desta página man foi criada por Felipe M Pereira <Felipe.Pereira@ic.unicamp.br>, Ricardo C.O.Freitas <english.quest@best-service.com> e Rafael Fontenelle <rafaelff@gnome.org>.

Esta tradução é uma documentação livre; leia a Licença Pública Geral GNU Versão 3 ou posterior para as condições de direitos autorais. Nenhuma responsabilidade é aceita.

Se você encontrar algum erro na tradução desta página de manual, envie um e-mail para a lista de discussão de tradutores.

5 fevereiro 2023 Linux man-pages 6.03