aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/ChangeLog4
-rw-r--r--common/estream.c33
-rw-r--r--common/estream.h4
3 files changed, 41 insertions, 0 deletions
diff --git a/common/ChangeLog b/common/ChangeLog
index 6c3c1f4d0..aa597f135 100644
--- a/common/ChangeLog
+++ b/common/ChangeLog
@@ -1,3 +1,7 @@
+2010-07-24 Werner Koch <[email protected]>
+
+ * estream.c (es_set_binary): New.
+
2010-07-19 Werner Koch <[email protected]>
* utf8conv.c (utf8_to_wchar): s/malloc/jnlib_malloc/.
diff --git a/common/estream.c b/common/estream.c
index 3ab68b5ff..fcc2850b8 100644
--- a/common/estream.c
+++ b/common/estream.c
@@ -3399,6 +3399,39 @@ es_setbuf (estream_t ES__RESTRICT stream, char *ES__RESTRICT buf)
ESTREAM_UNLOCK (stream);
}
+
+/* Put a stream into binary mode. This is only needed for the
+ standard streams if they are to be used in a binary way. On Unix
+ systems it is never needed but MSDOS based systems require such a
+ call. It needs to be called before any I/O is done on STREAM. */
+void
+es_set_binary (estream_t stream)
+{
+ ESTREAM_LOCK (stream);
+ if (!(stream->intern->modeflags & O_BINARY))
+ {
+ stream->intern->modeflags |= O_BINARY;
+#ifdef HAVE_DOSISH_SYSTEM
+ if (stream->intern->func_dest.func_read == es_func_fd_read)
+ {
+ estream_cookie_fd_t fd_cookie;
+
+ if (!IS_INVALID_FD (fd_cookie->fd))
+ setmode (fd, O_BINARY);
+ }
+ else if (stream->intern->func_dest.func_read == es_func_fp_read)
+ {
+ estream_cookie_fp_t fp_cookie;
+
+ if (fp_cookie->fd)
+ setmode (fileno (fp_cookie->fp), O_BINARY);
+ }
+#endif
+ }
+ ESTREAM_UNLOCK (stream);
+}
+
+
void
es_opaque_set (estream_t stream, void *opaque)
{
diff --git a/common/estream.h b/common/estream.h
index 6eb986fd6..8f45cce03 100644
--- a/common/estream.h
+++ b/common/estream.h
@@ -125,6 +125,7 @@
#define es_vfprintf_unlocked _ESTREAM_PREFIX(es_vfprint_unlocked)
#define es_setvbuf _ESTREAM_PREFIX(es_setvbuf)
#define es_setbuf _ESTREAM_PREFIX(es_setbuf)
+#define es_set_binary _ESTREAM_PREFIX(es_set_binary)
#define es_tmpfile _ESTREAM_PREFIX(es_tmpfile)
#define es_opaque_set _ESTREAM_PREFIX(es_opaque_set)
#define es_opaque_get _ESTREAM_PREFIX(es_opaque_get)
@@ -355,6 +356,9 @@ int es_setvbuf (estream_t ES__RESTRICT stream,
char *ES__RESTRICT buf, int mode, size_t size);
void es_setbuf (estream_t ES__RESTRICT stream, char *ES__RESTRICT buf);
+void es_set_binary (estream_t stream);
+
+
estream_t es_tmpfile (void);
void es_opaque_set (estream_t ES__RESTRICT stream, void *ES__RESTRICT opaque);