int main(int argc, char** argv) { FILE* fp; if (argc > 1) { if (argv[1][0] == '-' && argv[1][1] == '-') { fp = stdin; } else { fp = fopen(argv[1], "rb"); } } else { print_help(); return 0; } ubjr_context_t* rctx = ubjr_open_file(fp); ubjr_dynamic_t dyn = ubjr_read_dynamic(rctx); ubjw_context_t* wctx = ubjw_open_file(stdout); ubjrw_write_dynamic(wctx, dyn, 1); return 0; }
bool write_file(size_t object_size, bool sized) { char filename[64]; benchmark_filename(filename, sizeof(filename), object_size, BENCHMARK_FORMAT_UBJSON, sized ? NULL : "-unopt"); FILE* file = fopen(filename, "wb"); if (!file) { fprintf(stderr, "error opening file for writing!\n"); return false; } // ubjw_open_file() doesn't register any error handler, and // does not check the return value of calls to fwrite() either. // it doesn't seem to have any way of handling i/o errors at all, // such as disk full errors or broken pipes. this seems like // a serious flaw; there's no way to tell if the data was // truncated. ubjw_context_t* dst = ubjw_open_file(file); object_t* object = benchmark_object_create(object_size); bool ok = write_object(dst, object, sized); object_destroy(object); ubjw_close_context(dst); return ok; }