From f0f88722b48ee8cf418f31217c2bff78c10e083b Mon Sep 17 00:00:00 2001 From: "Mark K. Kim" Date: Thu, 9 Aug 2018 07:27:00 -0400 Subject: [PATCH] Fix macOS printing error message issue. Previously Tux Paint was raising an error informing the user it could not print even when it did print successfully. This appears to be due to our lpr printing routine's assumption that errno is reset on success whereas the C library in macOS does not appear to do so. To address this issue, errno is reset before calling pclose() (on macOS and macOS only - just in case this code has an unintended side-effect on other platforms). This code change assumes we're only interested in errno set by pclose(), and that our lpr printing routine is not interested in errno raised prior to pclose(). --- src/postscript_print.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/postscript_print.c b/src/postscript_print.c index 39d3f441c..e54594364 100644 --- a/src/postscript_print.c +++ b/src/postscript_print.c @@ -3,7 +3,7 @@ For Tux Paint PostScript(r) printing routine. - (for non-Windows, non-Mac OS X, non-BeOS platforms, e.g. Linux) + (for non-Windows, non-BeOS platforms, e.g. Linux and macOS) (moved from tuxpaint.c in 0.9.17) Copyright (c) 2009 by Bill Kendrick and others @@ -51,6 +51,7 @@ #include #include #include +#include "debug.h" #ifndef PAPER_H #error "---------------------------------------------------" @@ -296,13 +297,18 @@ int do_ps_save(FILE * fi, pid_t child_pid, w; int status; +#ifdef __APPLE__ + /* macOS does not always reset errno so Tux Paint thinks print never + * succeeds - let's reset before calling pclose() on macOS */ + errno = 0; +#endif + child_pid = pclose(fi); -/* debug */ -/* +#ifdef DEBUG printf("pclose returned %d\n", child_pid); fflush(stdout); printf("errno = %d\n", errno); fflush(stdout); -*/ +#endif if (child_pid < 0 || (errno != 0 && errno != EAGAIN)) { /* FIXME: This right? */ @@ -317,8 +323,7 @@ int do_ps_save(FILE * fi, { w = waitpid(child_pid, &status, 0); -/* debug */ -/* +#ifdef DEBUG if (w == -1) { perror("waitpid"); exit(EXIT_FAILURE); } if (WIFEXITED(status)) { printf("exited, status=%d\n", WEXITSTATUS(status)); @@ -329,7 +334,7 @@ int do_ps_save(FILE * fi, } else if (WIFCONTINUED(status)) { printf("continued\n"); } -*/ +#endif } while (w != -1 && !WIFEXITED(status) && !WIFSIGNALED(status));