From eaae266840146a0faa3332f253ba7bd63eecbb21 Mon Sep 17 00:00:00 2001 From: Rainer Keller Date: Wed, 29 Aug 2018 20:01:34 +0200 Subject: Support reading and writing pipes This is useful when using inkscape from the terminal and piping the output to further programs. Example usage: cat vector.svg | inkscape --export-png - --file - | convert - out.jpg Fixes bug: 171016 (forward-ported from commit fdb3b41a37f5c37bbb8e49d59e7e6195d5363fcb) --- src/io/sys.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/io/sys.cpp') diff --git a/src/io/sys.cpp b/src/io/sys.cpp index 00f91137e..21ee94ed3 100644 --- a/src/io/sys.cpp +++ b/src/io/sys.cpp @@ -67,6 +67,21 @@ void Inkscape::IO::dump_fopen_call( char const *utf8name, char const *id ) FILE *Inkscape::IO::fopen_utf8name( char const *utf8name, char const *mode ) { FILE* fp = nullptr; + + if (Glib::ustring( utf8name ) == Glib::ustring("-")) { + // user requests to use pipes + + Glib::ustring how( mode ); + if ( how.find("w") != Glib::ustring::npos ) { +#ifdef WIN32 + setmode(fileno(stdout), O_BINARY) +#endif + return stdout; + } else { + return stdin; + } + } + gchar *filename = g_filename_from_utf8( utf8name, -1, nullptr, nullptr, nullptr ); if ( filename ) { @@ -110,6 +125,10 @@ bool Inkscape::IO::file_test( char const *utf8name, GFileTest test ) { bool exists = false; + // in case the file to check is a pipe it doesn't need to exist + if (g_strcmp0(utf8name, "-") == 0 && G_FILE_TEST_IS_REGULAR) + return true; + if ( utf8name ) { gchar *filename = nullptr; if (utf8name && !g_utf8_validate(utf8name, -1, nullptr)) { -- cgit v1.2.3