Use funopen
or fwopen
and supply your own write function that writes to multiple FILE*
s.
Example:
FILE *files[2] = ...;
FILE *f = fwopen((void *)files, my_writefn);
// ... use f as you like ...
int my_writefn(void *cookie, const char *data, int n) {
FILE **files = (FILE **)cookie;
fwrite(data, n, 1, files[0]);
return fwrite(data, n, 1, files[1]);
}
(Error handling omitted.)
Note that funopen
and fwopen
are BSD and not in standard Linux. I'm not aware if there's a Linux-compatible equivalent.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…