Commit c382e9d0 c382e9d0b7b893cb5eb7d6a91bdbd21c1987f934 by Sergey Poznyakoff

Stream improvements.

* include/mailutils/stream.h (mu_stream_printf): Mark as printf-like.
* include/mailutils/sys/stream.h (_MU_STR_EVENT_CLOSE): New event.
(_mu_stream) <event_cb_data>: New member.
* libmailutils/stream.c (mu_stream_seek): Avoid unnecessary seeks
in mu_buffer_none mode.  Complements 906499db.
(mu_stream_close): Mark _MU_STR_EVENT_CLOSE event.
1 parent 30a7e0be
...@@ -140,7 +140,8 @@ int mu_stream_set_flags (mu_stream_t stream, int fl); ...@@ -140,7 +140,8 @@ int mu_stream_set_flags (mu_stream_t stream, int fl);
140 int mu_stream_clr_flags (mu_stream_t stream, int fl); 140 int mu_stream_clr_flags (mu_stream_t stream, int fl);
141 141
142 int mu_stream_vprintf (mu_stream_t str, const char *fmt, va_list ap); 142 int mu_stream_vprintf (mu_stream_t str, const char *fmt, va_list ap);
143 int mu_stream_printf (mu_stream_t stream, const char *fmt, ...); 143 int mu_stream_printf (mu_stream_t stream, const char *fmt, ...)
144 MU_PRINTFLIKE(2,3);
144 145
145 int mu_stream_copy (mu_stream_t dst, mu_stream_t src, mu_off_t size, 146 int mu_stream_copy (mu_stream_t dst, mu_stream_t src, mu_off_t size,
146 mu_off_t *pcsz); 147 mu_off_t *pcsz);
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
28 #define _MU_STR_EVENT_CLRFLAG 1 28 #define _MU_STR_EVENT_CLRFLAG 1
29 #define _MU_STR_EVENT_FILLBUF 2 29 #define _MU_STR_EVENT_FILLBUF 2
30 #define _MU_STR_EVENT_FLUSHBUF 3 30 #define _MU_STR_EVENT_FLUSHBUF 3
31 #define _MU_STR_EVENT_CLOSE 4
31 32
32 #define _MU_STR_EVMASK(n) (1<<(n)) 33 #define _MU_STR_EVMASK(n) (1<<(n))
33 34
...@@ -63,6 +64,7 @@ struct _mu_stream ...@@ -63,6 +64,7 @@ struct _mu_stream
63 64
64 void (*event_cb) (struct _mu_stream *, int code, unsigned long, void *); 65 void (*event_cb) (struct _mu_stream *, int code, unsigned long, void *);
65 int event_mask; 66 int event_mask;
67 void *event_cb_data;
66 68
67 const char *(*error_string) (struct _mu_stream *, int); 69 const char *(*error_string) (struct _mu_stream *, int);
68 70
......
...@@ -375,10 +375,11 @@ mu_stream_seek (mu_stream_t stream, mu_off_t offset, int whence, ...@@ -375,10 +375,11 @@ mu_stream_seek (mu_stream_t stream, mu_off_t offset, int whence,
375 return mu_stream_seterr (stream, EINVAL, 1); 375 return mu_stream_seterr (stream, EINVAL, 1);
376 } 376 }
377 377
378 if ((stream->buftype == mu_buffer_none && offset != stream->offset) 378 if (stream->buftype == mu_buffer_none ?
379 || stream->level == 0 379 (offset != stream->offset)
380 : (stream->level == 0
380 || offset < stream->offset 381 || offset < stream->offset
381 || offset > stream->offset + stream->level) 382 || offset > stream->offset + stream->level))
382 { 383 {
383 if ((rc = _stream_flush_buffer (stream, 1))) 384 if ((rc = _stream_flush_buffer (stream, 1)))
384 return rc; 385 return rc;
...@@ -945,10 +946,12 @@ mu_stream_close (mu_stream_t stream) ...@@ -945,10 +946,12 @@ mu_stream_close (mu_stream_t stream)
945 946
946 if (!stream) 947 if (!stream)
947 return EINVAL; 948 return EINVAL;
949
948 mu_stream_flush (stream); 950 mu_stream_flush (stream);
949 /* Do close the stream only if it is not used by anyone else */ 951 /* Do close the stream only if it is not used by anyone else */
950 if (stream->ref_count > 1) 952 if (stream->ref_count > 1)
951 return 0; 953 return 0;
954 _stream_event (stream, _MU_STR_EVENT_CLOSE, 0, NULL);
952 if (stream->close) 955 if (stream->close)
953 rc = stream->close (stream); 956 rc = stream->close (stream);
954 return rc; 957 return rc;
......