3 ms·
"Print-is-append" is something that I had done, in both ways, because it does make sense obviously. In C, you can use open_memstream to make a variable size buf
by zzo38computer 4y ago
"Print-is-append" is something that I had done, in both ways, because it does make sense obviously. In C, you can use open_memstream to make a variable size buffer to append to, similarly than they have there, and you can use any of the existing functions such as fwrite, fputc, fprintf, etc to write to it. If you want to do your own things with it instead of a buffer accumulation, you can use fopencookie. You do not need to do what is shown in that linked document because C already has such a thing; you can use the FILE object for many kind of streams, both built-in and custom streams. (However, custom streams is a GNU feature, so is not standard C, but it is useful sometimes.)
(I made a library to compute cryptographic hashes, which does use fopencookie and allows to specify a "echo stream", which if specified also copies the data to another stream too. This way, you can write data to a file or other stream and also compute the hash at the same time, without needing to store it in memory.)