From 7f8f7c5b851f4e15cf95c6e819bff284b7fda7ca Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Tue, 15 Nov 2022 10:09:01 +0100 Subject: Add support of .svgz image files to fluid The prototype of the public Fl_SVG_Image constructor is expanded to allow construction from in-memory, gzip'ed binary data. --- src/drivers/Posix/Fl_Posix_System_Driver.H | 4 ++++ src/drivers/Posix/Fl_Posix_System_Driver.cxx | 29 +++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) (limited to 'src/drivers/Posix') diff --git a/src/drivers/Posix/Fl_Posix_System_Driver.H b/src/drivers/Posix/Fl_Posix_System_Driver.H index df9407c17..5712f6be2 100644 --- a/src/drivers/Posix/Fl_Posix_System_Driver.H +++ b/src/drivers/Posix/Fl_Posix_System_Driver.H @@ -82,6 +82,10 @@ public: virtual int dot_file_hidden() {return 1;} virtual void gettime(time_t *sec, int *usec); virtual char* strdup(const char *s) {return ::strdup(s);} + virtual int close_fd(int fd); + // next 2 for support of Fl_SVG_Image + virtual int write_nonblocking_fd(int , const unsigned char *&, size_t &); + virtual void pipe_support(int &, int &, const unsigned char *, size_t ); #if defined(HAVE_PTHREAD) virtual void lock_ring(); virtual void unlock_ring(); diff --git a/src/drivers/Posix/Fl_Posix_System_Driver.cxx b/src/drivers/Posix/Fl_Posix_System_Driver.cxx index dcf9e8f1a..ec43ea741 100644 --- a/src/drivers/Posix/Fl_Posix_System_Driver.cxx +++ b/src/drivers/Posix/Fl_Posix_System_Driver.cxx @@ -1,7 +1,7 @@ // // Definition of Posix system driver (used by the X11, Wayland and macOS platforms). // -// Copyright 1998-2021 by Bill Spitzak and others. +// Copyright 1998-2022 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -308,6 +308,33 @@ bool Fl_Posix_System_Driver::probe_for_GTK(int major, int minor, void **p_ptr_gt #endif // HAVE_DLSYM && HAVE_DLFCN_H +int Fl_Posix_System_Driver::close_fd(int fd) { return close(fd); } + +int Fl_Posix_System_Driver::write_nonblocking_fd(int fdwrite, const unsigned char *&bytes, size_t &rest_bytes) { + if (rest_bytes > 0) { + ssize_t nw = write(fdwrite, bytes, rest_bytes); + if (nw == -1) { + close(fdwrite); + return 1; // error + } + bytes += nw; + rest_bytes -= nw; + if (rest_bytes == 0) close(fdwrite); + } + return 0; // success +} + +void Fl_Posix_System_Driver::pipe_support(int &fdread, int &fdwrite, const unsigned char *unused, size_t unused_s) { + int fds[2]; + if (pipe(fds)) { // create anonymous pipe + Fl_System_Driver::pipe_support(fdread, fdwrite, NULL, 0); // indicates error + } else { + fdread = fds[0]; + fdwrite = fds[1]; + fcntl(fdwrite, F_SETFL, O_NONBLOCK); // make pipe's write end non-blocking + } +} + //////////////////////////////////////////////////////////////// // POSIX threading... #if defined(HAVE_PTHREAD) -- cgit v1.2.3