From 402db78257ce506768ddad0c881c3780176ebb0e Mon Sep 17 00:00:00 2001 From: Luca Bacci Date: Tue, 4 Feb 2025 17:51:20 +0100 Subject: [PATCH] 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 --- boilerplate/cairo-boilerplate-pdf.c | 9 +++++++-- boilerplate/cairo-boilerplate-svg.c | 9 +++++++-- boilerplate/cairo-boilerplate.c | 9 +++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/boilerplate/cairo-boilerplate-pdf.c b/boilerplate/cairo-boilerplate-pdf.c index 4669040b9..1c3c2ad3e 100644 --- a/boilerplate/cairo-boilerplate-pdf.c +++ b/boilerplate/cairo-boilerplate-pdf.c @@ -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 diff --git a/boilerplate/cairo-boilerplate-svg.c b/boilerplate/cairo-boilerplate-svg.c index 0c9a3833e..9a6700f3a 100644 --- a/boilerplate/cairo-boilerplate-svg.c +++ b/boilerplate/cairo-boilerplate-svg.c @@ -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 diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c index 5f68216fd..d22407f9e 100644 --- a/boilerplate/cairo-boilerplate.c +++ b/boilerplate/cairo-boilerplate.c @@ -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)