mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [bug] Cannot fprintf/fwprintf numbers to a wmemstream
@ 2022-09-07 18:53 Knott, Isabelle
  2022-09-07 20:44 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Knott, Isabelle @ 2022-09-07 18:53 UTC (permalink / raw)
  To: musl

[AMD Official Use Only - General]

Hello, I have found that fprintf or fwprintf fails to write numbers to wmemstreams specifically, and also incorrectly reports how many characters were actually written:

Here is some sample code that reproduces the issue

    #include <stddef.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <wchar.h>

    int main() {
        wchar_t* buf;
        size_t buf_size;
        FILE* fd = open_wmemstream(&buf, &buf_size);
        if(fd == 0)
            return -1;
        //int chars_written = fprintf(fd, "%d", 40); // this also doesn't work
        int chars_written = fwprintf(fd, L"%d", 40);
        printf("chars_written: %d\n", chars_written);
        printf("buf_size: %ld\n", buf_size);
        fwprintf(stdout, L"expected: \"%d\"\n", 40);
        printf("actual: \"%ls\"\n", buf);
        return 0;

with musl-gcc compiles from 1.2.3:

    chars_written: 2
    buf_size: 0
    expected: "40"
    actual: ""

with glibc 2.35, using fprintf on the wmemstream fails, but fwprintf succeeds, though it won't write to stdout for some reason:

    chars_written: 2
    buf_size: 2
    actual: "40"


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-07 20:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-07 18:53 [musl] [bug] Cannot fprintf/fwprintf numbers to a wmemstream Knott, Isabelle
2022-09-07 20:44 ` Rich Felker

Code repositories for project(s) associated with this public inbox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).