| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #include <stdarg.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #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);
- }
|