int intfstream_close(intfstream_internal_t *intf) { if (!intf) return -1; switch (intf->type) { case INTFSTREAM_FILE: if (intf->file.fp) return filestream_close(intf->file.fp); return 0; case INTFSTREAM_MEMORY: if (intf->memory.fp) memstream_close(intf->memory.fp); return 0; case INTFSTREAM_CHD: #ifdef HAVE_CHD if (intf->chd.fp) chdstream_close(intf->chd.fp); #endif return 0; } return -1; }
int delim_output(FILE *stream, int *need_delimp, int (*writer)(FILE *stream, void *data), void *data) { int o; /* If we don't need a delimiter, then we don't need to go * through a temporary stream. It's all the same whether * WRITER emits anything or not. */ if (!*need_delimp) { o = writer(stream, data); } else { struct memstream ms; if (memstream_init(&ms) < 0) return -1; o = writer(ms.stream, data); if (memstream_close(&ms) < 0) o = -1; if (o > 0 && ((*need_delimp && account_output(&o, fprintf(stream, ", ")) < 0) || fwrite(ms.buf, 1, ms.size, stream) != ms.size)) o = -1; memstream_destroy(&ms); } if (o < 0) return -1; *need_delimp = *need_delimp || o > 0; return o; }
int intfstream_close(intfstream_internal_t *intf) { if (!intf) return -1; switch (intf->type) { case INTFSTREAM_FILE: return filestream_close(intf->file.fp); case INTFSTREAM_MEMORY: memstream_close(intf->memory.fp); return 0; } return -1; }