Boilerplate: Adapt system / popen commands for Windows

Both system() and popen() invoke the command interpreter;
that's CMD.exe on Windows (or whatever is specified in the
COMSPEC environment variable).

The Windows API supports forward slashes in paths just fine,
but CMD doesn't (well, it does in very specific cases [1]).
Forward slashes are always parsed as start of switches / options.

[1] https://devblogs.microsoft.com/oldnewthing/20180605-00/?p=98915
This commit is contained in:
Luca Bacci 2025-02-04 17:51:20 +01:00
parent 3ad2e95025
commit 402db78257
3 changed files with 21 additions and 6 deletions

View file

@ -171,8 +171,13 @@ _cairo_boilerplate_pdf_surface_write_to_png (cairo_surface_t *surface,
char command[4096];
int exitstatus;
sprintf (command, "./pdf2png %s %s 1",
ptc->filename, filename);
sprintf (command,
#ifndef _WIN32
"./pdf2png %s %s 1",
#else
".\\pdf2png %s %s 1",
#endif
ptc->filename, filename);
exitstatus = system (command);
#if _XOPEN_SOURCE && HAVE_SIGNAL_H

View file

@ -186,8 +186,13 @@ _cairo_boilerplate_svg_surface_write_to_png (cairo_surface_t *surface,
char command[4096];
int exitstatus;
sprintf (command, "./svg2png %s %s",
ptc->filename, filename);
sprintf (command,
#ifndef _WIN32
"./svg2png %s %s",
#else
".\\svg2png %s %s",
#endif
ptc->filename, filename);
exitstatus = system (command);
#if _XOPEN_SOURCE && HAVE_SIGNAL_H

View file

@ -906,8 +906,13 @@ cairo_boilerplate_open_any2ppm (const char *filename,
#endif
any2ppm = getenv ("ANY2PPM");
if (any2ppm == NULL)
any2ppm = "./any2ppm";
if (any2ppm == NULL) {
#ifndef _WIN32
any2ppm = "./any2ppm";
#else
any2ppm = ".\\any2ppm";
#endif
}
#if HAS_DAEMON
if (flags & CAIRO_BOILERPLATE_OPEN_NO_DAEMON)