diff options
author | Andy Wingo <wingo@pobox.com> | 2017-03-01 14:14:06 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2017-03-01 14:24:36 +0100 |
commit | 1da66a6ab14b6aaedeea2a77dce130c8b397cbf0 (patch) | |
tree | 70ae7a9aaaf1dbada07a9906d3a522ad5690c4a5 /libguile | |
parent | fcebf93ecba790356e4b8dc76e6e863a34fb6438 (diff) |
String ports can be truncated
* libguile/strports.c (string_port_truncate):
(scm_make_string_port_type): Support truncate-file on string ports.
* test-suite/tests/ports.test ("string ports"): Add tests.
Diffstat (limited to 'libguile')
-rw-r--r-- | libguile/strports.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/libguile/strports.c b/libguile/strports.c index b12d6694a..5f78785d1 100644 --- a/libguile/strports.c +++ b/libguile/strports.c @@ -134,6 +134,18 @@ string_port_seek (SCM port, scm_t_off offset, int whence) } #undef FUNC_NAME +static void +string_port_truncate (SCM port, scm_t_off length) +#define FUNC_NAME "string_port_truncate" +{ + struct string_port *stream = (void *) SCM_STREAM (port); + + if (0 <= length && stream->pos <= length && length <= stream->len) + stream->len = length; + else + scm_out_of_range (FUNC_NAME, scm_from_off_t_or_off64_t (length)); +} +#undef FUNC_NAME /* The initial size in bytes of a string port's buffer. */ @@ -372,6 +384,7 @@ scm_make_string_port_type () string_port_read, string_port_write); scm_set_port_seek (ptob, string_port_seek); + scm_set_port_truncate (ptob, string_port_truncate); return ptob; } |