From 55bbe8836df1bb8e521a6fb4e79a91d7e0702fb1 Mon Sep 17 00:00:00 2001 From: Chris Liddell Date: Wed, 24 Apr 2013 08:27:41 +0100 Subject: Bug 693932 (related): generate meaningful error Add a gp_fseekable() function, and use it to check the file object opened in gdev_prn_open_printer_seekable(). If the file is not seekable, print an error message and return an IOerror. No cluster differences. --- gs/base/gp.h | 2 ++ gs/base/gp_mswin.c | 15 +++++++++++++++ gs/base/gp_os2.c | 15 +++++++++++++++ gs/base/gp_unifs.c | 15 +++++++++++++++ gs/base/gp_vms.c | 15 +++++++++++++++ gs/devices/gdevtifs.c | 5 +++++ 6 files changed, 67 insertions(+) diff --git a/gs/base/gp.h b/gs/base/gp.h index b09092df0..e9cccdb98 100644 --- a/gs/base/gp.h +++ b/gs/base/gp.h @@ -489,6 +489,8 @@ int64_t gp_ftell_64(FILE *strm); int gp_fseek_64(FILE *strm, int64_t offset, int origin); +bool gp_fseekable (FILE *f); + /* We don't define gp_fread_64, gp_fwrite_64, because (1) known platforms allow regular fread, fwrite to be applied to a file opened with O_LARGEFILE, diff --git a/gs/base/gp_mswin.c b/gs/base/gp_mswin.c index 00d97c882..fdbf3380a 100644 --- a/gs/base/gp_mswin.c +++ b/gs/base/gp_mswin.c @@ -829,6 +829,21 @@ int gp_fseek_64(FILE *strm, gs_offset_t offset, int origin) #endif } +bool gp_fseekable (FILE *f) +{ + struct stat s; + int fno; + + fno = fileno(f); + if (fno < 0) + return(false); + + if (fstat(fno, &s) < 0) + return(false); + + return((bool)S_ISREG(s.st_mode)); +} + /* ------------------------- _snprintf -----------------------------*/ /* Microsoft Visual C++ 2005 doesn't properly define snprintf, diff --git a/gs/base/gp_os2.c b/gs/base/gp_os2.c index eabbdb9d0..5a7b98e3b 100644 --- a/gs/base/gp_os2.c +++ b/gs/base/gp_os2.c @@ -617,3 +617,18 @@ int gp_fseek_64(FILE *strm, int64_t offset, int origin) return -1; return fseek(strm, offset1, origin); } + +bool gp_fseekable (FILE *f) +{ + struct stat s; + int fno; + + fno = fileno(f); + if (fno < 0) + return(false); + + if (fstat(fno, &s) < 0) + return(false); + + return((bool)S_ISREG(s.st_mode)); +} diff --git a/gs/base/gp_unifs.c b/gs/base/gp_unifs.c index 340cb2f8b..eb13ae41c 100644 --- a/gs/base/gp_unifs.c +++ b/gs/base/gp_unifs.c @@ -544,3 +544,18 @@ int gp_fseek_64(FILE *strm, int64_t offset, int origin) return fseeko(strm, offset1, origin); #endif } + +bool gp_fseekable (FILE *f) +{ + struct stat s; + int fno; + + fno = fileno(f); + if (fno < 0) + return(false); + + if (fstat(fno, &s) < 0) + return(false); + + return((bool)S_ISREG(s.st_mode)); +} diff --git a/gs/base/gp_vms.c b/gs/base/gp_vms.c index fdb22a7fe..cc79f4370 100644 --- a/gs/base/gp_vms.c +++ b/gs/base/gp_vms.c @@ -712,3 +712,18 @@ int gp_fseek_64(FILE *strm, int64_t offset, int origin) return -1; return fseek(strm, offset1, origin); } + +bool gp_fseekable (FILE *f) +{ + struct stat s; + int fno; + + fno = fileno(f); + if (fno < 0) + return(false); + + if (fstat(fno, &s) < 0) + return(false); + + return((bool)S_ISREG(s.st_mode)); +} diff --git a/gs/devices/gdevtifs.c b/gs/devices/gdevtifs.c index d9d0bc8ae..9ccd9c4d9 100644 --- a/gs/devices/gdevtifs.c +++ b/gs/devices/gdevtifs.c @@ -60,6 +60,11 @@ tiff_output_page(gx_device *pdev, int num_copies, int flush) if (code < 0) return code; + if (!gp_fseekable(ppdev->file)) { + errprintf(pdev->memory, "I/O Error: Output File \"%s\" must be seekable\n", ppdev->fname); + return(gs_error_ioerror); + } + /* If copypage request, try to do it using buffer_page */ if ( !flush && (*ppdev->printer_procs.buffer_page) -- cgit v1.2.1