int xps_open_file(fz_context *ctx, xps_context **ctxp, char *filename) { char buf[2048]; fz_stream *file; char *p; int code; if (strstr(filename, "/_rels/.rels") || strstr(filename, "\\_rels\\.rels")) { fz_strlcpy(buf, filename, sizeof buf); p = strstr(buf, "/_rels/.rels"); if (!p) p = strstr(buf, "\\_rels\\.rels"); *p = 0; return xps_open_directory(ctx, ctxp, buf); } file = fz_open_file(ctx, filename); if (!file) return fz_error_make(ctx, "cannot open file '%s': %s", filename, strerror(errno)); code = xps_open_stream(ctxp, file); fz_close(file); if (code) return fz_error_note(ctx, code, "cannot load document '%s'", filename); return fz_okay; }
static void pdfapp_open_xps(pdfapp_t *app, char *filename, int fd) { fz_error error; fz_stream *file; file = fz_open_fd(fd); error = xps_open_stream(&app->xps, file); if (error) pdfapp_error(app, fz_rethrow(error, "cannot open document '%s'", filename)); fz_close(file); app->doctitle = filename; app->pagecount = xps_count_pages(app->xps); }