diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-08-21 20:09:11 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-08-21 20:09:11 -0700 |
commit | 5edadcdff0d80ceb5639dc31bbe7c2b43a1d2782 (patch) | |
tree | a8c900162613c7371b4cb3b836f17129b8a01308 | |
parent | 342d92341cade83e4ac981f557a5af44846370cc (diff) | |
download | txr-5edadcdff0d80ceb5639dc31bbe7c2b43a1d2782.tar.gz txr-5edadcdff0d80ceb5639dc31bbe7c2b43a1d2782.tar.bz2 txr-5edadcdff0d80ceb5639dc31bbe7c2b43a1d2782.zip |
Default the length argument of truncate-stream.
* stream.c (truncate_stream): If the len argument is missing,
default to the current position, obtained by using the seek
operation.
(stream_init): Fix up registration of truncate-stream for one
optional argument.
* txr.1: Documentation of truncate-stream updated.
-rw-r--r-- | stream.c | 4 | ||||
-rw-r--r-- | txr.1 | 17 |
2 files changed, 19 insertions, 2 deletions
@@ -3600,6 +3600,8 @@ val seek_stream(val stream, val offset, val whence) val truncate_stream(val stream, val len) { struct strm_ops *ops = coerce(struct strm_ops *, cobj_ops(stream, stream_s)); + if (missingp(len)) + len = ops->seek(stream, zero, strm_cur); return ops->truncate(stream, len); } @@ -4503,7 +4505,7 @@ void stream_init(void) reg_fun(intern(lit("fill-buf"), user_package), func_n3o(fill_buf, 1)); reg_fun(intern(lit("flush-stream"), user_package), func_n1o(flush_stream, 0)); reg_fun(intern(lit("seek-stream"), user_package), func_n3(seek_stream)); - reg_fun(intern(lit("truncate-stream"), user_package), func_n2(truncate_stream)); + reg_fun(intern(lit("truncate-stream"), user_package), func_n2o(truncate_stream, 1)); reg_fun(intern(lit("streamp"), user_package), func_n1(streamp)); reg_fun(intern(lit("real-time-stream-p"), user_package), func_n1(real_time_stream_p)); reg_fun(intern(lit("stream-set-prop"), user_package), func_n3(stream_set_prop)); @@ -42537,7 +42537,7 @@ On failure, it throws an exception of type .coNP Function @ truncate-stream .synb -.mets (truncate-stream < stream << length ) +.mets (truncate-stream < stream <> [ length ]) .syne .desc The @@ -42550,6 +42550,21 @@ bytes. The stream must be a file stream, and must be open for writing. +If +.meta length +is omitted, then it defaults to the current position, retrieved +as if by invoking the +.code seek-stream +with an +.meta offset +argument of zero and +.meta whence +argument of +.codn :from-current . +Hence, after the +.code truncate-stream +operation, that position is one byte past the end of the file. + .coNP Functions @ stream-get-prop and @ stream-set-prop .synb .mets (stream-get-prop < stream << indicator ) |