[Patch v2 3/7] util: convenience function to create gmime stream for stdout
David Bremner
david at tethera.net
Mon May 22 17:53:47 PDT 2017
It turns out that our use of GMimeStreamPipe has only succeeded
because gmime has been ignoring some seek failures; this will no
longer be the case in gmime 3.0, so we use a GMimeStreamPipe, which
does not assume seekability, wrapped in a buffering stream.
---
util/Makefile.local | 2 +-
util/gmime-extra.c | 20 ++++++++++++++++++++
util/gmime-extra.h | 6 ++++++
3 files changed, 27 insertions(+), 1 deletion(-)
create mode 100644 util/gmime-extra.c
create mode 100644 util/gmime-extra.h
diff --git a/util/Makefile.local b/util/Makefile.local
index a6962d49..3027880b 100644
--- a/util/Makefile.local
+++ b/util/Makefile.local
@@ -5,7 +5,7 @@ extra_cflags += -I$(srcdir)/$(dir)
libnotmuch_util_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c \
$(dir)/string-util.c $(dir)/talloc-extra.c $(dir)/zlib-extra.c \
- $(dir)/util.c
+ $(dir)/util.c $(dir)/gmime-extra.c
libnotmuch_util_modules := $(libnotmuch_util_c_srcs:.c=.o)
diff --git a/util/gmime-extra.c b/util/gmime-extra.c
new file mode 100644
index 00000000..f1538587
--- /dev/null
+++ b/util/gmime-extra.c
@@ -0,0 +1,20 @@
+#include "gmime-extra.h"
+
+GMimeStream *
+g_mime_stream_stdout_new()
+{
+ GMimeStream *stream_stdout = NULL;
+ GMimeStream *stream_buffered = NULL;
+
+ stream_stdout = g_mime_stream_pipe_new (STDOUT_FILENO);
+ if (!stream_stdout)
+ return NULL;
+
+ g_mime_stream_pipe_set_owner (GMIME_STREAM_PIPE (stream_stdout), FALSE);
+
+ stream_buffered = g_mime_stream_buffer_new (stream_stdout, GMIME_STREAM_BUFFER_BLOCK_WRITE);
+
+ g_object_unref (stream_stdout);
+
+ return stream_buffered;
+}
diff --git a/util/gmime-extra.h b/util/gmime-extra.h
new file mode 100644
index 00000000..e0432a94
--- /dev/null
+++ b/util/gmime-extra.h
@@ -0,0 +1,6 @@
+#ifndef _GMIME_EXTRA_H
+#define _GMIME_EXTRA_H
+#include <gmime/gmime.h>
+
+GMimeStream *g_mime_stream_stdout_new(void);
+#endif
--
2.11.0
More information about the notmuch
mailing list