summaryrefslogtreecommitdiffstats
path: root/stream.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-03-18 06:29:25 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-03-18 06:29:25 -0700
commit1ef8071c738db67214e7d20502496146d2a40821 (patch)
tree6b552ee894deab4c77915e45a8c96082ab42f850 /stream.c
parente84da36197b809c50a0c43cceb5c7b27b3d5733e (diff)
downloadtxr-1ef8071c738db67214e7d20502496146d2a40821.tar.gz
txr-1ef8071c738db67214e7d20502496146d2a40821.tar.bz2
txr-1ef8071c738db67214e7d20502496146d2a40821.zip
New l and u letters in stream open mode strings.
* stream.c (parse_mode): Recognize "l" and "u", and set new flags. (set_mode_props): More complicated behavior to integrate the new options with the line mode defaulting behavior of "i". * stream.h (struct stdio_mode): New members unbuf and linebuf. All members become bit fields of width 1. (stdio_mode_init_trivial): Initializers for new members. * txr.1: Documented.
Diffstat (limited to 'stream.c')
-rw-r--r--stream.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/stream.c b/stream.c
index e9ba359b..5798efcb 100644
--- a/stream.c
+++ b/stream.c
@@ -1186,6 +1186,20 @@ static struct stdio_mode parse_mode(val mode_str)
case 'i':
m.interactive = 1;
break;
+ case 'l':
+ if (m.unbuf) {
+ m.malformed = 1;
+ return m;
+ }
+ m.linebuf = 1;
+ break;
+ case 'u':
+ if (m.linebuf) {
+ m.malformed = 1;
+ return m;
+ }
+ m.unbuf = 1;
+ break;
default:
m.malformed = 1;
return m;
@@ -1245,12 +1259,18 @@ val normalize_mode(struct stdio_mode *m, val mode_str)
val set_mode_props(const struct stdio_mode m, val stream)
{
- if (m.interactive) {
+ if (m.interactive || m.linebuf || m.unbuf) {
struct stdio_handle *h = coerce(struct stdio_handle *,
cobj_handle(stream, stdio_stream_s));
- if (h->f && m.write)
- setvbuf(h->f, (char *) NULL, _IOLBF, 0);
- stream_set_prop(stream, real_time_k, t);
+ if (h->f) {
+ if (m.write && (m.linebuf || (m.interactive && !m.unbuf)))
+ setvbuf(h->f, 0, _IOLBF, 0);
+ else if (m.unbuf)
+ setbuf(h->f, 0);
+ }
+
+ if (m.interactive)
+ stream_set_prop(stream, real_time_k, t);
}
return stream;
}