Skip to content

Commit

Permalink
Switch from binary to text read for Windows PS (#7664)
Browse files Browse the repository at this point in the history
* Switch from binary to text read for Windows PS

When PSL_loadeps is called it opens the file in binary mode (which only applies to Windows) to read the binary 2-byte code,  and then later we read via gets which is a text mode operator.  This PR uses _setmode to switch to text mode on Windows before we read boundingbox via gets.

* Retarded first commit...
  • Loading branch information
PaulWessel authored Jul 22, 2023
1 parent 4187a07 commit 26ba611
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/postscriptlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@
#else
# define PRIuS "zu" /* printf size_t */
#endif
#if _WIN32
#include <fcntl.h> /* for _O_TEXT and _O_BINARY */
#endif

/* Define bswap32 */
#undef bswap32
Expand Down Expand Up @@ -6044,7 +6047,7 @@ int PSL_loadeps (struct PSL_CTRL *PSL, char *file, struct imageinfo *h, unsigned
unsigned char *buffer = NULL;
FILE *fp = NULL;

/* Open PostScript file */
/* Open PostScript file in binary mode; see below for reverting on Windows for gets reads */

if ((fp = fopen (file, "rb")) == NULL) {
PSL_message (PSL, PSL_MSG_ERROR, "Error: Cannot open image file %s!\n", file);
Expand All @@ -6070,6 +6073,14 @@ int PSL_loadeps (struct PSL_CTRL *PSL, char *file, struct imageinfo *h, unsigned

/* Scan for BoundingBox */

#ifdef _WIN32
/* Reset I/O to text mode since we are using gets in psl_get_boundingbox */
if ( _setmode(_fileno(stdin), _O_TEXT) == -1 ) {
PSL_message (PSL, PSL_MSG_WARNING, "Could not set text mode for %s.\n", file);
return 0;
}
#endif

psl_get_boundingbox (PSL, fp, &llx, &lly, &trx, &try, &h->llx, &h->lly, &h->trx, &h->try);

/* Fill header struct with appropriate values */
Expand Down

0 comments on commit 26ba611

Please sign in to comment.