diff options
author | Robin Watts <robin.watts@artifex.com> | 2016-03-16 13:44:47 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2016-03-16 15:39:53 +0000 |
commit | 5e0ac437e4b18f3216374242e307d4a2b70e25b4 (patch) | |
tree | f92da7465790cf9122f1fd446ffa50ec23c80a04 /source | |
parent | eb46bd17a6e99b8069b0c2a63382151fad091f26 (diff) | |
download | mupdf-5e0ac437e4b18f3216374242e307d4a2b70e25b4.tar.xz |
Spot when we are fz_outputting to /dev/null or nul:
Diffstat (limited to 'source')
-rw-r--r-- | source/fitz/output.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/source/fitz/output.c b/source/fitz/output.c index ed6e89a3..1904ee85 100644 --- a/source/fitz/output.c +++ b/source/fitz/output.c @@ -62,12 +62,45 @@ fz_new_output_with_file_ptr(fz_context *ctx, FILE *file, int close) return out; } +static void +null_write(fz_context *ctx, void *opaque, const void *buffer, int count) +{ + return; +} + +static void +null_seek(fz_context *ctx, void *opaque, fz_off_t off, int whence) +{ +} + +static fz_off_t +null_tell(fz_context *ctx, void *opaque) +{ + return 0; +} + +static fz_output * +null_filename(fz_context *ctx) +{ + fz_output *out = fz_malloc_struct(ctx, fz_output); + out->opaque = NULL; + out->write = null_write; + out->seek = null_seek; + out->tell = null_tell; + out->close = NULL; + return out; +} + fz_output * fz_new_output_with_path(fz_context *ctx, const char *filename, int append) { fz_output *out = NULL; + FILE *file; + + if (!strcmp(filename, "/dev/null") || !fz_strcasecmp(filename, "nul:")) + return null_filename(ctx); - FILE *file = fz_fopen(filename, append ? "ab" : "wb"); + file = fz_fopen(filename, append ? "ab" : "wb"); if (!file) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); |