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().
This commit is contained in:
parent
4231370205
commit
f0f88722b4
1 changed files with 12 additions and 7 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
For Tux Paint
|
For Tux Paint
|
||||||
PostScript(r) printing routine.
|
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)
|
(moved from tuxpaint.c in 0.9.17)
|
||||||
|
|
||||||
Copyright (c) 2009 by Bill Kendrick and others
|
Copyright (c) 2009 by Bill Kendrick and others
|
||||||
|
|
@ -51,6 +51,7 @@
|
||||||
#include <paper.h>
|
#include <paper.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
#ifndef PAPER_H
|
#ifndef PAPER_H
|
||||||
#error "---------------------------------------------------"
|
#error "---------------------------------------------------"
|
||||||
|
|
@ -296,13 +297,18 @@ int do_ps_save(FILE * fi,
|
||||||
pid_t child_pid, w;
|
pid_t child_pid, w;
|
||||||
int status;
|
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);
|
child_pid = pclose(fi);
|
||||||
|
|
||||||
/* debug */
|
#ifdef DEBUG
|
||||||
/*
|
|
||||||
printf("pclose returned %d\n", child_pid); fflush(stdout);
|
printf("pclose returned %d\n", child_pid); fflush(stdout);
|
||||||
printf("errno = %d\n", errno); fflush(stdout);
|
printf("errno = %d\n", errno); fflush(stdout);
|
||||||
*/
|
#endif
|
||||||
|
|
||||||
if (child_pid < 0 || (errno != 0 && errno != EAGAIN))
|
if (child_pid < 0 || (errno != 0 && errno != EAGAIN))
|
||||||
{ /* FIXME: This right? */
|
{ /* FIXME: This right? */
|
||||||
|
|
@ -317,8 +323,7 @@ int do_ps_save(FILE * fi,
|
||||||
{
|
{
|
||||||
w = waitpid(child_pid, &status, 0);
|
w = waitpid(child_pid, &status, 0);
|
||||||
|
|
||||||
/* debug */
|
#ifdef DEBUG
|
||||||
/*
|
|
||||||
if (w == -1) { perror("waitpid"); exit(EXIT_FAILURE); }
|
if (w == -1) { perror("waitpid"); exit(EXIT_FAILURE); }
|
||||||
if (WIFEXITED(status)) {
|
if (WIFEXITED(status)) {
|
||||||
printf("exited, status=%d\n", WEXITSTATUS(status));
|
printf("exited, status=%d\n", WEXITSTATUS(status));
|
||||||
|
|
@ -329,7 +334,7 @@ int do_ps_save(FILE * fi,
|
||||||
} else if (WIFCONTINUED(status)) {
|
} else if (WIFCONTINUED(status)) {
|
||||||
printf("continued\n");
|
printf("continued\n");
|
||||||
}
|
}
|
||||||
*/
|
#endif
|
||||||
}
|
}
|
||||||
while (w != -1 && !WIFEXITED(status) && !WIFSIGNALED(status));
|
while (w != -1 && !WIFEXITED(status) && !WIFSIGNALED(status));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue