5 #include "pack_private.h"
7 extern void packf(const char *format, ...)
10 va_start(args, format);
11 vfpackf(stdout, format, args);
15 extern void spackf(void *buffer, const char *format, ...)
18 va_start(args, format);
19 vspackf(buffer, format, args);
23 extern void fpackf(FILE *file, const char *format, ...)
26 va_start(args, format);
27 vfpackf(file, format, args);
31 extern void vspackf(void *buffer, const char *format, va_list args)
33 struct BinIOFormatCursor cursor;
34 struct BinIOPackContext context;
36 BinIOInitFormatCursor(&cursor, format);
38 context.buffer = (unsigned char *)buffer;
39 va_copy(context.args, args);
41 while (BinIONextChar(&context, &cursor, BinIOPack)) {}
46 extern void vfpackf(FILE *file, const char *format, va_list args)
48 size_t n_bytes = BinIOFormatByteCount(format);
49 void* buffer = malloc(n_bytes);
51 vspackf(buffer, format, args);
53 fwrite(buffer, n_bytes, 1, file);