summaryrefslogtreecommitdiffstats
path: root/src/io
diff options
context:
space:
mode:
authorRainer Keller <mail@rainerkeller.de>2018-08-29 18:01:34 +0000
committerEduard Braun <eduard.braun2@gmx.de>2018-09-15 13:05:12 +0000
commiteaae266840146a0faa3332f253ba7bd63eecbb21 (patch)
treea40f998ad6f46999a39cef05bb3c93f5dd965b7d /src/io
parentCI: Use separate caches for Linux/Mac build and disable for other jobs (diff)
downloadinkscape-eaae266840146a0faa3332f253ba7bd63eecbb21.tar.gz
inkscape-eaae266840146a0faa3332f253ba7bd63eecbb21.zip
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)
Diffstat (limited to 'src/io')
-rw-r--r--src/io/sys.cpp19
1 files changed, 19 insertions, 0 deletions
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)) {