diff options
-rw-r--r-- | src/estream.c | 31 | ||||
-rw-r--r-- | src/gpg-error.def.in | 1 | ||||
-rw-r--r-- | src/gpg-error.h.in | 2 | ||||
-rw-r--r-- | src/gpg-error.vers | 1 | ||||
-rw-r--r-- | src/gpgrt-int.h | 3 | ||||
-rw-r--r-- | src/visibility.c | 6 | ||||
-rw-r--r-- | src/visibility.h | 2 | ||||
-rw-r--r-- | tests/t-version.c | 1 |
8 files changed, 46 insertions, 1 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; diff --git a/src/gpg-error.def.in b/src/gpg-error.def.in index c2fabb0..9b522ea 100644 --- a/src/gpg-error.def.in +++ b/src/gpg-error.def.in @@ -220,5 +220,6 @@ EXPORTS gpgrt_cmp_version @169 + gpgrt_ftruncate @170 ;; end of file with public symbols for Windows. diff --git a/src/gpg-error.h.in b/src/gpg-error.h.in index 2bf6a6f..c0ac0eb 100644 --- a/src/gpg-error.h.in +++ b/src/gpg-error.h.in @@ -712,6 +712,7 @@ int _gpgrt_pending_unlocked (gpgrt_stream_t stream); /* (private) */ int gpgrt_fflush (gpgrt_stream_t stream); int gpgrt_fseek (gpgrt_stream_t stream, long int offset, int whence); int gpgrt_fseeko (gpgrt_stream_t stream, gpgrt_off_t offset, int whence); +int gpgrt_ftruncate (estream_t stream, gpgrt_off_t length); long int gpgrt_ftell (gpgrt_stream_t stream); gpgrt_off_t gpgrt_ftello (gpgrt_stream_t stream); void gpgrt_rewind (gpgrt_stream_t stream); @@ -868,6 +869,7 @@ int gpgrt_vsnprintf (char *buf,size_t bufsize, # define es_fflush gpgrt_fflush # define es_fseek gpgrt_fseek # define es_fseeko gpgrt_fseeko +# define es_ftruncate gpgrt_ftruncate # define es_ftell gpgrt_ftell # define es_ftello gpgrt_ftello # define es_rewind gpgrt_rewind diff --git a/src/gpg-error.vers b/src/gpg-error.vers index 8c50a15..f9524d7 100644 --- a/src/gpg-error.vers +++ b/src/gpg-error.vers @@ -192,6 +192,7 @@ GPG_ERROR_1.0 { gpgrt_cmp_version; + gpgrt_ftruncate; local: *; }; diff --git a/src/gpgrt-int.h b/src/gpgrt-int.h index b5a4dd1..09aad11 100644 --- a/src/gpgrt-int.h +++ b/src/gpgrt-int.h @@ -208,12 +208,12 @@ void _gpgrt_internal_trace_end (void); /* * A private cookie function to implement an internal IOCTL service. - * and ist IOCTL numbers. */ typedef int (*cookie_ioctl_function_t) (void *cookie, int cmd, void *ptr, size_t *len); #define COOKIE_IOCTL_SNATCH_BUFFER 1 #define COOKIE_IOCTL_NONBLOCK 2 +#define COOKIE_IOCTL_TRUNCATE 3 /* An internal variant of gpgrt_cookie_close_function_t with a slot * for the ioctl function. */ @@ -366,6 +366,7 @@ int _gpgrt_fseeko (gpgrt_stream_t stream, gpgrt_off_t offset, int whence); long int _gpgrt_ftell (gpgrt_stream_t stream); gpgrt_off_t _gpgrt_ftello (gpgrt_stream_t stream); void _gpgrt_rewind (gpgrt_stream_t stream); +int _gpgrt_ftruncate (estream_t stream, gpgrt_off_t length); int _gpgrt_fgetc (gpgrt_stream_t stream); int _gpgrt_fputc (int c, gpgrt_stream_t stream); diff --git a/src/visibility.c b/src/visibility.c index ab5e383..1947111 100644 --- a/src/visibility.c +++ b/src/visibility.c @@ -390,6 +390,12 @@ gpgrt_rewind (estream_t stream) } int +gpgrt_ftruncate (estream_t stream, gpgrt_off_t length) +{ + return _gpgrt_ftruncate (stream, length); +} + +int gpgrt_fgetc (estream_t stream) { return _gpgrt_fgetc (stream); diff --git a/src/visibility.h b/src/visibility.h index d6933df..46383c7 100644 --- a/src/visibility.h +++ b/src/visibility.h @@ -102,6 +102,7 @@ MARK_VISIBLE (gpgrt_fseeko) MARK_VISIBLE (gpgrt_ftell) MARK_VISIBLE (gpgrt_ftello) MARK_VISIBLE (gpgrt_rewind) +MARK_VISIBLE (gpgrt_ftruncate) MARK_VISIBLE (gpgrt_fgetc) MARK_VISIBLE (_gpgrt_getc_underflow) MARK_VISIBLE (gpgrt_fputc) @@ -276,6 +277,7 @@ MARK_VISIBLE (gpgrt_cmp_version); #define gpgrt_ftell _gpgrt_USE_UNDERSCORED_FUNCTION #define gpgrt_ftello _gpgrt_USE_UNDERSCORED_FUNCTION #define gpgrt_rewind _gpgrt_USE_UNDERSCORED_FUNCTION +#define gpgrt_ftruncate _gpgrt_USE_UNDERSCORED_FUNCTION #define gpgrt_fgetc _gpgrt_USE_UNDERSCORED_FUNCTION #define _gpgrt_getc_underflow _gpgrt_USE_DBLUNDERSCO_FUNCTION #define gpgrt_fputc _gpgrt_USE_UNDERSCORED_FUNCTION diff --git a/tests/t-version.c b/tests/t-version.c index 240d4b4..d71f360 100644 --- a/tests/t-version.c +++ b/tests/t-version.c @@ -164,6 +164,7 @@ main (int argc, char **argv) fprintf (stderr, "%s: gpg_error_check_version did not return an error" " for a newer version\n", logpfx); errorcount++; + show ("\n"); /* Reference this function to silence gcc. */ } if (verbose || errorcount) { |