#include #include #include #include #include "printxf.h" int printxf_test(const char *fmt, ...) { va_list ap, xap; FILE *fp, *xfp; char *buf, *xbuf; size_t loc, xloc; int len, xlen; fp = open_memstream( &buf, &loc); xfp = open_memstream(&xbuf, &xloc); va_start(ap, fmt); va_copy(xap, ap); len = vfprintf ( fp, fmt, ap); xlen = vfprintxf(NULL, xfp, fmt, xap); va_end(xap); va_end( ap); fclose(xfp); fclose( fp); if ((xlen == len) && (xloc == loc) && !strcmp(xbuf, buf)) { free(xbuf); free( buf); return 0; } printf("FAIL len:%2d loc:%2zd buf:\"%s\"\n", len, loc, buf); printf(" xlen:%2d xloc:%2zd xbuf:\"%s\"\n", xlen, xloc, xbuf); return -1; } int main(void) { printxf_test("testing %% %.*s %d\n%", 3, "w000t", 13); }