Skip to content

Commit

Permalink
Fix PPD_emit*() functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpopelka committed Nov 5, 2013
1 parent 653cfbc commit 9730137
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
6 changes: 2 additions & 4 deletions cupsconnection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1288,10 +1288,9 @@ Connection_getDocument (Connection *self, PyObject *args)
snprintf(docfilename, sizeof (docfilename), "%s/jobdoc-XXXXXX", _PATH_TMP);
fd = mkstemp (docfilename);
if (fd < 0) {
PyErr_SetFromErrno (PyExc_RuntimeError);
debugprintf ("<- Connection_getDocument() EXCEPTION\n");
ippDelete (request);
return NULL;
return PyErr_SetFromErrno (PyExc_RuntimeError);
}

Connection_begin_allow_threads (self);
Expand Down Expand Up @@ -2345,15 +2344,14 @@ Connection_addPrinter (Connection *self, PyObject *args, PyObject *kwds)
ppdfile = strdup(template);
fd = mkstemp (ppdfile);
if (fd < 0) {
PyErr_SetFromErrno (PyExc_RuntimeError);
debugprintf ("<- Connection_addPrinter() EXCEPTION\n");
free (name);
free (ppdfile);
free (ppdname);
free (info);
free (location);
free (device);
return NULL;
return PyErr_SetFromErrno (PyExc_RuntimeError);
}

args = Py_BuildValue ("(i)", fd);
Expand Down
28 changes: 12 additions & 16 deletions cupsppd.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,12 +632,12 @@ PPD_emit (PPD *self, PyObject *args)

#if PY_MAJOR_VERSION >= 3
int fd = PyObject_AsFileDescriptor(pyFile);
f = fdopen(fd, "a+");
f = fdopen(fd, "w");
#else
f = PyFile_AsFile(pyFile);
#endif
if (!f)
return NULL;
return PyErr_SetFromErrno (PyExc_RuntimeError);

if (!ppdEmit(self->ppd, f, section))
Py_RETURN_NONE;
Expand All @@ -662,12 +662,12 @@ PPD_emitAfterOrder (PPD *self, PyObject *args)

#if PY_MAJOR_VERSION >= 3
int fd = PyObject_AsFileDescriptor(pyFile);
f = fdopen(fd, "a+");
f = fdopen(fd, "w");
#else
f = PyFile_AsFile(pyFile);
#endif
if (!f)
return NULL;
return PyErr_SetFromErrno (PyExc_RuntimeError);

if (!ppdEmitAfterOrder(self->ppd, f, section, limit, min_order))
Py_RETURN_NONE;
Expand Down Expand Up @@ -720,12 +720,12 @@ PPD_emitJCL (PPD *self, PyObject *args)

#if PY_MAJOR_VERSION >= 3
int fd = PyObject_AsFileDescriptor(pyFile);
f = fdopen(fd, "a+");
f = fdopen(fd, "w");
#else
f = PyFile_AsFile(pyFile);
#endif
if (!f)
return NULL;
return PyErr_SetFromErrno (PyExc_RuntimeError);

if (!ppdEmitJCL(self->ppd, f, job_id, user, title))
Py_RETURN_NONE;
Expand All @@ -750,12 +750,12 @@ PPD_emitJCLEnd (PPD *self, PyObject *args)

#if PY_MAJOR_VERSION >= 3
int fd = PyObject_AsFileDescriptor(pyFile);
f = fdopen(fd, "a+");
f = fdopen(fd, "w");
#else
f = PyFile_AsFile(pyFile);
#endif
if (!f)
return NULL;
return PyErr_SetFromErrno (PyExc_RuntimeError);

if (!ppdEmitJCLEnd(self->ppd, f))
Py_RETURN_NONE;
Expand All @@ -774,16 +774,12 @@ PPD_writeFd (PPD *self, PyObject *args)
return NULL;

dfd = dup (fd);
if (dfd == -1) {
PyErr_SetFromErrno (PyExc_RuntimeError);
return NULL;
}
if (dfd == -1)
return PyErr_SetFromErrno (PyExc_RuntimeError);

out = fdopen (dfd, "w");
if (!out) {
PyErr_SetFromErrno (PyExc_RuntimeError);
return NULL;
}
if (!out)
return PyErr_SetFromErrno (PyExc_RuntimeError);

rewind (self->file);
while (!feof (self->file)) {
Expand Down

0 comments on commit 9730137

Please sign in to comment.