aboutsummaryrefslogtreecommitdiffstats
path: root/src/estream.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2018-11-26 19:06:36 +0000
committerWerner Koch <[email protected]>2018-11-26 19:09:53 +0000
commitffb49b72f132d954a3d9fa11e45803c36a62fd25 (patch)
treeef464194cfdc5392af615079ed010a1c1d0efc75 /src/estream.c
parentcore: New API gpgrt_cmp_version (diff)
downloadlibgpg-error-ffb49b72f132d954a3d9fa11e45803c36a62fd25.tar.gz
libgpg-error-ffb49b72f132d954a3d9fa11e45803c36a62fd25.zip
core: Add a limited version of gpgrt_ftruncate.
* src/gpg-error.h.in (gpgrt_ftruncate, es_ftruncate): New. * src/gpg-error.def.in, src/gpg-error.vers: Add gpgrt_ftruncate. * src/visibility.c (gpgrt_ftruncate): new. * src/gpgrt-int.h (COOKIE_IOCTL_TRUNCATE): New. * src/estream.c (func_mem_ioctl): Support new internal IOCTL. (_gpgrt_ftruncate): New. -- Right now the ftruncate works only on memory streams. Can easily be added to other stream times. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'src/estream.c')
-rw-r--r--src/estream.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/estream.c b/src/estream.c
index 8ad664e..72e93e0 100644
--- a/src/estream.c
+++ b/src/estream.c
@@ -820,6 +820,14 @@ func_mem_ioctl (void *cookie, int cmd, void *ptr, size_t *len)
mem_cookie->offset = 0;
ret = 0;
}
+ else if (cmd == COOKIE_IOCTL_TRUNCATE)
+ {
+ gpgrt_off_t length = *(gpgrt_off_t *)ptr;
+
+ ret = func_mem_seek (cookie, &length, SEEK_SET);
+ if (ret != -1)
+ mem_cookie->data_len = mem_cookie->offset;
+ }
else
{
_set_errno (EINVAL);
@@ -4027,6 +4035,29 @@ _gpgrt_rewind (estream_t stream)
int
+_gpgrt_ftruncate (estream_t stream, gpgrt_off_t length)
+{
+ cookie_ioctl_function_t func_ioctl;
+ int ret;
+
+ lock_stream (stream);
+ func_ioctl = stream->intern->func_ioctl;
+ if (!func_ioctl)
+ {
+ _set_errno (EOPNOTSUPP);
+ ret = -1;
+ }
+ else
+ {
+ ret = func_ioctl (stream->intern->cookie, COOKIE_IOCTL_TRUNCATE,
+ &length, NULL);
+ }
+ unlock_stream (stream);
+ return ret;
+}
+
+
+int
_gpgrt__getc_underflow (estream_t stream)
{
int err;