fwprintf return 什么时候是负数?
When does fwprintf return a negative number?
我在任何地方的文档中都找不到它,我只找到它 returns 发生错误时的负数。会是什么错误?
错误发生在如下所示的函数中:
void foo(wchar_t** a)
{
for (int i = 0; i < N; i++)
if (fwprintf(stderr, L"%ls ", a[i]) < 0)
puts("OOPS!");
fwprintf(stderr, L"\n");
}
此外,此错误仅在程序执行期间的某一时刻出现并停留在那里,就好像达到了某种限制。
根据fwprintf的定义:
Return Value
On success, the total number of characters written is returned.
If a writing error occurs, the error indicator (ferror) is set and a negative number is returned.
If a multibyte character encoding error occurs while writing wide characters, errno is set to EILSEQ and a negative number is returned.
所以它要么由于写入错误返回负数,要么由于多字节字符编码错误而返回。由于您使用的是宽字符双指针,因此很可能是后者,因此请检查 errno
以查看它是否设置为 EILSEQ
.
我相信,fwprintf()
are mostly the same with that of fputwc()
失败的原因。您可以随时查看 errno
了解错误的确切性质。
引用手册页,错误类型是,
[EAGAIN]
[EBADF]
[EFBIG]
[EFBIG]
[EINTR]
[EIO]
[ENOSPC]
[EPIPE]
[ENOMEM]
[ENXIO]
[EILSEQ]
[EINVAL]
我在任何地方的文档中都找不到它,我只找到它 returns 发生错误时的负数。会是什么错误?
错误发生在如下所示的函数中:
void foo(wchar_t** a)
{
for (int i = 0; i < N; i++)
if (fwprintf(stderr, L"%ls ", a[i]) < 0)
puts("OOPS!");
fwprintf(stderr, L"\n");
}
此外,此错误仅在程序执行期间的某一时刻出现并停留在那里,就好像达到了某种限制。
根据fwprintf的定义:
Return Value On success, the total number of characters written is returned.
If a writing error occurs, the error indicator (ferror) is set and a negative number is returned.
If a multibyte character encoding error occurs while writing wide characters, errno is set to EILSEQ and a negative number is returned.
所以它要么由于写入错误返回负数,要么由于多字节字符编码错误而返回。由于您使用的是宽字符双指针,因此很可能是后者,因此请检查 errno
以查看它是否设置为 EILSEQ
.
我相信,fwprintf()
are mostly the same with that of fputwc()
失败的原因。您可以随时查看 errno
了解错误的确切性质。
引用手册页,错误类型是,
[EAGAIN]
[EBADF]
[EFBIG]
[EFBIG]
[EINTR]
[EIO]
[ENOSPC]
[EPIPE]
[ENOMEM]
[ENXIO]
[EILSEQ]
[EINVAL]