Автор: karakurt2
Дата сообщения: 01.03.2011 17:52
AdVocem
[more=вот так ещё попробуйте]
Код:
[no]
static intptr_t
execGhostscript(int const inputPipeFd,
const char ghostscript_device[],
const char outfile_arg[],
int const xsize, int const ysize,
int const xres, int const yres,
const char input_filespec[], int const verbose) {
const char *arg0;
const char *ghostscriptProg;
const char *deviceopt;
const char *outfileopt;
const char *gopt;
const char *ropt;
int fdStdIn;
intptr_t pid;
int rc;
findGhostscriptProg(&ghostscriptProg);
setvbuf(stdin, NULL, _IONBF, 0);
fdStdIn = _dup(_fileno(stdin));
if (fdStdIn < 0) {
pm_error("failed to save the input pipe descriptor");
}
/* Put the input pipe on Standard Input */
rc = _dup2(inputPipeFd, _fileno(stdin));
if (rc != 0) {
pm_error("failed to put the input pipe on Standard Input");
}
_close(inputPipeFd);
asprintfN(&arg0, "gswin32c.exe");
asprintfN(&deviceopt, "-sDEVICE=%s", ghostscript_device);
asprintfN(&outfileopt, "-sOutputFile=%s", outfile_arg);
asprintfN(&gopt, "-g%dx%d", xsize, ysize);
asprintfN(&ropt, "-r%dx%d", xres, yres);
/* -dSAFER causes Postscript to disable %pipe and file operations,
which are almost certainly not needed here. This prevents our
Postscript program from doing crazy unexpected things, possibly
as a result of a malicious booby trapping of our Postscript file.
*/
if (verbose) {
pm_message("execing '%s' with args '%s' (arg 0), "
"'%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s'",
ghostscriptProg, arg0,
deviceopt, outfileopt, gopt, ropt, "-q", "-dNOPAUSE",
"-dSAFER", "-");
}
pid = _spawnl(_P_NOWAIT, ghostscriptProg, arg0, deviceopt, outfileopt, gopt, ropt, "-q",
"-dNOPAUSE", "-dSAFER", "-", NULL);
if (pid < 0) {
pm_error("execl() of Ghostscript ('%s') failed, errno=%d (%s)",
ghostscriptProg, errno, strerror(errno));
}
rc = _dup2(fdStdIn, _fileno(stdin));
if (rc != 0) {
pm_error("failed to restore input pipe descriptor");
}
_close (fdStdIn);
return pid;
}
[/no]